diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 75b500c0849..90ab6c01ccd 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -18,7 +18,7 @@ Default **language here is english**. So please prepare your contributions in en -Code +Submit code --------------------- ### Basic workflow @@ -35,12 +35,14 @@ Default **language here is english**. So please prepare your contributions in en Unless you're fixing a bug, all pull requests should be made against the *develop* branch. -If you're fixing a bug, it is preferred that you cook your fix and pull request it -against the oldest version affected that's still supported. +If you're fixing a bug, it is preferred that you cook your fix and pull request it against an oldest version affected. -We officially support versions N, N − 1 and N − 2 for N the latest version available. +We recommend to push it into N - 2 for N the latest version available, if not possible into version N - 1, and finally into develop. +This is just a recommendation, currently, if you push a bug fix on a very old version, it is still merged and propagated into +higher versions. -Choose your base branch accordingly. +The rule N - 2 is just a tip if you don't know which version to choose to get the best the best compromise between ease of correction +and number of potential beneficiaries of the correction. ### General rules Please don't edit the ChangeLog file. File will be generated from all commit messages during release process by the project manager. @@ -72,7 +74,7 @@ The keyword can be ommitted if your commit does not fit in any of the following - Close/CLOSE: for closing a referenced feature request - New/NEW: for an unreferenced new feature (Opening a feature request and using close is prefered) - Perf/PERF: for performance enhancement -- Qual/QUAL: for quality code enhancement or re-engeneering +- Qual/QUAL: for quality code enhancement or re-engineering #### Issuenum If your commit fixes a referenced bug or feature request. @@ -93,7 +95,7 @@ Feel free to express technical details, use cases or anything relevant to the cu This section can span multiple lines. -Try to keep lines under 120 characters. +If your PR is a change on interface, you must also paste a screenshot showing the new screen. #### Examples
@@ -105,7 +107,7 @@ NEW|New|QUAL|Qual|PERF|Perf Short description (In upper case to appear into Chan
 or
 Short description (when the commit is not introducing feature nor closing a bug)
 
-Long description (Can span accross multiple lines).
+Long description (Can span across multiple lines).
 
### Pull Requests @@ -133,7 +135,8 @@ If your PR has errors reported by the Continuous Integration Platform, it means If the PR is valid, and is kept open for a long time, a tag will also be added on the PR to describe the status of your PR and why the PR is kept open. By putting your mouse on the tag, you will get a full explanation of the tag/status that explain why your PR has not been integrated yet. In most cases, it gives you information of things you have to do to have the PR taken into consideration (for example a change is requested, a conflict is expected to be solved, some questions were asked). If you have a yellow, red flag of purple flag, don't expect to have your PR validated. You must first provide the answer the tag ask you. The majority of open PR are waiting an action of the author of the PR. -Statistics on Dolibarr project shows that 95% of submitted PR are reviewed and tagged. Average answer delay is also one of the best among Open source projects (just few days before having the Answer Tag set). This is one of the most important ratio of answered PR in Open Source world for a major project. Don't expect the core team to reach the 100%. A so high ratio is very rare on a so popular project and with the increasing popularity of Dolibarr, this ratio will probably decrease in future to a more common level. +Statistics on Dolibarr project shows that 95% of submitted PR are reviewed and tagged. Average answer delay is also one of the best among Open source projects (just few days before having the Answer Tag set). This is one of the most important ratio of answered PR in Open Source world for a major project. Don't expect the core team to reach the 100%. +A so high ratio is very rare on a so popular project and with the increasing popularity of Dolibarr, this ratio will probably decrease in future to a more common level. ### Resources diff --git a/.tx/config b/.tx/config index 59bad9a52be..4cf1d95955d 100644 --- a/.tx/config +++ b/.tx/config @@ -200,12 +200,6 @@ source_file = htdocs/langs/en_US/ldap.lang source_lang = en_US type = MOZILLAPROPERTIES -[o:dolibarr-association:p:dolibarr:r:link] -file_filter = htdocs/langs//link.lang -source_file = htdocs/langs/en_US/link.lang -source_lang = en_US -type = MOZILLAPROPERTIES - [o:dolibarr-association:p:dolibarr:r:loan] file_filter = htdocs/langs//loan.lang source_file = htdocs/langs/en_US/loan.lang diff --git a/ChangeLog b/ChangeLog index fae8969078c..a70b7b6da76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,8 +7,172 @@ English Dolibarr ChangeLog For users: ---------- +NEW: Compatibility with PHP 8.2 +NEW: Add a confirmation popup when deleting extrafields +NEW: Close #20930 Use ajax for state loading after country change +NEW: #23331 Add support for parent projects (#24856) +NEW: #22531 Expense report - Add two fields into export : Qty & Unit price (excl.) (#26309) +NEW: #22626 date filter thirdparties contracts projects (#22707) +NEW: #24085 Add the Project filter +NEW: #25312 Support extrafields in selectForForms +NEW: #26312 Manage intermediate BIC - SQL Part (#26325) +NEW: Accountancy - Add quick navigation with keyboard shortcut on ledger (#26221) +NEW: Accountancy - FEC/FEC2 format export with attachments (#26192) +NEW: Accountancy - Option to choose length of lettering code +NEW: Add a button to create a product or a service from an order or an invoice (#26173) +NEW: Add a button to re-encrypt data of a dolcrypt extrafield password +NEW: Add a CLI tool to regenerate all documents +NEW: Add a goto url from smartphone search page +NEW: Add all id prof checker on thirdparty for code compta customer and supplier +NEW: add and list external contributors on ticket public interface +NEW: Add a protection on purgeFiles +NEW: Add a public page to list all open surveys +NEW: Add chart of accounts PCG08-PYME-CAT for ES in catalan language +NEW: add constant to check if qty shipped not greater than qty ordered +NEW: Add context for the movement stock (role toconsume/toproduce) on mrp +NEW: Add contract link on ticket +NEW: Add culum Technical ID in list of details lines of an order (#26164) +NEW: ADD: custom compute for exports +NEW: Add custom Text on footer total (#26334) +NEW: Add different picto for each type of extrafields (date, string, ...) +NEW: Add edit line on MO (#26122) +NEW: Added notification on closed intervention +NEW: Added of a popup on validation instead of a database fielld to know if the user wants to include subwarehouse +NEW: Added of the field "include_sub_warehouse" in the table "llx_inventory" +NEW: Added total line to third-parties list (#26148) +NEW: Added VAT free & VAT amounts on payment input +NEW: Add ext payment system ID in the payment page with link to Stripe +NEW: Add field TechnicalID in list of users +NEW: Add filter on status of line of a dictionary +NEW: Add get_substitutionarray_other() on shipping odt (#25080) +NEW: add IdProfCheck on thirdparty for BE (xxxx.xxx.xxx) +NEW: Add index on prelevement_demande +NEW: Add invoice subtype in customer invoice (#26543) and template invoice (SQL part) (#26535) +NEW: Add label to price level when changing price (#26240) +NEW: Add modifications of template invoices into agenda +NEW: Add more company informations (ProfId7 to 10) (#25266) +NEW: Add more information to holiday mailings (#25461) +NEW: Add more param on fetch() to prepare perf optimization +NEW: Add more tables activated by module activation only +NEW: Add new field into $fields array + Creation of the function getChildWarehouse() +NEW: Add option for cancel consumed and produced lines (delete lines and rollback stocks) when delete or cancel an manufacturing order (#26254) +NEW: Add option in PDF for purchase order and quotation to hide prices +NEW: Add option TAKEPOS_HIDE_PRODUCT_PRICES to hide prices in TakePOS +NEW: add order supplier submit notif +NEW: add parent product column on list +NEW: Add picto in product/service list in object lines (#25511) +NEW: Add possibility to choose separator #21426 +NEW: Add preselected update keys attribute to import class and select it by default if filled +NEW: add product barcode on stock exports +NEW: Add recurring behaviour +NEW: add recursive deletion option for child m os (#26102) +NEW: Add refactoring user permission (#26162) +NEW: add sorting of product price list by customer (#26483) +NEW: Add tab Events/Agenda on recurring invoices +NEW: Add the formEditObjectLine hook on commande card and invoice card +NEW: Add the picto phone of thirdparty on the kanban view of projects +NEW: Add the status of partnership to select partnership for emailing +NEW: add Ticket tab on contract +NEW: agenda per user use quarter hour split instead of half hour split +NEW: Allow generation of delivery note through REST-API (#26226) +NEW: Allow sync of currency rates with currency layer by default. +NEW: Allow to have products not managed in stocks - SQL Part (#26190) +NEW: Assign contact to a ticket message (#24735) +NEW: Better protection against reserved words +NEW: billing on shipment+reception. Can be done before or after delivery. +NEW: can edit bomline workstation +NEW: Can edit both the Test and Live stripe customer account on payment +NEW: Can include product variants in list of products +NEW: Can manage ODT documents for groups of users. +NEW: Can modify the picto into modulebuilder +NEW: Can restore product in stock when deleting the supplier invoice +NEW: Can see the favicon file into setup of properties of a website +NEW: Can switch product batch management to no management. (#21691) +NEW: Can upload/delete ODT template for project and tasks +NEW: chart of accounts ES PCG08-PYME-CAT in catalan language +NEW: clone skill object (#26526) +NEW: close notification for interventions +NEW: column in table prelevement_lignes for fk_user (#26196) +NEW: CONF allow modify ticket classification even if closed +NEW: conf to display date entry stock exped and sort in date order (#22625) +NEW: create a product from a free line in a document (#22324) +NEW: customize position in complete_head_from_modules (#26406) +NEW: Date d'entree en stock sur les exped au moment de la création +NEW: Date field for shipment export (#25574) +NEW: Date format dayhoursec is using year on 2 char on smartphones +NEW: Default customer, category and product when enable TakePOS (#25031) +NEW: Disable not used PHP streams +NEW: do not add default value in list +NEW: drop down for action button show a simple button if only 1 action +NEW: Enhance github_commits_perversion to get more stats on git commits +NEW: Enhance IPN to support payment_intent.succeeded for both card/ban +NEW: extrafields password accepts 'dolcrypt' algorithm (reversible algo) +NEW: Factorize a lot of code for numbering modules +NEW: filter on from/to period rather than month/year (#26378) +NEW: FontAwesome - Add possibility to select another version +NEW: Form for add object's property on moduleBuilder +NEW: Can generate SEPA files for salaries (#26541) +NEW: massactions to delete projects +NEW: Generic doc template for donations (#26338) +NEW: Get list evaluation with skills details in user fiche (#26510) +NEW: hidden conf to disable use of dns_get_record (which can become unresponsive) (#26339) +NEW: improved resource data structure +NEW: Include sub warehouse in inventory +NEW: inventory without virtual products (kits) +NEW: Invoice subtypes for customers and vendors (#26233) +NEW: Invoice time from task, make task note better display in invoice line +NEW: lazy load to substitute project variables (#26451) +NEW: LDAP Active Directory UserAccountControl (#25507) +NEW: Library including math and financial functions (#25035) +NEW: Loan - Can upload a file with drag and drop +NEW: Manage rate indirect. (#26449) +NEW: memorize model name for pdf hooks +NEW: Menu editor is reponsive +NEW: Merge the "Create ..." buttons on contract into one. +NEW: More accurate tooltip on what admin permissions are +NEW: (#24834) new option for hide the footer (#25464) +NEW: (#25044) new option for choose project visibility +NEW: new option for hide the footer of tickets on the public interface +NEW: no need to create invoice supplier object on supplier card for standalone credit note +NEW: Option to show label, ref+label or only ref of product in TakePOS +NEW: payment full amount detail tooltip +NEW: possibility to deselect line when create a recurring invoice + missing to use fk_parent_line +NEW: Project - List - use select2 multiselect for status +NEW: Propagate invoice extrafields into template invoice (#26529) +NEW: remove include_subwarehouse form llx_inventory database table +NEW: resource improvements - data structure (#26285) +NEW: Retrieve vat details from the Greek Ministry of Finance GSIS SOAP web service and autocomplete third party fields +NEW: Right for stats orders (#24607) +NEW: rights and check access to create portal accounts +NEW: Row in list higher height (#26177) +NEW: Save date of RUM creation when creating a Stripe SEPA mandate +NEW: shipment can include service (for information and invoicing) (#26407) +NEW: Show id of module on the tooltip module help page +NEW: show VAT free amount on payment input close #26208 (#26209) +NEW: start and end date for due date filter on invoice list +NEW: Sub total in list (#26165) +NEW: Suport html content for combo list of email recipient +NEW: Website: Support of js into the Dolibarr server preview +NEW: TakePOS - add constant to check qty asked is available (#24820) +NEW: TakePOS - add constant to choose contact instead of customer (#24807) +NEW: TakePOS - amount label with or without tax in free product (#24829) +NEW: TakePOS compatibility with lots and serials +NEW: TakePOS compatibility with lots and serials (#26426) +NEW: Tooltips are using ajax by default +NEW: Top menu support picto of modules that are font awesome picto. +NEW: updating by adding massactions for delete projects in societe tab +NEW: updating by adding tooltip for api section in Modulebuilder +NEW: updating by adjust request Sql for Salary invoice (#26279) +NEW: updating for display Help title when try to delete Don (issue #25314) +NEW: Upgrade in module builder in menu section +NEW: use account address in sepa mandate (#23642) +NEW: VAT rate - Add entity +NEW: webportal site account +NEW: When an user unset the batch management of products, transformation of each batch stock mouvement in global stock mouvement + +SEC: #25512 applicative anti bruteforce - security on too many login attempts (#25520) +SEC: Add action confirm_... as sensitive to need a CSRF token -... For developers or integrators: ------------------------------ @@ -16,24 +180,110 @@ For developers or integrators: QUAL Reduce very seriously the technical debt (using PHPStan, Psalm and Rector) NEW Tool in dev/tools/rector to autofix code using style coding practice rules +PERF: Removed a useless fetch_thirdparty +PERF: Perf avoid 2 useless fetch into the triggers of agenda. +PERF: performance & code quality enhancements template sections + +QUAL: Remove hardcoded code for OVH sms. Generic method is ok now. +QUAL: Code fix using rector +QUAL: Force subclass MINVERSION (#26314) +QUAL: group all flag images into 1 sprite file. (#26459) +QUAL: Move conf->global into getDolGlobal... +QUAL: Refactor merging companies and fix #26272 with Reception objects (#26320) +QUAL: Removed deprecated field remise, remise_percent, remise_absolute +QUAL: Standardize code and look and feel for dictionaries +QUAL: Standardize code. Renamed ID of user properties into ->user_xxx_id +QUAL: Use dol_clone with parameter 2 for ->oldcopy +QUAL: use switch case instead of if elseif statements for actions + +NEW: [Add hook in user bank page] +NEW: #19501 Add two hooks in dolreceiptprinter.php (#26439) +NEW: Accountancy - Add hooks on PrintFieldList for expensereportsjournal, purchasesjournal, sellsjournal +NEW: add a $notrigger param to Product::updatePrice() method (#26404) +NEW: Add a rule to fix empty($conf->global->...) into !getDolGlobal... +NEW: Add column extraparams on societe_rib +NEW: Add hook on selectLotDataList() function (#25368) +NEW: add Hooks and prepare extrafields management for product invoices consumptions (#26280) +NEW: Add hooks on import, step 5 - 6 (#24915) +NEW: add hook tabContentCreateSupplierOrder (#26418) +NEW: add hook tabContentViewSupplierInvoice (#26431) +NEW: add new hook AfterImportInsert +NEW: add new hook OrderCard (#26380) +NEW: add new hook tabContentCreateOrder (#26408) +NEW: Add phpunit for REST API of contacts +NEW: Add triggers COMPANY_RIB_XXX already present in companybankaccount.class.php +NEW: Add triggers on import success +NEW: Add trigger when deleting a bank account line +NEW: subproduct triggers in product class (#25142) +NEW: ModuleBuilder: add section changeLog to Doc in MB +NEW: ModuleBuilder: Add api url to documentation in ModuleBuilder +NEW: ModuleBuilder: Checkin comments begin and end before each actions +NEW: ModuleBuilder: edit properties in description tab for ModuleBuilder +NEW: ModuleBuilder: remove dictionary in ModuleBuilder +NEW: ModuleBuilder: add page for create dictionary +NEW: ModuleBuilder: add badge for each tabs +NEW: ModuleBuilder: for edit name of dictionnary and delete it in MB +NEW: add barcode function to check if EAN13 is valid ( WARNING: +-------- -Following changes may create regressions for some external modules, but were necessary to make Dolibarr better: +The following changes may create regressions for some external modules, but were necessary to make Dolibarr better: * The property ->brouillon has been removed from all classes. It was not reliable and was a duplicate of ->status == self::STATUS_DRAFT. * The duplicated and deprecated property ->date_livraison that was renamed into ->delivery_date has been completely removed. * The property ->user_close to store ID of closing user has been renamed into ->user_closing_id. * The property ->user_validation to store ID of user validating has been renamed into ->user_validation_id. * The property ->user_creation to store ID of user of creation has been renamed into ->user_creation_id. * The property ->user_modification to store ID of user of modification has been renamed into ->user_modification_id. -* The duplicate property ->user_creat, ->date_creat, ->date_valid has been removed +* The duplicate property ->user_creat, ->date_creat, ->date_valid has been removed (use instead user_creation, date_creation, date_validation). * The method get_substitutionarray_shipment_lines() has been removed. Use the generic get_substitutionarray_lines() instead. * The method ProductcustomerPrice->fetch_all_log() has been renamed into camel case ->fetchAllLog() -* Recheck setup of your module workflow to see if you need to enable the new setting to have shipment set to billed automatically when +* Recheck the setup of your module Workflow to see if you need to enable the new setting to have shipment set to billed automatically when an invoice from a shipment is validated (and if your process is to make invoice on shipment and not on order), because this setup has changed. -* It was possible to use a variable $soc or $right inside a php code condition of some extrafields properties, this is no more true (this 2 variables are no more global variables). +* It was possible to use a variable $soc or $right inside a PHP code condition of some extrafields properties, this is no more true (this 2 variables are no more global variables). +* New hook files of modules actions_mymodule.class.php should now "extends CommonHookActions" +* Endpoint for API /partnershipapi and /recruitment has been renamed into /partnerships and /recruitments to follow name conventions. +***** ChangeLog for 18.0.3 compared to 18.0.2 ***** +FIX: #25793 Cannot add time spent (#26405) +FIX: #26100 Ticket - On edit, list of closed project must be excluded (#26223) +FIX: #26170 +FIX: #26195 Various payment - List of project excluded those assigned to third parties (#26222) +FIX: #26349 add_customer_ref_on_linked_shipment +FIX: avoid warning + CSRF +FIX: avoid warning if module not activated +FIX: Bad name for trigger in HRM module +FIX: check tva_tx before comparing price_min_ttc (#25220) +FIX: Compare the result of the send mail file function +FIX: dol_eval with function starting with ! +FIX: Error handling for computed values on import (#24897) +FIX: Error not returned on sales with takepos and batch module enabled +FIX: error of webhook not returned +FIX: firstname and lastname were not saved in attendee subscription +FIX: HTML in ODT templates (#26181) +FIX: Link to list of movement from the inventory code +FIX: Mass import of stock from a file must accept empty source +FIX: Max version of PHP (#26327) +FIX: missing load group members for ldap synchro (#26167) +FIX: missing project entity filter (Issue #26243) (#26247) +FIX: modification of complementary attributes in invoices (#26180) +FIX: On object validation, ecm index are not updated for uploaded files +FIX: Propal's negative quantities +FIX: public subscription page should not display acceptation for public register when it is not enabled (#26354) +FIX: regression on rounding stocks fields on product list +FIX: removed a non expected hidden input field in stockatdate page +FIX: src_object_id and ttype not filed when uploading a file with API. +FIX: suggested end for membership can be before subscription start (#26351) +FIX: Supplier card - VAT Reserve Charge - Undefined function isInEEC() (#26379) +FIX: syntax error +FIX: template invoice list extrafield filters (backport v17) (#26227) +FIX: Tooltip for search syntax must not appear on date fields +FIX: upload of files src_object_type +FIX: use event.key instead event.wich to avoid keyboard difference +FIX: Use of line->insert instead of line->create +FIX: user creation when LDAP is configured (#26332) +FIX: Wrong backtopage given for the stocktransfer button from the stocktransfer list (#26271) ***** ChangeLog for 18.0.2 compared to 18.0.1 ***** FIX: 17.0 PHP8: supplier invoice class diff --git a/README.md b/README.md index 1eca96e4c48..761b952983b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Dolibarr ERP & CRM is a modern software package that helps manage your organizat It's an Open Source Software suite (written in PHP with optional JavaScript enhancements) designed for small, medium or large companies, foundations and freelancers. -You can freely use, study, modify or distribute it according to its licence. +You can freely use, study, modify or distribute it according to its license. You can use it as a standalone application or as a web application to access it from the Internet or a LAN. @@ -49,7 +49,7 @@ On GNU/Linux, first check if your distribution has already packaged Dolibarr. - Uncompress the downloaded .zip archive to copy the "dolibarr/htdocs" directory and all its files inside your web server root or get the files directly from GitHub (recommended if you know git as it makes it easier if you want to upgrade later): - `git clone https://github.com/dolibarr/dolibarr -b x.y` (where x.y is main version like 3.6, 9.0, ...) + `git clone https://github.com/dolibarr/dolibarr -b x.y` (where x.y is the main version like 3.6, 9.0, ...) - Set up your web server to use "*dolibarr/htdocs*" as root if your web server does not have an already defined directory to point to. @@ -57,7 +57,7 @@ On GNU/Linux, first check if your distribution has already packaged Dolibarr. - From your browser, go to the dolibarr "install/" page - The URL will depends on how you web setup was setup to point to your dolibarr installation. It may looks like: + The URL will depends on how your web setup was set up to point to your dolibarr installation. It may look like: `http://localhost/dolibarr/htdocs/install/` @@ -71,7 +71,7 @@ On GNU/Linux, first check if your distribution has already packaged Dolibarr. - Follow the installer instructions -### Saas/Cloud setup +### SaaS/Cloud setup If you don't have time to install it yourself, you can try some commercial 'ready to use' Cloud offers (See [https://saas.dolibarr.org](https://saas.dolibarr.org)). However, this third solution is not free. @@ -81,7 +81,7 @@ Dolibarr supports upgrading, usually without the need for any (commercial) suppo - At first make a backup of your Dolibarr files & then [see](https://wiki.dolibarr.org/index.php/Installation_-_Upgrade#Upgrade_Dolibarr) - Check that your installed PHP version is supported by the new version [see PHP support](https://wiki.dolibarr.org/index.php/Releases). -- Overwrite all old files from 'dolibarr' directory with files provided into the new version's package. +- Overwrite all old files from the 'dolibarr' directory with files provided into the new version's package. - At first next access, Dolibarr will redirect you to the "install/" page to follow the upgrade process.  If an `install.lock` file exists to lock any other upgrade process, the application will ask you to remove the file manually (you should find the `install.lock` file in the directory used to store generated and uploaded documents, in most cases, it is the directory called "*documents*"). @@ -141,7 +141,7 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog) Collaboration -- Shared calendar/agenda (with ical and vcal import/export for third party tools integration) +- Shared calendar/agenda (with ical and vcal import/export for third-party tools integration) - Projects & Tasks management - Ticket System - Surveys @@ -168,20 +168,20 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog) - Payment platforms integration (PayPal, Stripe, Paybox...) - Email-Collector -(around 100 modules available by default, 1000+ on the addon market place) +(around 100 modules available by default, 1000+ on the addon marketplace) ### Other general features - Multi-Language Support (Localization in most major languages) -- Multi-Users and groups with finely grained rights +- Multi-users and groups with finely-grained rights - Multi-Currency - Multi-Company (by adding of an external module) -- Very user friendly and easy to use +- Very user-friendly and easy to use - Customizable dashboards - Highly customizable: enable only the modules you need, add user personalized fields, choose your skin, several menu managers (can be used by internal users as a back-office with a particular menu, or by external users as a front-office with another one) - APIs (REST, SOAP) - Code that is easy to understand, maintain and develop (PHP with no heavy framework; trigger and hook architecture) -- Support a lot of country specific features: +- Support a lot of country-specific features: - Spanish Tax RE and ISPF - French NPR VAT rate (VAT called "Non Perçue Récupérable" for DOM-TOM) - Canadian double taxes (federal/province) and other countries using cumulative VAT @@ -189,7 +189,7 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog) - Argentina invoice numbering using A,B,C... - ZATCA e-invoicing QR-Code - Compatible with [European directives](https://europa.eu/legislation_summaries/taxation/l31057_en.htm) (2006/112/CE ... 2010/45/UE) - - Compatible with data privacy rules (europe GDPR, ...) + - Compatible with data privacy rules (Europe GDPR, ...) - ... - Flexible PDF & ODT generation for invoices, proposals, orders... - ... @@ -204,7 +204,7 @@ See exact requirements on the [Wiki](https://wiki.dolibarr.org/index.php/Prerequ ### Extending -Dolibarr can be extended with a lot of other external application or modules from third party developers available at the [DoliStore](https://www.dolistore.com). +Dolibarr can be extended with a lot of other external applications or modules from third-party developers available at the [DoliStore](https://www.dolistore.com). ## WHAT DOLIBARR CAN'T DO YET @@ -212,19 +212,19 @@ These are features that Dolibarr does **not** yet fully support: - Tasks dependencies in projects - Payroll module -- No native embedded Webmail, but you can send email to contacts in Dolibarr with e.g. offers, invoices, etc. +- No native embedded Webmail, but you can send emails to contacts in Dolibarr with e.g. offers, invoices, etc. - Dolibarr can't do coffee (yet) ## DOCUMENTATION -Administrator, user, developer and translator's documentations are available along with other community resources in the [Wiki](https://wiki.dolibarr.org). +Administrator, user, developer and translator's documentation are available along with other community resources in the [Wiki](https://wiki.dolibarr.org). ## CONTRIBUTING This project exists thanks to all the people who contribute. -Please read the instructions how to contribute (report a bug/error, a feature request, send code ...) [[Contribute](https://github.com/Dolibarr/dolibarr/blob/develop/.github/CONTRIBUTING.md)] +Please read the instructions on how to contribute (report a bug/error, a feature request, send code ...) [[Contribute](https://github.com/Dolibarr/dolibarr/blob/develop/.github/CONTRIBUTING.md)] -A view on Contributors: +A View on Contributors: [![Dolibarr](https://opencollective.com/dolibarr/contributors.svg?width=890&button=false)](https://github.com/Dolibarr/dolibarr/graphs/contributors) diff --git a/dev/dolibarr_changes.txt b/dev/dolibarr_changes.txt index 89d87a4ab14..8305dbefbd9 100644 --- a/dev/dolibarr_changes.txt +++ b/dev/dolibarr_changes.txt @@ -18,7 +18,7 @@ With -CKEDITOR (4.6.2): +CKEDITOR (4.22.1): ----------------- * In ckeditor/ckeditor/contents.css Replace: @@ -26,7 +26,12 @@ Replace: With body { ... margin: 5px; - +* In ckeditor/ckeditor/ckeditor.js +Replace: + d.items&& +With + d&&d.items&& + ESCPOS: ------- diff --git a/dev/initdemo/initdemopassword.sh b/dev/initdemo/initdemopassword.sh index a67dec61785..bcf2b14887e 100755 --- a/dev/initdemo/initdemopassword.sh +++ b/dev/initdemo/initdemopassword.sh @@ -171,6 +171,7 @@ fi if [ -s "$mydir/initdemopostsql.sql" ]; then echo A file initdemopostsql.sql was found, we execute it. + echo "mysql -P$port $base < \"$mydir/initdemopostsql.sql\"" mysql -P$port $base < "$mydir/initdemopostsql.sql" else echo No file initdemopostsql.sql found, so no extra sql action done. diff --git a/dev/tools/github_commits_perversion.sh b/dev/tools/github_commits_perversion.sh index e8232397e60..f0fb2a90e5c 100755 --- a/dev/tools/github_commits_perversion.sh +++ b/dev/tools/github_commits_perversion.sh @@ -3,16 +3,47 @@ # Count number of commits per user and per versions (using date for version detection) # -Releases=("17.0" "18.0" "develop") -Dates=("2023-02-01" "2023-08-31" "2050-01-01") -let "counter = 1" +Releases=("3.9" "4.0" "5.0" "6.0" "7.0" "8.0" "9.0" "10.0" "11.0" "12.0" "13.0" "14.0" "15.0" "16.0" "17.0" "18.0" "develop") +let "counter = 0" +echo "Copy script into /tmp/github_commits_perversion.sh" +cp $0 /tmp/github_commits_perversion.sh + +echo "Delete /tmp/git" +rm -fr /tmp/git +echo "Create and go into /tmp/git" +mkdir /tmp/git +cd /tmp/git +git clone https://github.com/Dolibarr/dolibarr.git + +cd /tmp/git/dolibarr + +firstline=1 for i in "${Releases[@]}" do - echo "=== $counter git shortlog -s -n --after=${Dates[counter-1]} --before=${Dates[counter]}" - git shortlog -s -n --after=${Dates[counter-1]} --before=${Dates[counter]} - echo -n "Total $i: " - git log --pretty=oneline --after=${Dates[counter-1]} --before=${Dates[counter]} | wc -l + if [ $firstline -eq 1 ]; then + firstline=0 + continue + fi + + #echo "=== Version $i (counter $counter):" + echo "=== Version $i (counter $counter):" + echo "Get common commit ID between origin/${Releases[counter]} and origin/${Releases[counter+1]}" + echo "git merge-base origin/${Releases[counter]} origin/${Releases[counter+1]}" + commitidcommon=`git merge-base origin/${Releases[counter]} origin/${Releases[counter+1]}` + echo "Found commitid=$commitidcommon" + + echo "Checkout into version $i" + git checkout $i + #git shortlog -s -n --after=YYYY-MM-DD --before=YYYY-MM-DD | tr '[:lower:]' '[:upper:]' > /tmp/github_commits_perversion.txt + git shortlog -s -n $commitidcommon.. | tr '[:lower:]' '[:upper:]' > /tmp/github_commits_perversion.txt + #cat /tmp/github_commits_perversion.txt + echo "Total for version $i:" + echo -n "- Nb of commits: " + git log $commitidcommon.. --pretty=oneline | tr '[:lower:]' '[:upper:]' > /tmp/github_commits_perversion2.txt + cat /tmp/github_commits_perversion2.txt | wc -l + echo -n "- Nb of different authors: " + awk ' { print $2 } ' < /tmp/github_commits_perversion.txt | sort -u | wc -l echo "=======================" echo let "counter +=1" diff --git a/dev/tools/make_sprite.sh b/dev/tools/make_sprite.sh new file mode 100644 index 00000000000..41a280fb860 --- /dev/null +++ b/dev/tools/make_sprite.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# Based of: https://gist.github.com/jaymzcd/342399 and https://github.com/buren/flag-sprite-maker + +# uses imagemagick to stich together all images in a folder and +# then writes a css file with the correct offsets along with a +# test html page for verification that its all good + +# Usage: +# $ ./make_sprite.sh path class_name image_extension + +set -euo pipefail +IFS=$'\n\t' + +name='output'; # output will be placed in a folder named this +path="${1:-}" # Path to flag images +classname=${2:-flag}"-sprite" +ext="."${3:-png}; # the extension to iterate over for input files + +css="$name/$classname.css"; +html="$name/test.html"; + +rm -fr $name; +mkdir $name; +touch $css $html; + +echo "Generating sprite file..."; +convert $path*$ext -append $name/$classname$ext; +echo "Sprite complete! - Creating css & test output..."; + +echo -e "\n\n\t\n\n\n\t

Sprite test page

\n" >> $html + +echo -e ".$classname {\n\tbackground:url('$classname$ext') no-repeat top left; display:inline-block;\n}" >> $css; +counter=0; +offset=0; +for file in $path*$ext +do + width=`identify -format "%[fx:w]" "$file"`; + height=`identify -format "%[fx:h]" "$file"`; + idname=`basename "$file" $ext`; + clean=${idname// /-} + echo -e ".$classname.$clean {" >> $css; + echo -e "\tbackground-position:0 -${offset}px;" >> $css; + echo -e "\twidth: ${width}px;" >> $css; + echo -e "\theight: ${height}px;\n}" >> $css; + + echo -e "
$clean
\n" >> $html; + + let offset+=$height; + let counter+=1; + echo -e "\t#$counter done"; +done + +echo -e "

Full sprite:

\n" >> $html; +echo -e "\n" >> $html; + +echo -e "\nComplete! - $counter sprites created, css written & test page output."; diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php index 9bb31534dca..2a6557be0b9 100644 --- a/htdocs/accountancy/admin/account.php +++ b/htdocs/accountancy/admin/account.php @@ -40,6 +40,7 @@ $rowid = GETPOST('rowid', 'int'); $massaction = GETPOST('massaction', 'aZ09'); $optioncss = GETPOST('optioncss', 'alpha'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'accountingaccountlist'; // To manage different context of search +$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...) $search_account = GETPOST('search_account', 'alpha'); $search_label = GETPOST('search_label', 'alpha'); @@ -90,7 +91,7 @@ $arrayfields = array( 'aa.pcg_type'=>array('label'=>"Pcgtype", 'checked'=>1, 'help'=>'PcgtypeDesc'), 'categories'=>array('label'=>"AccountingCategories", 'checked'=>-1, 'help'=>'AccountingCategoriesDesc'), 'aa.reconcilable'=>array('label'=>"Reconcilable", 'checked'=>1), - 'aa.import_key'=>array('label'=>"ImportId", 'checked'=>-1), + 'aa.import_key'=>array('label'=>"ImportId", 'checked'=>-1, 'help'=>''), 'aa.active'=>array('label'=>"Activated", 'checked'=>1) ); diff --git a/htdocs/accountancy/admin/index.php b/htdocs/accountancy/admin/index.php index 8b71b118c4e..363fd2ecbb5 100644 --- a/htdocs/accountancy/admin/index.php +++ b/htdocs/accountancy/admin/index.php @@ -57,8 +57,8 @@ $list = array( ); $list_binding = array( - 'ACCOUNTING_DATE_START_BINDING', 'ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER', + 'ACCOUNTING_DATE_START_BINDING', ); $error = 0; diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 994cb9b1466..6b5f09693ce 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -435,8 +435,8 @@ if ($action != 'export_csv') { if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { print_liste_field_titre("OpeningBalance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); } - print_liste_field_titre("Debit", $_SERVER['PHP_SELF'], "t.debit", "", $param, 'class="right"', $sortfield, $sortorder); - print_liste_field_titre("Credit", $_SERVER['PHP_SELF'], "t.credit", "", $param, 'class="right"', $sortfield, $sortorder); + print_liste_field_titre("AccountingDebit", $_SERVER['PHP_SELF'], "t.debit", "", $param, 'class="right"', $sortfield, $sortorder); + print_liste_field_titre("AccountingCredit", $_SERVER['PHP_SELF'], "t.credit", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Balance", $_SERVER["PHP_SELF"], "", $param, "", 'class="right"', $sortfield, $sortorder); // Hook fields diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index 7135044ef09..3e4055510cd 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -2,7 +2,7 @@ /* Copyright (C) 2016 Neil Orley * Copyright (C) 2013-2016 Olivier Geffroy * Copyright (C) 2013-2020 Florian Henry - * Copyright (C) 2013-2022 Alexandre Spangaro + * Copyright (C) 2013-2023 Alexandre Spangaro * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -164,12 +164,13 @@ $arrayfields = array( 't.doc_date'=>array('label'=>$langs->trans("Docdate"), 'checked'=>1), 't.doc_ref'=>array('label'=>$langs->trans("Piece"), 'checked'=>1), 't.label_operation'=>array('label'=>$langs->trans("Label"), 'checked'=>1), + 't.lettering_code'=>array('label'=>$langs->trans("Lettering"), 'checked'=>1), 't.debit'=>array('label'=>$langs->trans("AccountingDebit"), 'checked'=>1), 't.credit'=>array('label'=>$langs->trans("AccountingCredit"), 'checked'=>1), - 't.lettering_code'=>array('label'=>$langs->trans("LetteringCode"), 'checked'=>1), - 't.date_export'=>array('label'=>$langs->trans("DateExport"), 'checked'=>1), - 't.date_validated'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>1, 'enabled'=>!getDolGlobalString("ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")), - 't.import_key'=>array('label'=>$langs->trans("ImportId"), 'checked'=>0, 'position'=>1100), + 't.balance'=>array('label'=>$langs->trans("Balance"), 'checked'=>1), + 't.date_export'=>array('label'=>$langs->trans("DateExport"), 'checked'=>-1), + 't.date_validated'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>-1, 'enabled'=>!getDolGlobalString("ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")), + 't.import_key'=>array('label'=>$langs->trans("ImportId"), 'checked'=>-1, 'position'=>1100), ); if (!getDolGlobalString('ACCOUNTING_ENABLE_LETTERING')) { @@ -260,9 +261,9 @@ if (empty($reshook)) { $search_date_validation_endyear = ''; $search_date_validation_endmonth = ''; $search_date_validation_endday = ''; + $search_lettering_code = ''; $search_debit = ''; $search_credit = ''; - $search_lettering_code = ''; $search_not_reconciled = ''; $search_import_key = ''; $toselect = array(); @@ -339,6 +340,10 @@ if (empty($reshook)) { $param .= '&search_ledger_code[]='.urlencode($code); } } + if (!empty($search_lettering_code)) { + $filter['t.lettering_code'] = $search_lettering_code; + $param .= '&search_lettering_code='.urlencode($search_lettering_code); + } if (!empty($search_debit)) { $filter['t.debit'] = $search_debit; $param .= '&search_debit='.urlencode($search_debit); @@ -347,10 +352,6 @@ if (empty($reshook)) { $filter['t.credit'] = $search_credit; $param .= '&search_credit='.urlencode($search_credit); } - if (!empty($search_lettering_code)) { - $filter['t.lettering_code'] = $search_lettering_code; - $param .= '&search_lettering_code='.urlencode($search_lettering_code); - } if (!empty($search_not_reconciled)) { $filter['t.reconciled_option'] = $search_not_reconciled; $param .= '&search_not_reconciled='.urlencode($search_not_reconciled); @@ -679,7 +680,6 @@ if (empty($reshook)) { $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected')); $newcardbutton .= dolGetButtonTitle($langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?type=sub&' . $url_param, '', 1, array('morecss' => 'marginleftonly')); } - $newcardbutton .= dolGetButtonTitleSeparator(); $newcardbutton .= dolGetButtonTitle($langs->trans('NewAccountingMvt'), '', 'fa fa-plus-circle paddingleft', DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?action=create'); } @@ -844,6 +844,13 @@ if (!empty($arrayfields['t.doc_ref']['checked'])) { if (!empty($arrayfields['t.label_operation']['checked'])) { print ''; } +// Lettering code +if (!empty($arrayfields['t.lettering_code']['checked'])) { + print ''; + print ''; + print '
'.$langs->trans("NotReconciled").''; + print ''; +} // Debit if (!empty($arrayfields['t.debit']['checked'])) { print ''; @@ -852,12 +859,9 @@ if (!empty($arrayfields['t.debit']['checked'])) { if (!empty($arrayfields['t.credit']['checked'])) { print ''; } -// Lettering code -if (!empty($arrayfields['t.lettering_code']['checked'])) { - print ''; - print ''; - print '
'.$langs->trans("NotReconciled").''; - print ''; +// Balance +if (!empty($arrayfields['t.balance']['checked'])) { + print ''; } // Date export if (!empty($arrayfields['t.date_export']['checked'])) { @@ -920,14 +924,17 @@ if (!empty($arrayfields['t.doc_ref']['checked'])) { if (!empty($arrayfields['t.label_operation']['checked'])) { print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder); } +if (!empty($arrayfields['t.lettering_code']['checked'])) { + print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center '); +} if (!empty($arrayfields['t.debit']['checked'])) { print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right '); } if (!empty($arrayfields['t.credit']['checked'])) { print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right '); } -if (!empty($arrayfields['t.lettering_code']['checked'])) { - print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center '); +if (!empty($arrayfields['t.balance']['checked'])) { + print_liste_field_titre($arrayfields['t.balance']['label'], "", "", "", $param, '', $sortfield, $sortorder, 'right '); } if (!empty($arrayfields['t.date_export']['checked'])) { print_liste_field_titre($arrayfields['t.date_export']['label'], $_SERVER['PHP_SELF'], "t.date_export", "", $param, '', $sortfield, $sortorder, 'center '); @@ -977,18 +984,23 @@ while ($i < min($num, $limit)) { //if (empty($accountg)) $accountg = '-'; $colspan = 0; // colspan before field 'label of operation' - $colspanend = 3; // colspan after debit/credit + $colspanend = 0; // colspan after debit/credit + if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + $colspan++; + } if (!empty($arrayfields['t.piece_num']['checked'])) { $colspan++; } if (!empty($arrayfields['t.code_journal']['checked'])) { $colspan++; } if (!empty($arrayfields['t.doc_date']['checked'])) { $colspan++; } if (!empty($arrayfields['t.doc_ref']['checked'])) { $colspan++; } if (!empty($arrayfields['t.label_operation']['checked'])) { $colspan++; } + if (!empty($arrayfields['t.lettering_code']['checked'])) { $colspan++; } + + if (!empty($arrayfields['t.balance']['checked'])) { $colspanend++; } if (!empty($arrayfields['t.date_export']['checked'])) { $colspanend++; } if (!empty($arrayfields['t.date_validating']['checked'])) { $colspanend++; } - if (!empty($arrayfields['t.lettering_code']['checked'])) { $colspanend++; } - if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { - $colspan++; - $colspanend--; + if (!empty($arrayfields['t.import_key']['checked'])) { $colspanend++; } + if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + $colspanend++; } // Is it a break ? @@ -1003,7 +1015,7 @@ while ($i < min($num, $limit)) { } print ''.price(price2num($sous_total_debit, 'MT')).''; print ''.price(price2num($sous_total_credit, 'MT')).''; - print ''; + if ($colspanend > 0) print ''; print ''; // Show balance of last shown account $balance = $sous_total_debit - $sous_total_credit; @@ -1020,7 +1032,7 @@ while ($i < min($num, $limit)) { print price(price2num($sous_total_credit - $sous_total_debit, 'MT')); print ''; } - print ''; + if ($colspanend > 0) print ''; print ''; } @@ -1189,6 +1201,14 @@ while ($i < min($num, $limit)) { } } + // Lettering code + if (!empty($arrayfields['t.lettering_code']['checked'])) { + print ''.$line->lettering_code.''; + if (!$i) { + $totalarray['nbfield']++; + } + } + // Amount debit if (!empty($arrayfields['t.debit']['checked'])) { print ''.($line->debit != 0 ? price($line->debit) : '').''; @@ -1213,12 +1233,16 @@ while ($i < min($num, $limit)) { $totalarray['val']['totalcredit'] += $line->credit; } - // Lettering code - if (!empty($arrayfields['t.lettering_code']['checked'])) { - print ''.$line->lettering_code.''; + // Amount balance + if (!empty($arrayfields['t.balance']['checked'])) { + print ''.price(price2num($sous_total_debit + $line->debit - $sous_total_credit - $line->credit, 'MT')).''; if (!$i) { $totalarray['nbfield']++; } + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 'totalbalance'; + }; + $totalarray['val']['totalbalance'] += $line->debit - $line->credit; } // Exported operation date @@ -1279,7 +1303,7 @@ if ($num > 0 && $colspan > 0) { print ''.$langs->trans("TotalForAccount").' '.$accountg.':'; print ''.price(price2num($sous_total_debit, 'MT')).''; print ''.price(price2num($sous_total_credit, 'MT')).''; - print ''; + if ($colspanend > 0) print ''; print ''; // Show balance of last shown account $balance = $sous_total_debit - $sous_total_credit; @@ -1296,7 +1320,7 @@ if ($num > 0 && $colspan > 0) { print price(price2num($sous_total_credit - $sous_total_debit, 'MT')); print ''; } - print ''; + if ($colspanend > 0) print ''; print ''; } @@ -1308,7 +1332,9 @@ if (!empty($totalarray['val']['totaldebit'])) { if (!empty($totalarray['val']['totalcredit'])) { $totalarray['val']['totalcredit'] = price2num($totalarray['val']['totalcredit'], 'MT'); } - +if (!empty($totalarray['val']['totalbalance'])) { + $totalarray['val']['totalbalance'] = price2num($totalarray['val']['totaldebit'] - $totalarray['val']['totalcredit'], 'MT'); +} // Show total line include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index bce01982e03..005056112f8 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -401,6 +401,7 @@ class AccountingAccount extends CommonObject { global $langs; + // TODO Looks a stupid check $sql = "(SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX."facturedet"; $sql .= " WHERE fk_code_ventilation=".((int) $this->id).")"; $sql .= "UNION"; @@ -496,7 +497,7 @@ class AccountingAccount extends CommonObject $url = ''; $labelurl = ''; if (empty($option) || $option == 'ledger') { - $url = DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start=' . urlencode($this->account_number) . '&search_accountancy_code_end=' . urlencode($this->account_number); + $url = DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start=' . urlencode((isset($this->account_number) ? $this->account_number : '')) . '&search_accountancy_code_end=' . urlencode((isset($this->account_number) ? $this->account_number : '')); $labelurl = $langs->trans("ShowAccountingAccountInLedger"); } elseif ($option == 'journals') { $url = DOL_URL_ROOT . '/accountancy/bookkeeping/list.php?search_accountancy_code_start=' . urlencode($this->account_number) . '&search_accountancy_code_end=' . urlencode($this->account_number); diff --git a/htdocs/accountancy/class/accountingjournal.class.php b/htdocs/accountancy/class/accountingjournal.class.php index 321891c2f53..9c50f4fec45 100644 --- a/htdocs/accountancy/class/accountingjournal.class.php +++ b/htdocs/accountancy/class/accountingjournal.class.php @@ -228,7 +228,7 @@ class AccountingJournal extends CommonObject } /** - * Return clicable name (with picto eventually) + * Return clickable name (with picto eventually) * * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto * @param int $withlabel 0=No label, 1=Include label of journal, 2=Include nature of journal @@ -281,7 +281,7 @@ class AccountingJournal extends CommonObject } $label_link = $this->code; - if ($withlabel != 2 && !empty($this->label)) { + if ($withlabel == 1 && !empty($this->label)) { $label_link .= ' - '.($nourl ? '' : '').$langs->transnoentities($this->label).($nourl ? '' : ''); } if ($withlabel == 2 && !empty($this->nature)) { diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 288e34b5dcb..48a3e6891cc 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -1176,7 +1176,6 @@ class BookKeeping extends CommonObject $sql = 'SELECT'; $sql .= " t.numero_compte,"; - $sql .= " t.label_compte,"; if (!empty($option)) { $sql .= " t.subledger_account,"; $sql .= " t.subledger_label,"; @@ -1221,11 +1220,11 @@ class BookKeeping extends CommonObject if (!empty($option)) { $sql .= " AND t.subledger_account IS NOT NULL"; $sql .= " AND t.subledger_account <> ''"; - $sql .= " GROUP BY t.numero_compte, t.label_compte, t.subledger_account, t.subledger_label"; + $sql .= " GROUP BY t.numero_compte, t.subledger_account, t.subledger_label"; $sortfield = 't.subledger_account'.($sortfield ? ','.$sortfield : ''); $sortorder = 'ASC'.($sortfield ? ','.$sortfield : ''); } else { - $sql .= ' GROUP BY t.numero_compte, t.label_compte'; + $sql .= ' GROUP BY t.numero_compte'; $sortfield = 't.numero_compte'.($sortfield ? ','.$sortfield : ''); $sortorder = 'ASC'.($sortorder ? ','.$sortorder : ''); } @@ -1246,7 +1245,7 @@ class BookKeeping extends CommonObject $line = new BookKeepingLine(); $line->numero_compte = $obj->numero_compte; - $line->label_compte = $obj->label_compte; + //$line->label_compte = $obj->label_compte; if (!empty($option)) { $line->subledger_account = $obj->subledger_account; $line->subledger_label = $obj->subledger_label; diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 73f7671b3d0..61c945450e9 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -319,9 +319,9 @@ if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) { $y = $year_current; -$buttonbind = ''.img_picto($langs->trans("ValidateHistory"), 'link', 'class="pictofixedwidth fa-color-unset"').$langs->trans("ValidateHistory").''; +$buttonbind = ''.img_picto($langs->trans("ValidateHistory"), 'link', 'class="pictofixedwidth fa-color-unset"').$langs->trans("ValidateHistory").''; -print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, $buttonbind, '', 0, 1, 1); +print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1, 0, $buttonbind); //print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, ''); print '
'; diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 0f09ad76d35..7f76f640101 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -74,6 +74,11 @@ $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_en $search_country = GETPOST('search_country', 'alpha'); $search_tvaintra = GETPOST('search_tvaintra', 'alpha'); +// Define begin binding date +if (empty($search_date_start) && getDolGlobalString('ACCOUNTING_DATE_START_BINDING')) { + $search_date_start = $db->idate($conf->global->ACCOUNTING_DATE_START_BINDING); +} + // Load variable for pagination $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (!getDolGlobalString('ACCOUNTING_LIMIT_LIST_VENTILATION') ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); $sortfield = GETPOST('sortfield', 'aZ09comma'); @@ -281,10 +286,6 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa4 ON " . $alias_so $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0"; $sql .= " AND l.product_type <= 2"; -// Define begin binding date -if (getDolGlobalString('ACCOUNTING_DATE_START_BINDING')) { - $sql .= " AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'"; -} // Add search filter like if ($search_societe) { $sql .= natural_search('s.nom', $search_societe); diff --git a/htdocs/accountancy/expensereport/index.php b/htdocs/accountancy/expensereport/index.php index 6d0980ac7b3..db31387b78e 100644 --- a/htdocs/accountancy/expensereport/index.php +++ b/htdocs/accountancy/expensereport/index.php @@ -193,10 +193,10 @@ print '
'; $y = $year_current; -$buttonbind = ''.img_picto('', 'link', 'class="paddingright fa-color-unset"').$langs->trans("ValidateHistory").''; +$buttonbind = ''.img_picto('', 'link', 'class="paddingright fa-color-unset"').$langs->trans("ValidateHistory").''; -print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, $buttonbind, '', 0, 1, 1); +print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1, 0, $buttonbind); //print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, ''); print '
'; diff --git a/htdocs/accountancy/expensereport/list.php b/htdocs/accountancy/expensereport/list.php index 57cdb5ef3a6..6ba6244e037 100644 --- a/htdocs/accountancy/expensereport/list.php +++ b/htdocs/accountancy/expensereport/list.php @@ -67,6 +67,11 @@ $search_date_endyear = GETPOST('search_date_endyear', 'int'); $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear); +// Define begin binding date +if (empty($search_date_start) && getDolGlobalString('ACCOUNTING_DATE_START_BINDING')) { + $search_date_start = $db->idate($conf->global->ACCOUNTING_DATE_START_BINDING); +} + // Load variable for pagination $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (!getDolGlobalString('ACCOUNTING_LIMIT_LIST_VENTILATION') ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); $sortfield = GETPOST('sortfield', 'aZ09comma'); @@ -240,10 +245,6 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_fees as f ON f.id = erd.fk_c_type_f $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = er.fk_user_author"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON f.accountancy_code = aa.account_number AND aa.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa.entity = ".$conf->entity; $sql .= " WHERE er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.") AND erd.fk_code_ventilation <= 0"; -// Define begin binding date -if (getDolGlobalString('ACCOUNTING_DATE_START_BINDING')) { - $sql .= " AND er.date_debut >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'"; -} // Add search filter like if (strlen(trim($search_login))) { $sql .= natural_search("u.login", $search_login); @@ -291,6 +292,7 @@ if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { $offset = 0; } } +//print $sql; $sql .= $db->plimit($limit + 1, $offset); diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php index 8c52a74052d..ae217414b5f 100644 --- a/htdocs/accountancy/journal/expensereportsjournal.php +++ b/htdocs/accountancy/journal/expensereportsjournal.php @@ -3,11 +3,11 @@ * Copyright (C) 2007-2010 Jean Heimburger * Copyright (C) 2011 Juanjo Menent * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2013-2021 Alexandre Spangaro + * Copyright (C) 2013-2023 Alexandre Spangaro * Copyright (C) 2013-2016 Olivier Geffroy * Copyright (C) 2013-2016 Florian Henry * Copyright (C) 2018 Frédéric France - * Copyright (C) 2018 Eric Seigne + * Copyright (C) 2018 Eric Seigne * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -71,6 +71,9 @@ if (!$user->hasRight('accounting', 'mouvements', 'lire')) { accessforbidden(); } +$error = 0; +$errorforinvoice = array(); + /* * Actions @@ -213,8 +216,27 @@ if ($result) { dol_print_error($db); } +// Load all unbound lines +$sql = "SELECT fk_expensereport, COUNT(erd.rowid) as nb"; +$sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as erd"; +$sql .= " WHERE erd.fk_code_ventilation <= 0"; +$sql .= " AND erd.total_ttc <> 0"; +$sql .= " AND fk_expensereport IN (".$db->sanitize(join(",", array_keys($taber))).")"; +$sql .= " GROUP BY fk_expensereport"; +$resql = $db->query($sql); + +$num = $db->num_rows($resql); +$i = 0; +while ($i < $num) { + $obj = $db->fetch_object($resql); + if ($obj->nb > 0) { + $errorforinvoice[$obj->fk_expensereport] = 'somelinesarenotbound'; + } + $i++; +} + // Bookkeeping Write -if ($action == 'writebookkeeping') { +if ($action == 'writebookkeeping' && !$error) { $now = dol_now(); $error = 0; @@ -229,6 +251,13 @@ if ($action == 'writebookkeeping') { $db->begin(); + // Error if some lines are not binded/ready to be journalized + if (!empty($errorforinvoice[$key]) && $errorforinvoice[$key] == 'somelinesarenotbound') { + $error++; + $errorforline++; + setEventMessages($langs->trans('ErrorInvoiceContainsLinesNotYetBounded', $val['ref']), null, 'errors'); + } + // Thirdparty if (!$errorforline) { foreach ($tabttc[$key] as $k => $mt) { @@ -265,10 +294,12 @@ if ($action == 'writebookkeeping') { if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists $error++; $errorforline++; + $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); } else { $error++; $errorforline++; + $errorforinvoice[$key] = 'other'; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); } } @@ -314,10 +345,12 @@ if ($action == 'writebookkeeping') { if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists $error++; $errorforline++; + $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); } else { $error++; $errorforline++; + $errorforinvoice[$key] = 'other'; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); } } @@ -376,10 +409,12 @@ if ($action == 'writebookkeeping') { if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists $error++; $errorforline++; + $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); } else { $error++; $errorforline++; + $errorforinvoice[$key] = 'other'; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); } } @@ -388,10 +423,11 @@ if ($action == 'writebookkeeping') { } } - // Protection against a bug on line before - if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) { + // Protection against a bug on lines before + if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) { $error++; $errorforline++; + $errorforinvoice[$key] = 'amountsnotbalanced'; setEventMessages('We tried to insert a non balanced transaction in book for '.$val["ref"].'. Canceled. Surely a bug.', null, 'errors'); } @@ -445,7 +481,7 @@ $form = new Form($db); $userstatic = new User($db); // Export -if ($action == 'exportcsv') { // ISO and not UTF8 ! +if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 ! $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; $filename = 'journal'; @@ -586,7 +622,7 @@ if (empty($action) || $action == 'view') { print ''.$langs->trans("AccountingCredit").""; print "\n"; - $r = ''; + $i = 0; $expensereportstatic = new ExpenseReport($db); $expensereportlinestatic = new ExpenseReportLine($db); @@ -598,6 +634,27 @@ if (empty($action) || $action == 'view') { $date = dol_print_date($val["date"], 'day'); + if ($errorforinvoice[$key] == 'somelinesarenotbound') { + print ''; + print ""; + print "".$date.""; + print "".$expensereportstatic->getNomUrl(1).""; + // Account + print ""; + print ''.$langs->trans('ErrorInvoiceContainsLinesNotYetBoundedShort', $val['ref']).''; + print ''; + // Subledger account + print ""; + print ''; + print ""; + print ""; + print ''; + print ''; + print ""; + + $i++; + } + // Fees foreach ($tabht[$key] as $k => $mt) { $accountingaccount = new AccountingAccount($db); diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php index 06cd60fca88..5dbfa51a470 100644 --- a/htdocs/accountancy/supplier/index.php +++ b/htdocs/accountancy/supplier/index.php @@ -311,10 +311,10 @@ print '
'; $y = $year_current; -$buttonbind = ''.img_picto('', 'link', 'class="paddingright fa-color-unset"').$langs->trans("ValidateHistory").''; +$buttonbind = ''.img_picto('', 'link', 'class="paddingright fa-color-unset smallpaddingimp"').$langs->trans("ValidateHistory").''; -print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, $buttonbind, '', 0, 1, 1); +print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1, 0, $buttonbind); //print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, ''); print '
'; diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index fc67608e8a8..616b39e7608 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -117,6 +117,11 @@ if (!$user->hasRight('accounting', 'mouvements', 'lire')) { accessforbidden(); } +// Define begin binding date +if (empty($search_date_start) && getDolGlobalString('ACCOUNTING_DATE_START_BINDING')) { + $search_date_start = $db->idate($conf->global->ACCOUNTING_DATE_START_BINDING); +} + /* * Actions @@ -282,10 +287,6 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON " . $alias_pr $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"; -// Define begin binding date -if (getDolGlobalString('ACCOUNTING_DATE_START_BINDING')) { - $sql .= " AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'"; -} // Add search filter like if ($search_societe) { $sql .= natural_search('s.nom', $search_societe); diff --git a/htdocs/adherents/admin/member.php b/htdocs/adherents/admin/member.php index 3f402440c9a..2993006bd91 100644 --- a/htdocs/adherents/admin/member.php +++ b/htdocs/adherents/admin/member.php @@ -9,6 +9,7 @@ * Copyright (C) 2012 J. Fernando Lagrange * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2020-2021 Frédéric France + * Copyright (C) 2023 Waël Almoman * * 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 @@ -103,13 +104,15 @@ if ($action == 'set_default') { } } elseif ($action == 'updatemainoptions') { $db->begin(); - $res1 = $res2 = $res3 = $res4 = $res5 = $res6 = $res7 = 0; + $res1 = $res2 = $res3 = $res4 = $res5 = $res6 = $res7 = $res8 = $res9 = 0; $res1 = dolibarr_set_const($db, 'ADHERENT_LOGIN_NOT_REQUIRED', GETPOST('ADHERENT_LOGIN_NOT_REQUIRED', 'alpha') ? 0 : 1, 'chaine', 0, '', $conf->entity); $res2 = dolibarr_set_const($db, 'ADHERENT_MAIL_REQUIRED', GETPOST('ADHERENT_MAIL_REQUIRED', 'alpha'), 'chaine', 0, '', $conf->entity); $res3 = dolibarr_set_const($db, 'ADHERENT_DEFAULT_SENDINFOBYMAIL', GETPOST('ADHERENT_DEFAULT_SENDINFOBYMAIL', 'alpha'), 'chaine', 0, '', $conf->entity); $res3 = dolibarr_set_const($db, 'ADHERENT_CREATE_EXTERNAL_USER_LOGIN', GETPOST('ADHERENT_CREATE_EXTERNAL_USER_LOGIN', 'alpha'), 'chaine', 0, '', $conf->entity); $res4 = dolibarr_set_const($db, 'ADHERENT_BANK_USE', GETPOST('ADHERENT_BANK_USE', 'alpha'), 'chaine', 0, '', $conf->entity); $res7 = dolibarr_set_const($db, 'MEMBER_PUBLIC_ENABLED', GETPOST('MEMBER_PUBLIC_ENABLED', 'alpha'), 'chaine', 0, '', $conf->entity); + $res8 = dolibarr_set_const($db, 'MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF', GETPOST('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF', 'alpha'), 'chaine', 0, '', $conf->entity); + $res9 = dolibarr_set_const($db, 'MEMBER_SUBSCRIPTION_START_AFTER', GETPOST('MEMBER_SUBSCRIPTION_START_AFTER', 'alpha'), 'chaine', 0, '', $conf->entity); // Use vat for invoice creation if (isModEnabled('facture')) { $res4 = dolibarr_set_const($db, 'ADHERENT_VAT_FOR_SUBSCRIPTIONS', GETPOST('ADHERENT_VAT_FOR_SUBSCRIPTIONS', 'alpha'), 'chaine', 0, '', $conf->entity); @@ -335,6 +338,24 @@ print ''.$langs->trans("Description").''; print ''.$langs->trans("Value").''; print "\n"; +// Start date of new membership +$startpoint[0] = $langs->trans("SubscriptionPayment"); +$startpoint["m"] = $langs->trans("Month"); +$startpoint["Y"] = $langs->trans("Year"); +print ''; +print $langs->trans("MemberSubscriptionStartFirstDayOf"); +print ''; +$startfirstdayof = !getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') ? 0 : getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF'); +print $form->selectarray("MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF", $startpoint, $startfirstdayof, 0); +print "\n"; + +// Delay to start the new membership ([+/-][0-99][Y/m/d], for instance, with "+4m", the subscription will start in 4 month.) +print ''; +print $langs->trans("MemberSubscriptionStartAfter"); +print ''; +print ''; +print "\n"; + // Mail required for members print ''.$langs->trans("AdherentMailRequired").''; print $form->selectyesno('ADHERENT_MAIL_REQUIRED', (getDolGlobalString('ADHERENT_MAIL_REQUIRED') ? $conf->global->ADHERENT_MAIL_REQUIRED : 0), 1); diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 5075154c4c8..8ae8c77146c 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -282,7 +282,7 @@ class AdherentStats extends Stats $sql .= " GROUP BY c.rowid, c.label"; $sql .= " ORDER BY label ASC"; - dol_syslog("box_members_by_type::select nb of members per type", LOG_DEBUG); + dol_syslog("box_members_by_tag::select nb of members per tag", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { diff --git a/htdocs/adherents/stats/index.php b/htdocs/adherents/stats/index.php index 2a0993efeb9..13dce1b030e 100644 --- a/htdocs/adherents/stats/index.php +++ b/htdocs/adherents/stats/index.php @@ -48,8 +48,11 @@ if ($user->socid > 0) { $result = restrictedArea($user, 'adherent', '', '', 'cotisation'); $year = dol_print_date(dol_now('gmt'), "%Y", 'gmt'); -$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS))); +$startyear = $year - (!getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS')))); $endyear = $year; +if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER')) { + $endyear = dol_print_date(dol_time_plus_duree(dol_now('gmt'), (int) substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), 0, -1), substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), -1)), "%Y", 'gmt'); +} // Load translation files required by the page $langs->loadLangs(array("companies", "members")); diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php index 99dc1844fc7..182957bc97d 100644 --- a/htdocs/adherents/subscription.php +++ b/htdocs/adherents/subscription.php @@ -6,6 +6,7 @@ * Copyright (C) 2015-2016 Alexandre Spangaro * Copyright (C) 2018-2023 Frédéric France * Copyright (C) 2019 Thibault FOUCART + * Copyright (C) 2023 Waël Almoman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -53,7 +54,7 @@ $typeid = GETPOST('typeid', 'int'); $cancel = GETPOST('cancel'); // Load variable for pagination -$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; +$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); @@ -81,9 +82,6 @@ $extrafields->fetch_name_optionals_label($object->table_element); $errmsg = ''; -$defaultdelay = 1; -$defaultdelayunit = 'y'; - // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('subscription')); @@ -213,6 +211,8 @@ if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'subscripti // Subscription informations $datesubscription = 0; $datesubend = 0; + $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1; + $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y'; $paymentdate = ''; // Do not use 0 here, default value is '' that means not filled where 0 means 1970-01-01 if (GETPOST("reyear", "int") && GETPOST("remonth", "int") && GETPOST("reday", "int")) { $datesubscription = dol_mktime(0, 0, 0, GETPOST("remonth", "int"), GETPOST("reday", "int"), GETPOST("reyear", "int")); @@ -476,6 +476,9 @@ if (! ($object->id > 0)) { $adht->fetch($object->typeid); +$defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1; +$defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y'; + $head = member_prepare_head($object); $rowspan = 10; @@ -958,8 +961,6 @@ if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->h print ''."\n"; print ''; - $now = dol_now(); - // Date payment if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday')) { $paymentdate = dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear')); @@ -975,10 +976,16 @@ if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->h } if (!$datefrom) { $datefrom = $object->datevalid; - if ($object->datefin > 0 && dol_time_plus_duree($object->datefin, $defaultdelay, $defaultdelayunit) > dol_now()) { + if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER')) { + $datefrom = dol_time_plus_duree($now, (int) substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), 0, -1), substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), -1)); + } elseif ($object->datefin > 0 && dol_time_plus_duree($object->datefin, $defaultdelay, $defaultdelayunit) > $now) { $datefrom = dol_time_plus_duree($object->datefin, 1, 'd'); - } else { - $datefrom = dol_get_first_day($currentyear); + } + + if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "m") { + $datefrom = dol_get_first_day(dol_print_date($datefrom, "%Y"), dol_print_date($datefrom, "%m")); + } elseif (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "Y") { + $datefrom = dol_get_first_day(dol_print_date($datefrom, "%Y")); } } print $form->selectDate($datefrom, '', '', '', '', "subscription", 1, 1); @@ -990,9 +997,9 @@ if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->h } if (!$dateto) { if (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH')) { - $dateto = dol_get_last_day($currentyear, $currentmonth); + $dateto = dol_get_last_day(dol_print_date($datefrom, "%Y"), dol_print_date($datefrom, "%m")); } elseif (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR')) { - $dateto = dol_get_last_day($currentyear); + $dateto = dol_get_last_day(dol_print_date($datefrom, "%Y")); } else { $dateto = -1; // By default, no date is suggested } diff --git a/htdocs/admin/fckeditor.php b/htdocs/admin/fckeditor.php index 2b5644a0642..91b8214b201 100644 --- a/htdocs/admin/fckeditor.php +++ b/htdocs/admin/fckeditor.php @@ -57,7 +57,7 @@ $modules = array( 'MAILING' => 'FCKeditorForMailing', 'MAIL' => 'FCKeditorForMail', 'TICKET' => 'FCKeditorForTicket', - 'SPECIALCHAR' => 'SpecialChar activation', + 'SPECIALCHAR' => 'SpecialCharActivation', ); // Conditions for the option to be offered $conditions = array( @@ -100,13 +100,9 @@ foreach ($modules as $const => $desc) { if ($const == 'PRODUCTDESC' && getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) { dolibarr_set_const($db, "FCKEDITOR_ENABLE_DETAILS", "1", 'chaine', 0, '', $conf->entity); } - header("Location: ".$_SERVER["PHP_SELF"]); - exit; } if ($action == 'disable_'.strtolower($const)) { dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "0", 'chaine', 0, '', $conf->entity); - header("Location: ".$_SERVER["PHP_SELF"]); - exit; } } @@ -179,9 +175,9 @@ if (empty($conf->use_javascript_ajax)) { print '"; diff --git a/htdocs/admin/mails_templates.php b/htdocs/admin/mails_templates.php index 851bb6bcbfd..114f2f3b7cd 100644 --- a/htdocs/admin/mails_templates.php +++ b/htdocs/admin/mails_templates.php @@ -934,7 +934,7 @@ foreach ($fieldlist as $field => $value) { if ($value == 'module') { print ''; } elseif ($value == 'label') { - print ''; + print ''; } elseif ($value == 'lang') { print ''; // Online payment with currency on document. This option should be on by default. -if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { +if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { print ''; print ''; print ''; print '
'; $value = (isset($conf->global->$constante) ? $conf->global->$constante : 0); if ($value == 0) { - print ''.img_picto($langs->trans("Disabled"), 'switch_off').''; + print ''.img_picto($langs->trans("Disabled"), 'switch_off').''; } elseif ($value == 1) { - print ''.img_picto($langs->trans("Enabled"), 'switch_on').''; + print ''.img_picto($langs->trans("Enabled"), 'switch_on').''; } print "'; print $formadmin->select_language($search_lang, 'search_lang', 0, null, 1, 0, 0, 'maxwidth100'); @@ -1227,7 +1227,7 @@ if ($num) { $valuetoshow = dol_escape_htmltag($valuetoshow); } if ($value == 'label') { - $class .= ' tdoverflowmax100'; + $class .= ' tdoverflowmax200'; } if ($value == 'topic') { $class .= ' tdoverflowmax200 small'; diff --git a/htdocs/admin/multicurrency.php b/htdocs/admin/multicurrency.php index 2b3263efbde..5afd1ce8c85 100644 --- a/htdocs/admin/multicurrency.php +++ b/htdocs/admin/multicurrency.php @@ -215,7 +215,7 @@ if ($conf->use_javascript_ajax) { print '
'.$langs->transnoentitiesnoconv("MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT").''; @@ -260,51 +260,6 @@ print '
'; print '
'; -print '
'; - -if (getDolGlobalString('MAIN_MULTICURRENCY_ALLOW_SYNCHRONIZATION')) { - print '
'; - print ''; - print ''; - - print '
'; - print ''; - - $urlforapilayer = 'https://currencylayer.com'; //https://apilayer.net - - print ''; - print ''."\n"; - print ''; - - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - - /*print ''; - print ''; - print '';*/ - - print '
'.$form->textwithpicto($langs->trans("CurrencyLayerAccount"), $langs->trans("CurrencyLayerAccount_help_to_synchronize", $urlforapilayer)).''; - print ''; - print ''; - print ''; - print '
'.$langs->transnoentitiesnoconv("multicurrency_appId").''; - print ' '; - print '
'.$langs->transnoentitiesnoconv("multicurrency_appCurrencySource").''; - print ' '; // Default: USD - print ''; - print '
'.$langs->transnoentitiesnoconv("multicurrency_alternateCurrencySource").''; - print ' '; // Example: EUR - print '
'; - print '
'; - print '
'; - - print ''; -} print '
'; print ''; @@ -377,6 +332,53 @@ print ' '; + +print '
'; + +if (!getDolGlobalString('MULTICURRENCY_DISABLE_SYNC_CURRENCYLAYER')) { + print ''; + print ''; + print ''; + + print '
'; + print '
'; + + $urlforapilayer = 'https://currencylayer.com'; //https://apilayer.net + + print ''; + print ''."\n"; + print ''; + + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + + /*print ''; + print ''; + print '';*/ + + print '
'.$form->textwithpicto($langs->trans("CurrencyLayerAccount"), $langs->trans("CurrencyLayerAccount_help_to_synchronize", $urlforapilayer)).''; + print ''; + print ''; + print ''; + print '
'.$langs->transnoentitiesnoconv("multicurrency_appId").''; + print ' '; + print '
'.$langs->transnoentitiesnoconv("multicurrency_appCurrencySource").''; + print ' '; // Default: USD + print '
'.$langs->transnoentitiesnoconv("multicurrency_alternateCurrencySource").''; + print ' '; // Example: EUR + print '
'; + print '
'; + print '
'; + + print ''; +} + + // End of page llxFooter(); $db->close(); diff --git a/htdocs/admin/pdf.php b/htdocs/admin/pdf.php index 9195c6e69ec..d999b91d32f 100644 --- a/htdocs/admin/pdf.php +++ b/htdocs/admin/pdf.php @@ -132,6 +132,10 @@ if ($action == 'update') { dolibarr_set_const($db, "MAIN_GENERATE_DOCUMENTS_HIDE_REF", GETPOST("MAIN_GENERATE_DOCUMENTS_HIDE_REF"), 'chaine', 0, '', $conf->entity); } + if (GETPOSTISSET('MAIN_GENERATE_DOCUMENTS_SHOW_PRODUCT_BARCODE')) { + dolibarr_set_const($db, "MAIN_GENERATE_DOCUMENTS_SHOW_PRODUCT_BARCODE", GETPOST("MAIN_GENERATE_DOCUMENTS_SHOW_PRODUCT_BARCODE"), 'chaine', 0, '', $conf->entity); + } + if (GETPOSTISSET('MAIN_DOCUMENTS_LOGO_HEIGHT')) { dolibarr_set_const($db, "MAIN_DOCUMENTS_LOGO_HEIGHT", GETPOST("MAIN_DOCUMENTS_LOGO_HEIGHT", 'int'), 'chaine', 0, '', $conf->entity); } @@ -532,6 +536,18 @@ if ($conf->use_javascript_ajax) { } print ''; +// Barcode + +if (isModEnabled('barcode')) { + print ''.$langs->trans("ShowProductBarcodeOnPDF").''; + if ($conf->use_javascript_ajax) { + print ajax_constantonoff('MAIN_GENERATE_DOCUMENTS_SHOW_PRODUCT_BARCODE'); + } else { + print $form->selectyesno('MAIN_GENERATE_DOCUMENTS_SHOW_PRODUCT_BARCODE', (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_PRODUCT_BARCODE)) ? $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_PRODUCT_BARCODE : 0, 1); + } + print ''; +} + // Desc print ''.$langs->trans("HideDescOnPDF").''; diff --git a/htdocs/admin/system/security.php b/htdocs/admin/system/security.php index 38f0958a89b..368f6cf5ae2 100644 --- a/htdocs/admin/system/security.php +++ b/htdocs/admin/system/security.php @@ -638,7 +638,7 @@ print '
'; print 'MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES = '.getDolGlobalString('MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES', ''.$langs->trans("Undefined").'   ('.$langs->trans("Recommended").': 1)')."
"; print '
'; -print 'MAIN_DISALLOW_EXT_URL_INTO_DESCRIPTIONS = '.getDolGlobalString('MAIN_DISALLOW_EXT_URL_INTO_DESCRIPTIONS', ''.$langs->trans("Undefined").'   ('.$langs->trans("Recommended").': '.$langs->trans("Undefined").' '.$langs->trans("or").' 0)')."
"; +print 'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = '.getDolGlobalString('MAIN_DISALLOW_URL_INTO_DESCRIPTIONS', ''.$langs->trans("Undefined").'   ('.$langs->trans("Recommended").': 1)')."
"; print '
'; print 'MAIN_ALLOW_SVG_FILES_AS_EXTERNAL_LINKS = '.getDolGlobalString('MAIN_ALLOW_SVG_FILES_AS_EXTERNAL_LINKS', ''.$langs->trans("Undefined").'   ('.$langs->trans("Recommended").': '.$langs->trans("Undefined").' '.$langs->trans("or").' 0)')."
"; diff --git a/htdocs/admin/tools/listevents.php b/htdocs/admin/tools/listevents.php index 3cff615d9dc..75ffcc781d7 100644 --- a/htdocs/admin/tools/listevents.php +++ b/htdocs/admin/tools/listevents.php @@ -28,6 +28,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/triggers/interface_20_all_Logevents.class.php'; if (!$user->admin) { accessforbidden(); @@ -477,6 +478,10 @@ if ($result) { // Description $text = $langs->trans($obj->description); $reg = array(); + if (InterfaceLogevents::isEventActionTextKey($obj->description)) { + $val = explode(' : ', $obj->description); + $text = $langs->trans($val[0], isset($val[1]) ? $val[1] : '', isset($val[2]) ? $val[2] : '', isset($val[3]) ? $val[3] : '', isset($val[4]) ? $val[4] : ''); + } if (preg_match('/\((.*)\)(.*)/i', $obj->description, $reg)) { $val = explode(',', $reg[1]); $text = $langs->trans($val[0], isset($val[1]) ? $val[1] : '', isset($val[2]) ? $val[2] : '', isset($val[3]) ? $val[3] : '', isset($val[4]) ? $val[4] : ''); diff --git a/htdocs/admin/webhook.php b/htdocs/admin/webhook.php index 5495a7633a2..8e978a30621 100644 --- a/htdocs/admin/webhook.php +++ b/htdocs/admin/webhook.php @@ -55,12 +55,7 @@ $setupnotempty = 0; $useFormSetup = 1; if (!class_exists('FormSetup')) { - // For retrocompatibility Dolibarr < 16.0 - if (floatval(DOL_VERSION) < 16.0 && !class_exists('FormSetup')) { - require_once __DIR__.'/../backport/v16/core/class/html.formsetup.class.php'; - } else { - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php'; - } + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php'; } $formSetup = new FormSetup($db); diff --git a/htdocs/admin/website_options.php b/htdocs/admin/website_options.php index a1403aea6f1..73a1cddbc68 100644 --- a/htdocs/admin/website_options.php +++ b/htdocs/admin/website_options.php @@ -68,12 +68,7 @@ if (!$user->admin || !isModEnabled('website')) { $useFormSetup = 1; if (!class_exists('FormSetup')) { - // For retrocompatibility Dolibarr < 16.0 - if (floatval(DOL_VERSION) < 16.0 && !class_exists('FormSetup')) { - require_once __DIR__.'/../backport/v16/core/class/html.formsetup.class.php'; - } else { - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php'; - } + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php'; } $formSetup = new FormSetup($db); diff --git a/htdocs/api/class/api_access.class.php b/htdocs/api/class/api_access.class.php index 48d57c67506..04c26a0e749 100644 --- a/htdocs/api/class/api_access.class.php +++ b/htdocs/api/class/api_access.class.php @@ -30,6 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/iUs require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/Resources.php'; require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/Defaults.php'; require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/RestException.php'; + use Luracast\Restler\iAuthenticate; use Luracast\Restler\iUseAuthentication; use Luracast\Restler\Resources; diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 1ae21b0d8ef..11afb4ca9e1 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -22,7 +22,7 @@ use Luracast\Restler\RestException; use Luracast\Restler\Format\UploadFormat; require_once DOL_DOCUMENT_ROOT.'/main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/api/class/api.php'; +require_once DOL_DOCUMENT_ROOT.'/api/class/api.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; /** @@ -596,7 +596,9 @@ class Documents extends DolibarrApi } elseif (is_array($ecmfile->lines) && count($ecmfile->lines) > 0) { $count = count($filearray); for ($i = 0 ; $i < $count ; $i++) { - if ($filearray[$i]['name'] == $ecmfile->lines[$i]->filename) $filearray[$i] = array_merge($filearray[$i], (array) $ecmfile->lines[0]); + if ($filearray[$i]['name'] == $ecmfile->lines[$i]->filename) { + $filearray[$i] = array_merge($filearray[$i], (array) $ecmfile->lines[0]); + } } } } @@ -621,7 +623,7 @@ class Documents extends DolibarrApi /** - * Upload a file. + * Upload a document. * * Test sample for invoice: { "filename": "mynewfile.txt", "modulepart": "invoice", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }. * Test sample for supplier invoice: { "filename": "mynewfile.txt", "modulepart": "supplier_invoice", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }. @@ -654,14 +656,12 @@ class Documents extends DolibarrApi //var_dump($filename); //var_dump($filecontent);exit; + $modulepartorig = $modulepart; + if (empty($modulepart)) { throw new RestException(400, 'Modulepart not provided.'); } - if (!DolibarrApiAccess::$user->rights->ecm->upload) { - throw new RestException(401); - } - $newfilecontent = ''; if (empty($fileencoding)) { $newfilecontent = $filecontent; @@ -783,10 +783,17 @@ class Documents extends DolibarrApi $tmpreldir = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier'); } - $relativefile = $tmpreldir.dol_sanitizeFileName($object->ref); - - $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, $ref, 'write'); - $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir + // Test on permissions + if ($modulepart != 'ecm') { + $relativefile = $tmpreldir.dol_sanitizeFileName($object->ref); + $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, $ref, 'write'); + $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir + } else { + if (!DolibarrApiAccess::$user->hasRight('ecm', 'upload')) { + throw new RestException(401, 'Missing permission to upload files in ECM module'); + } + $upload_dir = $conf->medias->multidir_output[$conf->entity]; + } if (empty($upload_dir) || $upload_dir == '/') { throw new RestException(500, 'This value of modulepart ('.$modulepart.') does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.'); @@ -799,9 +806,17 @@ class Documents extends DolibarrApi $modulepart = 'adherent'; } - $relativefile = $subdir; - $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write'); - $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir + // Test on permissions + if ($modulepart != 'ecm') { + $relativefile = $subdir; + $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write'); + $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir + } else { + if (!DolibarrApiAccess::$user->hasRight('ecm', 'upload')) { + throw new RestException(401, 'Missing permission to upload files in ECM module'); + } + $upload_dir = $conf->medias->multidir_output[$conf->entity]; + } if (empty($upload_dir) || $upload_dir == '/') { if (!empty($tmp['error'])) { @@ -891,7 +906,14 @@ class Documents extends DolibarrApi throw new RestException(500, "Refused to deliver file ".$dest_file); } - $result = dol_move($destfiletmp, $dest_file, 0, $overwriteifexists, 1, 1); + $moreinfo = array('note_private' => 'File uploaded using API /documents from IP '.getUserRemoteIP()); + if (!empty($object) && is_object($object) && $object->id > 0) { + $moreinfo['src_object_type'] = $object->table_element; + $moreinfo['src_object_id'] = $object->id; + } + + // Move the temporary file at its final emplacement + $result = dol_move($destfiletmp, $dest_file, 0, $overwriteifexists, 1, 1, $moreinfo); if (!$result) { throw new RestException(500, "Failed to move file into '".$destfile."'"); } diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 50118773b3e..5622d3e0e97 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -24,7 +24,7 @@ use Luracast\Restler\RestException; require_once DOL_DOCUMENT_ROOT.'/main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/api/class/api.php'; +require_once DOL_DOCUMENT_ROOT.'/api/class/api.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/cstate.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/cregion.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php'; diff --git a/htdocs/api/class/api_status.class.php b/htdocs/api/class/api_status.class.php index ac84072927d..899bd1b40aa 100644 --- a/htdocs/api/class/api_status.class.php +++ b/htdocs/api/class/api_status.class.php @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -require_once DOL_DOCUMENT_ROOT.'/api/class/api.php'; +require_once DOL_DOCUMENT_ROOT.'/api/class/api.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; diff --git a/htdocs/api/index.php b/htdocs/api/index.php index a140bb23057..d449e16339a 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -363,7 +363,7 @@ if (!empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && } } - dol_syslog('Search api file /'.$moduledirforclass.'/class/api_'.$classfile.'.class.php => dir_part_file='.$dir_part_file.' classname='.$classname); + dol_syslog('Search api file /'.$moduledirforclass.'/class/api_'.$classfile.'.class.php => dir_part_file='.$dir_part_file.', classname='.$classname); $res = false; if ($dir_part_file) { diff --git a/htdocs/asset/class/asset.class.php b/htdocs/asset/class/asset.class.php index a09d415a1f8..606aaa9b60c 100644 --- a/htdocs/asset/class/asset.class.php +++ b/htdocs/asset/class/asset.class.php @@ -1466,12 +1466,10 @@ class Asset extends CommonObject $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; - $this->user_creation_id = $obj->fk_user_author; - $this->user_validation_id = $obj->fk_user_valid; - $this->user_closing_id = $obj->fk_user_cloture; + $this->user_creation_id = $obj->fk_user_creat; + $this->user_modification_id = $obj->fk_user_modif; $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/asset/document.php b/htdocs/asset/document.php index 3ead3b3ed57..73ce96c7fe7 100644 --- a/htdocs/asset/document.php +++ b/htdocs/asset/document.php @@ -73,7 +73,7 @@ if ($id > 0 || !empty($ref)) { $upload_dir = $conf->asset->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object); } -$permissiontoadd = $user->rights->asset->asset->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php +$permissiontoadd = $user->rights->asset->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php // Security check (enable the most restrictive one) if ($user->socid > 0) accessforbidden(); diff --git a/htdocs/blockedlog/admin/blockedlog_list.php b/htdocs/blockedlog/admin/blockedlog_list.php index 671b016c527..d19019ae99f 100644 --- a/htdocs/blockedlog/admin/blockedlog_list.php +++ b/htdocs/blockedlog/admin/blockedlog_list.php @@ -540,6 +540,7 @@ if (is_array($blocks)) { $nbshown = 0; $MAXFORSHOWLINK = 100; $object_link = ''; + $object_link_title = ''; foreach ($blocks as &$block) { //if (empty($search_showonlyerrors) || ! $checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) @@ -548,8 +549,10 @@ if (is_array($blocks)) { if ($nbshown < $MAXFORSHOWLINK) { // For performance and memory purpose, we get/show the link of objects only for the 100 first output $object_link = $block->getObjectLink(); + $object_link_title = ''; } else { $object_link = $block->element.'/'.$block->fk_object; + $object_link_title = $langs->trans('LinkHasBeenDisabledForPerformancePurpose'); } print ''; @@ -581,7 +584,7 @@ if (is_array($blocks)) { print ''; // Link to source object - print ''; + print ''; print ''; // $object_link can be a ''; diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index b8d7eca4b19..6fcc8e99dd7 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -177,6 +177,7 @@ if (empty($reshook)) { $product = new Product($db); $res = $product->fetch($idprod); if ($res > 0 && $product->type == Product::TYPE_SERVICE) $fk_default_workstation = $product->fk_default_workstation; + if (empty($fk_unit)) $fk_unit = $product->fk_unit; } if ($qty == '') { diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index c16093ec851..c48d690e7ba 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -780,9 +780,9 @@ class BOM extends CommonObject $line->efficiency = $efficiency; $line->import_key = $import_key; $line->position = $rankToUse; - if (!empty($fk_unit)) { - $line->fk_unit = $fk_unit; - } + + if (!empty($fk_unit)) $line->fk_unit = $fk_unit; + if (is_array($array_options) && count($array_options) > 0) { // We replace values in this->line->array_options only for entries defined into $array_options @@ -987,6 +987,12 @@ class BOM extends CommonObject if (!$resql) { $error++; $this->error = $this->db->lasterror(); } + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'bom/".$this->db->escape($this->newref)."'"; + $sql .= " WHERE filepath = 'bom/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (!$resql) { + $error++; $this->error = $this->db->lasterror(); + } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); diff --git a/htdocs/bom/tpl/objectline_edit.tpl.php b/htdocs/bom/tpl/objectline_edit.tpl.php index 6d7ab47a822..a27d01b0e7b 100644 --- a/htdocs/bom/tpl/objectline_edit.tpl.php +++ b/htdocs/bom/tpl/objectline_edit.tpl.php @@ -128,7 +128,8 @@ print ''; if ($filtertype != 1) { if (getDolGlobalInt('PRODUCT_USE_UNITS')) { $coldisplay++; - print ''; + print ''; + print $formproduct->selectMeasuringUnits("fk_unit", '', (($line->fk_unit) ? $line->fk_unit : ''), 0, 0); print ''; } diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index fdc06609c24..c0a714de64d 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -128,7 +128,7 @@ print ''; if ($filtertype != 1) { if (getDolGlobalInt('PRODUCT_USE_UNITS')) { print ''; - $label = $tmpproduct->getLabelOfUnit('long'); + $label = measuringUnitString($line->fk_unit, '', '', 1); if ($label !== '') { print $langs->trans($label); } diff --git a/htdocs/bookcal/README.md b/htdocs/bookcal/README.md index 2077d7e1072..20e41a38217 100644 --- a/htdocs/bookcal/README.md +++ b/htdocs/bookcal/README.md @@ -1,8 +1,8 @@ -# BOOKCAL FOR [DOLIBARR ERP CRM](https://www.dolibarr.org) +# ONLINE APPOINTMENT FOR [DOLIBARR ERP CRM](https://www.dolibarr.org) ## Features -Provide features to be able to record online booking. +Provides an online appointment booking system. This allow anyone to book rendez-vous, according to predefined ranges or availabilities. "; - print "\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''; - print ''; - - $newclassname = $classname; - if ($newclassname == 'Propal') { - $newclassname = 'CommercialProposal'; - } elseif ($newclassname == 'Commande') { - $newclassname = 'Order'; - } elseif ($newclassname == 'Expedition') { - $newclassname = 'Sending'; - } elseif ($newclassname == 'Fichinter') { - $newclassname = 'Intervention'; - } - - print ''.$langs->trans($newclassname).''.$objectsrc->getNomUrl(1).''; - print ''.$langs->trans('AmountHT').''.price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency).''; - print ''.$langs->trans('AmountVAT').''.price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency).""; - if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1 - print ''.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency).""; - } - - if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2 - print ''.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency).""; - } - print ''.$langs->trans('AmountTTC').''.price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).""; - - if (isModEnabled("multicurrency")) { - print ''.$langs->trans('MulticurrencyAmountHT').''.price($objectsrc->multicurrency_total_ht).''; - print ''.$langs->trans('MulticurrencyAmountVAT').''.price($objectsrc->multicurrency_total_tva).""; - print ''.$langs->trans('MulticurrencyAmountTTC').''.price($objectsrc->multicurrency_total_ttc).""; - } - } - - print "\n"; - - - /* - * Combobox for copy function - */ - - if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) { - print ''; - } - - if (!empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) { - print '
'; - - // For backward compatibility - print ''; - print ''; - print ''; - print ''; + print ''; + $shipping_method_id = 0; + if ($socid > 0) { + print ''; + if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) { + $shipping_method_id = $soc->shipping_method_id; } - print $form->selectarray("copie_propal", $liste_propal, 0); + //$warehouse_id = $soc->warehouse_id; } else { - dol_print_error($db); + print ''; + } + print ''."\n"; + + if ($socid > 0) { + // Contacts (ask contact only if thirdparty already defined). + print ''; + + // Third party discounts info line + print ''; + } + + // Date + print ''; + + // Validaty duration + print ''; + + // Terms of payment + print ''; + + // Mode of payment + print ''; + + // Bank Account + if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && isModEnabled("banque")) { + print ''; + } + + // Source / Channel - What trigger creation + print ''; + + // Shipping Method + if (isModEnabled("expedition")) { + if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) { + $shipping_method_id = $soc->shipping_method_id; + } + print ''; + } + + // Warehouse + if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) { + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; + $formproduct = new FormProduct($db); + print ''; + } + + // Delivery delay + print ''; + + // Delivery date (or manufacturing) + print ''; + print ''; - print ''; - print ''; - print '
'.$langs->trans("CopyPropalFrom").' '; - $liste_propal = array(); - $liste_propal [0] = ''; - - $sql = "SELECT p.rowid as id, p.ref, s.nom"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal p"; - $sql .= ", ".MAIN_DB_PREFIX."societe s"; - $sql .= " WHERE s.rowid = p.fk_soc"; - $sql .= " AND p.entity IN (".getEntity('propal').")"; - $sql .= " AND p.fk_statut <> 0"; - $sql .= " ORDER BY Id"; - - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) { - $row = $db->fetch_row($resql); - $propalRefAndSocName = $row[1]." - ".$row[2]; - $liste_propal[$row[0]] = $propalRefAndSocName; - $i++; + // Third party + print '
'.$langs->trans('Customer').''; + print $soc->getNomUrl(1, 'customer'); + print ''; + print ''; + $filter = '((s.client:IN:1,2,3) AND (s.status:=:1))'; + print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company('', 'socid', $filter, 'SelectThirdParty', 1, 0, null, 0, 'minwidth300 maxwidth500 widthcentpercentminusxx'); + // reload page to retrieve customer informations + if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) { + print ''; + } + print ' '; + print '
'.$langs->trans("DefaultContact").''; + print img_picto('', 'contact', 'class="pictofixedwidth"'); + print $form->selectcontacts($soc->id, $contactid, 'contactid', 1, '', '', 0, 'minwidth300'); + print '
'.$langs->trans('Discounts').''; + + $absolute_discount = $soc->getAvailableDiscounts(); + + $thirdparty = $soc; + $discount_type = 0; + $backtopage = $_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.urlencode(GETPOST('origin')).'&originid='.urlencode(GETPOSTINT('originid')); + include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; + print '
'.$langs->trans('DatePropal').''; + print img_picto('', 'action', 'class="pictofixedwidth"'); + print $form->selectDate('', '', '', '', '', "addprop", 1, 1); + print '
'.$langs->trans("ValidityDuration").''.img_picto('', 'clock', 'class="pictofixedwidth"').' '.$langs->trans("days").'
'.$langs->trans('PaymentConditionsShort').''; + print img_picto('', 'payment', 'class="pictofixedwidth"'); + // at last resort we take the payment term id which may be filled by default values set (if not getpostisset) + print $form->getSelectConditionsPaiements($cond_reglement_id, 'cond_reglement_id', 1, 1, 0, '', $deposit_percent); + print '
'.$langs->trans('PaymentMode').''; + print img_picto('', 'bank', 'class="pictofixedwidth"'); + print $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id', 'CRDT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx', 1); + print '
'.$langs->trans('Source').''; + print img_picto('', 'question', 'class="pictofixedwidth"'); + $form->selectInputReason((GETPOSTISSET('demand_reason_id') ? GETPOST('demand_reason_id', 'int') : ''), 'demand_reason_id', "SRC_PROP", 1, 'maxwidth200 widthcentpercentminusx'); + print '
'.$langs->trans('SendingMethod').''; + print img_picto('', 'dolly', 'class="pictofixedwidth"'); + $form->selectShippingMethod((GETPOSTISSET('shipping_method_id') ? GETPOST('shipping_method_id', 'int') : $shipping_method_id), 'shipping_method_id', '', 1, '', 0, 'maxwidth200 widthcentpercentminusx'); + print '
'.$langs->trans('Warehouse').''; + print img_picto('', 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($warehouse_id, 'warehouse_id', '', 1, 0, 0, '', 0, 0, array(), 'maxwidth500 widthcentpercentminusxx'); + print '
'.$langs->trans('AvailabilityPeriod'); + if (isModEnabled('commande')) { + print ' ('.$langs->trans('AfterOrder').')'; + } + print ''; + print img_picto('', 'clock', 'class="pictofixedwidth"'); + $form->selectAvailabilityDelay((GETPOSTISSET('availability_id') ? GETPOST('availability_id', 'int') : ''), 'availability_id', '', 1, 'maxwidth200 widthcentpercentminusx'); + print '
'.$langs->trans("DeliveryDate").''; + print img_picto('', 'action', 'class="pictofixedwidth"'); + if (is_numeric(getDolGlobalString('DATE_LIVRAISON_WEEK_DELAY'))) { // If value set to 0 or a num, not empty + $tmpdte = time() + (7 * getDolGlobalInt('DATE_LIVRAISON_WEEK_DELAY') * 24 * 60 * 60); + $syear = date("Y", $tmpdte); + $smonth = date("m", $tmpdte); + $sday = date("d", $tmpdte); + print $form->selectDate($syear."-".$smonth."-".$sday, 'date_livraison', '', '', '', "addprop"); + } else { + print $form->selectDate(-1, 'date_livraison', '', '', '', "addprop", 1, 1); } print '
'.$langs->trans("CreateEmptyPropal").'
'; + // Project + if (isModEnabled('project')) { + $langs->load("projects"); + print ''; + print ''.$langs->trans("Project").''; + print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx'); + print '
id).'">'; + print ''; + print ''; + } + + // Incoterms + if (isModEnabled('incoterm')) { + print ''; + print ''; + print ''; + print img_picto('', 'incoterm', 'class="pictofixedwidth"'); + print $form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms : ''), (!empty($soc->location_incoterms) ? $soc->location_incoterms : '')); + print ''; + } + + // Template to use by default + print ''; + print ''.$langs->trans("DefaultModel").''; + print ''; + print img_picto('', 'pdf', 'class="pictofixedwidth"'); + $liste = ModelePDFPropales::liste_modeles($db); + $preselected = (!empty($conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT) ? $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT : getDolGlobalString("PROPALE_ADDON_PDF")); + print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1); + print ""; + + // Multicurrency + if (isModEnabled("multicurrency")) { + print ''; + print ''.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).''; + print ''; + print img_picto('', 'currency', 'class="pictofixedwidth"').$form->selectMultiCurrency(((GETPOSTISSET('multicurrency_code') && !GETPOST('changecompany'))?GETPOST('multicurrency_code'):$currency_code), 'multicurrency_code', 0); + print ''; + } + + // Public note + print ''; + print ''.$langs->trans('NotePublic').''; + print ''; + $note_public = $object->getDefaultCreateValueFor('note_public', (!empty($objectsrc) ? $objectsrc->note_public : (!empty($conf->global->PROPALE_ADDON_NOTE_PUBLIC_DEFAULT) ? $conf->global->PROPALE_ADDON_NOTE_PUBLIC_DEFAULT : null)), 'restricthtml'); + $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%'); + print $doleditor->Create(1); + + // Private note + if (empty($user->socid)) { + print ''; + print ''.$langs->trans('NotePrivate').''; + print ''; + $note_private = $object->getDefaultCreateValueFor('note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc)) ? $objectsrc->note_private : null)); + $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%'); + print $doleditor->Create(1); + // print ' + print ''; + } + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; + + // Lines from source + if (!empty($origin) && !empty($originid) && is_object($objectsrc)) { + // TODO for compatibility + if ($origin == 'contrat') { + // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva + //$objectsrc->remise_absolue = $remise_absolue; // deprecated + //$objectsrc->remise_percent = $remise_percent; + $objectsrc->update_price(1, 'auto', 1); + } + + print "\n"; + print "\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''; + print ''; + + $newclassname = $classname; + if ($newclassname == 'Propal') { + $newclassname = 'CommercialProposal'; + } elseif ($newclassname == 'Commande') { + $newclassname = 'Order'; + } elseif ($newclassname == 'Expedition') { + $newclassname = 'Sending'; + } elseif ($newclassname == 'Fichinter') { + $newclassname = 'Intervention'; + } + + print ''.$langs->trans($newclassname).''.$objectsrc->getNomUrl(1).''; + print ''.$langs->trans('AmountHT').''.price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency).''; + print ''.$langs->trans('AmountVAT').''.price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency).""; + if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1 + print ''.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency).""; + } + + if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2 + print ''.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency).""; + } + print ''.$langs->trans('AmountTTC').''.price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).""; + + if (isModEnabled("multicurrency")) { + print ''.$langs->trans('MulticurrencyAmountHT').''.price($objectsrc->multicurrency_total_ht).''; + print ''.$langs->trans('MulticurrencyAmountVAT').''.price($objectsrc->multicurrency_total_tva).""; + print ''.$langs->trans('MulticurrencyAmountTTC').''.price($objectsrc->multicurrency_total_ttc).""; + } + } + + print "\n"; + + + /* + * Combobox for copy function + */ + + if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) { + print ''; + } + + if (!empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) { + print '
'; + + // For backward compatibility + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print '
'.$langs->trans("CopyPropalFrom").' '; + $liste_propal = array(); + $liste_propal [0] = ''; + + $sql = "SELECT p.rowid as id, p.ref, s.nom"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal p"; + $sql .= ", ".MAIN_DB_PREFIX."societe s"; + $sql .= " WHERE s.rowid = p.fk_soc"; + $sql .= " AND p.entity IN (".getEntity('propal').")"; + $sql .= " AND p.fk_statut <> 0"; + $sql .= " ORDER BY Id"; + + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) { + $row = $db->fetch_row($resql); + $propalRefAndSocName = $row[1]." - ".$row[2]; + $liste_propal[$row[0]] = $propalRefAndSocName; + $i++; + } + print $form->selectarray("copie_propal", $liste_propal, 0); + } else { + dol_print_error($db); + } + print '
'.$langs->trans("CreateEmptyPropal").'
'; + } } print dol_get_fiche_end(); @@ -2474,479 +2480,484 @@ if ($action == 'create') { dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + // Call Hook tabContentViewProposal + $parameters = array(); + // Note that $action and $object may be modified by hook + $reshook = $hookmanager->executeHooks('tabContentViewProposal', $parameters, $object, $action); + if (empty($reshook)) { + print '
'; + print '
'; + print '
'; - print '
'; - print '
'; - print '
'; + print ''; - print '
'; - - // Link for thirdparty discounts - if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice - $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice - } else { - $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')"; - $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; - } - - print ''; - - // Date of proposal - print ''; - print ''; - // Date end proposal - print ''; - print ''; - print ''; + print ''; - print ''; + $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount); + $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote); + $absolute_discount = price2num($absolute_discount, 'MT'); + $absolute_creditnote = price2num($absolute_creditnote, 'MT'); - // Payment mode - print ''; - print ''; + $caneditfield = ($object->statut != Propal::STATUS_SIGNED && $object->statut != Propal::STATUS_BILLED); - // Delivery date - $langs->load('deliveries'); - print ''; - print ''; + $thirdparty = $soc; + $discount_type = 0; + $backtopage = $_SERVER["PHP_SELF"].'?id='.$object->id; + include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; - // Delivery delay - print ''; - print ''; - print ''; - - // Shipping Method - if (isModEnabled("expedition")) { - print ''; - print ''; - } - - // Warehouse - if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) { - $langs->load('stocks'); - require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; - $formproduct = new FormProduct($db); - print ''; - print ''; - } - - // Origin of demand - print ''; - print ''; - - // Multicurrency - if (isModEnabled("multicurrency")) { - // Multicurrency code + // Date of proposal print ''; print ''; - - // Margin Infos - if (isModEnabled('margin')) { - $formmargin->displayMarginInfos($object); - } - - - print ''; - print ''; // Close fichecenter - - print '

'; - - if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { - $blocname = 'contacts'; - $title = $langs->trans('ContactsAddresses'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } - - if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { - $blocname = 'notes'; - $title = $langs->trans('Notes'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } - - /* - * Lines - */ - - // Get object lines - $result = $object->getLinesArray(); - - // Add products/services form - //$forceall = 1; - global $inputalsopricewithtax; - $inputalsopricewithtax = 1; - - print ' - - - - - - - '; - - if (!empty($conf->use_javascript_ajax) && $object->statut == Commande::STATUS_DRAFT) { - include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; - } - - print '
'; - print '
'.$langs->trans('Discounts').''; - - $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount); - $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote); - $absolute_discount = price2num($absolute_discount, 'MT'); - $absolute_creditnote = price2num($absolute_creditnote, 'MT'); - - $caneditfield = ($object->statut != Propal::STATUS_SIGNED && $object->statut != Propal::STATUS_BILLED); - - $thirdparty = $soc; - $discount_type = 0; - $backtopage = $_SERVER["PHP_SELF"].'?id='.$object->id; - include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; - - print '
'; - // print ''; - // if ($action != 'editdate' && $usercancreate && $caneditfield) { - // print ''; - // } - - // print '
'; - // print $langs->trans('DatePropal'); - // print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; - $editenable = $usercancreate && $caneditfield && $object->statut == Propal::STATUS_DRAFT; - print $form->editfieldkey("DatePropal", 'date', '', $object, $editenable); - print '
'; - if ($action == 'editdate' && $usercancreate && $caneditfield) { - print '
'; - print ''; - print ''; - print ''; - print $form->selectDate($object->date, 're', '', '', 0, "editdate"); - print ''; - print '
'; - } else { - if ($object->date) { - print dol_print_date($object->date, 'day'); + // Link for thirdparty discounts + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { + $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice + $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice } else { - print ' '; + $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')"; + $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; } - } - print '
'; - print ''; - if ($action != 'editecheance' && $usercancreate && $caneditfield) { - print ''; - } - print '
'; - print $langs->trans('DateEndPropal'); - print 'id.'">'.img_edit($langs->trans('SetConditions'), 1).'
'; - print '
'; - if ($action == 'editecheance' && $usercancreate && $caneditfield) { - print '
'; - print ''; - print ''; - print ''; - print $form->selectDate($object->fin_validite, 'ech', '', '', '', "editecheance"); - print ''; - print '
'; - } else { - if (!empty($object->fin_validite)) { - print dol_print_date($object->fin_validite, 'day'); - if ($object->statut == Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) { - print img_warning($langs->trans("Late")); - } - } else { - print ' '; - } - } - print '
'.$langs->trans('Discounts').''; - // Payment term - print '
'; - print ''; - if ($action != 'editconditions' && $usercancreate && $caneditfield) { - print ''; - } - print '
'; - print $langs->trans('PaymentConditionsShort'); - print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'), 1).'
'; - print '
'; - if ($action == 'editconditions' && $usercancreate && $caneditfield) { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 0, '', 1, $object->deposit_percent); - } else { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 0, '', 1, $object->deposit_percent); - } - print '
'; - print ''; - if ($action != 'editmode' && $usercancreate && $caneditfield) { - print ''; - } - print '
'; - print $langs->trans('PaymentMode'); - print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'), 1).'
'; - print '
'; - if ($action == 'editmode' && $usercancreate && $caneditfield) { - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1); - } else { - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none'); - } - print '
'; - print $form->editfieldkey($langs->trans('DeliveryDate'), 'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield, 'datepicker'); - print ''; - print $form->editfieldval($langs->trans('DeliveryDate'), 'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield, 'datepicker'); - print '
'; - print ''; - if ($action != 'editavailability' && $usercancreate && $caneditfield) { - print ''; - } - print '
'; - if (isModEnabled('commande')) { - print $form->textwithpicto($langs->trans('AvailabilityPeriod'), $langs->trans('AvailabilityPeriod').' ('.$langs->trans('AfterOrder').')'); - } else { - print $langs->trans('AvailabilityPeriod'); - } - print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetAvailability'), 1).'
'; - print '
'; - if ($action == 'editavailability' && $usercancreate && $caneditfield) { - $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'availability_id', 1); - } else { - $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'none', 1); - } + print '
'; - print ''; - if ($action != 'editshippingmethod' && $usercancreate && $caneditfield) { - print ''; - } - print '
'; - print $langs->trans('SendingMethod'); - print 'id.'">'.img_edit($langs->trans('SetShippingMode'), 1).'
'; - print '
'; - if ($action == 'editshippingmethod' && $usercancreate && $caneditfield) { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); - } else { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); - } - print '
'; - $editenable = $usercancreate; - print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $editenable); - print ''; - if ($action == 'editwarehouse') { - $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1); - } else { - $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none'); - } - print '
'; - print ''; - if ($action != 'editdemandreason' && $usercancreate) { - print ''; - } - print '
'; - print $langs->trans('Source'); - print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetDemandReason'), 1).'
'; - print '
'; - if ($action == 'editdemandreason' && $usercancreate) { - $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'demand_reason_id', 1); - } else { - $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'none'); - } - print '
'; - print ''; - if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT && $usercancreate) { - print ''; + + // Date end proposal + print ''; + print ''; + print ''; + + // Payment term + print ''; + print ''; + + // Payment mode + print ''; + print ''; - // Multicurrency rate - if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { - print ''; - print '
'; - print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0); + // print ''; + // if ($action != 'editdate' && $usercancreate && $caneditfield) { + // print ''; + // } + + // print '
'; + // print $langs->trans('DatePropal'); + // print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; + $editenable = $usercancreate && $caneditfield && $object->statut == Propal::STATUS_DRAFT; + print $form->editfieldkey("DatePropal", 'date', '', $object, $editenable); + print '
'; + if ($action == 'editdate' && $usercancreate && $caneditfield) { + print '
'; + print ''; + print ''; + print ''; + print $form->selectDate($object->date, 're', '', '', 0, "editdate"); + print ''; + print '
'; + } else { + if ($object->date) { + print dol_print_date($object->date, 'day'); + } else { + print ' '; + } + } print '
id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'
'; + print ''; + if ($action != 'editecheance' && $usercancreate && $caneditfield) { + print ''; } print '
'; + print $langs->trans('DateEndPropal'); + print 'id.'">'.img_edit($langs->trans('SetConditions'), 1).'
'; print '
'; - if ($object->statut == $object::STATUS_DRAFT && $action == 'editmulticurrencycode' && $usercancreate) { - $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code'); + if ($action == 'editecheance' && $usercancreate && $caneditfield) { + print '
'; + print ''; + print ''; + print ''; + print $form->selectDate($object->fin_validite, 'ech', '', '', '', "editecheance"); + print ''; + print '
'; } else { - $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none'); + if (!empty($object->fin_validite)) { + print dol_print_date($object->fin_validite, 'day'); + if ($object->statut == Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) { + print img_warning($langs->trans("Late")); + } + } else { + print ' '; + } + } + print '
'; + print ''; + if ($action != 'editconditions' && $usercancreate && $caneditfield) { + print ''; + } + print '
'; + print $langs->trans('PaymentConditionsShort'); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'), 1).'
'; + print '
'; + if ($action == 'editconditions' && $usercancreate && $caneditfield) { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 0, '', 1, $object->deposit_percent); + } else { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 0, '', 1, $object->deposit_percent); + } + print '
'; + print ''; + if ($action != 'editmode' && $usercancreate && $caneditfield) { + print ''; + } + print '
'; + print $langs->trans('PaymentMode'); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'), 1).'
'; + print '
'; + if ($action == 'editmode' && $usercancreate && $caneditfield) { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1); + } else { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none'); } print '
'; - print ''; - print ''; + print ''; + + // Delivery delay + print ''; + print ''; + + // Shipping Method + if (isModEnabled("expedition")) { + print ''; + print ''; + print ''; } - } - if ($soc->outstanding_limit) { - // Outstanding Bill - print ''; - print ''; - } + // Warehouse + if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) { + $langs->load('stocks'); + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; + $formproduct = new FormProduct($db); + print ''; + print ''; + } - if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && isModEnabled("banque")) { - // Bank Account + // Origin of demand print ''; if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.ref']['checked'])) { print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.ref_client']['checked'])) { print_liste_field_titre($arrayfields['p.ref_client']['label'], $_SERVER["PHP_SELF"], 'p.ref_client', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['pr.ref']['checked'])) { print_liste_field_titre($arrayfields['pr.ref']['label'], $_SERVER["PHP_SELF"], 'pr.ref', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['pr.title']['checked'])) { print_liste_field_titre($arrayfields['pr.title']['label'], $_SERVER["PHP_SELF"], 'pr.title', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['s.nom']['checked'])) { print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['s.name_alias']['checked'])) { print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], 's.name_alias', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['s.town']['checked'])) { print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['s.zip']['checked'])) { print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['state.nom']['checked'])) { print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['country.code_iso']['checked'])) { print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'class="center"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['typent.code']['checked'])) { print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'class="center"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.date']['checked'])) { print_liste_field_titre($arrayfields['p.date']['label'], $_SERVER["PHP_SELF"], 'p.datep', '', $param, 'class="center"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.fin_validite']['checked'])) { print_liste_field_titre($arrayfields['p.fin_validite']['label'], $_SERVER["PHP_SELF"], 'dfv', '', $param, 'class="center"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.date_livraison']['checked'])) { print_liste_field_titre($arrayfields['p.date_livraison']['label'], $_SERVER["PHP_SELF"], 'p.date_livraison', '', $param, 'class="center"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.date_signature']['checked'])) { print_liste_field_titre($arrayfields['p.date_signature']['label'], $_SERVER["PHP_SELF"], 'p.date_signature', '', $param, 'class="center"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['ava.rowid']['checked'])) { print_liste_field_titre($arrayfields['ava.rowid']['label'], $_SERVER["PHP_SELF"], 'availability', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.fk_shipping_method']['checked'])) { print_liste_field_titre($arrayfields['p.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "p.fk_shipping_method", "", $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.fk_input_reason']['checked'])) { print_liste_field_titre($arrayfields['p.fk_input_reason']['label'], $_SERVER["PHP_SELF"], "p.fk_input_reason", "", $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) { print_liste_field_titre($arrayfields['p.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_cond_reglement", "", $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) { print_liste_field_titre($arrayfields['p.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_mode_reglement", "", $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.total_ht']['checked'])) { print_liste_field_titre($arrayfields['p.total_ht']['label'], $_SERVER["PHP_SELF"], 'p.total_ht', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.total_tva']['checked'])) { print_liste_field_titre($arrayfields['p.total_tva']['label'], $_SERVER["PHP_SELF"], 'p.total_tva', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.total_ttc']['checked'])) { print_liste_field_titre($arrayfields['p.total_ttc']['label'], $_SERVER["PHP_SELF"], 'p.total_ttc', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) { print_liste_field_titre($arrayfields['p.total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.total_invoiced']['checked'])) { print_liste_field_titre($arrayfields['p.total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.multicurrency_code']['checked'])) { print_liste_field_titre($arrayfields['p.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_code', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.multicurrency_tx']['checked'])) { print_liste_field_titre($arrayfields['p.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_tx', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) { print_liste_field_titre($arrayfields['p.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) { print_liste_field_titre($arrayfields['p.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) { print_liste_field_titre($arrayfields['p.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) { print_liste_field_titre($arrayfields['p.multicurrency_total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) { print_liste_field_titre($arrayfields['p.multicurrency_total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['u.login']['checked'])) { print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'class="center"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['sale_representative']['checked'])) { print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['total_pa']['checked'])) { print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['total_margin']['checked'])) { print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['total_margin_rate']['checked'])) { print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['total_mark_rate']['checked'])) { print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; @@ -1612,30 +1656,38 @@ if ($resql) { print $hookmanager->resPrint; if (!empty($arrayfields['p.datec']['checked'])) { print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.tms']['checked'])) { print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.date_cloture']['checked'])) { print_liste_field_titre($arrayfields['p.date_cloture']['label'], $_SERVER["PHP_SELF"], "p.date_cloture", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.note_public']['checked'])) { print_liste_field_titre($arrayfields['p.note_public']['label'], $_SERVER["PHP_SELF"], "p.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.note_private']['checked'])) { print_liste_field_titre($arrayfields['p.note_private']['label'], $_SERVER["PHP_SELF"], "p.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + $totalarray['nbfield']++; } if (!empty($arrayfields['p.fk_statut']['checked'])) { print_liste_field_titre($arrayfields['p.fk_statut']['label'], $_SERVER["PHP_SELF"], "p.fk_statut", "", $param, 'class="right"', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); + $totalarray['nbfield']++; } print ''."\n"; - $now = dol_now(); - $i = 0; + // Loop on record + // -------------------------------------------------------------------- $typenArray = null; + $now = dol_now(); $with_margin_info = false; if (isModEnabled('margin') && ( @@ -1650,13 +1702,16 @@ if ($resql) { $total_ht = 0; $total_margin = 0; + $i = 0; $savnbfield = $totalarray['nbfield']; $totalarray = array(); $totalarray['nbfield'] = 0; - $imaxinloop = ($limit ? min($num, $limit) : $num); while ($i < $imaxinloop) { $obj = $db->fetch_object($resql); + if (empty($obj)) { + break; // Should not happen + } $objectstatic->id = $obj->rowid; $objectstatic->ref = $obj->ref; @@ -1721,9 +1776,8 @@ if ($resql) { } // Output Kanban $userstatic->fetch($obj->fk_user_author); - $objectstatic->author = $userstatic->getNomUrl(1); - $objectstatic->fk_project = $projectstatic->getNomUrl(1); - print $objectstatic->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected))); + $arrayofparams = array('selected' => in_array($object->id, $arrayofselected), 'authorlink' => $userstatic->getNomUrl(-2), 'projectlink' => $projectstatic->getNomUrl(2)); + print $objectstatic->getKanbanView('', $arrayofparams); if ($i == ($imaxinloop - 1)) { print ''; print ''; @@ -2326,24 +2380,26 @@ if ($resql) { print ''."\n"; - $hidegeneratedfilelistifempty = 1; - if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { - $hidegeneratedfilelistifempty = 0; + if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) { + $hidegeneratedfilelistifempty = 1; + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { + $hidegeneratedfilelistifempty = 0; + } + + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; + $formfile = new FormFile($db); + + // Show list of available documents + $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; + $urlsource .= str_replace('&', '&', $param); + + $filedir = $diroutputmassaction; + $genallowed = $permissiontoread; + $delallowed = $permissiontoadd; + + print $formfile->showdocuments('massfilesarea_proposals', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); } - // Show list of available documents - $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; - $urlsource .= str_replace('&', '&', $param); - - $filedir = $diroutputmassaction; - $genallowed = $user->hasRight('propal', 'lire'); - $delallowed = $user->hasRight('propal', 'creer'); - - print $formfile->showdocuments('massfilesarea_proposals', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); -} else { - dol_print_error($db); -} - -// End of page -llxFooter(); -$db->close(); + // End of page + llxFooter(); + $db->close(); diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 5b3449ea5df..b6fd2fec085 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -6,7 +6,7 @@ * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2013 Juanjo Menent * Copyright (C) 2011-2023 Philippe Grand - * Copyright (C) 2012-2013 Christophe Battarel + * Copyright (C) 2012-2023 Christophe Battarel * Copyright (C) 2012-2016 Marcos García * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013 Florian Henry @@ -1026,11 +1026,11 @@ if (empty($reshook)) { // Check price is not lower than minimum if ($usermustrespectpricemin) { - if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) { + if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min)) && $price_base_type == 'HT') { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)); setEventMessages($mesg, null, 'errors'); $error++; - } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) { + } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc)) && $price_base_type == 'TTC') { $mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)); setEventMessages($mesg, null, 'errors'); $error++; @@ -1195,12 +1195,12 @@ if (empty($reshook)) { // Check price is not lower than minimum if ($usermustrespectpricemin) { - if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) { + if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min)) && $price_base_type == 'HT') { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)); setEventMessages($mesg, null, 'errors'); $error++; $action = 'editline'; - } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) { + } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc)) && $price_base_type == 'TTC') { $mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)); setEventMessages($mesg, null, 'errors'); $error++; @@ -1319,7 +1319,9 @@ if (empty($reshook)) { if (!$error) { $locationTarget = ''; + $db->begin(); + $result = $object->valid($user, $idwarehouse); if ($result >= 0) { $error = 0; @@ -1814,289 +1816,295 @@ if ($action == 'create' && $usercancreate) { print dol_get_fiche_head(''); - print '
'; - print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0); + // Delivery date + $langs->load('deliveries'); + print '
'; + print $form->editfieldkey($langs->trans('DeliveryDate'), 'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield, 'datepicker'); + print ''; + print $form->editfieldval($langs->trans('DeliveryDate'), 'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield, 'datepicker'); + print '
'; + print ''; + if ($action != 'editavailability' && $usercancreate && $caneditfield) { + print ''; + } + print '
'; + if (isModEnabled('commande')) { + print $form->textwithpicto($langs->trans('AvailabilityPeriod'), $langs->trans('AvailabilityPeriod').' ('.$langs->trans('AfterOrder').')'); + } else { + print $langs->trans('AvailabilityPeriod'); + } + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetAvailability'), 1).'
'; + print '
'; + if ($action == 'editavailability' && $usercancreate && $caneditfield) { + $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'availability_id', 1); + } else { + $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'none', 1); + } + + print '
'; + print ''; - if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $usercancreate) { - print ''; + if ($action != 'editshippingmethod' && $usercancreate && $caneditfield) { + print ''; } print '
'; + print $langs->trans('SendingMethod'); print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'id.'">'.img_edit($langs->trans('SetShippingMode'), 1).'
'; print '
'; - if ($object->statut == $object::STATUS_DRAFT && ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') && $usercancreate) { - if ($action == 'actualizemulticurrencyrate') { - list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); - } - $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code); + if ($action == 'editshippingmethod' && $usercancreate && $caneditfield) { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); } else { - $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); - if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { - print '
        '; - print ''.$langs->trans("ActualizeCurrency").''; - print '
'; - } + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); } - print '
'; - print $langs->trans('OutstandingBill'); - print ''; - $arrayoutstandingbills = $soc->getOutstandingBills(); - print ($arrayoutstandingbills['opened'] > $soc->outstanding_limit ? img_warning() : ''); - print price($arrayoutstandingbills['opened']).' / '; - print price($soc->outstanding_limit, 0, $langs, 1, - 1, - 1, $conf->currency); - print '
'; + $editenable = $usercancreate; + print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $editenable); + print ''; + if ($action == 'editwarehouse') { + $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1); + } else { + $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none'); + } + print '
'; - print ''; print ''; - } - $tmparray = $object->getTotalWeightVolume(); - $totalWeight = $tmparray['weight']; - $totalVolume = $tmparray['volume']; - if ($totalWeight) { - print ''; - print ''; - } - if ($totalVolume) { - print ''; - print ''; - } - - // Incoterms - if (isModEnabled('incoterm')) { - print ''; - print ''; - } - - // Other attributes - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; - - print '
'; - print $langs->trans('BankAccount'); + print ''; - if ($action != 'editbankaccount' && $usercancreate) { - print ''; + if ($action != 'editdemandreason' && $usercancreate) { + print ''; } print '
'; + print $langs->trans('Source'); print 'id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'id.'">'.img_edit($langs->transnoentitiesnoconv('SetDemandReason'), 1).'
'; print '
'; - if ($action == 'editbankaccount') { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + if ($action == 'editdemandreason' && $usercancreate) { + $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'demand_reason_id', 1); } else { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'none'); } print '
'.$langs->trans("CalculatedWeight").''; - print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no', 0); - print '
'.$langs->trans("CalculatedVolume").''; - print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no', 0); - print '
'; - print '
'; - print $langs->trans('IncotermLabel'); - print ''; - if ($action != 'editincoterm' && $usercancreate && $caneditfield) { - print ''.img_edit().''; - } else { - print ' '; - } - print '
'; - print '
'; - if ($action == 'editincoterm' && $usercancreate && $caneditfield) { - print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id); - } else { - print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); - } - print '
'; - - print ''; - print '
'; - print '
'; - - print ''; - - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; - } - print ''; - - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; - } - print ''; - - if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; - } - print ''; - - if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { + // Multicurrency + if (isModEnabled("multicurrency")) { + // Multicurrency code print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; + print ''; + + // Multicurrency rate + if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { + print ''; + print ''; + } + } + + if ($soc->outstanding_limit) { + // Outstanding Bill + print ''; print ''; } - } - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; - } - print ''; - - print '
' . $langs->trans('AmountHT') . '' . price($object->total_ht, '', $langs, 1, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_ht, '', $langs, 1, -1, -1, $object->multicurrency_code) . '
' . $langs->trans('AmountVAT') . '' . price($object->total_tva, '', $langs, 1, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_tva, '', $langs, 1, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($object->total_localtax1, '', $langs, 1, -1, -1, $conf->currency) . '' . price($object->total_localtax1, '', $langs, 1, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($object->total_localtax2, '', $langs, 1, -1, -1, $conf->currency) . '' . price($object->total_localtax2, '', $langs, 1, -1, -1, $object->multicurrency_code) . ''; + print ''; + if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT && $usercancreate) { + print ''; } + print '
'; + print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'
'; + print '
'; + if ($object->statut == $object::STATUS_DRAFT && $action == 'editmulticurrencycode' && $usercancreate) { + $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code'); + } else { + $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none'); + } + print '
'; + print ''; + print ''; + if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $usercancreate) { + print ''; + } + print '
'; + print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'
'; + print '
'; + if ($object->statut == $object::STATUS_DRAFT && ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') && $usercancreate) { + if ($action == 'actualizemulticurrencyrate') { + list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); + } + $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code); + } else { + $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); + if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { + print '
        '; + print ''.$langs->trans("ActualizeCurrency").''; + print '
'; + } + } + print '
'; + print $langs->trans('OutstandingBill'); + print ''; + $arrayoutstandingbills = $soc->getOutstandingBills(); + print ($arrayoutstandingbills['opened'] > $soc->outstanding_limit ? img_warning() : ''); + print price($arrayoutstandingbills['opened']).' / '; + print price($soc->outstanding_limit, 0, $langs, 1, - 1, - 1, $conf->currency); + print '
' . $langs->trans('AmountTTC') . '' . price($object->total_ttc, '', $langs, 1, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_ttc, '', $langs, 1, -1, -1, $object->multicurrency_code) . '
'; - - // Margin Infos - if (isModEnabled('margin')) { - $formmargin->displayMarginInfos($object); - } - - print '
'; - print ''; - - print '

'; - - if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { - $blocname = 'contacts'; - $title = $langs->trans('ContactsAddresses'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } - - if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { - $blocname = 'notes'; - $title = $langs->trans('Notes'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } - - /* - * Lines - */ - - // Get object lines - $result = $object->getLinesArray(); - - // Add products/services form - //$forceall = 1; - global $inputalsopricewithtax; - $inputalsopricewithtax = 1; - - print '
- - - - - - - '; - - if (!empty($conf->use_javascript_ajax) && $object->statut == Propal::STATUS_DRAFT) { - include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; - } - - print '
'; - if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline')) { - print ''; - } - - if (!empty($object->lines)) { - $object->printObjectLines($action, $mysoc, $object->thirdparty, $lineid, 1); - } - - // Form to add new line - if ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines') { - if ($action != 'editline') { - $parameters = array(); - $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - if (empty($reshook)) - $object->formAddObjectLine(1, $mysoc, $soc); - } else { - $parameters = array(); - $reshook = $hookmanager->executeHooks('formEditObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && isModEnabled("banque")) { + // Bank Account + print ''; + print ''; } - } - if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline')) { + $tmparray = $object->getTotalWeightVolume(); + $totalWeight = $tmparray['weight']; + $totalVolume = $tmparray['volume']; + if ($totalWeight) { + print ''; + print ''; + } + if ($totalVolume) { + print ''; + print ''; + } + + // Incoterms + if (isModEnabled('incoterm')) { + print ''; + print ''; + } + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + print '
'; + print ''; + if ($action != 'editbankaccount' && $usercancreate) { + print ''; + } + print '
'; + print $langs->trans('BankAccount'); + print 'id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'
'; + print '
'; + if ($action == 'editbankaccount') { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + } else { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + } + print '
'.$langs->trans("CalculatedWeight").''; + print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no', 0); + print '
'.$langs->trans("CalculatedVolume").''; + print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no', 0); + print '
'; + print '
'; + print $langs->trans('IncotermLabel'); + print ''; + if ($action != 'editincoterm' && $usercancreate && $caneditfield) { + print ''.img_edit().''; + } else { + print ' '; + } + print '
'; + print '
'; + if ($action == 'editincoterm' && $usercancreate && $caneditfield) { + print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id); + } else { + print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); + } + print '
'; - } - print '
'; - print "
\n"; + print ''; + print '
'; + print '
'; + + print ''; + + print ''; + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + print ''; + } + print ''; + + print ''; + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + print ''; + } + print ''; + + if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { + print ''; + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + print ''; + } + print ''; + + if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { + print ''; + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + print ''; + } + print ''; + } + } + + print ''; + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + print ''; + } + print ''; + + print '
' . $langs->trans('AmountHT') . '' . price($object->total_ht, '', $langs, 1, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_ht, '', $langs, 1, -1, -1, $object->multicurrency_code) . '
' . $langs->trans('AmountVAT') . '' . price($object->total_tva, '', $langs, 1, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_tva, '', $langs, 1, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($object->total_localtax1, '', $langs, 1, -1, -1, $conf->currency) . '' . price($object->total_localtax1, '', $langs, 1, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($object->total_localtax2, '', $langs, 1, -1, -1, $conf->currency) . '' . price($object->total_localtax2, '', $langs, 1, -1, -1, $object->multicurrency_code) . '
' . $langs->trans('AmountTTC') . '' . price($object->total_ttc, '', $langs, 1, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_ttc, '', $langs, 1, -1, -1, $object->multicurrency_code) . '
'; + + // Margin Infos + if (isModEnabled('margin')) { + $formmargin->displayMarginInfos($object); + } + + print '
'; + print ''; + + print '

'; + + if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { + $blocname = 'contacts'; + $title = $langs->trans('ContactsAddresses'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { + $blocname = 'notes'; + $title = $langs->trans('Notes'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + /* + * Lines + */ + + // Get object lines + $result = $object->getLinesArray(); + + // Add products/services form + //$forceall = 1; + global $inputalsopricewithtax; + $inputalsopricewithtax = 1; + + print '
+ + + + + + + '; + + if (!empty($conf->use_javascript_ajax) && $object->statut == Propal::STATUS_DRAFT) { + include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; + } + + print '
'; + if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline')) { + print ''; + } + + if (!empty($object->lines)) { + $object->printObjectLines($action, $mysoc, $object->thirdparty, $lineid, 1); + } + + // Form to add new line + if ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines') { + if ($action != 'editline') { + $parameters = array(); + $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if (empty($reshook)) + $object->formAddObjectLine(1, $mysoc, $soc); + } else { + $parameters = array(); + $reshook = $hookmanager->executeHooks('formEditObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + } + } + + if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline')) { + print '
'; + } + print '
'; + + print "
\n"; + } print dol_get_fiche_end(); diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index b122114793c..a672e19d351 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -2045,6 +2045,12 @@ class Propal extends CommonObject $error++; $this->error = $this->db->lasterror(); } + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'propale/".$this->db->escape($this->newref)."'"; + $sql .= " WHERE filepath = 'propale/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (!$resql) { + $error++; $this->error = $this->db->lasterror(); + } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); @@ -2474,6 +2480,7 @@ class Propal extends CommonObject * @return int <0 if ko, >0 if ok * @deprecated remise_percent is a deprecated field for object parent */ + /* public function set_remise_percent($user, $remise, $notrigger = 0) { // phpcs:enable @@ -2526,7 +2533,7 @@ class Propal extends CommonObject return -1; } - + */ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** @@ -3153,6 +3160,7 @@ class Propal extends CommonObject // Delete record into ECM index and physically if (!$error) { $res = $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive + $res = $this->deleteEcmFiles(1); // Deleting files physically is done later with the dol_delete_dir_recursive if (!$res) { $error++; } @@ -3175,7 +3183,7 @@ class Propal extends CommonObject } } if (file_exists($dir)) { - $res = @dol_delete_dir_recursive($dir); + $res = @dol_delete_dir_recursive($dir); // delete files physically + into ecm tables if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $this->errors[] = $this->error; @@ -4003,17 +4011,17 @@ class Propal extends CommonObject if ($selected >= 0) { $return .= ''; } - if (property_exists($this, 'fk_project')) { - $return .= ' | '.$this->fk_project.''; + if (!empty($arraydata['projectlink'])) { + $return .= ' | '.$arraydata['projectlink'].''; } - if (property_exists($this, 'author')) { - $return .= '
'.$this->author.''; + if (!empty($arraydata['authorlink'])) { + $return .= '
'.$arraydata['authorlink'].''; } if (property_exists($this, 'total_ht')) { - $return .='
'.$langs->trans("AmountHT").' : '.price($this->total_ht).''; + $return .='
'.price($this->total_ht).''; } if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; + $return .= '
'.$this->getLibStatut(3).'
'; } $return .= ''; $return .= ''; diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index db1cd738592..6424a67f38c 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -317,85 +317,86 @@ if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } -include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; - -// Do we click on purge search criteria ? -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers - $search_categ = ''; - $search_user = ''; - $search_sale = ''; - $search_ref = ''; - $search_refcustomer = ''; - $search_refproject = ''; - $search_project = ''; - $search_societe = ''; - $search_societe_alias = ''; - $search_montant_ht = ''; - $search_montant_vat = ''; - $search_montant_ttc = ''; - $search_warehouse = ''; - $search_multicurrency_code = ''; - $search_multicurrency_tx = ''; - $search_multicurrency_montant_ht = ''; - $search_multicurrency_montant_vat = ''; - $search_multicurrency_montant_ttc = ''; - $search_login = ''; - $search_product_category = ''; - $search_town = ''; - $search_zip = ""; - $search_state = ""; - $search_type = ''; - $search_country = ''; - $search_type_thirdparty = ''; - $search_date_startday = ''; - $search_date_startmonth = ''; - $search_date_startyear = ''; - $search_date_endday = ''; - $search_date_endmonth = ''; - $search_date_endyear = ''; - $search_date_start = ''; - $search_date_end = ''; - $search_date_end_startday = ''; - $search_date_end_startmonth = ''; - $search_date_end_startyear = ''; - $search_date_end_endday = ''; - $search_date_end_endmonth = ''; - $search_date_end_endyear = ''; - $search_date_end_start = ''; - $search_date_end_end = ''; - $search_date_delivery_startday = ''; - $search_date_delivery_startmonth = ''; - $search_date_delivery_startyear = ''; - $search_date_delivery_endday = ''; - $search_date_delivery_endmonth = ''; - $search_date_delivery_endyear = ''; - $search_date_delivery_start = ''; - $search_date_delivery_end = ''; - $search_availability = ''; - $search_status = ''; - $object_statut = ''; - $toselect = array(); - $search_array_options = array(); - $search_categ_cus = 0; - $search_fk_cond_reglement = ''; - $search_fk_shipping_method = ''; - $search_fk_input_reason = ''; - $search_fk_mode_reglement = ''; - $search_date_signature_startday = ''; - $search_date_signature_startmonth = ''; - $search_date_signature_startyear = ''; - $search_date_signature_endday = ''; - $search_date_signature_endmonth = ''; - $search_date_signature_endyear = ''; - $search_date_signature_start = ''; - $search_date_signature_end = ''; -} -if ($object_statut != '') { - $search_status = $object_statut; -} - - if (empty($reshook)) { + // Selection of new fields + include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + + // Purge search criteria + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers + $search_categ = ''; + $search_user = ''; + $search_sale = ''; + $search_ref = ''; + $search_refcustomer = ''; + $search_refproject = ''; + $search_project = ''; + $search_societe = ''; + $search_societe_alias = ''; + $search_montant_ht = ''; + $search_montant_vat = ''; + $search_montant_ttc = ''; + $search_warehouse = ''; + $search_multicurrency_code = ''; + $search_multicurrency_tx = ''; + $search_multicurrency_montant_ht = ''; + $search_multicurrency_montant_vat = ''; + $search_multicurrency_montant_ttc = ''; + $search_login = ''; + $search_product_category = ''; + $search_town = ''; + $search_zip = ""; + $search_state = ""; + $search_type = ''; + $search_country = ''; + $search_type_thirdparty = ''; + $search_date_startday = ''; + $search_date_startmonth = ''; + $search_date_startyear = ''; + $search_date_endday = ''; + $search_date_endmonth = ''; + $search_date_endyear = ''; + $search_date_start = ''; + $search_date_end = ''; + $search_date_end_startday = ''; + $search_date_end_startmonth = ''; + $search_date_end_startyear = ''; + $search_date_end_endday = ''; + $search_date_end_endmonth = ''; + $search_date_end_endyear = ''; + $search_date_end_start = ''; + $search_date_end_end = ''; + $search_date_delivery_startday = ''; + $search_date_delivery_startmonth = ''; + $search_date_delivery_startyear = ''; + $search_date_delivery_endday = ''; + $search_date_delivery_endmonth = ''; + $search_date_delivery_endyear = ''; + $search_date_delivery_start = ''; + $search_date_delivery_end = ''; + $search_availability = ''; + $search_status = ''; + $object_statut = ''; + $search_categ_cus = 0; + $search_fk_cond_reglement = ''; + $search_fk_shipping_method = ''; + $search_fk_input_reason = ''; + $search_fk_mode_reglement = ''; + $search_date_signature_startday = ''; + $search_date_signature_startmonth = ''; + $search_date_signature_startyear = ''; + $search_date_signature_endday = ''; + $search_date_signature_endmonth = ''; + $search_date_signature_endyear = ''; + $search_date_signature_start = ''; + $search_date_signature_end = ''; + $toselect = array(); + $search_array_options = array(); + } + if ($object_statut != '') { + $search_status = $object_statut; + } + + // Mass actions $objectclass = 'Propal'; $objectlabel = 'Proposals'; $uploaddir = $conf->propal->multidir_output[$conf->entity]; @@ -828,6 +829,7 @@ if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { $db->free($resql); } +// Complete request and execute it with limit $sql .= $db->order($sortfield, $sortorder); $sql .= ', p.ref DESC'; if ($limit) { @@ -835,213 +837,216 @@ if ($limit) { } $resql = $db->query($sql); +if (!$resql) { + dol_print_error($db); + exit; +} -if ($resql) { $objectstatic = new Propal($db); $userstatic = new User($db); - if ($socid > 0) { - $soc = new Societe($db); - $soc->fetch($socid); - $title = $langs->trans('Proposals').' - '.$soc->name; - if (empty($search_societe)) { - $search_societe = $soc->name; - } - } else { - $title = $langs->trans('Proposals'); +if ($socid > 0) { + $soc = new Societe($db); + $soc->fetch($socid); + $title = $langs->trans('Proposals').' - '.$soc->name; + if (empty($search_societe)) { + $search_societe = $soc->name; } +} else { + $title = $langs->trans('Proposals'); +} $num = $db->num_rows($resql); $arrayofselected = is_array($toselect) ? $toselect : array(); - if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) { - $obj = $db->fetch_object($resql); +if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) { + $obj = $db->fetch_object($resql); - $id = $obj->rowid; + $id = $obj->rowid; - header("Location: ".DOL_URL_ROOT.'/comm/propal/card.php?id='.$id); - exit; - } + header("Location: ".DOL_URL_ROOT.'/comm/propal/card.php?id='.$id); + exit; +} $help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos'; llxHeader('', $title, $help_url); $param = '&search_status='.urlencode($search_status); - if (!empty($mode)) { - $param .= '&mode='.urlencode($mode); - } - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { - $param .= '&contextpage='.urlencode($contextpage); - } - if ($limit > 0 && $limit != $conf->liste_limit) { - $param .= '&limit='.((int) $limit); - } - if ($sall) { - $param .= '&sall='.urlencode($sall); - } - if ($search_date_startday) { - $param .= '&search_date_startday='.urlencode($search_date_startday); - } - if ($search_date_startmonth) { - $param .= '&search_date_startmonth='.urlencode($search_date_startmonth); - } - if ($search_date_startyear) { - $param .= '&search_date_startyear='.urlencode($search_date_startyear); - } - if ($search_date_endday) { - $param .= '&search_date_endday='.urlencode($search_date_endday); - } - if ($search_date_endmonth) { - $param .= '&search_date_endmonth='.urlencode($search_date_endmonth); - } - if ($search_date_endyear) { - $param .= '&search_date_endyear='.urlencode($search_date_endyear); - } - if ($search_date_end_startday) { - $param .= '&search_date_end_startday='.urlencode($search_date_end_startday); - } - if ($search_date_end_startmonth) { - $param .= '&search_date_end_startmonth='.urlencode($search_date_end_startmonth); - } - if ($search_date_end_startyear) { - $param .= '&search_date_end_startyear='.urlencode($search_date_end_startyear); - } - if ($search_date_end_endday) { - $param .= '&search_date_end_endday='.urlencode($search_date_end_endday); - } - if ($search_date_end_endmonth) { - $param .= '&search_date_end_endmonth='.urlencode($search_date_end_endmonth); - } - if ($search_date_end_endyear) { - $param .= '&search_date_end_endyear='.urlencode($search_date_end_endyear); - } - if ($search_date_delivery_startday) { - $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday); - } - if ($search_date_delivery_startmonth) { - $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth); - } - if ($search_date_delivery_startyear) { - $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear); - } - if ($search_date_delivery_endday) { - $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday); - } - if ($search_date_delivery_endmonth) { - $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth); - } - if ($search_date_delivery_endyear) { - $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear); - } - if ($search_ref) { - $param .= '&search_ref='.urlencode($search_ref); - } - if ($search_refcustomer) { - $param .= '&search_refcustomer='.urlencode($search_refcustomer); - } - if ($search_refproject) { - $param .= '&search_refproject='.urlencode($search_refproject); - } - if ($search_societe) { - $param .= '&search_societe='.urlencode($search_societe); - } - if ($search_societe_alias) { - $param .= '&search_societe_alias='.urlencode($search_societe_alias); - } - if ($search_user > 0) { - $param .= '&search_user='.urlencode($search_user); - } - if ($search_sale > 0) { - $param .= '&search_sale='.urlencode($search_sale); - } - if ($search_montant_ht) { - $param .= '&search_montant_ht='.urlencode($search_montant_ht); - } - if ($search_multicurrency_code != '') { - $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code); - } - if ($search_multicurrency_tx != '') { - $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx); - } - if ($search_multicurrency_montant_ht != '') { - $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht); - } - if ($search_multicurrency_montant_vat != '') { - $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat); - } - if ($search_multicurrency_montant_ttc != '') { - $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc); - } - if ($search_login) { - $param .= '&search_login='.urlencode($search_login); - } - if ($search_town) { - $param .= '&search_town='.urlencode($search_town); - } - if ($search_zip) { - $param .= '&search_zip='.urlencode($search_zip); - } - if ($socid > 0) { - $param .= '&socid='.urlencode($socid); - } - if ($optioncss != '') { - $param .= '&optioncss='.urlencode($optioncss); - } - if ($search_categ_cus > 0) { - $param .= '&search_categ_cus='.urlencode($search_categ_cus); - } - if ($search_product_category != '') { - $param .= '&search_product_category='.urlencode($search_product_category); - } - if ($search_fk_cond_reglement > 0) { - $param .= '&search_fk_cond_reglement='.urlencode($search_fk_cond_reglement); - } - if ($search_fk_shipping_method > 0) { - $param .= '&search_fk_shipping_method='.urlencode($search_fk_shipping_method); - } - if ($search_fk_input_reason > 0) { - $param .= '&search_fk_input_reason='.urlencode($search_fk_input_reason); - } - if ($search_fk_mode_reglement > 0) { - $param .= '&search_fk_mode_reglement='.urlencode($search_fk_mode_reglement); - } - if ($search_type_thirdparty > 0) { - $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty); - } - if ($search_town) { - $param .= '&search_town='.urlencode($search_town); - } - if ($search_zip) { - $param .= '&search_zip='.urlencode($search_zip); - } - if ($search_state) { - $param .= '&search_state='.urlencode($search_state); - } - if ($search_town) { - $param .= '&search_town='.urlencode($search_town); - } - if ($search_country) { - $param .= '&search_country='.urlencode($search_country); - } - if ($search_date_signature_startday) { - $param .= '&search_date_signature_startday='.urlencode($search_date_signature_startday); - } - if ($search_date_signature_startmonth) { - $param .= '&search_date_signature_startmonth='.urlencode($search_date_signature_startmonth); - } - if ($search_date_signature_startyear) { - $param .= '&search_date_signature_startyear='.urlencode($search_date_signature_startyear); - } - if ($search_date_signature_endday) { - $param .= '&search_date_signature_endday='.urlencode($search_date_signature_endday); - } - if ($search_date_signature_endmonth) { - $param .= '&search_date_signature_endmonth='.urlencode($search_date_signature_endmonth); - } - if ($search_date_signature_endyear) { - $param .= '&search_date_signature_endyear='.urlencode($search_date_signature_endyear); - } +if (!empty($mode)) { + $param .= '&mode='.urlencode($mode); +} +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); +} +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.((int) $limit); +} +if ($sall) { + $param .= '&sall='.urlencode($sall); +} +if ($search_date_startday) { + $param .= '&search_date_startday='.urlencode($search_date_startday); +} +if ($search_date_startmonth) { + $param .= '&search_date_startmonth='.urlencode($search_date_startmonth); +} +if ($search_date_startyear) { + $param .= '&search_date_startyear='.urlencode($search_date_startyear); +} +if ($search_date_endday) { + $param .= '&search_date_endday='.urlencode($search_date_endday); +} +if ($search_date_endmonth) { + $param .= '&search_date_endmonth='.urlencode($search_date_endmonth); +} +if ($search_date_endyear) { + $param .= '&search_date_endyear='.urlencode($search_date_endyear); +} +if ($search_date_end_startday) { + $param .= '&search_date_end_startday='.urlencode($search_date_end_startday); +} +if ($search_date_end_startmonth) { + $param .= '&search_date_end_startmonth='.urlencode($search_date_end_startmonth); +} +if ($search_date_end_startyear) { + $param .= '&search_date_end_startyear='.urlencode($search_date_end_startyear); +} +if ($search_date_end_endday) { + $param .= '&search_date_end_endday='.urlencode($search_date_end_endday); +} +if ($search_date_end_endmonth) { + $param .= '&search_date_end_endmonth='.urlencode($search_date_end_endmonth); +} +if ($search_date_end_endyear) { + $param .= '&search_date_end_endyear='.urlencode($search_date_end_endyear); +} +if ($search_date_delivery_startday) { + $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday); +} +if ($search_date_delivery_startmonth) { + $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth); +} +if ($search_date_delivery_startyear) { + $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear); +} +if ($search_date_delivery_endday) { + $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday); +} +if ($search_date_delivery_endmonth) { + $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth); +} +if ($search_date_delivery_endyear) { + $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear); +} +if ($search_ref) { + $param .= '&search_ref='.urlencode($search_ref); +} +if ($search_refcustomer) { + $param .= '&search_refcustomer='.urlencode($search_refcustomer); +} +if ($search_refproject) { + $param .= '&search_refproject='.urlencode($search_refproject); +} +if ($search_societe) { + $param .= '&search_societe='.urlencode($search_societe); +} +if ($search_societe_alias) { + $param .= '&search_societe_alias='.urlencode($search_societe_alias); +} +if ($search_user > 0) { + $param .= '&search_user='.urlencode($search_user); +} +if ($search_sale > 0) { + $param .= '&search_sale='.urlencode($search_sale); +} +if ($search_montant_ht) { + $param .= '&search_montant_ht='.urlencode($search_montant_ht); +} +if ($search_multicurrency_code != '') { + $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code); +} +if ($search_multicurrency_tx != '') { + $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx); +} +if ($search_multicurrency_montant_ht != '') { + $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht); +} +if ($search_multicurrency_montant_vat != '') { + $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat); +} +if ($search_multicurrency_montant_ttc != '') { + $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc); +} +if ($search_login) { + $param .= '&search_login='.urlencode($search_login); +} +if ($search_town) { + $param .= '&search_town='.urlencode($search_town); +} +if ($search_zip) { + $param .= '&search_zip='.urlencode($search_zip); +} +if ($socid > 0) { + $param .= '&socid='.urlencode($socid); +} +if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); +} +if ($search_categ_cus > 0) { + $param .= '&search_categ_cus='.urlencode($search_categ_cus); +} +if ($search_product_category != '') { + $param .= '&search_product_category='.urlencode($search_product_category); +} +if ($search_fk_cond_reglement > 0) { + $param .= '&search_fk_cond_reglement='.urlencode($search_fk_cond_reglement); +} +if ($search_fk_shipping_method > 0) { + $param .= '&search_fk_shipping_method='.urlencode($search_fk_shipping_method); +} +if ($search_fk_input_reason > 0) { + $param .= '&search_fk_input_reason='.urlencode($search_fk_input_reason); +} +if ($search_fk_mode_reglement > 0) { + $param .= '&search_fk_mode_reglement='.urlencode($search_fk_mode_reglement); +} +if ($search_type_thirdparty > 0) { + $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty); +} +if ($search_town) { + $param .= '&search_town='.urlencode($search_town); +} +if ($search_zip) { + $param .= '&search_zip='.urlencode($search_zip); +} +if ($search_state) { + $param .= '&search_state='.urlencode($search_state); +} +if ($search_town) { + $param .= '&search_town='.urlencode($search_town); +} +if ($search_country) { + $param .= '&search_country='.urlencode($search_country); +} +if ($search_date_signature_startday) { + $param .= '&search_date_signature_startday='.urlencode($search_date_signature_startday); +} +if ($search_date_signature_startmonth) { + $param .= '&search_date_signature_startmonth='.urlencode($search_date_signature_startmonth); +} +if ($search_date_signature_startyear) { + $param .= '&search_date_signature_startyear='.urlencode($search_date_signature_startyear); +} +if ($search_date_signature_endday) { + $param .= '&search_date_signature_endday='.urlencode($search_date_signature_endday); +} +if ($search_date_signature_endmonth) { + $param .= '&search_date_signature_endmonth='.urlencode($search_date_signature_endmonth); +} +if ($search_date_signature_endyear) { + $param .= '&search_date_signature_endyear='.urlencode($search_date_signature_endyear); +} // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -1481,120 +1486,159 @@ if ($resql) { print '
'; - - // Reference - print ''; - - // Reference client - print ''; - } else { - print ''; - } - print ''; - - // Thirdparty - print ''; - print ''; - if ($socid > 0) { - print ''; - } else { - print ''; - } - print ''."\n"; - - // Contact of order - if ($socid > 0) { - // Contacts (ask contact only if thirdparty already defined). - print "'; - - // Ligne info remises tiers - print ''; - } - - // Date - print ''; - - // Date delivery planned - print ''; - print '\n"; - print ''; - - // Delivery delay - print ''; - - // Terms of payment - print ''; - - // Payment mode - print ''; - - // Bank Account - if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && isModEnabled("banque")) { - print ''; - } - - // Shipping Method - if (isModEnabled('expedition')) { - print ''; - } - - // Warehouse - if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) { - require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; - $formproduct = new FormProduct($db); - print ''; - } - - // Source / Channel - What trigger creation - print ''; - - // TODO How record was recorded OrderMode (llx_c_input_method) - - // Project - if (isModEnabled('project')) { - $langs->load("projects"); - print ''; - print ''; - print ''; - } - - // Incoterms - if (isModEnabled('incoterm')) { - print ''; - print ''; - print ''; - } - - // Other attributes + // Call Hook tabContentCreateOrder $parameters = array(); - if (!empty($origin) && !empty($originid) && is_object($objectsrc)) { - $parameters['objectsrc'] = $objectsrc; - } - $parameters['socid'] = $socid; - // Note that $action and $object may be modified by hook - $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); - print $hookmanager->resPrint; + $reshook = $hookmanager->executeHooks('tabContentCreateOrder', $parameters, $object, $action); if (empty($reshook)) { - if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER) && !empty($soc->id)) { - // copy from thirdparty - $tpExtrafields = new ExtraFields($db); - $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element); - if ($soc->fetch_optionals() > 0) { - $object->array_options = array_merge($object->array_options, $soc->array_options); + print '
'.$langs->trans('Ref').''.$langs->trans("Draft").'
'.$langs->trans('RefCustomer').''; - if (!empty($conf->global->MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER) && !empty($origin) && !empty($originid)) { - print '
'.$langs->trans('Customer').''; - print $soc->getNomUrl(1, 'customer'); - print ''; - print ''; - $filter = '((s.client:IN:1,2,3) AND (s.status:=:1))'; - print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company('', 'socid', $filter, 'SelectThirdParty', 1, 0, null, 0, 'minwidth175 maxwidth500 widthcentpercentminusxx'); - // reload page to retrieve customer informations - if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) { - print ''; - } - print ' '; - print '
".$langs->trans("DefaultContact").''; - print img_picto('', 'contact', 'class="pictofixedwidth"'); - print $form->selectcontacts($soc->id, $contactid, 'contactid', 1, !empty($srccontactslist)?$srccontactslist:"", '', 1, 'maxwidth200 widthcentpercentminusx'); - print '
'.$langs->trans('Discounts').''; - - $absolute_discount = $soc->getAvailableDiscounts(); - - $thirdparty = $soc; - $discount_type = 0; - $backtopage = $_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.urlencode(GETPOST('origin')).'&originid='.urlencode(GETPOSTINT('originid')); - include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; - - print '
'.$langs->trans('Date').''; - print img_picto('', 'action', 'class="pictofixedwidth"'); - print $form->selectDate('', 're', '', '', '', "crea_commande", 1, 1); // Always autofill date with current date - print '
'.$langs->trans("DateDeliveryPlanned").''; - $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date); - print img_picto('', 'action', 'class="pictofixedwidth"'); - print $form->selectDate($date_delivery ? $date_delivery : -1, 'liv_', 1, 1, 1); - print "
'.$langs->trans('AvailabilityPeriod').''; - print img_picto('', 'clock', 'class="pictofixedwidth"'); - $form->selectAvailabilityDelay((GETPOSTISSET('availability_id') ? GETPOST('availability_id') : $availability_id), 'availability_id', '', 1, 'maxwidth200 widthcentpercentminusx'); - print '
'.$langs->trans('PaymentConditionsShort').''; - print img_picto('', 'payment', 'class="pictofixedwidth"'); - print $form->getSelectConditionsPaiements($cond_reglement_id, 'cond_reglement_id', 1, 1, 0, 'maxwidth200 widthcentpercentminusx', $deposit_percent); - print '
'.$langs->trans('PaymentMode').''; - print img_picto('', 'bank', 'class="pictofixedwidth"'); - print $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id', 'CRDT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx', 1); - print '
'.$langs->trans('BankAccount').''; - print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes($fk_account, 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1); - print '
'.$langs->trans('SendingMethod').''; - print img_picto('', 'object_dolly', 'class="pictofixedwidth"'); - $form->selectShippingMethod(((GETPOSTISSET('shipping_method_id') && GETPOST('shipping_method_id', 'int') != 0) ? GETPOST('shipping_method_id') : $shipping_method_id), 'shipping_method_id', '', 1, '', 0, 'maxwidth200 widthcentpercentminusx'); - print '
'.$langs->trans('Warehouse').''; - print img_picto('', 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses((GETPOSTISSET('warehouse_id')?GETPOST('warehouse_id'):$warehouse_id), 'warehouse_id', '', 1, 0, 0, '', 0, 0, array(), 'maxwidth500 widthcentpercentminusxx'); - print '
'.$langs->trans('Channel').''; - print img_picto('', 'question', 'class="pictofixedwidth"'); - $form->selectInputReason((GETPOSTISSET('demand_reason_id')?GETPOST('demand_reason_id'):$demand_reason_id), 'demand_reason_id', '', 1, 'maxwidth200 widthcentpercentminusx'); - print '
'.$langs->trans("Project").''; - print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), (GETPOSTISSET('projectid')?GETPOST('projectid'):$projectid), 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx'); - print ' id).'">'; - print '
'; - $incoterm_id = GETPOST('incoterm_id'); - $incoterm_location = GETPOST('location_incoterms'); - if (empty($incoterm_id)) { - $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms); - $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms); - } - print img_picto('', 'incoterm', 'class="pictofixedwidth"'); - print $form->select_incoterms($incoterm_id, $incoterm_location); - print '
'; + + // Reference + print ''; + + // Reference client + print ''; + } else { + print ''; + } + print ''; + + // Thirdparty + print ''; + print ''; + if ($socid > 0) { + print ''; + } else { + print ''; + } + print ''."\n"; + + // Contact of order + if ($socid > 0) { + // Contacts (ask contact only if thirdparty already defined). + print "'; + + // Ligne info remises tiers + print ''; + } + + // Date + print ''; + + // Date delivery planned + print ''; + print '\n"; + print ''; + + // Delivery delay + print ''; + + // Terms of payment + print ''; + + // Payment mode + print ''; + + // Bank Account + if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && isModEnabled("banque")) { + print ''; + } + + // Shipping Method + if (isModEnabled('expedition')) { + print ''; + } + + // Warehouse + if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) { + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; + $formproduct = new FormProduct($db); + print ''; + } + + // Source / Channel - What trigger creation + print ''; + + // TODO How record was recorded OrderMode (llx_c_input_method) + + // Project + if (isModEnabled('project')) { + $langs->load("projects"); + print ''; + print ''; + print ''; + } + + // Incoterms + if (isModEnabled('incoterm')) { + print ''; + print ''; + print ''; + } + + // Other attributes + $parameters = array(); + if (!empty($origin) && !empty($originid) && is_object($objectsrc)) { + $parameters['objectsrc'] = $objectsrc; + } + $parameters['socid'] = $socid; + + // Note that $action and $object may be modified by hook + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); + print $hookmanager->resPrint; + if (empty($reshook)) { + if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER) && !empty($soc->id)) { + // copy from thirdparty + $tpExtrafields = new ExtraFields($db); + $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element); + if ($soc->fetch_optionals() > 0) { + $object->array_options = array_merge($object->array_options, $soc->array_options); + } + } + + print $object->showOptionals($extrafields, 'create', $parameters); + } + + // Template to use by default + print ''; + print '"; + + // Multicurrency + if (isModEnabled("multicurrency")) { + print ''; + print ''; + print ''; + } + + // Note public + print ''; + print ''; + print ''; + + // Note private + if (empty($user->socid)) { + print ''; + print ''; + print ''; + } + + if (!empty($origin) && !empty($originid) && is_object($objectsrc)) { + // TODO for compatibility + if ($origin == 'contrat') { + // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva + //$objectsrc->remise_absolue = $remise_absolue; + //$objectsrc->remise_percent = $remise_percent; + $objectsrc->update_price(1); + } + + print "\n"; + print "\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''; + print ''; + + switch ($classname) { + case 'Propal': + $newclassname = 'CommercialProposal'; + break; + case 'Commande': + $newclassname = 'Order'; + break; + case 'Expedition': + $newclassname = 'Sending'; + break; + case 'Contrat': + $newclassname = 'Contract'; + break; + default: + $newclassname = $classname; + } + + print ''; + + // Amount + print ''; + print '"; + if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1 RE + print '"; + } + + if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2 IRPF + print '"; + } + + print '"; + + if (isModEnabled("multicurrency")) { + print ''; + print '"; + print '"; } } - print $object->showOptionals($extrafields, 'create', $parameters); - } - - // Template to use by default - print ''; - print '"; - - // Multicurrency - if (isModEnabled("multicurrency")) { - print ''; - print ''; - print ''; - } - - // Note public - print ''; - print ''; - print ''; - - // Note private - if (empty($user->socid)) { - print ''; - print ''; - print ''; - } - - if (!empty($origin) && !empty($originid) && is_object($objectsrc)) { - // TODO for compatibility - if ($origin == 'contrat') { - // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva - //$objectsrc->remise_absolue = $remise_absolue; - //$objectsrc->remise_percent = $remise_percent; - $objectsrc->update_price(1); - } - - print "\n"; print "\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''; - print ''; - switch ($classname) { - case 'Propal': - $newclassname = 'CommercialProposal'; - break; - case 'Commande': - $newclassname = 'Order'; - break; - case 'Expedition': - $newclassname = 'Sending'; - break; - case 'Contrat': - $newclassname = 'Contract'; - break; - default: - $newclassname = $classname; - } - - print ''; - - // Amount - print ''; - print '"; - if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1 RE - print '"; - } - - if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2 IRPF - print '"; - } - - print '"; - - if (isModEnabled("multicurrency")) { - print ''; - print '"; - print '"; - } + print '
'.$langs->trans('Ref').''.$langs->trans("Draft").'
'.$langs->trans('RefCustomer').''; + if (!empty($conf->global->MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER) && !empty($origin) && !empty($originid)) { + print '
'.$langs->trans('Customer').''; + print $soc->getNomUrl(1, 'customer'); + print ''; + print ''; + $filter = '((s.client:IN:1,2,3) AND (s.status:=:1))'; + print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company('', 'socid', $filter, 'SelectThirdParty', 1, 0, null, 0, 'minwidth175 maxwidth500 widthcentpercentminusxx'); + // reload page to retrieve customer informations + if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) { + print ''; + } + print ' '; + print '
".$langs->trans("DefaultContact").''; + print img_picto('', 'contact', 'class="pictofixedwidth"'); + print $form->selectcontacts($soc->id, $contactid, 'contactid', 1, !empty($srccontactslist)?$srccontactslist:"", '', 1, 'maxwidth200 widthcentpercentminusx'); + print '
'.$langs->trans('Discounts').''; + + $absolute_discount = $soc->getAvailableDiscounts(); + + $thirdparty = $soc; + $discount_type = 0; + $backtopage = $_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.urlencode(GETPOST('origin')).'&originid='.urlencode(GETPOSTINT('originid')); + include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; + + print '
'.$langs->trans('Date').''; + print img_picto('', 'action', 'class="pictofixedwidth"'); + print $form->selectDate('', 're', '', '', '', "crea_commande", 1, 1); // Always autofill date with current date + print '
'.$langs->trans("DateDeliveryPlanned").''; + $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date); + print img_picto('', 'action', 'class="pictofixedwidth"'); + print $form->selectDate($date_delivery ? $date_delivery : -1, 'liv_', 1, 1, 1); + print "
'.$langs->trans('AvailabilityPeriod').''; + print img_picto('', 'clock', 'class="pictofixedwidth"'); + $form->selectAvailabilityDelay((GETPOSTISSET('availability_id') ? GETPOST('availability_id') : $availability_id), 'availability_id', '', 1, 'maxwidth200 widthcentpercentminusx'); + print '
'.$langs->trans('PaymentConditionsShort').''; + print img_picto('', 'payment', 'class="pictofixedwidth"'); + print $form->getSelectConditionsPaiements($cond_reglement_id, 'cond_reglement_id', 1, 1, 0, 'maxwidth200 widthcentpercentminusx', $deposit_percent); + print '
'.$langs->trans('PaymentMode').''; + print img_picto('', 'bank', 'class="pictofixedwidth"'); + print $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id', 'CRDT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx', 1); + print '
'.$langs->trans('BankAccount').''; + print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes($fk_account, 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1); + print '
'.$langs->trans('SendingMethod').''; + print img_picto('', 'object_dolly', 'class="pictofixedwidth"'); + $form->selectShippingMethod(((GETPOSTISSET('shipping_method_id') && GETPOST('shipping_method_id', 'int') != 0) ? GETPOST('shipping_method_id') : $shipping_method_id), 'shipping_method_id', '', 1, '', 0, 'maxwidth200 widthcentpercentminusx'); + print '
'.$langs->trans('Warehouse').''; + print img_picto('', 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses((GETPOSTISSET('warehouse_id')?GETPOST('warehouse_id'):$warehouse_id), 'warehouse_id', '', 1, 0, 0, '', 0, 0, array(), 'maxwidth500 widthcentpercentminusxx'); + print '
'.$langs->trans('Channel').''; + print img_picto('', 'question', 'class="pictofixedwidth"'); + $form->selectInputReason((GETPOSTISSET('demand_reason_id')?GETPOST('demand_reason_id'):$demand_reason_id), 'demand_reason_id', '', 1, 'maxwidth200 widthcentpercentminusx'); + print '
'.$langs->trans("Project").''; + print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), (GETPOSTISSET('projectid')?GETPOST('projectid'):$projectid), 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx'); + print ' id).'">'; + print '
'; + $incoterm_id = GETPOST('incoterm_id'); + $incoterm_location = GETPOST('location_incoterms'); + if (empty($incoterm_id)) { + $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms); + $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms); + } + print img_picto('', 'incoterm', 'class="pictofixedwidth"'); + print $form->select_incoterms($incoterm_id, $incoterm_location); + print '
'.$langs->trans('DefaultModel').''; + include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php'; + $liste = ModelePDFCommandes::liste_modeles($db); + $preselected = $conf->global->COMMANDE_ADDON_PDF; + print img_picto('', 'pdf', 'class="pictofixedwidth"'); + print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1); + print "
'.$form->editfieldkey("Currency", 'multicurrency_code', '', $object, 0).''; + print img_picto('', 'currency', 'class="pictofixedwidth"').$form->selectMultiCurrency(((GETPOSTISSET('multicurrency_code') && !GETPOST('changecompany'))?GETPOST('multicurrency_code'):$currency_code), 'multicurrency_code', 0, '', false, 'maxwidth200 widthcentpercentminusx'); + print '
'.$langs->trans('NotePublic').''; + + $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%'); + print $doleditor->Create(1); + // print ''; + print '
'.$langs->trans('NotePrivate').''; + + $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%'); + print $doleditor->Create(1); + // print ''; + print '
'.$langs->trans($newclassname).''.$objectsrc->getNomUrl(1).'
'.$langs->trans('AmountHT').''.price($objectsrc->total_ht).'
'.$langs->trans('AmountVAT').''.price($objectsrc->total_tva)."
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($objectsrc->total_localtax1)."
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($objectsrc->total_localtax2)."
'.$langs->trans('AmountTTC').''.price($objectsrc->total_ttc)."
'.$langs->trans('MulticurrencyAmountHT').''.price($objectsrc->multicurrency_total_ht).'
'.$langs->trans('MulticurrencyAmountVAT').''.price($objectsrc->multicurrency_total_tva)."
'.$langs->trans('MulticurrencyAmountTTC').''.price($objectsrc->multicurrency_total_ttc)."
'.$langs->trans('DefaultModel').''; - include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php'; - $liste = ModelePDFCommandes::liste_modeles($db); - $preselected = $conf->global->COMMANDE_ADDON_PDF; - print img_picto('', 'pdf', 'class="pictofixedwidth"'); - print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1); - print "
'.$form->editfieldkey("Currency", 'multicurrency_code', '', $object, 0).''; - print img_picto('', 'currency', 'class="pictofixedwidth"').$form->selectMultiCurrency(((GETPOSTISSET('multicurrency_code') && !GETPOST('changecompany'))?GETPOST('multicurrency_code'):$currency_code), 'multicurrency_code', 0, '', false, 'maxwidth200 widthcentpercentminusx'); - print '
'.$langs->trans('NotePublic').''; - - $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%'); - print $doleditor->Create(1); - // print ''; - print '
'.$langs->trans('NotePrivate').''; - - $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%'); - print $doleditor->Create(1); - // print ''; - print '
'.$langs->trans($newclassname).''.$objectsrc->getNomUrl(1).'
'.$langs->trans('AmountHT').''.price($objectsrc->total_ht).'
'.$langs->trans('AmountVAT').''.price($objectsrc->total_tva)."
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($objectsrc->total_localtax1)."
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($objectsrc->total_localtax2)."
'.$langs->trans('AmountTTC').''.price($objectsrc->total_ttc)."
'.$langs->trans('MulticurrencyAmountHT').''.price($objectsrc->multicurrency_total_ht).'
'.$langs->trans('MulticurrencyAmountVAT').''.price($objectsrc->multicurrency_total_tva)."
'.$langs->trans('MulticurrencyAmountTTC').''.price($objectsrc->multicurrency_total_ttc)."
'; } - print "\n"; - - print '
'; - print dol_get_fiche_end(); print $form->buttonsSaveCancel("CreateDraft"); @@ -2452,430 +2460,435 @@ if ($action == 'create' && $usercancreate) { dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + // Call Hook tabContentViewOrder + $parameters = array(); + // Note that $action and $object may be modified by hook + $reshook = $hookmanager->executeHooks('tabContentViewOrder', $parameters, $object, $action); + if (empty($reshook)) { + print '
'; + print '
'; + print '
'; - print '
'; - print '
'; - print '
'; + print ''; - print '
'; - - if ($soc->outstanding_limit) { - // Outstanding Bill - print ''; - print ''; - } - - // Relative and absolute discounts - if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice - $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice - } else { - $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')"; - $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; - } - - $addrelativediscount = ''.$langs->trans("EditRelativeDiscounts").''; - $addabsolutediscount = ''.$langs->trans("EditGlobalDiscounts").''; - $addcreditnote = ''.$langs->trans("AddCreditNote").''; - - print ''; - - // Date - print ''; + print ''; } - } - print ''; - print ''; - // Delivery date planed - print ''; - print ''; - - // Delivery delay - print ''; - - // Shipping Method - if (isModEnabled('expedition')) { - print ''; - print ''; - } - // Warehouse - if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) { - $langs->load('stocks'); - require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; - $formproduct = new FormProduct($db); + $addrelativediscount = ''.$langs->trans("EditRelativeDiscounts").''; + $addabsolutediscount = ''.$langs->trans("EditGlobalDiscounts").''; + $addcreditnote = ''.$langs->trans("AddCreditNote").''; + + print ''; + + // Date print ''; - print ''; - } - - // Source reason (why we have an order) - print ''; - - // Terms of payment - print ''; - - print ''; - - // Mode of payment - print ''; - - // Multicurrency - if (isModEnabled("multicurrency")) { - // Multicurrency code - print ''; - print ''; + print ''; + + // Delivery date planed + print ''; + print ''; + + // Delivery delay + print ''; - // Multicurrency rate - if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { + // Shipping Method + if (isModEnabled('expedition')) { + print ''; + print ''; + } + + // Warehouse + if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) { + $langs->load('stocks'); + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; + $formproduct = new FormProduct($db); + print ''; + print ''; + } + + // Source reason (why we have an order) + print ''; + + // Terms of payment + print ''; + + print ''; + + // Mode of payment + print ''; + + // Multicurrency + if (isModEnabled("multicurrency")) { + // Multicurrency code print ''; print ''; + + // Multicurrency rate + if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { + print ''; + print ''; + } + } + + // TODO Order mode (how we receive order). Not yet implemented + /* + print ''; + */ + + $tmparray = $object->getTotalWeightVolume(); + $totalWeight = $tmparray['weight']; + $totalVolume = $tmparray['volume']; + if ($totalWeight) { + print ''; + print ''; + } + if ($totalVolume) { + print ''; + print ''; + } + + // TODO How record was recorded OrderMode (llx_c_input_method) + + // Incoterms + if (isModEnabled('incoterm')) { + print ''; + print ''; } - } - // TODO Order mode (how we receive order). Not yet implemented - /* - print ''; - */ - - $tmparray = $object->getTotalWeightVolume(); - $totalWeight = $tmparray['weight']; - $totalVolume = $tmparray['volume']; - if ($totalWeight) { - print ''; - print ''; - } - if ($totalVolume) { - print ''; - print ''; - } - - // TODO How record was recorded OrderMode (llx_c_input_method) - - // Incoterms - if (isModEnabled('incoterm')) { - print ''; - print ''; + print ''; } - print ''; - } - // Bank Account - if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && isModEnabled("banque")) { - print '
'; - print $langs->trans('OutstandingBill'); - print ''; - $arrayoutstandingbills = $soc->getOutstandingBills(); - print price($arrayoutstandingbills['opened']).' / '; - print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency); - print '
'.$langs->trans('Discounts').''; - - $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount); - $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote); - $absolute_discount = price2num($absolute_discount, 'MT'); - $absolute_creditnote = price2num($absolute_creditnote, 'MT'); - - $thirdparty = $soc; - $discount_type = 0; - $backtopage = $_SERVER["PHP_SELF"].'?id='.$object->id; - include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; - - print '
'; - $editenable = $usercancreate && $object->statut == Commande::STATUS_DRAFT; - print $form->editfieldkey("Date", 'date', '', $object, $editenable); - print ''; - if ($action == 'editdate') { - print '
'; - print ''; - print ''; - print ''; - print $form->selectDate($object->date, 'order_', '', '', '', "setdate"); - print ''; - print '
'; - } else { - print $object->date ? dol_print_date($object->date, 'day') : ' '; - if ($object->hasDelay() && empty($object->delivery_date)) { // If there is a delivery date planned, warning should be on this date - print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning"); + if ($soc->outstanding_limit) { + // Outstanding Bill + print '
'; + print $langs->trans('OutstandingBill'); + print ''; + $arrayoutstandingbills = $soc->getOutstandingBills(); + print price($arrayoutstandingbills['opened']).' / '; + print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency); + print '
'; - $editenable = $usercancreate; - print $form->editfieldkey("DateDeliveryPlanned", 'date_livraison', '', $object, $editenable); - print ''; - if ($action == 'editdate_livraison') { - print '
'; - print ''; - print ''; - print ''; - print $form->selectDate($object->delivery_date ? $object->delivery_date : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0); - print ''; - print '
'; - } else { - print $object->delivery_date ? dol_print_date($object->delivery_date, 'dayhour') : ' '; - if ($object->hasDelay() && !empty($object->delivery_date)) { - print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning"); - } - } - print '
'; - $editenable = $usercancreate; - print $form->editfieldkey("AvailabilityPeriod", 'availability', '', $object, $editenable); - print ''; - if ($action == 'editavailability') { - $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'availability_id', 1); - } else { - $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'none', 1); - } - print '
'; - $editenable = $usercancreate; - print $form->editfieldkey("SendingMethod", 'shippingmethod', '', $object, $editenable); - print ''; - if ($action == 'editshippingmethod') { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); + // Relative and absolute discounts + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { + $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice + $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice } else { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); + $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')"; + $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; } - print '
'.$langs->trans('Discounts').''; + + $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount); + $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote); + $absolute_discount = price2num($absolute_discount, 'MT'); + $absolute_creditnote = price2num($absolute_creditnote, 'MT'); + + $thirdparty = $soc; + $discount_type = 0; + $backtopage = $_SERVER["PHP_SELF"].'?id='.$object->id; + include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; + + print '
'; - $editenable = $usercancreate; - print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $editenable); - print ''; - if ($action == 'editwarehouse') { - $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1); - } else { - $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none'); - } - print '
'; - $editenable = $usercancreate; - print $form->editfieldkey("Source", 'demandreason', '', $object, $editenable); - print ''; - if ($action == 'editdemandreason') { - $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'demand_reason_id', 1); - } else { - $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'none'); - } - print '
'; - $editenable = $usercancreate; - print $form->editfieldkey("PaymentConditionsShort", 'conditions', '', $object, $editenable); - print ''; - if ($action == 'editconditions') { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1, '', 1, $object->deposit_percent); - } else { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1, '', 1, $object->deposit_percent); - } - print '
'; - $editenable = $usercancreate; - print $form->editfieldkey("PaymentMode", 'mode', '', $object, $editenable); - print ''; - if ($action == 'editmode') { - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1); - } else { - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none'); - } - print '
'; $editenable = $usercancreate && $object->statut == Commande::STATUS_DRAFT; - print $form->editfieldkey("Currency", 'multicurrencycode', '', $object, $editenable); + print $form->editfieldkey("Date", 'date', '', $object, $editenable); print ''; - if ($action == 'editmulticurrencycode') { - $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code'); + if ($action == 'editdate') { + print '
'; + print ''; + print ''; + print ''; + print $form->selectDate($object->date, 'order_', '', '', '', "setdate"); + print ''; + print '
'; } else { - $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none'); + print $object->date ? dol_print_date($object->date, 'day') : ' '; + if ($object->hasDelay() && empty($object->delivery_date)) { // If there is a delivery date planned, warning should be on this date + print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning"); + } + } + print '
'; + $editenable = $usercancreate; + print $form->editfieldkey("DateDeliveryPlanned", 'date_livraison', '', $object, $editenable); + print ''; + if ($action == 'editdate_livraison') { + print '
'; + print ''; + print ''; + print ''; + print $form->selectDate($object->delivery_date ? $object->delivery_date : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0); + print ''; + print '
'; + } else { + print $object->delivery_date ? dol_print_date($object->delivery_date, 'dayhour') : ' '; + if ($object->hasDelay() && !empty($object->delivery_date)) { + print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning"); + } + } + print '
'; + $editenable = $usercancreate; + print $form->editfieldkey("AvailabilityPeriod", 'availability', '', $object, $editenable); + print ''; + if ($action == 'editavailability') { + $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'availability_id', 1); + } else { + $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'none', 1); } print '
'; + $editenable = $usercancreate; + print $form->editfieldkey("SendingMethod", 'shippingmethod', '', $object, $editenable); + print ''; + if ($action == 'editshippingmethod') { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); + } else { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); + } + print '
'; + $editenable = $usercancreate; + print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $editenable); + print ''; + if ($action == 'editwarehouse') { + $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1); + } else { + $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none'); + } + print '
'; + $editenable = $usercancreate; + print $form->editfieldkey("Source", 'demandreason', '', $object, $editenable); + print ''; + if ($action == 'editdemandreason') { + $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'demand_reason_id', 1); + } else { + $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'none'); + } + print '
'; + $editenable = $usercancreate; + print $form->editfieldkey("PaymentConditionsShort", 'conditions', '', $object, $editenable); + print ''; + if ($action == 'editconditions') { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1, '', 1, $object->deposit_percent); + } else { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1, '', 1, $object->deposit_percent); + } + print '
'; + $editenable = $usercancreate; + print $form->editfieldkey("PaymentMode", 'mode', '', $object, $editenable); + print ''; + if ($action == 'editmode') { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1); + } else { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none'); + } + print '
'; - $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == $object::STATUS_DRAFT; - print $form->editfieldkey("CurrencyRate", 'multicurrencyrate', '', $object, $editenable); + $editenable = $usercancreate && $object->statut == Commande::STATUS_DRAFT; + print $form->editfieldkey("Currency", 'multicurrencycode', '', $object, $editenable); print ''; - if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') { - if ($action == 'actualizemulticurrencyrate') { - list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); - } - $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code); + if ($action == 'editmulticurrencycode') { + $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code'); } else { - $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); - if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { - print '
        '; - print ''.$langs->trans("ActualizeCurrency").''; - print '
'; + $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none'); + } + print '
'; + $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == $object::STATUS_DRAFT; + print $form->editfieldkey("CurrencyRate", 'multicurrencyrate', '', $object, $editenable); + print ''; + if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') { + if ($action == 'actualizemulticurrencyrate') { + list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); + } + $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code); + } else { + $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); + if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { + print '
        '; + print ''.$langs->trans("ActualizeCurrency").''; + print '
'; + } } + print '
'; + $editenable = $usercancreate; + print $form->editfieldkey("SourceMode", 'inputmode', '', $object, $editenable); + print ''; + if ($action == 'editinputmode') { + $form->formInputMode($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->source, 'input_mode_id', 1); + } else { + $form->formInputMode($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->source, 'none'); + } + print '
'.$langs->trans("CalculatedWeight").''; + print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no'); + print '
'.$langs->trans("CalculatedVolume").''; + print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no'); + print '
'; + $editenable = $usercancreate; + print $form->editfieldkey("IncotermLabel", 'incoterm', '', $object, $editenable); + print ''; + if ($action != 'editincoterm') { + print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); + } else { + print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id); } print '
'; - $editenable = $usercancreate; - print $form->editfieldkey("SourceMode", 'inputmode', '', $object, $editenable); - print ''; - if ($action == 'editinputmode') { - $form->formInputMode($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->source, 'input_mode_id', 1); - } else { - $form->formInputMode($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->source, 'none'); - } - print '
'.$langs->trans("CalculatedWeight").''; - print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no'); - print '
'.$langs->trans("CalculatedVolume").''; - print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no'); - print '
'; - $editenable = $usercancreate; - print $form->editfieldkey("IncotermLabel", 'incoterm', '', $object, $editenable); - print ''; - if ($action != 'editincoterm') { - print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); - } else { - print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id); + // Bank Account + if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && isModEnabled("banque")) { + print '
'; + $editenable = $usercancreate; + print $form->editfieldkey("BankAccount", 'bankaccount', '', $object, $editenable); + print ''; + if ($action == 'editbankaccount') { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + } else { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + } + print '
'; - $editenable = $usercancreate; - print $form->editfieldkey("BankAccount", 'bankaccount', '', $object, $editenable); - print ''; - if ($action == 'editbankaccount') { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); - } else { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + print '
'; + + print '
'; + print '
'; + print '
'; + + print ''; + + $alert = ''; + if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->order_min_amount) { + $alert = ' ' . img_warning($langs->trans('OrderMinAmount') . ': ' . price($object->thirdparty->order_min_amount)); } - print ''; - print ''; - } - // Other attributes - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; - - print '
'; - - print '
'; - print '
'; - print '
'; - - print ''; - - $alert = ''; - if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->order_min_amount) { - $alert = ' ' . img_warning($langs->trans('OrderMinAmount') . ': ' . price($object->thirdparty->order_min_amount)); - } - - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - // Multicurrency Amount HT - print ''; - } - print ''; - - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - // Multicurrency Amount VAT - print ''; - } - print ''; - - // Amount Local Taxes - if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { print ''; - print ''; - print ''; + print ''; + print ''; if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; + // Multicurrency Amount HT + print ''; + } + print ''; + + print ''; + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + // Multicurrency Amount VAT + print ''; } print ''; // Amount Local Taxes - if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { + if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { print ''; - print ''; - print ''; + print ''; + print ''; if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; + print ''; } print ''; + + // Amount Local Taxes + if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { + print ''; + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + print ''; + } + print ''; + } } - } - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - // Multicurrency Amount TTC - print ''; - } - print ''."\n"; - - print '
' . $langs->trans('AmountHT') . '' . price($object->total_ht, '', $langs, 0, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_ht, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->trans('AmountVAT') . '' . price($object->total_tva, '', $langs, 0, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_tva, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($object->total_localtax1, '', $langs, 0, -1, -1, $conf->currency) . '' . $langs->trans('AmountHT') . '' . price($object->total_ht, '', $langs, 0, -1, -1, $conf->currency) . '' . price($object->total_localtax1, '', $langs, 0, -1, -1, $object->multicurrency_code) . '' . price($object->multicurrency_total_ht, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->trans('AmountVAT') . '' . price($object->total_tva, '', $langs, 0, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_tva, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($object->total_localtax2, '', $langs, 0, -1, -1, $conf->currency) . '' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($object->total_localtax1, '', $langs, 0, -1, -1, $conf->currency) . '' . price($object->total_localtax2, '', $langs, 0, -1, -1, $object->multicurrency_code) . '' . price($object->total_localtax1, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($object->total_localtax2, '', $langs, 0, -1, -1, $conf->currency) . '' . price($object->total_localtax2, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->trans('AmountTTC') . '' . price($object->total_ttc, 1, '', 1, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_ttc, 1, '', 1, -1, -1, $object->multicurrency_code) . '
'; - - // Statut - //print '
' . $langs->trans('Status') . '' . $object->getLibStatut(4) . '
'; - - // Show object lines - if (!empty($object->lines)) { - $object->printObjectLines($action, $mysoc, $soc, $lineid, 1); - } - - $numlines = count($object->lines); - - /* - * Form to add new line - */ - if ($object->statut == Commande::STATUS_DRAFT && $usercancreate && $action != 'selectlines') { - if ($action != 'editline') { - // Add free products/services - - $parameters = array(); - // Note that $action and $object may be modified by hook - $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - if (empty($reshook)) - $object->formAddObjectLine(1, $mysoc, $soc); - } else { - $parameters = array(); - $reshook = $hookmanager->executeHooks('formEditObjectLine', $parameters, $object, $action); + print ''; + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + // Multicurrency Amount TTC + print ''; } - } - print '
' . $langs->trans('AmountTTC') . '' . price($object->total_ttc, 1, '', 1, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_ttc, 1, '', 1, -1, -1, $object->multicurrency_code) . '
'; - print '
'; + print ''."\n"; - print "\n"; + print ''; + + // Statut + //print '' . $langs->trans('Status') . '' . $object->getLibStatut(4) . ''; + + // Margin Infos + if (isModEnabled('margin')) { + $formmargin->displayMarginInfos($object); + } + + + print '
'; + print '
'; // Close fichecenter + + print '

'; + + if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { + $blocname = 'contacts'; + $title = $langs->trans('ContactsAddresses'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { + $blocname = 'notes'; + $title = $langs->trans('Notes'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + /* + * Lines + */ + + // Get object lines + $result = $object->getLinesArray(); + + // Add products/services form + //$forceall = 1; + global $inputalsopricewithtax; + $inputalsopricewithtax = 1; + + print '
+ + + + + + + '; + + if (!empty($conf->use_javascript_ajax) && $object->statut == Commande::STATUS_DRAFT) { + include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; + } + + print '
'; + print ''; + + // Show object lines + if (!empty($object->lines)) { + $object->printObjectLines($action, $mysoc, $soc, $lineid, 1); + } + + $numlines = count($object->lines); + + /* + * Form to add new line + */ + if ($object->statut == Commande::STATUS_DRAFT && $usercancreate && $action != 'selectlines') { + if ($action != 'editline') { + // Add free products/services + + $parameters = array(); + // Note that $action and $object may be modified by hook + $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); + if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if (empty($reshook)) + $object->formAddObjectLine(1, $mysoc, $soc); + } else { + $parameters = array(); + $reshook = $hookmanager->executeHooks('formEditObjectLine', $parameters, $object, $action); + } + } + print '
'; + print '
'; + + print "
\n"; + } print dol_get_fiche_end(); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index f4b13e1a3b9..eef8dc9e7da 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -286,6 +286,7 @@ class Commande extends CommonOrder public $online_payment_url; + /** * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" @@ -569,6 +570,12 @@ class Commande extends CommonOrder if (!$resql) { $error++; $this->error = $this->db->lasterror(); } + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'commande/".$this->db->escape($this->newref)."'"; + $sql .= " WHERE filepath = 'commande/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (!$resql) { + $error++; $this->error = $this->db->lasterror(); + } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); @@ -2344,7 +2351,7 @@ class Commande extends CommonOrder * * TODO FONCTION NON FINIE A FINIR */ - public function stock_array($filtre_statut = self::STATUS_CANCELED) + /*public function stock_array($filtre_statut = self::STATUS_CANCELED) { // phpcs:enable $this->stocks = array(); @@ -2372,7 +2379,7 @@ class Commande extends CommonOrder } } return 0; - } + }*/ /** * Delete an order line @@ -3500,6 +3507,7 @@ class Commande extends CommonOrder // Delete record into ECM index and physically if (!$error) { $res = $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive + $res = $this->deleteEcmFiles(1); // Deleting files physically is done later with the dol_delete_dir_recursive if (!$res) { $error++; } diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index d956306d63f..8c10c3ce7ab 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -472,7 +472,7 @@ if (empty($reshook)) { $array_options = $lines[$i]->array_options; } - $objecttmp->context['createfromclone']; + $objecttmp->context['createfromclone'] = 'createfromclone'; $rang = ($nbOrders > 1) ? -1 : $lines[$i]->rang; //there may already be rows from previous orders @@ -718,9 +718,9 @@ if ($action == 'shipped' && $permissiontoadd) { if ($objecttmp->fetch($checked)) { if ($objecttmp->statut == 1 || $objecttmp->statut == 2) { if ($objecttmp->cloture($user)) { - setEventMessages($langs->trans('PassedInClosedStatus', $objecttmp->ref), null, 'mesgs'); + setEventMessages($langs->trans('StatusOrderDelivered', $objecttmp->ref), null, 'mesgs'); } else { - setEventMessages($langs->trans('CantBeClosed'), null, 'errors'); + setEventMessages($langs->trans('ErrorOrderStatusCantBeSetToDelivered'), null, 'errors'); $error++; } } else { diff --git a/htdocs/commande/list_det.php b/htdocs/commande/list_det.php index 50f6fd82e15..9029cb986ea 100644 --- a/htdocs/commande/list_det.php +++ b/htdocs/commande/list_det.php @@ -11,7 +11,7 @@ * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2016-2021 Ferran Marcet * Copyright (C) 2018 Charlene Benke - * Copyright (C) 2021-2022 Anthony Berton + * Copyright (C) 2021-2023 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 @@ -48,6 +48,11 @@ require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +if (isModEnabled('categorie')) { + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php'; + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +} + // Load translation files required by the page $langs->loadLangs(array("orders", 'sendings', 'deliveries', 'companies', 'compta', 'bills', 'stocks', 'products')); @@ -73,7 +78,16 @@ $search_dateorder_start = dol_mktime(0, 0, 0, GETPOST('search_dateorder_start_mo $search_dateorder_end = dol_mktime(23, 59, 59, GETPOST('search_dateorder_end_month', 'int'), GETPOST('search_dateorder_end_day', 'int'), GETPOST('search_dateorder_end_year', 'int')); $search_datedelivery_start = dol_mktime(0, 0, 0, GETPOST('search_datedelivery_start_month', 'int'), GETPOST('search_datedelivery_start_day', 'int'), GETPOST('search_datedelivery_start_year', 'int')); $search_datedelivery_end = dol_mktime(23, 59, 59, GETPOST('search_datedelivery_end_month', 'int'), GETPOST('search_datedelivery_end_day', 'int'), GETPOST('search_datedelivery_end_year', 'int')); -$search_product_category = GETPOST('search_product_category', 'int'); + +if (isModEnabled('categorie')) { + $search_product_category_array = GETPOST("search_category_".Categorie::TYPE_PRODUCT."_list", "array"); + $searchCategoryProductOperator = 0; + if (GETPOSTISSET('formfilteraction')) { + $searchCategoryProductOperator = GETPOSTINT('search_category_product_operator'); + } elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) { + $searchCategoryProductOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT; + } +} // Détail commande $search_id = GETPOST('search_id', 'alpha'); @@ -159,7 +173,7 @@ $search_array_options = $extrafields->getOptionalsFromPost($object->table_elemen $fieldstosearchall = array( 'c.ref'=>'Ref', 'c.ref_client'=>'RefCustomerOrder', - 'pd.description'=>'Description', + 'cdet.description'=>'Description', 's.nom'=>"ThirdParty", 's.name_alias'=>"AliasNameShort", 's.zip'=>"Zip", @@ -257,7 +271,8 @@ if (empty($reshook)) { $search_categ = ''; $search_user = ''; $search_sale = ''; - $search_product_category = ''; + $search_product_category_array = array(); + $searchCategoryProductOperator = 0; $search_id = ''; $search_refProduct = ''; $search_descProduct = ''; @@ -404,12 +419,6 @@ $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as pr ON pr.rowid=cdet.fk_product' if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_extrafields as ef on (c.rowid = ef.fk_object)"; } -if ($sall || $search_product_category > 0) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON c.rowid=pd.fk_commande'; -} -if ($search_product_category > 0) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; -} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = c.fk_projet"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON c.fk_user_author = u.rowid'; @@ -421,7 +430,6 @@ if ($search_user > 0) { $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec"; $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc"; } - // Add table from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook @@ -440,9 +448,6 @@ if (!empty($productonly)) { if (!empty($disablelinefree)) { $sql .= " AND cdet.fk_product IS NOT NULL"; } -if ($search_product_category > 0) { - $sql .= " AND cp.fk_categorie = ".((int) $search_product_category); -} if ($socid > 0) { $sql .= ' AND s.rowid = '.((int) $socid); } @@ -592,8 +597,39 @@ if ($search_fk_input_reason > 0) { $sql .= " AND c.fk_input_reason = ".((int) $search_fk_input_reason); } +// Search for tag/category ($searchCategoryProductList is an array of ID) +$searchCategoryProductList = $search_product_category_array; +if (!empty($searchCategoryProductList)) { + $searchCategoryProjectSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryProductList as $searchCategoryProject) { + if (intval($searchCategoryProject) == -2) { + $searchCategoryProjectSqlList[] = "NOT EXISTS (SELECT cp.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as cp WHERE cdet.fk_product = cp.fk_product)"; + } elseif (intval($searchCategoryProject) > 0) { + if ($searchCategoryProductOperator == 0) { + $searchCategoryProjectSqlList[] = " EXISTS (SELECT cp.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as cp WHERE cdet.fk_product = cp.fk_product AND cp.fk_categorie = ".((int) $searchCategoryProject).")"; + } else { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProject); + } + } + } + if ($listofcategoryid) { + $searchCategoryProjectSqlList[] = " EXISTS (SELECT cp.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as cp WHERE cdet.fk_product = cp.fk_product AND cp.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryProductOperator == 1) { + if (!empty($searchCategoryProjectSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryProjectSqlList).")"; + } + } else { + if (!empty($searchCategoryProjectSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryProjectSqlList).")"; + } + } +} + // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; + // Add where from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook @@ -782,8 +818,10 @@ if ($resql) { if ($search_type_thirdparty && $search_type_thirdparty != '-1') { $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty); } - if ($search_product_category != '') { - $param .= '&search_product_category='.urlencode($search_product_category); + if (!empty($search_product_category_array)) { + foreach ($search_product_category_array as $tmpval) { + $param .= '&search_categegory_product_list[]='.urlencode($tmpval); + } } if (($search_categ_cus > 0) || ($search_categ_cus == -2)) { $param .= '&search_categ_cus='.urlencode($search_categ_cus); @@ -894,14 +932,10 @@ if ($resql) { $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx'); $moreforfilter .= '
'; } - // If the user can view prospects other than his' + // Filter on categories if (isModEnabled("categorie") && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) { - include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $moreforfilter .= '
'; - $tmptitle = $langs->trans('IncludingProductWithTag'); - $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); - $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth300 widthcentpercentminusx', 1); - $moreforfilter .= '
'; + $formcategory = new FormCategory($db); + $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PRODUCT, $search_product_category_array, 'minwidth300imp minwidth300', $searchCategoryProductOperator ? $searchCategoryProductOperator : 0); } if (isModEnabled("categorie") && $user->hasRight('categorie', 'lire')) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index e18d0c01e28..f3c590e6ff1 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -581,9 +581,11 @@ if ($action == 'create') { } if (isModEnabled('paymentbybanktransfer')) { - print ''.$form->textwithpicto($langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformation"), $langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformationHelp")).''; - print ''; - print ''; + if ($mysoc->isInEEC()) { + print ''.$form->textwithpicto($langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformation"), $langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformationHelp")).''; + print ''; + print ''; + } } print ''; print '
'; @@ -830,15 +832,17 @@ if ($action == 'create') { print ''; } - // TODO ICS is not used with bank transfer ! if (isModEnabled('paymentbybanktransfer')) { - print ''.$form->textwithpicto($langs->trans("IDS"), $langs->trans("IDS").' ('.$langs->trans("UsedFor", $langs->transnoentitiesnoconv("BankTransfer")).')').''; - print ''.$object->ics_transfer.''; - print ''; - - print ''.$form->textwithpicto($langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformation"), $langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformationHelp")).''; - print (empty($object->pti_in_ctti) ? $langs->trans("No") : $langs->trans("Yes")); - print "\n"; + if (getDolGlobalString("SEPA_USE_IDS")) { // ICS is not used with bank transfer ! + print ''.$form->textwithpicto($langs->trans("IDS"), $langs->trans("IDS").' ('.$langs->trans("UsedFor", $langs->transnoentitiesnoconv("BankTransfer")).')').''; + print ''.$object->ics_transfer.''; + print ''; + } + if ($mysoc->isInEEC()) { + print ''.$form->textwithpicto($langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformation"), $langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformationHelp")).''; + print (empty($object->pti_in_ctti) ? $langs->trans("No") : $langs->trans("Yes")); + print "\n"; + } } print ''.$langs->trans("BankAccountOwner").''; @@ -1123,14 +1127,14 @@ if ($action == 'create') { // IBAN print ''; $tooltip = $langs->trans("Example").':
CH93 0076 2011 6238 5295 7
LT12 1000 0111 0100 1000
FR14 2004 1010 0505 0001 3M02 606
LU28 0019 4006 4475 0000
DE89 3704 0044 0532 0130 00'; - print $form->textwithpicto($langs->trans($ibankey), $tooltip); + print $form->textwithpicto($langs->trans($ibankey), $tooltip, 1, 'help', '', 0, 3, 'iban'); print ''; print ''; // BIC print ''; $tooltip = $langs->trans("Example").': LIABLT2XXXX'; - print $form->textwithpicto($langs->trans($bickey), $tooltip); + print $form->textwithpicto($langs->trans($bickey), $tooltip, 1, 'help', '', 0, 3, 'bic'); print ''; print ''; @@ -1166,12 +1170,15 @@ if ($action == 'create') { } if (isModEnabled('paymentbybanktransfer')) { - print ''.$form->textwithpicto($langs->trans("IDS"), $langs->trans("IDS").' ('.$langs->trans("UsedFor", $langs->transnoentitiesnoconv("BankTransfer")).')').''; - print ''; - - print ''.$form->textwithpicto($langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformation"), $langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformationHelp")).''; - print 'pti_in_ctti ? ' checked ' : '') . '>'; - print ''; + if (getDolGlobalString("SEPA_USE_IDS")) { // ICS is not used with bank transfer ! + print ''.$form->textwithpicto($langs->trans("IDS"), $langs->trans("IDS").' ('.$langs->trans("UsedFor", $langs->transnoentitiesnoconv("BankTransfer")).')').''; + print ''; + } + if ($mysoc->isInEEC()) { + print ''.$form->textwithpicto($langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformation"), $langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformationHelp")).''; + print 'pti_in_ctti ? ' checked ' : '') . '>'; + print ''; + } } print ''.$langs->trans("BankAccountOwner").''; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 5888499127a..bf8e7037f5f 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -278,7 +278,6 @@ class Account extends CommonObject public $ics_transfer; - /** * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" @@ -1568,11 +1567,11 @@ class Account extends CommonObject // Call functions to check BAN if (!checkIbanForAccount($this)) { $error++; - $this->error_message = 'IBANNotValid'; + $this->error = 'IBANNotValid'; } if (!checkSwiftForAccount($this)) { $error++; - $this->error_message = 'SwiftNotValid'; + $this->error = 'SwiftNotValid'; } if (! $error) { @@ -2014,6 +2013,10 @@ class AccountLine extends CommonObjectLine public $note; + /** + * User author of the rapprochement. + */ + public $user_rappro; /** diff --git a/htdocs/compta/bank/class/paymentvarious.class.php b/htdocs/compta/bank/class/paymentvarious.class.php index 5eaf0d72e55..74434a047c8 100644 --- a/htdocs/compta/bank/class/paymentvarious.class.php +++ b/htdocs/compta/bank/class/paymentvarious.class.php @@ -747,9 +747,9 @@ class PaymentVarious extends CommonObject $this->id = $obj->rowid; $this->user_creation = $obj->fk_user_author; - $this->user_modif = $obj->fk_user_modif; + $this->user_modification_id = $obj->fk_user_modif; $this->date_creation = $this->db->jdate($obj->datec); - $this->date_modif = $this->db->jdate($obj->tms); + $this->date_modification = $this->db->jdate($obj->tms); } $this->db->free($result); } else { diff --git a/htdocs/compta/bank/releve.php b/htdocs/compta/bank/releve.php index 43c72e4a8f5..643b0796c59 100644 --- a/htdocs/compta/bank/releve.php +++ b/htdocs/compta/bank/releve.php @@ -201,7 +201,7 @@ if ($action == 'confirm_editbankreceipt' && !empty($oldbankreceipt) && !empty($n if ($resql) { $obj = $db->fetch_object($resql); if ($obj && $obj->rowid) { - setEventMessages('ErrorThisBankReceiptIsAlreadyUsed', null, 'errors'); + setEventMessages('ErrorBankReceiptAlreadyExists', null, 'errors'); $error++; } } else { @@ -371,7 +371,7 @@ if (empty($numref)) { } else { print ''; print ''; - print ''; + print ''; print ''; } print ''; diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index 15ca3646425..412dd620392 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -9,6 +9,7 @@ * Copyright (C) 2015 Alexandre Spangaro * Copyright (C) 2016 Meziane Sof * Copyright (C) 2017-2018 Frédéric France + * Copyright (C) 2023 Nick Fragoulis * * 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 @@ -203,25 +204,31 @@ if (empty($reshook)) { } if (!$error) { - $object->title = GETPOST('title', 'alphanohtml'); - $object->note_private = GETPOST('note_private', 'restricthtml'); - $object->note_public = GETPOST('note_public', 'restricthtml'); - $object->model_pdf = GETPOST('modelpdf', 'alphanohtml'); - $object->usenewprice = GETPOST('usenewprice', 'alphanohtml'); + $object->subtype = GETPOST('subtype'); + $object->title = GETPOST('title', 'alphanohtml'); + $object->note_private = GETPOST('note_private', 'restricthtml'); + $object->note_public = GETPOST('note_public', 'restricthtml'); + $object->model_pdf = GETPOST('modelpdf', 'alphanohtml'); + $object->usenewprice = GETPOST('usenewprice', 'alphanohtml'); - $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int'); - $object->cond_reglement_id = GETPOST('cond_reglement_id', 'int'); + $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int'); + $object->cond_reglement_id = GETPOST('cond_reglement_id', 'int'); - $object->frequency = $frequency; - $object->unit_frequency = GETPOST('unit_frequency', 'alpha'); - $object->nb_gen_max = $nb_gen_max; - $object->auto_validate = GETPOST('auto_validate', 'int'); - $object->generate_pdf = GETPOST('generate_pdf', 'int'); - $object->fk_project = $projectid; + $object->frequency = $frequency; + $object->unit_frequency = GETPOST('unit_frequency', 'alpha'); + $object->nb_gen_max = $nb_gen_max; + $object->auto_validate = GETPOST('auto_validate', 'int'); + $object->generate_pdf = GETPOST('generate_pdf', 'int'); + $object->fk_project = $projectid; $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear); $object->date_when = $date_next_execution; + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) { + $error++; + } + // Get first contract linked to invoice used to generate template (facid is id of source invoice) if (GETPOST('facid', 'int') > 0) { $srcObject = new Facture($db); @@ -996,6 +1003,13 @@ if ($action == 'create') { print ''.$langs->trans("Customer").''.$object->thirdparty->getNomUrl(1, 'customer').''; print ''; + // Invoice subtype + if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED')) { + print "".$langs->trans("InvoiceSubtype").""; + print $form->getSelectInvoiceSubtype(GETPOSTISSET('subtype') ? GETPOST('subtype') : $object->subtype, 'subtype', -1, 0, 0, ''); + print ""; + } + $note_public = GETPOSTISSET('note_public') ? GETPOST('note_public', 'restricthtml') : $object->note_public; $note_private = GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : $object->note_private; @@ -1023,28 +1037,6 @@ if ($action == 'create') { } $htmltext .= ''; - // Public note - print ''; - print ''; - print $form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic'); - print ''; - print ''; - $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%'); - print $doleditor->Create(1); - - // Private note - if (empty($user->socid)) { - print ''; - print ''; - print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext, 1, 'help', '', 0, 2, 'noteprivate'); - print ''; - print ''; - $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%'); - print $doleditor->Create(1); - // print ' - print ''; - } - // Author print "".$langs->trans("Author")."".$user->getFullName($langs).""; @@ -1068,6 +1060,18 @@ if ($action == 'create') { print ""; } + //extrafields + $draft = new Facture($db); + $draft->fetch(GETPOST('facid', 'int')); + + $extralabels = new ExtraFields($db); + $extralabels = $extrafields->fetch_name_optionals_label($draft->table_element); + if ($draft->fetch_optionals() > 0) { + $object->array_options = array_merge($object->array_options, $draft->array_options); + } + + print $object->showOptionals($extrafields, 'create', $parameters); + // Project if (isModEnabled('project') && is_object($object->thirdparty) && $object->thirdparty->id > 0) { $projectid = GETPOST('projectid') ?GETPOST('projectid') : $object->fk_project; @@ -1087,15 +1091,38 @@ if ($action == 'create') { print $form->selectarray('modelpdf', $list, $conf->global->FACTURE_ADDON_PDF); print ""; + // Public note + print ''; + print ''; + print $form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic'); + print ''; + print ''; + $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%'); + print $doleditor->Create(1); + + // Private note + if (empty($user->socid)) { + print ''; + print ''; + print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext, 1, 'help', '', 0, 2, 'noteprivate'); + print ''; + print ''; + $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%'); + print $doleditor->Create(1); + // print ' + print ''; + } + print ""; print dol_get_fiche_end(); - // Autogeneration $title = $langs->trans("Recurrence"); print load_fiche_titre(img_picto('', 'recurring', 'class="pictofixedwidth"').$title, '', ''); + print ''.$langs->trans("ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv('Module2300Name')).'

'; + print dol_get_fiche_head(null, '', '', 0); print ''; @@ -1118,7 +1145,7 @@ if ($action == 'create') { print ""; // Auto validate the invoice - print ""; @@ -1266,14 +1293,26 @@ if ($action == 'create') { print '
".$langs->trans("StatusOfGeneratedInvoices").""; + print "
".$langs->trans("StatusOfAutoGeneratedInvoices").""; $select = array('0'=>$langs->trans('BillStatusDraft'), '1'=>$langs->trans('BillStatusValidated')); print $form->selectarray('auto_validate', $select, GETPOST('auto_validate')); print "
'; + // Invoice subtype + if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED')) { + print ""; + } + + // Author print '"; + // Amount (excl. tax) print ''; print ''; print ''; + // Amount tax print ''; print ''; @@ -1405,22 +1444,6 @@ if ($action == 'create') { } $htmltext .= ''; - // Note public - print ''; - print ''; - - // Note private - print ''; - print ''; - // Bank Account print '
".$langs->trans("InvoiceSubtype").""; + if ($object->subtype > 0) { + print $object->getSubtypeLabel('facture_rec'); + } + print "
'.$langs->trans("Author").''; print $author->getNomUrl(-1); print "
'.$langs->trans("AmountHT").''.price($object->total_ht, '', $langs, 1, -1, -1, $conf->currency).'
'.$langs->trans("AmountVAT").''.price($object->total_tva, '', $langs, 1, -1, -1, $conf->currency).'
'; - print $form->editfieldkey($form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic'), 'note_public', $object->note_public, $object, $user->hasRight('facture', 'creer')); - print ''; - print $form->editfieldval($langs->trans("NotePublic"), 'note_public', $object->note_public, $object, $user->hasRight('facture', 'creer'), 'textarea:'.ROWS_4.':90%', '', null, null, '', 1); - print '
'; - print $form->editfieldkey($form->textwithpicto($langs->trans("NotePrivate"), $htmltext, 1, 'help', '', 0, 2, 'noteprivate'), 'note_private', $object->note_private, $object, $user->hasRight('facture', 'creer')); - print ''; - print $form->editfieldval($langs->trans("NotePrivate"), 'note_private', $object->note_private, $object, $user->hasRight('facture', 'creer'), 'textarea:'.ROWS_4.':90%', '', null, null, '', 1); - print '
'; print '"; print ''; + // Extrafields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + + // Note public + print ''; + print ''; + + // Note private + print ''; + print ''; + // Model pdf print ''; - print ''; - print ''; - print '"; - if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1 - print '"; - } - - if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2 - print '"; - } - print '"; - - if (isModEnabled('multicurrency')) { - print ''; - print '"; - print '"; - } - } - - print "
'; @@ -1439,6 +1462,26 @@ if ($action == 'create') { print "
'; + print $form->editfieldkey($form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic'), 'note_public', $object->note_public, $object, $user->hasRight('facture', 'creer')); + print ''; + print $form->editfieldval($langs->trans("NotePublic"), 'note_public', $object->note_public, $object, $user->hasRight('facture', 'creer'), 'textarea:'.ROWS_4.':90%', '', null, null, '', 1); + print '
'; + print $form->editfieldkey($form->textwithpicto($langs->trans("NotePrivate"), $htmltext, 1, 'help', '', 0, 2, 'noteprivate'), 'note_private', $object->note_private, $object, $user->hasRight('facture', 'creer')); + print ''; + print $form->editfieldval($langs->trans("NotePrivate"), 'note_private', $object->note_private, $object, $user->hasRight('facture', 'creer'), 'textarea:'.ROWS_4.':90%', '', null, null, '', 1); + print '
'; print '
'; @@ -1466,7 +1509,7 @@ if ($action == 'create') { // Other attributes $cols = 2; - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + print '
'; diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 32dd9d686df..069de0018b1 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -6,7 +6,7 @@ * Copyright (C) 2005-2015 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2015 Juanjo Menent - * Copyright (C) 2012-2013 Christophe Battarel + * Copyright (C) 2012-2023 Christophe Battarel * Copyright (C) 2012-2013 Cédric Salvador * Copyright (C) 2012-2014 Raphaël Doursenaud * Copyright (C) 2013 Jean-Francois FERRY @@ -126,6 +126,9 @@ if ($id > 0 || !empty($ref)) { $fetch_situation = true; } $ret = $object->fetch($id, $ref, '', '', $fetch_situation); + if ($ret > 0 && isset($object->fk_project)) { + $ret = $object->fetch_project(); + } } } @@ -2378,11 +2381,11 @@ if (empty($reshook)) { // Check price is not lower than minimum (check is done only for standard or replacement invoices) if ($usermustrespectpricemin && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT)) { - if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) { + if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min)) && $price_base_type == 'HT') { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)); setEventMessages($mesg, null, 'errors'); $error++; - } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) { + } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc)) && $price_base_type == 'TTC') { $mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)); setEventMessages($mesg, null, 'errors'); $error++; @@ -2594,12 +2597,12 @@ if (empty($reshook)) { // Check price is not lower than minimum (check is done only for standard or replacement invoices) if ($usermustrespectpricemin && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT)) { - if ($pu_equivalent && $price_min && (((float) price2num($pu_equivalent) * (1 - (float) $remise_percent / 100)) < (float) price2num($price_min))) { + if ($pu_equivalent && $price_min && (((float) price2num($pu_equivalent) * (1 - (float) $remise_percent / 100)) < (float) price2num($price_min)) && $price_base_type == 'HT') { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)); setEventMessages($mesg, null, 'errors'); $error++; $action = 'editline'; - } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - (float) $remise_percent / 100)) < price2num($price_min_ttc))) { + } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - (float) $remise_percent / 100)) < price2num($price_min_ttc)) && $price_base_type == 'TTC') { $mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)); setEventMessages($mesg, null, 'errors'); $error++; @@ -3182,9 +3185,9 @@ if ($action == 'create') { } } } else { - $cond_reglement_id = $soc->cond_reglement_id; - $mode_reglement_id = $soc->mode_reglement_id; - $fk_account = $soc->fk_account; + $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id; + $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id; + $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account; //$remise_percent = $soc->remise_percent; //$remise_absolue = 0; $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $dateinvoice); // Do not set 0 here (0 for a date is 1970) @@ -3194,6 +3197,19 @@ if ($action == 'create') { } } + // If form was posted (but error returned), we must reuse the value posted in priority (standard Dolibarr behaviour) + if (!GETPOST('changecompany')) { + if (GETPOSTISSET('cond_reglement_id')) { + $cond_reglement_id = GETPOST('cond_reglement_id', 'int'); + } + if (GETPOSTISSET('mode_reglement_id')) { + $mode_reglement_id = GETPOST('mode_reglement_id', 'int'); + } + if (GETPOSTISSET('cond_reglement_id')) { + $fk_account = GETPOST('fk_account', 'int'); + } + } + // when payment condition is empty (means not override by payment condition form a other object, like third-party), try to use default value if (empty($cond_reglement_id)) { $cond_reglement_id = GETPOST("cond_reglement_id", 'int'); @@ -3205,11 +3221,11 @@ if ($action == 'create') { } // when bank account is empty (means not override by payment mode form a other object, like third-party), try to use default value - if ($socid > 0 && $fk_account) { // A company has already been set and it has a default fk_account - $fk_account = GETPOSTISSET('fk_account') ? GETPOST("fk_account", 'int') : $fk_account; // The GETPOST is used only if form was posted to avoid to take default value, because in such case, the default must be the one of the company - } else { // No company forced - $fk_account = GETPOST("fk_account", 'int'); - } + // if ($socid > 0 && $fk_account) { // A company has already been set and it has a default fk_account + // $fk_account = GETPOSTISSET('fk_account') ? GETPOST("fk_account", 'int') : $fk_account; // The GETPOST is used only if form was posted to avoid to take default value, because in such case, the default must be the one of the company + // } else { // No company forced + // $fk_account = GETPOST("fk_account", 'int'); + // } if (!empty($soc->id)) { $absolute_discount = $soc->getAvailableDiscounts(); @@ -3256,783 +3272,788 @@ if ($action == 'create') { print dol_get_fiche_head(''); - print ''; + // Call Hook tabContentCreateInvoice + $parameters = array(); + // Note that $action and $object may be modified by hook + $reshook = $hookmanager->executeHooks('tabContentCreateInvoice', $parameters, $object, $action); + if (empty($reshook)) { + print '
'; - // Ref - //print ''; + // Ref + //print ''; - $exampletemplateinvoice = new FactureRec($db); - $invoice_predefined = new FactureRec($db); - if (empty($origin) && empty($originid) && GETPOST('fac_rec', 'int') > 0) { - $invoice_predefined->fetch(GETPOST('fac_rec', 'int')); - } + $exampletemplateinvoice = new FactureRec($db); + $invoice_predefined = new FactureRec($db); + if (empty($origin) && empty($originid) && GETPOST('fac_rec', 'int') > 0) { + $invoice_predefined->fetch(GETPOST('fac_rec', 'int')); + } - // Thirdparty - if ($soc->id > 0 && (!GETPOST('fac_rec', 'int') || !empty($invoice_predefined->frequency))) { - // If thirdparty known and not a predefined invoiced without a recurring rule - print ''; - print ''; + print ''; - print ''."\n"; - } else { - print ''; - print ''; - print ''."\n"; - } - - // Overwrite some values if creation of invoice is from a predefined invoice - if (empty($origin) && empty($originid) && GETPOST('fac_rec', 'int') > 0) { - $invoice_predefined->fetch(GETPOST('fac_rec', 'int')); - - $dateinvoice = $invoice_predefined->date_when; // To use next gen date by default later - if (empty($projectid)) { - $projectid = $invoice_predefined->fk_project; - } - $cond_reglement_id = $invoice_predefined->cond_reglement_id; - $mode_reglement_id = $invoice_predefined->mode_reglement_id; - $fk_account = $invoice_predefined->fk_account; - $note_public = $invoice_predefined->note_public; - $note_private = $invoice_predefined->note_private; - - if (!empty($invoice_predefined->multicurrency_code)) { - $currency_code = $invoice_predefined->multicurrency_code; - } - if (!empty($invoice_predefined->multicurrency_tx)) { - $currency_tx = $invoice_predefined->multicurrency_tx; - } - - $sql = 'SELECT r.rowid, r.titre as title, r.total_ttc'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_rec as r'; - $sql .= ' WHERE r.fk_soc = '.((int) $invoice_predefined->socid); - - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - - if ($num > 0) { - print ''; - } - $db->free($resql); - } else { - dol_print_error($db); - } - } - - print ''; + print ''."\n"; } - // Replacement - if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) { - // Type de facture - $facids = $facturestatic->list_replacable_invoices($soc->id); - if ($facids < 0) { - dol_print_error($db, $facturestatic->error, $facturestatic->errors); - exit(); + // Overwrite some values if creation of invoice is from a predefined invoice + if (empty($origin) && empty($originid) && GETPOST('fac_rec', 'int') > 0) { + $invoice_predefined->fetch(GETPOST('fac_rec', 'int')); + + $dateinvoice = $invoice_predefined->date_when; // To use next gen date by default later + if (empty($projectid)) { + $projectid = $invoice_predefined->fk_project; } - $options = ""; - if (is_array($facids)) { - foreach ($facids as $facparam) { - $options .= ''; - } + $cond_reglement_id = $invoice_predefined->cond_reglement_id; + $mode_reglement_id = $invoice_predefined->mode_reglement_id; + $fk_account = $invoice_predefined->fk_account; + $note_public = $invoice_predefined->note_public; + $note_private = $invoice_predefined->note_private; + + if (!empty($invoice_predefined->multicurrency_code)) { + $currency_code = $invoice_predefined->multicurrency_code; + } + if (!empty($invoice_predefined->multicurrency_tx)) { + $currency_tx = $invoice_predefined->multicurrency_tx; } - print ''; - print '
'; - $tmp = 'id > 0) { - $tmp .= ' disabled'; - } - $tmp .= '> '; - print ''; - $text = $tmp.''; - $text .= '
'; + } + $db->free($resql); } else { - $text .= ''; + dol_print_error($db); } - $text .= ''; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3); - print $desc; - print ''; - } - } else { - if (!empty($conf->global->INVOICE_USE_SITUATION)) { - print '
'; - $tmp = ' '; - $text = $tmp.' '; - $text .= '('.$langs->trans("YouMustCreateInvoiceFromThird").') '; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3, 'firstsituationonsmartphone'); - print $desc; - print '
'; } + print ''; + // pre-filled extra fields with selected credit note + $newinvoice_static->fetch_optionals($key); + $object->array_options = $newinvoice_static->array_options; + } + $optionsav .= '>'; + $optionsav .= $newinvoice_static->ref; + $optionsav .= ' ('.$newinvoice_static->getLibStatut(1, $valarray ['paymentornot']).')'; + $optionsav .= ''; + } - // Invoice Subtype - if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED')) { - print ''; - } + print '
'; + $tmp = 'global->INVOICE_CREDIT_NOTE_STANDALONE)) || $invoice_predefined->id > 0) { + $tmp .= ' disabled'; + } + $tmp .= '> '; + // Show credit note options only if we checked credit note and disable standard invoice if "create credit note" button is pressed + print ''; + $text = ' '; + $text .= ''; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); + print $desc; - if ($socid > 0) { - // Discounts for third party - print '
'; - } - - $newdateinvoice = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'), 'tzserver'); - $date_pointoftax = dol_mktime(0, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'), 'tzserver'); - - // Date invoice - print ''; - - // Date point of tax - if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) { - print ''; - } - - // Payment term - print ''; - - - if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) { - $rwStyle = 'display:none;'; - if (in_array(GETPOST('type', 'int'), $retainedWarrantyInvoiceAvailableType)) { - $rwStyle = ''; - } - - $retained_warranty = GETPOST('retained_warranty', 'int'); - if (empty($retained_warranty)) { - if (!empty($objectsrc->retained_warranty)) { // use previous situation value - $retained_warranty = $objectsrc->retained_warranty; - } - } - $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT; - - print ''; + + // Invoice Subtype + if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED')) { + print ''; + } + + if ($socid > 0) { + // Discounts for third party + print ''; + } + + $newdateinvoice = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'), 'tzserver'); + $date_pointoftax = dol_mktime(0, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'), 'tzserver'); + + // Date invoice + print ''; + + // Date point of tax + if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) { + print ''; + } + + // Payment term + print ''; + + + if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) { + $rwStyle = 'display:none;'; + if (in_array(GETPOST('type', 'int'), $retainedWarrantyInvoiceAvailableType)) { + $rwStyle = ''; + } + + $retained_warranty = GETPOST('retained_warranty', 'int'); + if (empty($retained_warranty)) { + if (!empty($objectsrc->retained_warranty)) { // use previous situation value + $retained_warranty = $objectsrc->retained_warranty; + } + } + $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT; + + print ''; + print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement', -1, 1); + print ''; - print ''; - } - - // Payment mode - print ''; - - // Bank Account - if (isModEnabled("banque")) { - print ''; - } - - // Project - if (isModEnabled('project')) { - $langs->load('projects'); - print ''; - } - - // Incoterms - if (isModEnabled('incoterm')) { - print ''; - print ''; - print ''; - } - // Other attributes - $parameters = array('objectsrc' => !empty($objectsrc) ? $objectsrc : 0, 'colspan' => ' colspan="2"', 'cols' => '2', 'socid'=>$socid); - $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - if (empty($reshook)) { - if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE) && !empty($soc->id)) { - // copy from thirdparty - $tpExtrafields = new ExtraFields($db); - $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element); - if ($soc->fetch_optionals() > 0) { - $object->array_options = array_merge($object->array_options, $soc->array_options); + // Payment mode + print ''; + + // Bank Account + if (isModEnabled("banque")) { + print ''; + } + + // Project + if (isModEnabled('project')) { + $langs->load('projects'); + print ''; + } + + // Incoterms + if (isModEnabled('incoterm')) { + print ''; + print ''; + print ''; } - print $object->showOptionals($extrafields, 'create', $parameters); - } + // Other attributes + $parameters = array('objectsrc' => !empty($objectsrc) ? $objectsrc : 0, 'colspan' => ' colspan="2"', 'cols' => '2', 'socid'=>$socid); + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (empty($reshook)) { + if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE) && !empty($soc->id)) { + // copy from thirdparty + $tpExtrafields = new ExtraFields($db); + $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element); + if ($soc->fetch_optionals() > 0) { + $object->array_options = array_merge($object->array_options, $soc->array_options); + } + } - // Template to use by default - print ''; - print '"; - - // Multicurrency - if (isModEnabled('multicurrency')) { - print ''; - print ''; - print ''; - } - - // Help of substitution key - $htmltext = ''; - if (GETPOST('fac_rec', 'int') > 0) { - $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice); - if (empty($dateexample)) { - $dateexample = dol_now(); + print $object->showOptionals($extrafields, 'create', $parameters); } - $substitutionarray = array( - '__TOTAL_HT__' => $langs->trans("AmountHT").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ht).')', - '__TOTAL_TTC__' => $langs->trans("AmountTTC").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ttc).')', - '__INVOICE_PREVIOUS_MONTH__' => $langs->trans("PreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%m').')', - '__INVOICE_MONTH__' => $langs->trans("MonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%m').')', - '__INVOICE_NEXT_MONTH__' => $langs->trans("NextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%m').')', - '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans("TextPreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%B').')', - '__INVOICE_MONTH_TEXT__' => $langs->trans("TextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%B').')', - '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans("TextNextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%B').')', - '__INVOICE_PREVIOUS_YEAR__' => $langs->trans("PreviousYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'y'), '%Y').')', - '__INVOICE_YEAR__' => $langs->trans("YearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%Y').')', - '__INVOICE_NEXT_YEAR__' => $langs->trans("NextYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'y'), '%Y').')' - ); - $htmltext = ''.$langs->trans("FollowingConstantsWillBeSubstituted").':
'; - foreach ($substitutionarray as $key => $val) { - $htmltext .= $key.' = '.$langs->trans($val).'
'; + // Template to use by default + print '
'; + print '"; - // Public note - print ''; - print ''; - print ''; + print ''; + print ''; + } - // Private note - if (empty($user->socid)) { + // Help of substitution key + $htmltext = ''; + if (GETPOST('fac_rec', 'int') > 0) { + $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice); + if (empty($dateexample)) { + $dateexample = dol_now(); + } + $substitutionarray = array( + '__TOTAL_HT__' => $langs->trans("AmountHT").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ht).')', + '__TOTAL_TTC__' => $langs->trans("AmountTTC").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ttc).')', + '__INVOICE_PREVIOUS_MONTH__' => $langs->trans("PreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%m').')', + '__INVOICE_MONTH__' => $langs->trans("MonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%m').')', + '__INVOICE_NEXT_MONTH__' => $langs->trans("NextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%m').')', + '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans("TextPreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%B').')', + '__INVOICE_MONTH_TEXT__' => $langs->trans("TextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%B').')', + '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans("TextNextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%B').')', + '__INVOICE_PREVIOUS_YEAR__' => $langs->trans("PreviousYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'y'), '%Y').')', + '__INVOICE_YEAR__' => $langs->trans("YearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%Y').')', + '__INVOICE_NEXT_YEAR__' => $langs->trans("NextYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'y'), '%Y').')' + ); + + $htmltext = ''.$langs->trans("FollowingConstantsWillBeSubstituted").':
'; + foreach ($substitutionarray as $key => $val) { + $htmltext .= $key.' = '.$langs->trans($val).'
'; + } + $htmltext .= '
'; + } + + // Public note print '
'; print ''; print ''; + + // Private note + if (empty($user->socid)) { + print ''; + print ''; + print ''; + } + + // Lines from source (TODO Show them also when creating invoice from template invoice) + if (!empty($origin) && !empty($originid) && is_object($objectsrc)) { + $langs->loadLangs(array('orders', 'propal')); + + // TODO for compatibility + if ($origin == 'contrat') { + // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva + //$objectsrc->remise_absolue = $remise_absolue; + //$objectsrc->remise_percent = $remise_percent; + $objectsrc->update_price(1, 'auto', 1); + } + + print "\n\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + // The commented lines below are fields already added as hidden parameters before + //print ''; + //print ''; + + switch (get_class($objectsrc)) { + case 'Propal': + $newclassname = 'CommercialProposal'; + break; + case 'Commande': + $newclassname = 'Order'; + break; + case 'Expedition': + $newclassname = 'Sending'; + break; + case 'Contrat': + $newclassname = 'Contract'; + break; + case 'Fichinter': + $newclassname = 'Intervention'; + break; + default: + $newclassname = get_class($objectsrc); + } + + // Ref of origin + print ''; + print ''; + print ''; + print '"; + if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1 + print '"; + } + + if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2 + print '"; + } + print '"; + + if (isModEnabled('multicurrency')) { + print ''; + print '"; + print '"; + } + } + + print "
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('Customer').''; - print $soc->getNomUrl(1, 'customer'); - print ''; - // Outstanding Bill - $arrayoutstandingbills = $soc->getOutstandingBills(); - $outstandingBills = $arrayoutstandingbills['opened']; - print ' - '.$langs->trans('CurrentOutstandingBill').': '; - print ''.price($outstandingBills, '', $langs, 0, 0, -1, $conf->currency).''; - if ($soc->outstanding_limit != '') { - if ($outstandingBills > $soc->outstanding_limit) { - print img_warning($langs->trans("OutstandingBillReached")); + // Thirdparty + if ($soc->id > 0 && (!GETPOST('fac_rec', 'int') || !empty($invoice_predefined->frequency))) { + // If thirdparty known and not a predefined invoiced without a recurring rule + print '
'.$langs->trans('Customer').''; + print $soc->getNomUrl(1, 'customer'); + print ''; + // Outstanding Bill + $arrayoutstandingbills = $soc->getOutstandingBills(); + $outstandingBills = $arrayoutstandingbills['opened']; + print ' - '.$langs->trans('CurrentOutstandingBill').': '; + print ''.price($outstandingBills, '', $langs, 0, 0, -1, $conf->currency).''; + if ($soc->outstanding_limit != '') { + if ($outstandingBills > $soc->outstanding_limit) { + print img_warning($langs->trans("OutstandingBillReached")); + } + print ' / '.price($soc->outstanding_limit, '', $langs, 0, 0, -1, $conf->currency); } - print ' / '.price($soc->outstanding_limit, '', $langs, 0, 0, -1, $conf->currency); - } - print '
'.$langs->trans('Customer').''; - $filter = '((s.client:IN:1,2,3) AND (s.status:=:1))'; - print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company($soc->id, 'socid', $filter, 'SelectThirdParty', 1, 0, null, 0, 'minwidth300 widthcentpercentminusxx maxwidth500'); - // Option to reload page to retrieve customer informations. - if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) { - print ''; - } - if (!GETPOST('fac_rec', 'int')) { - print ' '; - } - print '
'.$langs->trans('CreateFromRepeatableInvoice').''; - //print ''; - print ''; - - print ajax_combobox("fac_rec"); - - // Option to reload page to retrieve customer informations. Note, this clear other input - if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) { - print ''; - } - print '
'.$langs->trans('Type').''; - print '
'."\n"; - - // Standard invoice - print '
'; - $tmp = ' '; - $tmp = $tmp.''; - $desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceStandardDesc"), 1, 'help', '', 0, 3, 'standardonsmartphone'); - print ''; - print ''; - if ((($origin == 'propal') || ($origin == 'commande')) && (!empty($originid))) { - /*print '';*/ - print ''; - } - print '
'; - print $desc; - print ''; - $arraylist = array( - //'amount' => $langs->transnoentitiesnoconv('FixAmount', $langs->transnoentitiesnoconv('Deposit')), - //'variable' => $langs->transnoentitiesnoconv('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit')), - 'variablealllines' => $langs->transnoentitiesnoconv('VarAmountAllLines') - ); - print $form->selectarray('typestandard', $arraylist, GETPOST('typestandard', 'aZ09'), 0, 0, 0, '', 1); - print ''; - print ''.$langs->trans('PercentOfOriginalObject').':'; - print '
'; - print '
'; - - if ((empty($origin)) || ((($origin == 'propal') || ($origin == 'commande')) && (!empty($originid)))) { - // Deposit - Down payment - if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) { - print '
'; - $tmp = ' '; - print ''; - - print ''; - print ''; - if (($origin == 'propal') || ($origin == 'commande')) { - print ''; - print ''; + print ''."\n"; + } else { + print ''; + print '
'; - $tmp = $tmp.''; - $desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3, 'depositonsmartphone'); - print $desc; print ''; - $arraylist = array( - 'amount' => $langs->transnoentitiesnoconv('FixAmount', $langs->transnoentitiesnoconv('Deposit')), - 'variable' => $langs->transnoentitiesnoconv('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit')), - 'variablealllines' => $langs->transnoentitiesnoconv('VarAmountAllLines') - ); - $typedeposit = GETPOST('typedeposit', 'aZ09'); - $valuedeposit = GETPOST('valuedeposit', 'int'); - if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) { - $origin_payment_conditions_deposit_percent = getDictionaryValue('c_payment_term', 'deposit_percent', $objectsrc->cond_reglement_id); - if (!empty($origin_payment_conditions_deposit_percent)) { - $typedeposit = 'variable'; - } - } - if (empty($valuedeposit) && $typedeposit == 'variable' && !empty($objectsrc->deposit_percent)) { - $valuedeposit = $objectsrc->deposit_percent; - } - print $form->selectarray('typedeposit', $arraylist, $typedeposit, 0, 0, 0, '', 1); - print ''; - print ''.$langs->trans("AmountOrPercent").''; - print '
'.$langs->trans('Customer').''; + $filter = '((s.client:IN:1,2,3) AND (s.status:=:1))'; + print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company($soc->id, 'socid', $filter, 'SelectThirdParty', 1, 0, null, 0, 'minwidth300 widthcentpercentminusxx maxwidth500'); + // Option to reload page to retrieve customer informations. + if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) { + print ''; } - print '
'; - - print '
'; - } - } - - if ($socid > 0) { - if (!empty($conf->global->INVOICE_USE_SITUATION)) { - // First situation invoice - print '
'; - $tmp = ' '; - $tmp = $tmp.''; - $desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3, 'firstsituationonsmartphone'); - print $desc; - print '
'; - - // Next situation invoice - $opt = $form->selectSituationInvoices(GETPOST('originid', 'int'), $socid); - - print '
'; - $tmp = ''.$langs->trans('NoSituations').'') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande')) { - $tmp .= ' disabled'; + if (!GETPOST('fac_rec', 'int')) { + print ' '; } - $tmp .= '> '; - $text = $tmp.' '; - $text .= ''; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceSituationDesc"), 1, 'help', '', 0, 3); - print $desc; - print '
'; + print '
'.$langs->trans('CreateFromRepeatableInvoice').''; + //print ''; + print ''; + + print ajax_combobox("fac_rec"); + + // Option to reload page to retrieve customer informations. Note, this clear other input + if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) { + print ''; + } + print '
'.$langs->trans('Type').''; + print '
'."\n"; + + // Standard invoice print '
'; - $tmp = ' '; - $text = $tmp.' '; - //$text .= '('.$langs->trans("YouMustCreateInvoiceFromThird").') '; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc").'

'.$langs->trans("YouMustCreateInvoiceFromThird"), 1, 'help', '', 0, 3, 'replacementonsmartphone'); + $tmp = ' '; + $tmp = $tmp.''; + $desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceStandardDesc"), 1, 'help', '', 0, 3, 'standardonsmartphone'); + print ''; + print ''; + if ((($origin == 'propal') || ($origin == 'commande')) && (!empty($originid))) { + /*print '';*/ + print ''; + } + print '
'; print $desc; + print ''; + $arraylist = array( + //'amount' => $langs->transnoentitiesnoconv('FixAmount', $langs->transnoentitiesnoconv('Deposit')), + //'variable' => $langs->transnoentitiesnoconv('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit')), + 'variablealllines' => $langs->transnoentitiesnoconv('VarAmountAllLines') + ); + print $form->selectarray('typestandard', $arraylist, GETPOST('typestandard', 'aZ09'), 0, 0, 0, '', 1); + print ''; + print ''.$langs->trans('PercentOfOriginalObject').':'; + print '
'; print '
'; - } - - if (empty($origin)) { - if ($socid > 0) { - // Credit note - if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) { - // Show link for credit note - $facids = $facturestatic->list_qualified_avoir_invoices($soc->id); - if ($facids < 0) { - dol_print_error($db, $facturestatic->error, $facturestatic->errors); - exit; - } - $optionsav = ""; - $newinvoice_static = new Facture($db); - foreach ($facids as $key => $valarray) { - $newinvoice_static->id = $key; - $newinvoice_static->ref = $valarray ['ref']; - $newinvoice_static->statut = $valarray ['status']; - $newinvoice_static->type = $valarray ['type']; - $newinvoice_static->paye = $valarray ['paye']; - - $optionsav .= ''; - } + if ((empty($origin)) || ((($origin == 'propal') || ($origin == 'commande')) && (!empty($originid)))) { + // Deposit - Down payment + if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) { print '
'; - $tmp = 'global->INVOICE_CREDIT_NOTE_STANDALONE)) || $invoice_predefined->id > 0) { - $tmp .= ' disabled'; - } - $tmp .= '> '; - // Show credit note options only if we checked credit note and disable standard invoice if "create credit note" button is pressed + $tmp = ' '; print ''; - $text = ' '; - $text .= ''; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); - print $desc; + jQuery(document).ready(function() { + jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() { + jQuery("#radio_standard").prop("checked", true); + }); + jQuery("#typedeposit, #valuedeposit").click(function() { + jQuery("#radio_deposit").prop("checked", true); + }); + jQuery("#typedeposit").change(function() { + console.log("We change type of down payment"); + jQuery("#radio_deposit").prop("checked", true); + setRadioForTypeOfInvoice(); + }); + jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() { + setRadioForTypeOfInvoice(); + }); + function setRadioForTypeOfInvoice() { + console.log("Change radio"); + if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) { + jQuery(".checkforselect").prop("disabled", true); + jQuery(".checkforselect").prop("checked", false); + } else { + jQuery(".checkforselect").prop("disabled", false); + jQuery(".checkforselect").prop("checked", true); + } + } + }); + '; - print '
'; - print '    0 ? 'checked' : '').' /> "; - print '
    0 ? 'checked' : '').' /> "; - print '
'; + print ''; + print ''; + if (($origin == 'propal') || ($origin == 'commande')) { + print ''; + print ''; + } + print '
'; + $tmp = $tmp.''; + $desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3, 'depositonsmartphone'); + print $desc; + print ''; + $arraylist = array( + 'amount' => $langs->transnoentitiesnoconv('FixAmount', $langs->transnoentitiesnoconv('Deposit')), + 'variable' => $langs->transnoentitiesnoconv('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit')), + 'variablealllines' => $langs->transnoentitiesnoconv('VarAmountAllLines') + ); + $typedeposit = GETPOST('typedeposit', 'aZ09'); + $valuedeposit = GETPOST('valuedeposit', 'int'); + if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) { + $origin_payment_conditions_deposit_percent = getDictionaryValue('c_payment_term', 'deposit_percent', $objectsrc->cond_reglement_id); + if (!empty($origin_payment_conditions_deposit_percent)) { + $typedeposit = 'variable'; + } + } + if (empty($valuedeposit) && $typedeposit == 'variable' && !empty($objectsrc->deposit_percent)) { + $valuedeposit = $objectsrc->deposit_percent; + } + print $form->selectarray('typedeposit', $arraylist, $typedeposit, 0, 0, 0, '', 1); + print ''; + print ''.$langs->trans("AmountOrPercent").''; + print '
'; + print '
'; + } + } + + if ($socid > 0) { + if (!empty($conf->global->INVOICE_USE_SITUATION)) { + // First situation invoice + print '
'; + $tmp = ' '; + $tmp = $tmp.''; + $desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3, 'firstsituationonsmartphone'); + print $desc; + print '
'; + + // Next situation invoice + $opt = $form->selectSituationInvoices(GETPOST('originid', 'int'), $socid); + + print '
'; + $tmp = ''.$langs->trans('NoSituations').'') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande')) { + $tmp .= ' disabled'; + } + $tmp .= '> '; + $text = $tmp.' '; + $text .= ''; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceSituationDesc"), 1, 'help', '', 0, 3); + print $desc; + print '
'; + } + + // Replacement + if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) { + // Type de facture + $facids = $facturestatic->list_replacable_invoices($soc->id); + if ($facids < 0) { + dol_print_error($db, $facturestatic->error, $facturestatic->errors); + exit(); + } + $options = ""; + if (is_array($facids)) { + foreach ($facids as $facparam) { + $options .= ''; + } + } + + print ''; + print '
'; + $tmp = 'id > 0) { + $tmp .= ' disabled'; + } + $tmp .= '> '; + print ''; + $text = $tmp.''; + $text .= ''; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3); + print $desc; print '
'; } } else { + if (!empty($conf->global->INVOICE_USE_SITUATION)) { + print '
'; + $tmp = ' '; + $text = $tmp.' '; + $text .= '('.$langs->trans("YouMustCreateInvoiceFromThird").') '; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3, 'firstsituationonsmartphone'); + print $desc; + print '
'; + } + print '
'; - if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) { - $tmp = ' '; - } else { - $tmp = ' '; - } - $text = $tmp.' '; + $tmp = ' '; + $text = $tmp.' '; //$text .= '('.$langs->trans("YouMustCreateInvoiceFromThird").') '; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc").'

'.$langs->trans("YouMustCreateInvoiceFromThird"), 1, 'help', '', 0, 3, 'creditnoteonsmartphone'); + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc").'

'.$langs->trans("YouMustCreateInvoiceFromThird"), 1, 'help', '', 0, 3, 'replacementonsmartphone'); print $desc; - print '
'."\n"; - } - } - - // Template invoice - print '
'; - $tmp = ' '; - $text = $tmp.' '; - $desc = $form->textwithpicto($text, $langs->transnoentities("YouMustCreateStandardInvoiceFirstDesc"), 1, 'help', '', 0, 3, 'templateonsmartphone'); - print $desc; - print '
'; - - print '
'; - - - if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) { // Hidden conf - // Add auto select default document model - $listtType = array(Facture::TYPE_STANDARD, Facture::TYPE_REPLACEMENT, Facture::TYPE_CREDIT_NOTE, Facture::TYPE_DEPOSIT, Facture::TYPE_SITUATION); - $jsListType = ''; - foreach ($listtType as $type) { - $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type; - $curent = getDolGlobalString($thisTypeConfName, getDolGlobalString('FACTURE_ADDON_PDF')); - $jsListType .= (!empty($jsListType) ? ',' : '').'"'.$type.'":"'.$curent.'"'; + print ''; } - print ''; - } + if (empty($origin)) { + if ($socid > 0) { + // Credit note + if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) { + // Show link for credit note + $facids = $facturestatic->list_qualified_avoir_invoices($soc->id); + if ($facids < 0) { + dol_print_error($db, $facturestatic->error, $facturestatic->errors); + exit; + } + $optionsav = ""; + $newinvoice_static = new Facture($db); + foreach ($facids as $key => $valarray) { + $newinvoice_static->id = $key; + $newinvoice_static->ref = $valarray ['ref']; + $newinvoice_static->statut = $valarray ['status']; + $newinvoice_static->type = $valarray ['type']; + $newinvoice_static->paye = $valarray ['paye']; + $optionsav .= '
'.$langs->trans('InvoiceSubtype').''; - print $form->getSelectInvoiceSubtype(GETPOST('subtype'), 'subtype', 1, 0, ''); - print '
'.$langs->trans('DiscountStillRemaining').''; + print '
'; + print '    0 ? 'checked' : '').' /> "; + print '
    0 ? 'checked' : '').' /> "; + print '
'; - $thirdparty = $soc; - $discount_type = 0; - $backtopage = $_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.urlencode(GETPOST('origin')).'&originid='.urlencode(GETPOSTINT('originid')); - include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; - - print '
'.$langs->trans('DateInvoice').''; - print img_picto('', 'action', 'class="pictofixedwidth"'); - print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice, '', '', '', '', "add", 1, 1); - print '
'.$langs->trans('DatePointOfTax').''; - print img_picto('', 'action', 'class="pictofixedwidth"'); - print $form->selectDate($date_pointoftax ? $date_pointoftax : -1, 'date_pointoftax', '', '', '', "add", 1, 1); - print '
'.$langs->trans('PaymentConditionsShort').''; - print img_picto('', 'payment', 'class="pictofixedwidth"'); - print $form->getSelectConditionsPaiements((GETPOSTISSET('cond_reglement_id') && GETPOST('cond_reglement_id', 'int') != 0) ? GETPOST('cond_reglement_id', 'int') : $cond_reglement_id, 'cond_reglement_id', -1, 1, 0, 'maxwidth500 widthcentpercentminusx'); - print '
'.$langs->trans('RetainedWarranty').''; - print '%'; - - // Retained warranty payment term - print '
'.$langs->trans('PaymentConditionsShortRetainedWarranty').''; - $retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); - if (empty($retained_warranty_fk_cond_reglement)) { - $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; - if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) { // use previous situation value - $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement; + print ''; + } } else { + print '
'; + if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) { + $tmp = ' '; + } else { + $tmp = ' '; + } + $text = $tmp.' '; + //$text .= '('.$langs->trans("YouMustCreateInvoiceFromThird").') '; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc").'

'.$langs->trans("YouMustCreateInvoiceFromThird"), 1, 'help', '', 0, 3, 'creditnoteonsmartphone'); + print $desc; + print '
'."\n"; + } + } + + // Template invoice + print '
'; + $tmp = ' '; + $text = $tmp.' '; + $desc = $form->textwithpicto($text, $langs->transnoentities("YouMustCreateStandardInvoiceFirstDesc"), 1, 'help', '', 0, 3, 'templateonsmartphone'); + print $desc; + print '
'; + + print ''; + + + if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) { // Hidden conf + // Add auto select default document model + $listtType = array(Facture::TYPE_STANDARD, Facture::TYPE_REPLACEMENT, Facture::TYPE_CREDIT_NOTE, Facture::TYPE_DEPOSIT, Facture::TYPE_SITUATION); + $jsListType = ''; + foreach ($listtType as $type) { + $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type; + $curent = getDolGlobalString($thisTypeConfName, getDolGlobalString('FACTURE_ADDON_PDF')); + $jsListType .= (!empty($jsListType) ? ',' : '').'"'.$type.'":"'.$curent.'"'; + } + + print ''; + } + + + print '
'.$langs->trans('InvoiceSubtype').''; + print $form->getSelectInvoiceSubtype(GETPOST('subtype'), 'subtype', 1, 0, ''); + print '
'.$langs->trans('DiscountStillRemaining').''; + + $thirdparty = $soc; + $discount_type = 0; + $backtopage = $_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.urlencode(GETPOST('origin')).'&originid='.urlencode(GETPOSTINT('originid')); + include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; + + print '
'.$langs->trans('DateInvoice').''; + print img_picto('', 'action', 'class="pictofixedwidth"'); + print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice, '', '', '', '', "add", 1, 1); + print '
'.$langs->trans('DatePointOfTax').''; + print img_picto('', 'action', 'class="pictofixedwidth"'); + print $form->selectDate($date_pointoftax ? $date_pointoftax : -1, 'date_pointoftax', '', '', '', "add", 1, 1); + print '
'.$langs->trans('PaymentConditionsShort').''; + print img_picto('', 'payment', 'class="pictofixedwidth"'); + print $form->getSelectConditionsPaiements($cond_reglement_id, 'cond_reglement_id', -1, 1, 0, 'maxwidth500 widthcentpercentminusx'); + print '
'.$langs->trans('RetainedWarranty').''; + print '%'; + + // Retained warranty payment term + print '
'.$langs->trans('PaymentConditionsShortRetainedWarranty').''; + $retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); + if (empty($retained_warranty_fk_cond_reglement)) { $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; + if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) { // use previous situation value + $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement; + } else { + $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; + } } - } - print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement', -1, 1); - print '
'.$langs->trans('PaymentMode').''; - print img_picto('', 'bank', 'class="pictofixedwidth"'); - print $form->select_types_paiements((GETPOSTISSET('mode_reglement_id') && GETPOST('mode_reglement_id') != 0)? GETPOST('mode_reglement_id') : $mode_reglement_id, 'mode_reglement_id', 'CRDT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx', 1); - print '
'.$langs->trans('BankAccount').''; - print img_picto('', 'bank_account', 'class="pictofixedwidth"'); - print $form->select_comptes(($fk_account < 0 ? '' : $fk_account), 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1); - print '
'.$langs->trans('Project').''; - print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx'); - print ' id.($fac_rec ? '&fac_rec='.$fac_rec : '')).'">'; - print '
'; - $incoterm_id = GETPOST('incoterm_id'); - $incoterm_location = GETPOST('location_incoterms'); - if (empty($incoterm_id)) { - $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms); - $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms); + '; } - print img_picto('', 'incoterm', 'class="pictofixedwidth"'); - print $form->select_incoterms($incoterm_id, $incoterm_location); - print '
'.$langs->trans('PaymentMode').''; + print img_picto('', 'bank', 'class="pictofixedwidth"'); + print $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id', 'CRDT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx', 1); + print '
'.$langs->trans('BankAccount').''; + print img_picto('', 'bank_account', 'class="pictofixedwidth"'); + print $form->select_comptes($fk_account, 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1); + print '
'.$langs->trans('Project').''; + print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx'); + print ' id.($fac_rec ? '&fac_rec='.$fac_rec : '')).'">'; + print '
'; + $incoterm_id = GETPOST('incoterm_id'); + $incoterm_location = GETPOST('location_incoterms'); + if (empty($incoterm_id)) { + $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms); + $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms); } + print img_picto('', 'incoterm', 'class="pictofixedwidth"'); + print $form->select_incoterms($incoterm_id, $incoterm_location); + print '
'.$langs->trans('Model').''; - print img_picto('', 'pdf', 'class="pictofixedwidth"'); - include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; - $liste = ModelePDFFactures::liste_modeles($db); - if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) { - // Hidden conf - $paramkey = 'FACTURE_ADDON_PDF_'.$object->type; - $preselected = !empty($conf->global->$paramkey) ? $conf->global->$paramkey : $conf->global->FACTURE_ADDON_PDF; - } else { - $preselected = $conf->global->FACTURE_ADDON_PDF; - } - print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1); - print "
'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).''; - print img_picto('', 'currency', 'class="pictofixedwidth"'); - print $form->selectMultiCurrency(((GETPOSTISSET('multicurrency_code') && !GETPOST('changecompany'))?GETPOST('multicurrency_code'):$currency_code), 'multicurrency_code'); - print '
'.$langs->trans('Model').''; + print img_picto('', 'pdf', 'class="pictofixedwidth"'); + include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; + $liste = ModelePDFFactures::liste_modeles($db); + if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) { + // Hidden conf + $paramkey = 'FACTURE_ADDON_PDF_'.$object->type; + $preselected = !empty($conf->global->$paramkey) ? $conf->global->$paramkey : $conf->global->FACTURE_ADDON_PDF; + } else { + $preselected = $conf->global->FACTURE_ADDON_PDF; } - $htmltext .= ''; - } + print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1); + print "
'; - print $form->textwithpicto($langs->trans('NotePublic'), $htmltext); - print ''; - $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%'); - print $doleditor->Create(1); + // Multicurrency + if (isModEnabled('multicurrency')) { + print '
'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).''; + print img_picto('', 'currency', 'class="pictofixedwidth"'); + print $form->selectMultiCurrency(((GETPOSTISSET('multicurrency_code') && !GETPOST('changecompany'))?GETPOST('multicurrency_code'):$currency_code), 'multicurrency_code'); + print '
'; - print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext); + print $form->textwithpicto($langs->trans('NotePublic'), $htmltext); print ''; - $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%'); + $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%'); print $doleditor->Create(1); - // print ' - print '
'; + print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext); + print ''; + $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%'); + print $doleditor->Create(1); + // print ' + print '
'.$langs->trans($newclassname).''; + print $objectsrc->getNomUrl(1); + // We check if Origin document (id and type is known) has already at least one invoice attached to it + $objectsrc->fetchObjectLinked($originid, $origin, '', 'facture'); + if (isset($objectsrc->linkedObjects['facture']) && is_array($objectsrc->linkedObjects['facture']) && count($objectsrc->linkedObjects['facture']) >= 1) { + setEventMessages('WarningBillExist', null, 'warnings'); + echo ' - '.$langs->trans('LatestRelatedBill').' '.end($objectsrc->linkedObjects['facture'])->getNomUrl(1); + } + echo '
'.$langs->trans('AmountHT').''.price($objectsrc->total_ht).'
'.$langs->trans('AmountVAT').''.price($objectsrc->total_tva)."
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($objectsrc->total_localtax1)."
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($objectsrc->total_localtax2)."
'.$langs->trans('AmountTTC').''.price($objectsrc->total_ttc)."
'.$langs->trans('MulticurrencyAmountHT').''.price($objectsrc->multicurrency_total_ht).'
'.$langs->trans('MulticurrencyAmountVAT').''.price($objectsrc->multicurrency_total_tva)."
'.$langs->trans('MulticurrencyAmountTTC').''.price($objectsrc->multicurrency_total_ttc)."
\n"; } - - // Lines from source (TODO Show them also when creating invoice from template invoice) - if (!empty($origin) && !empty($originid) && is_object($objectsrc)) { - $langs->loadLangs(array('orders', 'propal')); - - // TODO for compatibility - if ($origin == 'contrat') { - // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva - //$objectsrc->remise_absolue = $remise_absolue; - //$objectsrc->remise_percent = $remise_percent; - $objectsrc->update_price(1, 'auto', 1); - } - - print "\n\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - // The commented lines below are fields already added as hidden parameters before - //print ''; - //print ''; - - switch (get_class($objectsrc)) { - case 'Propal': - $newclassname = 'CommercialProposal'; - break; - case 'Commande': - $newclassname = 'Order'; - break; - case 'Expedition': - $newclassname = 'Sending'; - break; - case 'Contrat': - $newclassname = 'Contract'; - break; - case 'Fichinter': - $newclassname = 'Intervention'; - break; - default: - $newclassname = get_class($objectsrc); - } - - // Ref of origin - print '
'.$langs->trans($newclassname).''; - print $objectsrc->getNomUrl(1); - // We check if Origin document (id and type is known) has already at least one invoice attached to it - $objectsrc->fetchObjectLinked($originid, $origin, '', 'facture'); - if (isset($objectsrc->linkedObjects['facture']) && is_array($objectsrc->linkedObjects['facture']) && count($objectsrc->linkedObjects['facture']) >= 1) { - setEventMessages('WarningBillExist', null, 'warnings'); - echo ' - '.$langs->trans('LatestRelatedBill').' '.end($objectsrc->linkedObjects['facture'])->getNomUrl(1); - } - echo '
'.$langs->trans('AmountHT').''.price($objectsrc->total_ht).'
'.$langs->trans('AmountVAT').''.price($objectsrc->total_tva)."
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($objectsrc->total_localtax1)."
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($objectsrc->total_localtax2)."
'.$langs->trans('AmountTTC').''.price($objectsrc->total_ttc)."
'.$langs->trans('MulticurrencyAmountHT').''.price($objectsrc->multicurrency_total_ht).'
'.$langs->trans('MulticurrencyAmountVAT').''.price($objectsrc->multicurrency_total_tva)."
'.$langs->trans('MulticurrencyAmountTTC').''.price($objectsrc->multicurrency_total_ttc)."
\n"; - print dol_get_fiche_end(); print $form->buttonsSaveCancel("CreateDraft"); @@ -4507,1076 +4528,1083 @@ if ($action == 'create') { dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', ''); - print '
'; - print '
'; - print '
'; + // Call Hook tabContentViewInvoice + $parameters = array(); + // Note that $action and $object may be modified by hook + $reshook = $hookmanager->executeHooks('tabContentViewInvoice', $parameters, $object, $action); + if (empty($reshook)) { + print '
'; + print '
'; + print '
'; - print ''; + print '
'; - // Type - print ''; + if ($objectidnext > 0) { + $facthatreplace = new Facture($db); + $facthatreplace->fetch($objectidnext); + print ' '.str_replace('{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities("ReplacedByInvoice", '{s1}')).''; + } - // Relative and absolute discounts - print ''."\n"; - print ''; - print ''; + if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { + $discount = new DiscountAbsolute($db); + $result = $discount->fetch(0, $object->id); + if ($result > 0) { + print ' '; + $s = $langs->trans("CreditNoteConvertedIntoDiscount", '{s1}', '{s2}'); + $s = str_replace('{s1}', $object->getLibType(0), $s); + $s = str_replace('{s2}', $discount->getNomUrl(1, 'discount'), $s); + print $s; + print '
'; + } + } - // Date invoice - print ''; - if ($action == 'editinvoicedate') { - $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->date, 'invoicedate'); - } else { - print ''.dol_print_date($object->date, 'day').''; - } - print ''; + // Relative and absolute discounts + print ''."\n"; + print ''; + print ''; - print ''; - - if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) { - // Date invoice point of tax + // Date invoice print ''; - } - - // Payment term - print ''; - - // Date payment term - print ''; - - // Payment mode - print ''; - - // Multicurrency - if (isModEnabled('multicurrency')) { - // Multicurrency code - print ''; - print ''; - // Multicurrency rate - if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { - print ''; - print ''; - print ''; - print ''; - print ''; - - print '
'.$langs->trans('Type').''; - print $object->getLibType(2); - print $object->getSubtypeLabel('facture'); - if ($object->module_source) { - print ' ('.$langs->trans("POS").' '.dol_escape_htmltag(ucfirst($object->module_source)).' - '.$langs->trans("Terminal").' '.dol_escape_htmltag($object->pos_source).')'; - } - if ($object->type == Facture::TYPE_REPLACEMENT) { - $facreplaced = new Facture($db); - $facreplaced->fetch($object->fk_facture_source); - print ' '.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1, '', 32)).''; - } - if ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($object->fk_facture_source)) { - $facusing = new Facture($db); - $facusing->fetch($object->fk_facture_source); - print ' '.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1, '', 32)).''; - } + // Type + print '
'.$langs->trans('Type').''; + print $object->getLibType(2); + if ($object->subtype > 0) { + print ' '.$object->getSubtypeLabel('facture'); + } + if ($object->module_source) { + print ' ('.$langs->trans("POS").' '.dol_escape_htmltag(ucfirst($object->module_source)).' - '.$langs->trans("Terminal").' '.dol_escape_htmltag($object->pos_source).')'; + } + if ($object->type == Facture::TYPE_REPLACEMENT) { + $facreplaced = new Facture($db); + $facreplaced->fetch($object->fk_facture_source); + print ' '.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1, '', 32)).''; + } + if ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($object->fk_facture_source)) { + $facusing = new Facture($db); + $facusing->fetch($object->fk_facture_source); + print ' '.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1, '', 32)).''; + } - $facidavoir = $object->getListIdAvoirFromInvoice(); - if (count($facidavoir) > 0) { - print ' '.$langs->transnoentities("InvoiceHasAvoir"); - $i = 0; - foreach ($facidavoir as $id) { - if ($i == 0) { - print ' '; - } else { - print ','; + $facidavoir = $object->getListIdAvoirFromInvoice(); + if (count($facidavoir) > 0) { + print ' '.$langs->transnoentities("InvoiceHasAvoir"); + $i = 0; + foreach ($facidavoir as $id) { + if ($i == 0) { + print ' '; + } else { + print ','; + } + $facavoir = new Facture($db); + $facavoir->fetch($id); + print $facavoir->getNomUrl(1, '', 32); } - $facavoir = new Facture($db); - $facavoir->fetch($id); - print $facavoir->getNomUrl(1, '', 32); - } - print ''; - } - if ($objectidnext > 0) { - $facthatreplace = new Facture($db); - $facthatreplace->fetch($objectidnext); - print ' '.str_replace('{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities("ReplacedByInvoice", '{s1}')).''; - } - - if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { - $discount = new DiscountAbsolute($db); - $result = $discount->fetch(0, $object->id); - if ($result > 0) { - print ' '; - $s = $langs->trans("CreditNoteConvertedIntoDiscount", '{s1}', '{s2}'); - $s = str_replace('{s1}', $object->getLibType(0), $s); - $s = str_replace('{s2}', $discount->getNomUrl(1, 'discount'), $s); - print $s; - print '
'; - } - } - - if ($object->fk_fac_rec_source > 0) { - $tmptemplate = new FactureRec($db); - $result = $tmptemplate->fetch($object->fk_fac_rec_source); - if ($result > 0) { - print ' '; - $s = $langs->transnoentities("GeneratedFromTemplate", '{s1}'); - $s = str_replace('{s1}', $tmptemplate->getNomUrl(1, '', 32), $s); - print $s; print ''; } - } - print '
'.$langs->trans('DiscountStillRemaining').''; - $thirdparty = $soc; - $discount_type = 0; - $backtopage = $_SERVER["PHP_SELF"].'?facid='.$object->id; - include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; - print '
'; - print ''; - if ($action != 'editinvoicedate' && $object->status == $object::STATUS_DRAFT && $usercancreate && !getDolGlobalString('FAC_FORCE_DATE_VALIDATION')) { - print ''; - } - print '
'; - print $langs->trans('DateInvoice'); - print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; - print '
'; + if ($object->fk_fac_rec_source > 0) { + $tmptemplate = new FactureRec($db); + $result = $tmptemplate->fetch($object->fk_fac_rec_source); + if ($result > 0) { + print ' '; + $s = $langs->transnoentities("GeneratedFromTemplate", '{s1}'); + $s = str_replace('{s1}', $tmptemplate->getNomUrl(1, '', 32), $s); + print $s; + print ''; + } + } + print '
'.$langs->trans('DiscountStillRemaining').''; + $thirdparty = $soc; + $discount_type = 0; + $backtopage = $_SERVER["PHP_SELF"].'?facid='.$object->id; + include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; + print '
'; print ''; - print ''; - print '
'; - print $langs->trans('DatePointOfTax'); + print $langs->trans('DateInvoice'); print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; - print '
'; - if ($action == 'editdate_pointoftax') { - $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->date_pointoftax, 'date_pointoftax'); - } else { - print ''.dol_print_date($object->date_pointoftax, 'day').''; - } - print '
'; - print ''; - if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && $usercancreate) { - print ''; - } - print '
'; - print $langs->trans('PaymentConditionsShort'); - print 'id.'">'.img_edit($langs->trans('SetConditions'), 1).'
'; - print '
'; - if ($object->type != Facture::TYPE_CREDIT_NOTE) { - if ($action == 'editconditions') { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id'); - } else { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->cond_reglement_id, 'none'); - } - } else { - print ' '; - } - print '
'; - print ''; - if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $usercancreate) { - print ''; - } - print '
'; - print $langs->trans('DateMaxPayment'); - print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; - print '
'; - if ($object->type != Facture::TYPE_CREDIT_NOTE) { - if ($action == 'editpaymentterm') { - $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->date_lim_reglement, 'paymentterm'); - } else { - print ''.dol_print_date($object->date_lim_reglement, 'day').''; - if ($object->hasDelay()) { - print img_warning($langs->trans('Late')); - } - } - } else { - print ' '; - } - print '
'; - print ''; - if ($action != 'editmode' && $usercancreate) { - print ''; - } - print '
'; - print $langs->trans('PaymentMode'); - print 'id.'">'.img_edit($langs->trans('SetMode'), 1).'
'; - print '
'; - if ($action == 'editmode') { - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1); - } else { - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'none', 'CRDT'); - } - print '
'; - print ''; - if ($usercancreate && $action != 'editmulticurrencycode' && $object->status == $object::STATUS_DRAFT) { - print ''; + if ($action != 'editinvoicedate' && $object->status == $object::STATUS_DRAFT && $usercancreate && !getDolGlobalString('FAC_FORCE_DATE_VALIDATION')) { + print ''; } print '
'; - print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0); - print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; print '
'; - $htmlname = (($usercancreate && $action == 'editmulticurrencycode') ? 'multicurrency_code' : 'none'); - $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, $htmlname); - print '
'; - print ''; + + print ''; + + if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) { + // Date invoice point of tax + print ''; } - } - // Bank Account - if (isModEnabled("banque")) { - print '
'; - print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0); + if ($action == 'editinvoicedate') { + $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->date, 'invoicedate'); + } else { + print ''.dol_print_date($object->date, 'day').''; + } + print '
'; + print ''; - if ($usercancreate && $action != 'editmulticurrencyrate' && $object->status == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { - print ''; - } + print ''; print '
'; + print $langs->trans('DatePointOfTax'); print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; print '
'; - if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') { - if ($action == 'actualizemulticurrencyrate') { - list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); - } - $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ? 'multicurrency_tx' : 'none'), $object->multicurrency_code); + if ($action == 'editdate_pointoftax') { + $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->date_pointoftax, 'date_pointoftax'); } else { - $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); - if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { - print '
        '; - print ''.$langs->trans("ActualizeCurrency").''; - print '
'; - } + print ''.dol_print_date($object->date_pointoftax, 'day').''; } print '
'; - print ''; + // Payment term + print '"; - print ''; - } - - // Incoterms - if (isModEnabled('incoterm')) { - print ''; - print ''; - } - - - if (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) { - $displayWarranty = true; - if (!in_array($object->type, $retainedWarrantyInvoiceAvailableType) && empty($object->retained_warranty)) { - $displayWarranty = false; - } - - if ($displayWarranty) { - // Retained Warranty - print ''; - - // Retained warranty payment term - print ''; - - // Retained Warranty payment date limit - print ''; - } - } - - - // Other attributes - $cols = 2; - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; - - print '
'; - print $langs->trans('BankAccount'); - print ''; - if (($action != 'editbankaccount') && $usercancreate) { - print 'id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'
'; + print ''; + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && $usercancreate) { + print ''; } print '
'; + print $langs->trans('PaymentConditionsShort'); + print 'id.'">'.img_edit($langs->trans('SetConditions'), 1).'
'; print '
'; - if ($action == 'editbankaccount') { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); - } else { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); - } - print "
'; - print '
'; - print $langs->trans('IncotermLabel'); - print ''; - if ($usercancreate) { - print ''.img_edit().''; + if ($object->type != Facture::TYPE_CREDIT_NOTE) { + if ($action == 'editconditions') { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id'); + } else { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->cond_reglement_id, 'none'); + } } else { print ' '; } - print '
'; - print '
'; - if ($action != 'editincoterm') { - print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); - } else { - print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id); - } print '
'; - print ''; - if ($action != 'editretainedwarranty' && $user->hasRight('facture', 'creer') && $object->statut == Facture::STATUS_DRAFT) { - print ''; - } - - print '
'; - print $langs->trans('RetainedWarranty'); - print 'id.'">'.img_edit($langs->trans('setretainedwarranty'), 1).'
'; - print '
'; - if ($action == 'editretainedwarranty' && $object->statut == Facture::STATUS_DRAFT) { - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print '
'; - } else { - print price($object->retained_warranty).'%'; - } - print '
'; - print ''; - if ($action != 'editretainedwarrantypaymentterms' && $user->hasRight('facture', 'creer') && $object->statut == Facture::STATUS_DRAFT) { - print ''; - } - - print '
'; - print $langs->trans('PaymentConditionsShortRetainedWarranty'); - print 'id.'">'.img_edit($langs->trans('setPaymentConditionsShortRetainedWarranty'), 1).'
'; - print '
'; - $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime('-1 years', $object->date_lim_reglement); - if ($object->date > $defaultDate) { - $defaultDate = $object->date; - } - - if ($action == 'editretainedwarrantypaymentterms' && $object->statut == Facture::STATUS_DRAFT) { - //date('Y-m-d',$object->date_lim_reglement) - print '
'; - print ''; - print ''; - print ''; - $retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); - $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement; - $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; - print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement', -1, 1); - print ''; - print '
'; - } else { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->retained_warranty_fk_cond_reglement, 'none'); - if (!$displayWarranty) { - print img_picto($langs->trans('RetainedWarrantyNeed100Percent'), 'warning.png', 'class="pictowarning valignmiddle" '); - } - } - print '
'; - print ''; - if ($action != 'editretainedwarrantydatelimit' && $user->hasRight('facture', 'creer') && $object->statut == Facture::STATUS_DRAFT) { - print ''; - } - - print '
'; - print $langs->trans('RetainedWarrantyDateLimit'); - print 'id.'">'.img_edit($langs->trans('setretainedwarrantyDateLimit'), 1).'
'; - print '
'; - $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime('-1 years', $object->date_lim_reglement); - if ($object->date > $defaultDate) { - $defaultDate = $object->date; - } - - if ($action == 'editretainedwarrantydatelimit' && $object->statut == Facture::STATUS_DRAFT) { - //date('Y-m-d',$object->date_lim_reglement) - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print '
'; - } else { - print dol_print_date($object->retained_warranty_date_limit, 'day'); - } - print '
'; - - print ''; - print '
'; - - print ''."\n"; - print '
'."\n"; - - print ''; - - $sign = 1; - if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) { - $sign = -1; // We invert sign for output - } - print ''; - // Amount HT - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - // Multicurrency Amount HT - print ''; - } - print ''; - - print ''; - // Amount VAT - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - // Multicurrency Amount VAT - print ''; - } - print ''; - - // Amount Local Taxes - if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) { - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; - } - print ''; - - if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) { - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; - } - print ''; - } - } - - - // Add the revenue stamp - if ($selleruserevenustamp) { - print ''; - } - print ''; - // Amount TTC - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - // Multicurrency Amount TTC - print ''; - } - print ''; - - print '
' . $langs->trans('AmountHT') . '' . price($sign * $object->total_ht, '', $langs, 0, -1, -1, $conf->currency) . '' . price($sign * $object->multicurrency_total_ht, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->trans('AmountVAT') . '' . price($sign * $object->total_tva, '', $langs, 0, -1, -1, $conf->currency) . '' . price($sign * $object->multicurrency_total_tva, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($sign * $object->total_localtax1, '', $langs, 0, -1, -1, $conf->currency) . '' . price($sign * $object->total_localtax1, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($sign * $object->total_localtax2, '', $langs, 0, -1, -1, $conf->currency) . '' . price($sign * $object->total_localtax2, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
'; + // Date payment term + print '
'; print ''; - if ($action != 'editrevenuestamp' && $object->status == $object::STATUS_DRAFT && $usercancreate) { - print ''; + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $usercancreate) { + print ''; } print '
'; - print $langs->trans('RevenueStamp'); + print $langs->trans('DateMaxPayment'); print 'id.'">'.img_edit($langs->trans('SetRevenuStamp'), 1).'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; - print '
'; - if ($action == 'editrevenuestamp') { - print '
'; - print ''; - print ''; - print ''; - print ''; - print $formother->select_revenue_stamp('', 'revenuestamp_type', $mysoc->country_code); - print ' → '; - print ' '; - print '
'; - print " "; + print '
'; + if ($object->type != Facture::TYPE_CREDIT_NOTE) { + if ($action == 'editpaymentterm') { + $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->date_lim_reglement, 'paymentterm'); + } else { + print ''.dol_print_date($object->date_lim_reglement, 'day').''; + if ($object->hasDelay()) { + print img_warning($langs->trans('Late')); + } + } } else { - print price($object->revenuestamp, 1, '', 1, -1, -1, $conf->currency); + print ' '; } print '
' . $langs->trans('AmountTTC') . '' . price($sign * $object->total_ttc, '', $langs, 0, -1, -1, $conf->currency) . '' . price($sign * $object->multicurrency_total_ttc, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
'; - - $nbrows = 8; - $nbcols = 3; - if (isModEnabled('project')) { - $nbrows++; - } - if (isModEnabled("banque")) { - $nbrows++; - $nbcols++; - } - if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { - $nbrows++; - } - if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { - $nbrows++; - } - if ($selleruserevenustamp) { - $nbrows++; - } - if (isModEnabled('multicurrency')) { - $nbrows += 5; - } - if (isModEnabled('incoterm')) { - $nbrows += 1; - } - - // List of previous situation invoices - if (($object->situation_cycle_ref > 0) && !empty($conf->global->INVOICE_USE_SITUATION)) { - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - if (isModEnabled("banque")) { - print ''; - } - print ''; - print ''; - print ''; - print ''; - - $total_prev_ht = $total_prev_ttc = 0; - $total_global_ht = $total_global_ttc = 0; - - if (count($object->tab_previous_situation_invoice) > 0) { - // List of previous invoices - - $current_situation_counter = array(); - foreach ($object->tab_previous_situation_invoice as $prev_invoice) { - $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement(); - $total_prev_ht += $prev_invoice->total_ht; - $total_prev_ttc += $prev_invoice->total_ttc; - $current_situation_counter[] = (($prev_invoice->type == Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $prev_invoice->situation_counter; - print ''; - print ''; - print ''; - print ''; - if (isModEnabled("banque")) { - print ''; - } - print ''; - print ''; - print ''; - print ''; - } - } - - - $total_global_ht += $total_prev_ht; - $total_global_ttc += $total_prev_ttc; - $total_global_ht += $object->total_ht; - $total_global_ttc += $object->total_ttc; - $current_situation_counter[] = (($object->type == Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $object->situation_counter; - print ''; - print ''; - print ''; - print ''; - if (isModEnabled("banque")) { - print ''; - } - print ''; - print ''; - print ''; - print ''; - - - print ''; - print ''; - print ''; + // Multicurrency + if (isModEnabled('multicurrency')) { + // Multicurrency code + print ''; + print ''; - if (count($object->tab_next_situation_invoice) > 0) { - // List of next invoices - /*print ''; - print ''; - print ''; - print ''; - if (isModEnabled('banque')) print ''; - print ''; - print ''; - print ''; - print '';*/ - - $total_next_ht = $total_next_ttc = 0; - - foreach ($object->tab_next_situation_invoice as $next_invoice) { - $totalpaid = $next_invoice->getSommePaiement(); - $total_next_ht += $next_invoice->total_ht; - $total_next_ttc += $next_invoice->total_ttc; - - print ''; - print ''; - print ''; - print ''; - if (isModEnabled("banque")) { - print ''; + // Multicurrency rate + if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { + print ''; + print ''; + } + } + + // Bank Account + if (isModEnabled("banque")) { + print '"; + print ''; + } + + // Incoterms + if (isModEnabled('incoterm')) { + print ''; + print ''; + } + + + + if (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) { + $displayWarranty = true; + if (!in_array($object->type, $retainedWarrantyInvoiceAvailableType) && empty($object->retained_warranty)) { + $displayWarranty = false; } - $total_global_ht += $total_next_ht; - $total_global_ttc += $total_next_ttc; + if ($displayWarranty) { + // Retained Warranty + print ''; + + // Retained warranty payment term + print ''; + + // Retained Warranty payment date limit + print ''; + } + } + + + // Other attributes + $cols = 2; + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + print '
'.$langs->trans('ListOfSituationInvoices').''.$langs->trans('Situation').''.$langs->trans('AmountHT').''.$langs->trans('AmountTTC').' 
'.$prev_invoice->getNomUrl(1).''.(($prev_invoice->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$prev_invoice->situation_counter.''.price($prev_invoice->total_ht).''.price($prev_invoice->total_ttc).''.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).'
'.$object->getNomUrl(1).''.(($object->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$object->situation_counter.''.price($object->total_ht).''.price($object->total_ttc).''.$object->getLibStatut(3, $object->getSommePaiement()).'
'.$langs->trans('CurrentSituationTotal').''; - $i = 0; - foreach ($current_situation_counter as $sit) { - $curSign = $sit > 0 ? '+' : '-'; - $curType = $sit > 0 ? $langs->trans('situationInvoiceShortcode_S') : $langs->trans('situationInvoiceShortcode_AS'); - if ($i > 0) { - print ' '.$curSign.' '; - } - print $curType.abs($sit); - $i++; - } + // Payment mode + print '
'; + print ''; - if (isModEnabled("banque")) { - print ''; + if ($action != 'editmode' && $usercancreate) { + print ''; } - print ''; - print ''; - print ''; - print ''; + print '
'; + print $langs->trans('PaymentMode'); print 'id.'">'.img_edit($langs->trans('SetMode'), 1).''.price($total_global_ht).''.price($total_global_ttc).' 
'; + print '
'; + if ($action == 'editmode') { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1); + } else { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'none', 'CRDT'); + } + print '
'; + print ''; + if ($usercancreate && $action != 'editmulticurrencycode' && $object->status == $object::STATUS_DRAFT) { + print ''; + } + print '
'; + print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'
'; + print '
'; + $htmlname = (($usercancreate && $action == 'editmulticurrencycode') ? 'multicurrency_code' : 'none'); + $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, $htmlname); + print '
' . $langs->trans('ListOfNextSituationInvoices') . '' . $langs->trans('AmountHT') . '' . $langs->trans('AmountTTC') . ' 
'.$next_invoice->getNomUrl(1).''.(($next_invoice->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$next_invoice->situation_counter.'
'; + print ''; + if ($usercancreate && $action != 'editmulticurrencyrate' && $object->status == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { + print ''; } - print ''; - print ''; - print ''; - print ''; + print '
'; + print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).''.price($next_invoice->total_ht).''.price($next_invoice->total_ttc).''.$next_invoice->getLibStatut(3, $totalpaid).'
'; + print '
'; + if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') { + if ($action == 'actualizemulticurrencyrate') { + list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); + } + $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ? 'multicurrency_tx' : 'none'), $object->multicurrency_code); + } else { + $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); + if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { + print '
        '; + print ''.$langs->trans("ActualizeCurrency").''; + print '
'; + } + } + print '
'; + print ''; + } + print '
'; + print $langs->trans('BankAccount'); + print ''; + if (($action != 'editbankaccount') && $usercancreate) { + print 'id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'
'; + print '
'; + if ($action == 'editbankaccount') { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + } else { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + } + print "
'; + print '
'; + print $langs->trans('IncotermLabel'); + print ''; + if ($usercancreate) { + print ''.img_edit().''; + } else { + print ' '; + } + print '
'; + print '
'; + if ($action != 'editincoterm') { + print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); + } else { + print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id); + } + print '
'; + print ''; + if ($action != 'editretainedwarranty' && $user->hasRight('facture', 'creer') && $object->statut == Facture::STATUS_DRAFT) { + print ''; + } - print ''; - print ''; + print '
'; + print $langs->trans('RetainedWarranty'); + print 'id.'">'.img_edit($langs->trans('setretainedwarranty'), 1).'
'; + print '
'; + if ($action == 'editretainedwarranty' && $object->statut == Facture::STATUS_DRAFT) { + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + } else { + print price($object->retained_warranty).'%'; + } + print '
'; + print ''; + if ($action != 'editretainedwarrantypaymentterms' && $user->hasRight('facture', 'creer') && $object->statut == Facture::STATUS_DRAFT) { + print ''; + } + + print '
'; + print $langs->trans('PaymentConditionsShortRetainedWarranty'); + print 'id.'">'.img_edit($langs->trans('setPaymentConditionsShortRetainedWarranty'), 1).'
'; + print '
'; + $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime('-1 years', $object->date_lim_reglement); + if ($object->date > $defaultDate) { + $defaultDate = $object->date; + } + + if ($action == 'editretainedwarrantypaymentterms' && $object->statut == Facture::STATUS_DRAFT) { + //date('Y-m-d',$object->date_lim_reglement) + print '
'; + print ''; + print ''; + print ''; + $retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); + $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement; + $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; + print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement', -1, 1); + print ''; + print '
'; + } else { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->retained_warranty_fk_cond_reglement, 'none'); + if (!$displayWarranty) { + print img_picto($langs->trans('RetainedWarrantyNeed100Percent'), 'warning.png', 'class="pictowarning valignmiddle" '); + } + } + print '
'; + print ''; + if ($action != 'editretainedwarrantydatelimit' && $user->hasRight('facture', 'creer') && $object->statut == Facture::STATUS_DRAFT) { + print ''; + } + + print '
'; + print $langs->trans('RetainedWarrantyDateLimit'); + print 'id.'">'.img_edit($langs->trans('setretainedwarrantyDateLimit'), 1).'
'; + print '
'; + $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime('-1 years', $object->date_lim_reglement); + if ($object->date > $defaultDate) { + $defaultDate = $object->date; + } + + if ($action == 'editretainedwarrantydatelimit' && $object->statut == Facture::STATUS_DRAFT) { + //date('Y-m-d',$object->date_lim_reglement) + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + } else { + print dol_print_date($object->retained_warranty_date_limit, 'day'); + } + print '
'; + + print '
'; + print '
'; + + print ''."\n"; + print '
'."\n"; + + print ''; + + $sign = 1; + if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) { + $sign = -1; // We invert sign for output + } + print ''; + // Amount HT + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + // Multicurrency Amount HT + print ''; + } + print ''; + + print ''; + // Amount VAT + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + // Multicurrency Amount VAT + print ''; + } + print ''; + + // Amount Local Taxes + if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) { + print ''; + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + print ''; + } + print ''; + + if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) { + print ''; + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + print ''; + } + print ''; + } + } + + + // Add the revenue stamp + if ($selleruserevenustamp) { + print ''; + } + + print ''; + // Amount TTC + print ''; + print ''; + if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { + // Multicurrency Amount TTC + print ''; + } + print ''; + + print '
' . $langs->trans('AmountHT') . '' . price($sign * $object->total_ht, '', $langs, 0, -1, -1, $conf->currency) . '' . price($sign * $object->multicurrency_total_ht, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->trans('AmountVAT') . '' . price($sign * $object->total_tva, '', $langs, 0, -1, -1, $conf->currency) . '' . price($sign * $object->multicurrency_total_tva, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($sign * $object->total_localtax1, '', $langs, 0, -1, -1, $conf->currency) . '' . price($sign * $object->total_localtax1, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($sign * $object->total_localtax2, '', $langs, 0, -1, -1, $conf->currency) . '' . price($sign * $object->total_localtax2, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
'; + print ''; + if ($action != 'editrevenuestamp' && $object->status == $object::STATUS_DRAFT && $usercancreate) { + print ''; + } + print '
'; + print $langs->trans('RevenueStamp'); + print 'id.'">'.img_edit($langs->trans('SetRevenuStamp'), 1).'
'; + print '
'; + if ($action == 'editrevenuestamp') { + print '
'; + print ''; + print ''; + print ''; + print ''; + print $formother->select_revenue_stamp('', 'revenuestamp_type', $mysoc->country_code); + print ' → '; + print ' '; + print '
'; + print " "; + } else { + print price($object->revenuestamp, 1, '', 1, -1, -1, $conf->currency); + } + print '
' . $langs->trans('AmountTTC') . '' . price($sign * $object->total_ttc, '', $langs, 0, -1, -1, $conf->currency) . '' . price($sign * $object->multicurrency_total_ttc, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
'; + + $nbrows = 8; + $nbcols = 3; + if (isModEnabled('project')) { + $nbrows++; + } + if (isModEnabled("banque")) { + $nbrows++; + $nbcols++; + } + if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { + $nbrows++; + } + if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { + $nbrows++; + } + if ($selleruserevenustamp) { + $nbrows++; + } + if (isModEnabled('multicurrency')) { + $nbrows += 5; + } + if (isModEnabled('incoterm')) { + $nbrows += 1; + } + + // List of previous situation invoices + if (($object->situation_cycle_ref > 0) && !empty($conf->global->INVOICE_USE_SITUATION)) { + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; if (isModEnabled("banque")) { print ''; } + print ''; + print ''; + print ''; + print ''; + + $total_prev_ht = $total_prev_ttc = 0; + $total_global_ht = $total_global_ttc = 0; + + if (count($object->tab_previous_situation_invoice) > 0) { + // List of previous invoices + + $current_situation_counter = array(); + foreach ($object->tab_previous_situation_invoice as $prev_invoice) { + $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement(); + $total_prev_ht += $prev_invoice->total_ht; + $total_prev_ttc += $prev_invoice->total_ttc; + $current_situation_counter[] = (($prev_invoice->type == Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $prev_invoice->situation_counter; + print ''; + print ''; + print ''; + print ''; + if (isModEnabled("banque")) { + print ''; + } + print ''; + print ''; + print ''; + print ''; + } + } + + + $total_global_ht += $total_prev_ht; + $total_global_ttc += $total_prev_ttc; + $total_global_ht += $object->total_ht; + $total_global_ttc += $object->total_ttc; + $current_situation_counter[] = (($object->type == Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $object->situation_counter; + print ''; + print ''; + print ''; + print ''; + if (isModEnabled("banque")) { + print ''; + } + print ''; + print ''; + print ''; + print ''; + + + print ''; + print ''; + print ''; + if (isModEnabled("banque")) { + print ''; + } print ''; print ''; print ''; print ''; + + + if (count($object->tab_next_situation_invoice) > 0) { + // List of next invoices + /*print ''; + print ''; + print ''; + print ''; + if (isModEnabled('banque')) print ''; + print ''; + print ''; + print ''; + print '';*/ + + $total_next_ht = $total_next_ttc = 0; + + foreach ($object->tab_next_situation_invoice as $next_invoice) { + $totalpaid = $next_invoice->getSommePaiement(); + $total_next_ht += $next_invoice->total_ht; + $total_next_ttc += $next_invoice->total_ttc; + + print ''; + print ''; + print ''; + print ''; + if (isModEnabled("banque")) { + print ''; + } + print ''; + print ''; + print ''; + print ''; + } + + $total_global_ht += $total_next_ht; + $total_global_ttc += $total_next_ttc; + + print ''; + print ''; + if (isModEnabled("banque")) { + print ''; + } + print ''; + print ''; + print ''; + print ''; + } + + print '
'.$langs->trans('ListOfSituationInvoices').''.$langs->trans('Situation').''.$langs->trans('AmountHT').''.$langs->trans('AmountTTC').' 
'.$prev_invoice->getNomUrl(1).''.(($prev_invoice->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$prev_invoice->situation_counter.''.price($prev_invoice->total_ht).''.price($prev_invoice->total_ttc).''.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).'
'.$object->getNomUrl(1).''.(($object->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$object->situation_counter.''.price($object->total_ht).''.price($object->total_ttc).''.$object->getLibStatut(3, $object->getSommePaiement()).'
'.$langs->trans('CurrentSituationTotal').''; + $i = 0; + foreach ($current_situation_counter as $sit) { + $curSign = $sit > 0 ? '+' : '-'; + $curType = $sit > 0 ? $langs->trans('situationInvoiceShortcode_S') : $langs->trans('situationInvoiceShortcode_AS'); + if ($i > 0) { + print ' '.$curSign.' '; + } + print $curType.abs($sit); + $i++; + } + print ''.price($total_global_ht).''.price($total_global_ttc).' 
' . $langs->trans('ListOfNextSituationInvoices') . '' . $langs->trans('AmountHT') . '' . $langs->trans('AmountTTC') . ' 
'.$next_invoice->getNomUrl(1).''.(($next_invoice->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$next_invoice->situation_counter.''.price($next_invoice->total_ht).''.price($next_invoice->total_ttc).''.$next_invoice->getLibStatut(3, $totalpaid).'
'.price($total_global_ht).''.price($total_global_ttc).' 
'; } - print '
'; - } + $sign = 1; + if ($object->type == $object::TYPE_CREDIT_NOTE) { + $sign = -1; + } - $sign = 1; - if ($object->type == $object::TYPE_CREDIT_NOTE) { - $sign = -1; - } + // List of payments already done - // List of payments already done + print ''; + print '
'; + print ''; - print ''; - print '
'; - print '
'; + print ''; + print ''; + print ''; + print ''; + if (isModEnabled("banque")) { + print ''; + } + print ''; + print ''; + print ''; - print ''; - print ''; - print ''; - print ''; - if (isModEnabled("banque")) { - print ''; - } - print ''; - print ''; - print ''; + // Payments already done (from payment on this invoice) + $sql = 'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,'; + $sql .= ' c.code as payment_code, c.libelle as payment_label,'; + $sql .= ' pf.amount,'; + $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal, ba.currency_code as bacurrency_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 c ON p.fk_paiement = c.id'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; + $sql .= ' WHERE pf.fk_facture = '.((int) $object->id).' AND pf.fk_paiement = p.rowid'; + $sql .= ' AND p.entity IN ('.getEntity('invoice').')'; + $sql .= ' ORDER BY p.datep, p.tms'; - // Payments already done (from payment on this invoice) - $sql = 'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,'; - $sql .= ' c.code as payment_code, c.libelle as payment_label,'; - $sql .= ' pf.amount,'; - $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal, ba.currency_code as bacurrency_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 c ON p.fk_paiement = c.id'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; - $sql .= ' WHERE pf.fk_facture = '.((int) $object->id).' AND pf.fk_paiement = p.rowid'; - $sql .= ' AND p.entity IN ('.getEntity('invoice').')'; - $sql .= ' ORDER BY p.datep, p.tms'; + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - $i = 0; + if ($num > 0) { + while ($i < $num) { + $objp = $db->fetch_object($result); - if ($num > 0) { - while ($i < $num) { - $objp = $db->fetch_object($result); + $paymentstatic->id = $objp->rowid; + $paymentstatic->datepaye = $db->jdate($objp->dp); + $paymentstatic->ref = $objp->ref; + $paymentstatic->num_payment = $objp->num_payment; + $paymentstatic->paiementcode = $objp->payment_code; - $paymentstatic->id = $objp->rowid; - $paymentstatic->datepaye = $db->jdate($objp->dp); - $paymentstatic->ref = $objp->ref; - $paymentstatic->num_payment = $objp->num_payment; - $paymentstatic->paiementcode = $objp->payment_code; - - print ''; - print ''; - $label = ($langs->trans("PaymentType".$objp->payment_code) != ("PaymentType".$objp->payment_code)) ? $langs->trans("PaymentType".$objp->payment_code) : $objp->payment_label; - print ''; - if (isModEnabled("banque")) { - $bankaccountstatic->id = $objp->baid; - $bankaccountstatic->ref = $objp->baref; - $bankaccountstatic->label = $objp->baref; - $bankaccountstatic->number = $objp->banumber; - $bankaccountstatic->currency_code = $objp->bacurrency_code; - - if (isModEnabled('accounting')) { - $bankaccountstatic->account_number = $objp->account_number; - - $accountingjournal = new AccountingJournal($db); - $accountingjournal->fetch($objp->fk_accountancy_journal); - $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1); - } - - print ''; + print ''; - } - print ''; - print ''; - print ''; - $i++; - } - } + $label = ($langs->trans("PaymentType".$objp->payment_code) != ("PaymentType".$objp->payment_code)) ? $langs->trans("PaymentType".$objp->payment_code) : $objp->payment_label; + print ''; + if (isModEnabled("banque")) { + $bankaccountstatic->id = $objp->baid; + $bankaccountstatic->ref = $objp->baref; + $bankaccountstatic->label = $objp->baref; + $bankaccountstatic->number = $objp->banumber; + $bankaccountstatic->currency_code = $objp->bacurrency_code; - $db->free($result); - } else { - dol_print_error($db); - } + if (isModEnabled('accounting')) { + $bankaccountstatic->account_number = $objp->account_number; - if ($object->type != Facture::TYPE_CREDIT_NOTE) { - // Total already paid - print ''; + $accountingjournal = new AccountingJournal($db); + $accountingjournal->fetch($objp->fk_accountancy_journal); + $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1); + } - $resteapayeraffiche = $resteapayer; - $cssforamountpaymentcomplete = 'amountpaymentcomplete'; - - // Loop on each credit note or deposit amount applied - $creditnoteamount = 0; - $depositamount = 0; - $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 .= " WHERE fk_facture = ".((int) $object->id); - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - $invoice = new Facture($db); - while ($i < $num) { - $obj = $db->fetch_object($resql); - $invoice->fetch($obj->fk_facture_source); - print ''; - print ''; - print ''; - $i++; - if ($invoice->type == Facture::TYPE_CREDIT_NOTE) { - $creditnoteamount += $obj->amount_ttc; - } - if ($invoice->type == Facture::TYPE_DEPOSIT) { - $depositamount += $obj->amount_ttc; + print ''; + } + print ''; + print ''; + print ''; + $i++; } } + + $db->free($result); } else { dol_print_error($db); } - // Partially paid 'discount' - if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'discount_vat') { - print ''; - $resteapayeraffiche = 0; - $cssforamountpaymentcomplete = 'amountpaymentneutral'; - } - // Partially paid or abandoned 'badcustomer' - if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'badcustomer') { - print ''; - // $resteapayeraffiche=0; - $cssforamountpaymentcomplete = 'amountpaymentneutral'; - } - // Partially paid or abandoned 'product_returned' - if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'product_returned') { - print ''; - $resteapayeraffiche = 0; - $cssforamountpaymentcomplete = 'amountpaymentneutral'; - } - // Partially paid or abandoned 'abandoned' - if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'abandon') { - print ''; - $resteapayeraffiche = 0; - $cssforamountpaymentcomplete = 'amountpaymentneutral'; - } - - // Billed - print ''; - // Remainder to pay - print ''; - print ''; - - // Remainder to pay Multicurrency - if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { + if ($object->type != Facture::TYPE_CREDIT_NOTE) { + // Total already paid print ''; + + $resteapayeraffiche = $resteapayer; + $cssforamountpaymentcomplete = 'amountpaymentcomplete'; + + // Loop on each credit note or deposit amount applied + $creditnoteamount = 0; + $depositamount = 0; + $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 .= " WHERE fk_facture = ".((int) $object->id); + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + $invoice = new Facture($db); + while ($i < $num) { + $obj = $db->fetch_object($resql); + $invoice->fetch($obj->fk_facture_source); + print ''; + print ''; + print ''; + $i++; + if ($invoice->type == Facture::TYPE_CREDIT_NOTE) { + $creditnoteamount += $obj->amount_ttc; + } + if ($invoice->type == Facture::TYPE_DEPOSIT) { + $depositamount += $obj->amount_ttc; + } + } + } else { + dol_print_error($db); + } + + // Partially paid 'discount' + if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'discount_vat') { + print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = 'amountpaymentneutral'; + } + // Partially paid or abandoned 'badcustomer' + if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'badcustomer') { + print ''; + // $resteapayeraffiche=0; + $cssforamountpaymentcomplete = 'amountpaymentneutral'; + } + // Partially paid or abandoned 'product_returned' + if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'product_returned') { + print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = 'amountpaymentneutral'; + } + // Partially paid or abandoned 'abandoned' + if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'abandon') { + print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = 'amountpaymentneutral'; + } + + // Billed + print ''; + // Remainder to pay + print ''; - print ''; - } + print ''; - // Retained warranty : usualy use on construction industry - if (!empty($object->situation_final) && !empty($object->retained_warranty) && $displayWarranty) { - // Billed - retained warranty - if ($object->type == Facture::TYPE_SITUATION) { - $retainedWarranty = $total_global_ttc * $object->retained_warranty / 100; - } else { - // Because one day retained warranty could be used on standard invoices - $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100; + // Remainder to pay Multicurrency + if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { + print ''; + print ''; } - $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty; + // Retained warranty : usualy use on construction industry + if (!empty($object->situation_final) && !empty($object->retained_warranty) && $displayWarranty) { + // Billed - retained warranty + if ($object->type == Facture::TYPE_SITUATION) { + $retainedWarranty = $total_global_ttc * $object->retained_warranty / 100; + } else { + // Because one day retained warranty could be used on standard invoices + $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100; + } - print ''; + $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty; - // retained warranty - print ''; - } - } else { // Credit note - $resteapayeraffiche = $resteapayer; - $cssforamountpaymentcomplete = 'amountpaymentneutral'; + print ''; - // Total already paid back - print ''; + // retained warranty + print ''; + } + } else { // Credit note + $resteapayeraffiche = $resteapayer; + $cssforamountpaymentcomplete = 'amountpaymentneutral'; - // Billed - print ''; - - // Remainder to pay back - print ''; - print ''; - print ''; - - // Remainder to pay back Multicurrency - if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { + // Total already paid back print ''; + + // Billed + print ''; + + // Remainder to pay back + print ''; - print ''; - } + print ''; + print ''; + print ''; - // Sold credit note - // print ''; - // print ''; - } - - print '
'.($object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).''.$langs->trans('Date').''.$langs->trans('Type').''.$langs->trans('BankAccount').''.$langs->trans('Amount').' 
'.($object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).''.$langs->trans('Date').''.$langs->trans('Type').''.$langs->trans('BankAccount').''.$langs->trans('Amount').' 
'; - print $paymentstatic->getNomUrl(1); - print ''; - $dateofpayment = $db->jdate($objp->dp); - $tmparray = dol_getdate($dateofpayment); - if ($tmparray['seconds'] == 0 && $tmparray['minutes'] == 0 && ($tmparray['hours'] == 0 || $tmparray['hours'] == 12)) { // We set hours to 0:00 or 12:00 because we don't know it - print dol_print_date($dateofpayment, 'day'); - } else { // Hours was set to real date of payment (special case for POS for example) - print dol_print_date($dateofpayment, 'dayhour', 'tzuser'); - } - print ''.dol_escape_htmltag($label.' '.$objp->num_payment).''; - if ($bankaccountstatic->id) { - print $bankaccountstatic->getNomUrl(1, 'transactions'); + print '
'; + print $paymentstatic->getNomUrl(1); + print ''; + $dateofpayment = $db->jdate($objp->dp); + $tmparray = dol_getdate($dateofpayment); + if ($tmparray['seconds'] == 0 && $tmparray['minutes'] == 0 && ($tmparray['hours'] == 0 || $tmparray['hours'] == 12)) { // We set hours to 0:00 or 12:00 because we don't know it + print dol_print_date($dateofpayment, 'day'); + } else { // Hours was set to real date of payment (special case for POS for example) + print dol_print_date($dateofpayment, 'dayhour', 'tzuser'); } print ''.price($sign * $objp->amount).''; - if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0 && $user->socid == 0) { - print 'rowid.'">'; - print img_delete(); - print ''; - } - print '
'.dol_escape_htmltag($label.' '.$objp->num_payment).'
'; - print ''; - if ($object->type != Facture::TYPE_DEPOSIT) { - print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits'); - } else { - print $langs->trans('AlreadyPaid'); - } - print ''.price($totalpaid).' 
'; - print ''; - if ($invoice->type == Facture::TYPE_CREDIT_NOTE) { - print $langs->trans("CreditNote").' '; - } - if ($invoice->type == Facture::TYPE_DEPOSIT) { - print $langs->trans("Deposit").' '; - } - print $invoice->getNomUrl(0); - print ''; - print ''.price($obj->amount_ttc).''; - print 'rowid.'">'; - print img_picto($langs->transnoentitiesnoconv("RemoveDiscount"), 'unlink'); - print ''; - print '
'; + if ($bankaccountstatic->id) { + print $bankaccountstatic->getNomUrl(1, 'transactions'); + } + print ''.price($sign * $objp->amount).''; + if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0 && $user->socid == 0) { + print 'rowid.'">'; + print img_delete(); + print ''; + } + print '
'; - print ''; - print $form->textwithpicto($langs->trans("Discount"), $langs->trans("HelpEscompte"), - 1); - print ''; - print ''.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid, 'MT')).' 
'; - print ''; - print $form->textwithpicto($langs->trans("Abandoned"), $langs->trans("HelpAbandonBadCustomer"), - 1); - print ''; - print ''.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid, 'MT')).' 
'; - print ''; - print $form->textwithpicto($langs->trans("ProductReturned"), $langs->trans("HelpAbandonProductReturned"), - 1); - print ''; - print ''.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid, 'MT')).' 
'; - $text = $langs->trans("HelpAbandonOther"); - if ($object->close_note) { - $text .= '

'.$langs->trans("Reason").':'.$object->close_note; - } - print ''; - print $form->textwithpicto($langs->trans("Abandoned"), $text, - 1); - print ''; - print '
'.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid, 'MT')).' 
'; - print ''; - print $langs->trans("Billed"); - print ''.price($object->total_ttc).' 
'; - print ''; - print $langs->trans('RemainderToPay'); - if ($resteapayeraffiche < 0) { - print ' ('.$langs->trans('NegativeIfExcessReceived').')'; - } - print ''; - print ''.price($resteapayeraffiche).' 
'; print ''; - print $langs->trans('RemainderToPayMulticurrency'); + if ($object->type != Facture::TYPE_DEPOSIT) { + print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits'); + } else { + print $langs->trans('AlreadyPaid'); + } + print ''.price($totalpaid).' 
'; + print ''; + if ($invoice->type == Facture::TYPE_CREDIT_NOTE) { + print $langs->trans("CreditNote").' '; + } + if ($invoice->type == Facture::TYPE_DEPOSIT) { + print $langs->trans("Deposit").' '; + } + print $invoice->getNomUrl(0); + print ''; + print ''.price($obj->amount_ttc).''; + print 'rowid.'">'; + print img_picto($langs->transnoentitiesnoconv("RemoveDiscount"), 'unlink'); + print ''; + print '
'; + print ''; + print $form->textwithpicto($langs->trans("Discount"), $langs->trans("HelpEscompte"), - 1); + print ''; + print ''.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid, 'MT')).' 
'; + print ''; + print $form->textwithpicto($langs->trans("Abandoned"), $langs->trans("HelpAbandonBadCustomer"), - 1); + print ''; + print ''.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid, 'MT')).' 
'; + print ''; + print $form->textwithpicto($langs->trans("ProductReturned"), $langs->trans("HelpAbandonProductReturned"), - 1); + print ''; + print ''.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid, 'MT')).' 
'; + $text = $langs->trans("HelpAbandonOther"); + if ($object->close_note) { + $text .= '

'.$langs->trans("Reason").':'.$object->close_note; + } + print ''; + print $form->textwithpicto($langs->trans("Abandoned"), $text, - 1); + print ''; + print '
'.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid, 'MT')).' 
'; + print ''; + print $langs->trans("Billed"); + print ''.price($object->total_ttc).' 
'; + print ''; + print $langs->trans('RemainderToPay'); if ($resteapayeraffiche < 0) { print ' ('.$langs->trans('NegativeIfExcessReceived').')'; } print ''; print ''; - //print (empty($object->multicurrency_code) ? $conf->currency : $object->multicurrency_code).' '; - print price(price2num($object->multicurrency_tx*$resteapayeraffiche, 'MT'), 1, $langs, 1, -1, -1, (empty($object->multicurrency_code) ? $conf->currency : $object->multicurrency_code)).' 
'.price($resteapayeraffiche).' 
'; + print ''; + print $langs->trans('RemainderToPayMulticurrency'); + if ($resteapayeraffiche < 0) { + print ' ('.$langs->trans('NegativeIfExcessReceived').')'; + } + print ''; + print ''; + //print (empty($object->multicurrency_code) ? $conf->currency : $object->multicurrency_code).' '; + print price(price2num($object->multicurrency_tx*$resteapayeraffiche, 'MT'), 1, $langs, 1, -1, -1, (empty($object->multicurrency_code) ? $conf->currency : $object->multicurrency_code)).' 
'.$langs->trans("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')).' :'.price($billedWithRetainedWarranty).' 
'; - print $langs->trans("RetainedWarranty").' ('.$object->retained_warranty.'%)'; - print !empty($object->retained_warranty_date_limit) ? ' '.$langs->trans("ToPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : ''; - print ' :'.price($retainedWarranty).' 
'.$langs->trans("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')).' :'.price($billedWithRetainedWarranty).' 
'; - print ''.$langs->trans('AlreadyPaidBack').''; - print ''.price($sign * $totalpaid).' 
'; + print $langs->trans("RetainedWarranty").' ('.$object->retained_warranty.'%)'; + print !empty($object->retained_warranty_date_limit) ? ' '.$langs->trans("ToPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : ''; + print ' :'.price($retainedWarranty).' 
'.$langs->trans("Billed").''.price($sign * $object->total_ttc).' 
'; - print ''.$langs->trans('RemainderToPayBack'); - if ($resteapayeraffiche > 0) { - print ' ('.$langs->trans('NegativeIfExcessRefunded').')'; - } - print ''.price($sign * $resteapayeraffiche).' 
'; - print ''.$langs->trans('RemainderToPayBackMulticurrency'); + print ''.$langs->trans('AlreadyPaidBack').''; + print ''.price($sign * $totalpaid).' 
'.$langs->trans("Billed").''.price($sign * $object->total_ttc).' 
'; + print ''.$langs->trans('RemainderToPayBack'); if ($resteapayeraffiche > 0) { print ' ('.$langs->trans('NegativeIfExcessRefunded').')'; } - print ''; - print ''.(!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency).' '.price(price2num($sign * $object->multicurrency_tx * $resteapayeraffiche, 'MT')).' 
'.price($sign * $resteapayeraffiche).' 
'.$langs->trans('TotalTTC').' :'.price($sign * - // $object->total_ttc).' 
'; - print '
'; - - // Margin Infos - if (isModEnabled('margin')) { - $formmargin->displayMarginInfos($object); - } - - print ''; - print ''; - - print '


'; - - if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { - $blocname = 'contacts'; - $title = $langs->trans('ContactsAddresses'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } - - if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { - $blocname = 'notes'; - $title = $langs->trans('Notes'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } - - // Get object lines - $result = $object->getLinesArray(); - - // Add products/services form - //$forceall = 1; - global $inputalsopricewithtax; - $inputalsopricewithtax = 1; - - // Show global modifiers for situation invoices - if (!empty($conf->global->INVOICE_USE_SITUATION)) { - if ($object->situation_cycle_ref && $object->statut == 0) { - print ''."\n"; - print '
'; - - print '
'; - print ''; - print ''; - print ''; - print ''; - - print ''; - - print ''; - - // Adds a line numbering column - if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { - print ''; + // Remainder to pay back Multicurrency + if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { + print ''; + print ''; } - print ''; - print ''; - print ''; - print "\n"; - print ''; - // Adds a line numbering column - if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { - print ''; + // Sold credit note + // print ''; + // print ''; + } + + print '
 
'; + print ''.$langs->trans('RemainderToPayBackMulticurrency'); + if ($resteapayeraffiche > 0) { + print ' ('.$langs->trans('NegativeIfExcessRefunded').')'; + } + print ''; + print ''.(!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency).' '.price(price2num($sign * $object->multicurrency_tx * $resteapayeraffiche, 'MT')).' 
'.$langs->trans('ModifyAllLines').''.$langs->trans('Progress').' 
 
'.$langs->trans('TotalTTC').' :'.price($sign * + // $object->total_ttc).' 
'; + print '
'; + + // Margin Infos + if (isModEnabled('margin')) { + $formmargin->displayMarginInfos($object); + } + + print ''; + print ''; + + print '


'; + + if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { + $blocname = 'contacts'; + $title = $langs->trans('ContactsAddresses'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { + $blocname = 'notes'; + $title = $langs->trans('Notes'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + // Get object lines + $result = $object->getLinesArray(); + + // Add products/services form + //$forceall = 1; + global $inputalsopricewithtax; + $inputalsopricewithtax = 1; + + // Show global modifiers for situation invoices + if (!empty($conf->global->INVOICE_USE_SITUATION)) { + if ($object->situation_cycle_ref && $object->statut == 0) { + print ''."\n"; + print '
'; + + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + + print ''; + + // Adds a line numbering column + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { + print ''; + } + print ''; + print ''; + print ''; + print "\n"; + + print ''; + // Adds a line numbering column + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { + print ''; + } + print ''; + print ''; + print ''; + print ''; + + print '
 '.$langs->trans('ModifyAllLines').''.$langs->trans('Progress').' 
  %
'; + + print ''; + + print '
'; } - print '
 %
'; - - print ''; - - print '
'; } - } - print '
- - - - - - - '; + print ' + + + + + + + '; - if (!empty($conf->use_javascript_ajax) && $object->statut == 0) { - include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; - } - - print '
'; - print ''; - - // Show object lines - if (!empty($object->lines)) { - $object->printObjectLines($action, $mysoc, $soc, $lineid, 1); - } - - // Form to add new line - if ($object->statut == 0 && $usercancreate && $action != 'valid') { - if ($action != 'editline' && $action != 'selectlines') { - // Add free products/services - - $parameters = array(); - $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - if (empty($reshook)) - $object->formAddObjectLine(1, $mysoc, $soc); - } else { - $parameters = array(); - $reshook = $hookmanager->executeHooks('formEditObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if (!empty($conf->use_javascript_ajax) && $object->statut == 0) { + include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; } + + print '
'; + print '
'; + + // Show object lines + if (!empty($object->lines)) { + $object->printObjectLines($action, $mysoc, $soc, $lineid, 1); + } + + // Form to add new line + if ($object->statut == 0 && $usercancreate && $action != 'valid') { + if ($action != 'editline' && $action != 'selectlines') { + // Add free products/services + + $parameters = array(); + $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if (empty($reshook)) + $object->formAddObjectLine(1, $mysoc, $soc); + } else { + $parameters = array(); + $reshook = $hookmanager->executeHooks('formEditObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + } + } + + print "
\n"; + print "
"; + + print "
\n"; } - - print "
\n"; - print "
"; - - print "\n"; - print dol_get_fiche_end(); diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index ce297c63f5f..0a6ad7c2423 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -7,6 +7,7 @@ * Copyright (C) 2013 Florian Henry * Copyright (C) 2015 Marcos García * Copyright (C) 2017-2020 Frédéric France + * Copyright (C) 2023 Nick Fragoulis * * 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 @@ -86,6 +87,10 @@ class FactureRec extends CommonInvoice */ public $titre; + /** + * @var double + */ + public $multicurrency_subprice; public $socid; public $number; public $date; @@ -170,7 +175,8 @@ class FactureRec extends CommonInvoice 'titre' =>array('type'=>'varchar(100)', 'label'=>'Titre', 'enabled'=>1, 'showoncombobox' => 1, 'visible'=>-1, 'position'=>15), 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>20, 'index'=>1), 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'enabled'=>'isModEnabled("societe")', 'visible'=>-1, 'notnull'=>1, 'position'=>25), - 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>30), + 'subtype' =>array('type'=>'smallint(6)', 'label'=>'InvoiceSubtype', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>30), + 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>35), 'total_tva' =>array('type'=>'double(24,8)', 'label'=>'Tva', 'enabled'=>1, 'visible'=>-1, 'position'=>55, 'isameasure'=>1), 'localtax1' =>array('type'=>'double(24,8)', 'label'=>'Localtax1', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'isameasure'=>1), 'localtax2' =>array('type'=>'double(24,8)', 'label'=>'Localtax2', 'enabled'=>1, 'visible'=>-1, 'position'=>65, 'isameasure'=>1), @@ -264,11 +270,12 @@ class FactureRec extends CommonInvoice $facsrc = new Facture($this->db); $result = $facsrc->fetch($facid); if ($result > 0) { - $this->fk_soc = $facsrc->socid; + $this->socid = $facsrc->socid; $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec ("; $sql .= "titre"; $sql .= ", fk_soc"; + $sql .= ", subtype"; $sql .= ", entity"; $sql .= ", datec"; $sql .= ", amount"; @@ -296,7 +303,8 @@ class FactureRec extends CommonInvoice $sql .= ", suspended"; $sql .= ") VALUES ("; $sql .= "'".$this->db->escape($this->titre ? $this->titre : $this->title)."'"; - $sql .= ", ".((int) $this->fk_soc); + $sql .= ", ".((int) $this->socid); + $sql .= ", ".($this->subtype ? "'".$this->db->escape($this->subtype)."'" : "null"); $sql .= ", ".((int) $conf->entity); $sql .= ", '".$this->db->idate($now)."'"; $sql .= ", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) : '0'); @@ -492,8 +500,7 @@ class FactureRec extends CommonInvoice $sql .= " localtax1 = ".((float) $this->total_localtax1).","; $sql .= " localtax2 = ".((float) $this->total_localtax2).","; $sql .= " total_ht = ".((float) $this->total_ht).","; - $sql .= " total_ttc = ".((float) $this->total_ttc).","; - $sql .= " remise_percent = ".((float) $this->remise_percent); + $sql .= " total_ttc = ".((float) $this->total_ttc); // TODO Add missing fields $sql .= " WHERE rowid = ".((int) $this->id); @@ -534,13 +541,15 @@ class FactureRec extends CommonInvoice * @param int $rowid Id of object to load * @param string $ref Reference of recurring invoice * @param string $ref_ext External reference of invoice + * @param int $noextrafields 0=Default to load extrafields, 1=No extrafields + * @param int $nolines 0=Default to load lines, 1=No lines * @return int >0 if OK, <0 if KO, 0 if not found */ - public function fetch($rowid, $ref = '', $ref_ext = '') + public function fetch($rowid, $ref = '', $ref_ext = '', $noextrafields = 0, $nolines = 0) { dol_syslog('FactureRec::fetch', LOG_DEBUG); - $sql = 'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc, f.total_tva, f.localtax1, f.localtax2, f.total_ht, f.total_ttc'; + $sql = 'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc, f.subtype, f.total_tva, f.localtax1, f.localtax2, f.total_ht, f.total_ttc'; $sql .= ', f.date_lim_reglement as dlr'; $sql .= ', f.note_private, f.note_public, f.fk_user_author'; $sql .= ', f.modelpdf as model_pdf'; @@ -578,6 +587,7 @@ class FactureRec extends CommonInvoice $this->titre = $obj->title; // deprecated $this->title = $obj->title; $this->ref = $obj->title; + $this->subtype = $obj->subtype; $this->suspended = $obj->suspended; $this->total_ht = $obj->total_ht; $this->total_tva = $obj->total_tva; @@ -620,16 +630,23 @@ class FactureRec extends CommonInvoice // Retrieve all extrafield // fetch optionals attributes and labels - $this->fetch_optionals(); - - /* - * Lines - */ - $result = $this->fetch_lines(); - if ($result < 0) { - $this->error = $this->db->lasterror(); - return -3; + if (empty($noextrafields)) { + $result = $this->fetch_optionals(); + if ($result < 0) { + $this->error = $this->db->lasterror(); + return -4; + } } + + // Retreive lines + if (empty($nolines)) { + $result = $this->fetch_lines(); + if ($result < 0) { + $this->error = $this->db->lasterror(); + return -3; + } + } + return 1; } else { $this->error = 'Bill with id '.$rowid.' or ref '.$ref.' not found'; @@ -1333,6 +1350,7 @@ class FactureRec extends CommonInvoice $facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice $facture->type = self::TYPE_STANDARD; + $facture->subtype = $facturerec->subtype; $facture->statut = self::STATUS_DRAFT; // deprecated $facture->status = self::STATUS_DRAFT; $facture->date = (empty($facturerec->date_when) ? $now : $facturerec->date_when); // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later. diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 0f7facb6e26..6d14a6077bb 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -157,13 +157,6 @@ class Facture extends CommonInvoice */ public $ref_customer; - //public $remise_absolue; - - /** - * @deprecated - */ - //public $remise_percent; - public $total_ht; public $total_tva; public $total_localtax1; @@ -255,6 +248,18 @@ class Facture extends CommonInvoice */ public $retained_warranty_fk_cond_reglement; + /** + * @var int availabilty ID + */ + public $availability_id; + + public $date_closing; + + /** + * @var int + */ + public $source; + /** @@ -2274,19 +2279,17 @@ class Facture extends CommonInvoice public function fetch_lines($only_product = 0, $loadalsotranslation = 0) { // phpcs:enable - global $langs, $conf; - $this->lines = array(); $sql = 'SELECT l.rowid, l.fk_facture, l.fk_product, l.fk_parent_line, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx,'; $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise_percent, l.fk_remise_except, l.subprice, l.ref_ext,'; $sql .= ' l.situation_percent, l.fk_prev_id,'; - $sql .= ' l.rang, l.special_code,'; + $sql .= ' l.rang, l.special_code, l.batch, l.fk_warehouse,'; $sql .= ' l.date_start as date_start, l.date_end as date_end,'; $sql .= ' l.info_bits, l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc, l.fk_code_ventilation, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,'; $sql .= ' l.fk_unit,'; $sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,'; - $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc'; + $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc, p.barcode as product_barcode'; $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet as l'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; $sql .= ' WHERE l.fk_facture = '.((int) $this->id); @@ -2312,6 +2315,7 @@ class Facture extends CommonInvoice $line->product_ref = $objp->product_ref; // Ref product $line->libelle = $objp->product_label; // deprecated $line->product_label = $objp->product_label; // Label product + $line->product_barcode = $objp->product_barcode; // Barcode number product $line->product_desc = $objp->product_desc; // Description product $line->fk_product_type = $objp->fk_product_type; // Type of product $line->qty = $objp->qty; @@ -2350,6 +2354,9 @@ class Facture extends CommonInvoice $line->fk_prev_id = $objp->fk_prev_id; $line->fk_unit = $objp->fk_unit; + $line->batch = $objp->batch; + $line->fk_warehouse = $objp->fk_warehouse; + // Accountancy $line->fk_accounting_account = $objp->fk_code_ventilation; @@ -2859,7 +2866,8 @@ class Facture extends CommonInvoice $resql = $this->db->query($sql); if ($resql) { // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive - $this->deleteEcmFiles(); + $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive + $this->deleteEcmFiles(1); // Deleting files physically is done later with the dol_delete_dir_recursive // On efface le repertoire de pdf provisoire $ref = dol_sanitizeFileName($this->ref); @@ -3492,6 +3500,12 @@ class Facture extends CommonInvoice $error++; $this->error = $this->db->lasterror(); } + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'facture/".$this->db->escape($this->newref)."'"; + $sql .= " WHERE filepath = 'facture/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (!$resql) { + $error++; $this->error = $this->db->lasterror(); + } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); @@ -5955,7 +5969,7 @@ class Facture extends CommonInvoice } if (method_exists($this, 'getLibStatut')) { $alreadypaid = (empty($arraydata['alreadypaid']) ? 0 : $arraydata['alreadypaid']); - $return .= '
'.$this->getLibStatut(3, $alreadypaid).'
'; + $return .= '
'.$this->getLibStatut(3, $alreadypaid).'
'; } $return .= '
'; $return .= ''; @@ -6005,18 +6019,41 @@ class FactureLigne extends CommonInvoiceLine public $marge_tx; public $marque_tx; + /** + * @var int + */ + public $tva_npr; + public $remise_percent; - public $special_code; // Liste d'options non cumulabels: - // 1: frais de port - // 2: ecotaxe - // 3: ?? + /** + * List of special options to define line: + * 1: shipment cost lines + * 2: ecotaxe + * 3: ?? + * idofmodule: a meaning for the module + */ + public $special_code; + + /** + * @var string To store the batch to consume in stock when using a POS module + */ + public $batch; + /** + * @var string To store the warehouse where to consume stock when using a POS module + */ + public $fk_warehouse; + public $origin; public $origin_id; + /** + * @var integer Id in table llx_accounting_bookeeping to know accounting account for product line + */ public $fk_code_ventilation = 0; + public $date_start; public $date_end; diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index f1ffc8608b8..9f684ef0595 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -2131,8 +2131,12 @@ if ($num > 0) { // Invoice Subtype if (!empty($arrayfields['f.subtype']['checked'])) { - print ''; - print $facturestatic->getSubtypeLabel('facture'); + $labeltoshow = ''; + if ($facturestatic->subtype > 0) { + $labeltoshow = $facturestatic->getSubtypeLabel('facture'); + } + print ''; + print $labeltoshow; print ""; if (!$i) { $totalarray['nbfield']++; diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index bb97a63aa87..36446a0640b 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -618,7 +618,7 @@ if ($object->id > 0) { print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic; if (!empty($bac->iban)) { if ($bac->verif() <= 0) { - print img_warning('Error on default bank number for IBAN : '.$bac->error_message); + print img_warning('Error on default bank number for IBAN : '.$bac->error); } } else { if ($numopen || ($type != 'bank-transfer' && $object->mode_reglement_code == 'PRE') || ($type == 'bank-transfer' && $object->mode_reglement_code == 'VIR')) { diff --git a/htdocs/compta/localtax/class/localtax.class.php b/htdocs/compta/localtax/class/localtax.class.php index 086481dbacf..1010590c818 100644 --- a/htdocs/compta/localtax/class/localtax.class.php +++ b/htdocs/compta/localtax/class/localtax.class.php @@ -49,6 +49,24 @@ class Localtax extends CommonObject public $datev; public $amount; + /** + * @var int + */ + public $accountid; + + /** + * @var string + */ + public $fk_type; + + public $paymenttype; + + /** + * @var int + */ + public $rappro; + + /** * @var string local tax */ @@ -216,7 +234,6 @@ class Localtax extends CommonObject */ public function fetch($id) { - global $langs; $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.localtaxtype,"; @@ -225,7 +242,7 @@ class Localtax extends CommonObject $sql .= " t.datev,"; $sql .= " t.amount,"; $sql .= " t.label,"; - $sql .= " t.note,"; + $sql .= " t.note as note_private,"; $sql .= " t.fk_bank,"; $sql .= " t.fk_user_creat,"; $sql .= " t.fk_user_modif,"; @@ -250,7 +267,8 @@ class Localtax extends CommonObject $this->datev = $this->db->jdate($obj->datev); $this->amount = $obj->amount; $this->label = $obj->label; - $this->note = $obj->note; + $this->note = $obj->note_private; + $this->note_private = $obj->note_private; $this->fk_bank = $obj->fk_bank; $this->fk_user_creat = $obj->fk_user_creat; $this->fk_user_modif = $obj->fk_user_modif; @@ -515,7 +533,7 @@ class Localtax extends CommonObject $bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs($this->amount), '', '', $user); - // Mise a jour fk_bank dans llx_localtax. On connait ainsi la ligne de localtax qui a g�n�r� l'�criture bancaire + // Update fk_bank into llx_localtax so we know the line of localtax used to generate the bank entry. if ($bank_line_id > 0) { $this->update_fk_bank($bank_line_id); } else { diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index 4ae310fe421..b1a120b1df9 100644 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -30,7 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Load translation files required by the page -$langs->load("bills"); +$langs->loadLangs(array("banks", "bills", "compta")); $chid = GETPOST("id", 'int'); $action = GETPOST('action', 'aZ09'); @@ -208,7 +208,8 @@ if ($action == 'create') { print ''; print ''.$langs->trans("PaymentMode").''; - $form->select_types_paiements(GETPOSTISSET("paiementtype") ? GETPOST("paiementtype") : $charge->paiementtype, "paiementtype"); + print img_picto('', 'bank', 'class="pictofixedwidth"'); + print $form->select_types_paiements(GETPOSTISSET("paiementtype") ? GETPOST("paiementtype") : $charge->paiementtype, "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusxx', 1); print "\n"; print ''; @@ -216,18 +217,20 @@ if ($action == 'create') { print ''.$langs->trans('AccountToDebit').''; print ''; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); - $form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid", 'int') : $charge->accountid, "accountid", 0, '', 2); // Show opend bank account list + print $form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid", 'int') : $charge->accountid, "accountid", 0, '', 2, '', 0, 'maxwidth500 widthcentpercentminusx', 1); // Show opend bank account list print ''; // Number print ''.$langs->trans('Numero'); - print ' ('.$langs->trans("ChequeOrTransferNumber").')'; + if (empty($conf->dol_optimize_smallscreen)) { + print ' ('.$langs->trans("ChequeOrTransferNumber").')'; + } print ''; - print ''."\n"; + print ''."\n"; print ''; print ''.$langs->trans("Comments").''; - print ''; + print ''; print ''; print ''; @@ -240,6 +243,7 @@ if ($action == 'create') { $num = 1; $i = 0; + print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''; print ''; //print ''; @@ -265,13 +269,13 @@ if ($action == 'create') { print "\n"; } - print '"; + print '"; - print '"; + print '"; - print '"; + print '"; - print '
'.$langs->trans("SocialContribution").'!!!'.price($objp->amount)."'.price($objp->amount)."'.price($sumpaid)."'.price($sumpaid)."'.price($objp->amount - $sumpaid)."'.price($objp->amount - $sumpaid)."'; + print ''; if ($sumpaid < $objp->amount) { $namef = "amount_".$objp->id; $nameRemain = "remain_".$objp->id; @@ -304,6 +308,7 @@ if ($action == 'create') { } print "
"; + print '
'; // Save payment button print '
'.$langs->trans("ClosePaidContributionsAutomatically"); diff --git a/htdocs/compta/paymentbybanktransfer/index.php b/htdocs/compta/paymentbybanktransfer/index.php index 45e1f6695fc..825a26fc3a7 100644 --- a/htdocs/compta/paymentbybanktransfer/index.php +++ b/htdocs/compta/paymentbybanktransfer/index.php @@ -33,6 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; // Load translation files required by the page $langs->loadLangs(array('banks', 'categories', 'withdrawals')); @@ -65,6 +66,12 @@ if (prelevement_check_config('bank-transfer') < 0) { setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("PaymentByBankTransfer")), null, 'errors'); } +$thirdpartystatic = new Societe($db); +$invoicestatic = new FactureFournisseur($db); +$bprev = new BonPrelevement($db); +$salary = new Salary($db); +$user = new User($db); + $newcardbutton = ''; if ($usercancreate) { $newcardbutton .= dolGetButtonTitle($langs->trans('NewPaymentByBankTransfer'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type=bank-transfer'); @@ -76,129 +83,197 @@ print load_fiche_titre($langs->trans("SuppliersStandingOrdersArea"), $newcardbut print '
'; -$thirdpartystatic = new Societe($db); -$invoicestatic = new FactureFournisseur($db); -$bprev = new BonPrelevement($db); - print '
'; print ''; print ''; -print ''; -print ''; +$totaltoshow = 0; -print ''; +if (isModEnabled('supplier_invoice')) { + print ''; + print ''; + $totaltoshow += $bprev->SommeAPrelever('bank-transfer'); +} + +if (isModEnabled('salaries')) { + print ''; + print ''; + $totaltoshow += $bprev->SommeAPrelever('bank-transfer', 'salary'); +} + +print ''; print '
'.$langs->trans("Statistics").'
'.$langs->trans("NbOfInvoiceToPayByBankTransfer").''; -print ''; -print $bprev->nbOfInvoiceToPay('bank-transfer'); -print ''; -print '
'.$langs->trans("AmountToTransfer").'
'.$langs->trans("NbOfInvoiceToPayByBankTransfer").''; + print ''; + print $bprev->nbOfInvoiceToPay('bank-transfer'); + print ''; + print '
'.$langs->trans("NbOfInvoiceToPayByBankTransferForSalaries").''; + print ''; + print $bprev->nbOfInvoiceToPay('bank-transfer', 'salary'); + print ''; + print '
'.$langs->trans("Total").''; -print price($bprev->SommeAPrelever('bank-transfer'), '', '', 1, -1, -1, 'auto'); +print price($totaltoshow, '', '', 1, -1, -1, 'auto'); print '

'; - /* * Invoices waiting for withdraw */ -$sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type, f.datef, f.date_lim_reglement,"; -$sql .= " pfd.date_demande, pfd.amount,"; -$sql .= " s.nom as name, s.email, s.rowid as socid, s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6"; -$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,"; -$sql .= " ".MAIN_DB_PREFIX."societe as s"; -if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; -} -$sql .= ", ".MAIN_DB_PREFIX."prelevement_demande as pfd"; -$sql .= " WHERE s.rowid = f.fk_soc"; -$sql .= " AND f.entity IN (".getEntity('supplier_invoice').")"; -$sql .= " AND f.total_ttc > 0"; -if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { - $sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_VALIDATED; -} -$sql .= " AND pfd.traite = 0"; -$sql .= " AND pfd.ext_payment_id IS NULL"; -$sql .= " AND pfd.fk_facture_fourn = f.rowid"; -if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); -} -if ($socid) { - $sql .= " AND f.fk_soc = ".((int) $socid); -} - -$resql = $db->query($sql); -if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - - print '
'; - print ''; - print ''; - print ''; - if ($num) { - while ($i < $num && $i < 20) { - $obj = $db->fetch_object($resql); - - $invoicestatic->id = $obj->rowid; - $invoicestatic->ref = $obj->ref; - $invoicestatic->status = $obj->fk_statut; - $invoicestatic->statut = $obj->fk_statut; // For backward comaptibility - $invoicestatic->paye = $obj->paye; - $invoicestatic->type = $obj->type; - $invoicestatic->date = $db->jdate($obj->datef); - $invoicestatic->date_echeance = $db->jdate($obj->date_lim_reglement); - $invoicestatic->total_ttc = $obj->total_ttc; - $alreadypayed = $invoicestatic->getSommePaiement(); - - $thirdpartystatic->id = $obj->socid; - $thirdpartystatic->name = $obj->name; - $thirdpartystatic->email = $obj->email; - $thirdpartystatic->tva_intra = $obj->tva_intra; - $thirdpartystatic->siren = $obj->idprof1; - $thirdpartystatic->siret = $obj->idprof2; - $thirdpartystatic->ape = $obj->idprof3; - $thirdpartystatic->idprof1 = $obj->idprof1; - $thirdpartystatic->idprof2 = $obj->idprof2; - $thirdpartystatic->idprof3 = $obj->idprof3; - $thirdpartystatic->idprof4 = $obj->idprof4; - $thirdpartystatic->idprof5 = $obj->idprof5; - $thirdpartystatic->idprof6 = $obj->idprof6; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - print ''; - $i++; - } - } else { - $titlefortab = $langs->transnoentitiesnoconv("BankTransfer"); - print ''; +if (isModEnabled('supplier_invoice')) { + $sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type, f.datef, f.date_lim_reglement,"; + $sql .= " pfd.date_demande, pfd.amount,"; + $sql .= " s.nom as name, s.email, s.rowid as socid, s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,"; + $sql .= " ".MAIN_DB_PREFIX."societe as s"; + if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + $sql .= ", ".MAIN_DB_PREFIX."prelevement_demande as pfd"; + $sql .= " WHERE s.rowid = f.fk_soc"; + $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")"; + $sql .= " AND f.total_ttc > 0"; + if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { + $sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_VALIDATED; + } + $sql .= " AND pfd.traite = 0"; + $sql .= " AND pfd.ext_payment_id IS NULL"; + $sql .= " AND pfd.fk_facture_fourn = f.rowid"; + if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); + } + if ($socid) { + $sql .= " AND f.fk_soc = ".((int) $socid); + } + + $sqlForSalary = "SELECT * FROM ".MAIN_DB_PREFIX."salary as s, ".MAIN_DB_PREFIX."prelevement_demande as pd"; + $sqlForSalary .= " WHERE s.rowid = pd.fk_salary AND s.paye = 0 AND pd.traite = 0"; + $sqlForSalary .= " AND s.entity IN (".getEntity('salary').")"; + + $resql = $db->query($sql); + + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + + print '
'; + print '
'.$langs->trans("SupplierInvoiceWaitingWithdraw").' ('.$num.')
'; - print $invoicestatic->getNomUrl(1, 'withdraw'); - print ''; - print $thirdpartystatic->getNomUrl(1, 'supplier'); - print ''; - print ''.price($obj->amount).''; - print ''; - print dol_print_date($db->jdate($obj->date_demande), 'day'); - print ''; - print $invoicestatic->getLibStatut(3, $alreadypayed); - print '
'.$langs->trans("NoSupplierInvoiceToWithdraw", $titlefortab, $titlefortab).'
'; + print ''; + print ''; + if ($num) { + while ($i < $num && $i < 20) { + $obj = $db->fetch_object($resql); + + $invoicestatic->id = $obj->rowid; + $invoicestatic->ref = $obj->ref; + $invoicestatic->status = $obj->fk_statut; + $invoicestatic->statut = $obj->fk_statut; // For backward comaptibility + $invoicestatic->paye = $obj->paye; + $invoicestatic->type = $obj->type; + $invoicestatic->date = $db->jdate($obj->datef); + $invoicestatic->date_echeance = $db->jdate($obj->date_lim_reglement); + $invoicestatic->total_ttc = $obj->total_ttc; + + $alreadypayed = $invoicestatic->getSommePaiement(); + + $thirdpartystatic->id = $obj->socid; + $thirdpartystatic->name = $obj->name; + $thirdpartystatic->email = $obj->email; + $thirdpartystatic->tva_intra = $obj->tva_intra; + $thirdpartystatic->idprof1 = $obj->idprof1; + $thirdpartystatic->idprof2 = $obj->idprof2; + $thirdpartystatic->idprof3 = $obj->idprof3; + $thirdpartystatic->idprof4 = $obj->idprof4; + $thirdpartystatic->idprof5 = $obj->idprof5; + $thirdpartystatic->idprof6 = $obj->idprof6; + + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + print ''; + $i++; + } + } else { + $titlefortab = $langs->transnoentitiesnoconv("BankTransfer"); + print ''; + } + print "
'.$langs->trans("SupplierInvoiceWaitingWithdraw").' ('.$num.')
'; + print $invoicestatic->getNomUrl(1, 'withdraw'); + print ''; + print $thirdpartystatic->getNomUrl(1, 'supplier'); + print ''; + print ''.price($obj->amount).''; + print ''; + print dol_print_date($db->jdate($obj->date_demande), 'day'); + print ''; + print $invoicestatic->getLibStatut(3, $alreadypayed); + print '
'.$langs->trans("NoSupplierInvoiceToWithdraw", $titlefortab, $titlefortab).'

"; + } else { + dol_print_error($db); + } +} + +if (isModEnabled('salaries')) { + $resql2 = $db->query($sqlForSalary); + if ($resql2) { + $numRow = $db->num_rows($resql2); + $j = 0 ; + + print '
'; + print ''; + print ''; + print ''; + + if ($numRow) { + while ($j < $numRow && $j<10) { + $objSalary = $db->fetch_object($resql2); + + $user->fetch($objSalary->fk_user); + + $salary->fetch($objSalary->fk_salary); + + $alreadypayedS = $salary->getSommePaiement(); + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + print ''; + $j++; + } + } else { + $titlefortab = $langs->transnoentitiesnoconv("BankTransfer"); + print ''; + } + print "
'.$langs->trans("SalaryInvoiceWaitingWithdraw").' ('.$numRow.')
'; + print $salary->getNomUrl(1); + print ''; + print $user->getNomUrl(-1); + print ''; + print ''.price($objSalary->amount).''; + print ''; + print dol_print_date($db->jdate($objSalary->date_demande), 'day'); + print ''; + print $salary->getLibStatut(3, $alreadypayedS); + print '
'.$langs->trans("NoSalaryInvoiceToWithdraw", $titlefortab, $titlefortab).'

"; + } else { + dol_print_error($db); } - print "

"; -} else { - dol_print_error($db); } print '
'; - /* * Withdraw receipts */ diff --git a/htdocs/compta/prelevement/card.php b/htdocs/compta/prelevement/card.php index 0fa29f5f66b..f385266d493 100644 --- a/htdocs/compta/prelevement/card.php +++ b/htdocs/compta/prelevement/card.php @@ -71,7 +71,8 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ $hookmanager->initHooks(array('directdebitprevcard', 'globalcard', 'directdebitprevlist')); $type = $object->type; - +// chek if salary pl +$salaryBonPl = $object->checkIfSalaryBonPrelevement(); if ($type == 'bank-transfer') { $result = restrictedArea($user, 'paymentbybanktransfer', '', '', ''); @@ -430,20 +431,27 @@ if ($id > 0 || $ref) { /* * Lines into withdraw request */ - $sql = "SELECT pl.rowid, pl.statut, pl.amount,"; - $sql .= " s.rowid as socid, s.nom as name"; - $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; - $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $id); - $sql .= " AND pl.fk_prelevement_bons = pb.rowid"; - $sql .= " AND pb.entity = ".((int) $conf->entity); // No sharing of entity here - $sql .= " AND pl.fk_soc = s.rowid"; - if ($socid) { - $sql .= " AND s.rowid = ".((int) $socid); + if ($salaryBonPl) { + $sql = "SELECT pl.rowid, pl.statut, pl.amount,pl.fk_user"; + $sql .=" FROM llx_prelevement as p, llx_prelevement_lignes as pl, llx_salary as s"; + $sql .= " WHERE pl.rowid = p.fk_prelevement_lignes"; + $sql .= " AND p.fk_salary = s.rowid"; + $sql .= " AND pl.fk_prelevement_bons = ".((int) $id); + } else { + $sql = "SELECT pl.rowid, pl.statut, pl.amount,"; + $sql .= " s.rowid as socid, s.nom as name"; + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; + $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb"; + $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $id); + $sql .= " AND pl.fk_prelevement_bons = pb.rowid"; + $sql .= " AND pb.entity = ".((int) $conf->entity); // No sharing of entity here + $sql .= " AND pl.fk_soc = s.rowid"; + if ($socid) { + $sql .= " AND s.rowid = ".((int) $socid); + } + $sql .= $db->order($sortfield, $sortorder); } - $sql .= $db->order($sortfield, $sortorder); - // Count total nb of records $nbtotalofrecords = ''; if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { @@ -491,7 +499,7 @@ if ($id > 0 || $ref) { print ''; print ''; print_liste_field_titre("Lines", $_SERVER["PHP_SELF"], "pl.rowid", '', $urladd, '', $sortfield, $sortorder); - print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", '', $urladd, '', $sortfield, $sortorder); + print_liste_field_titre((!$salaryBonPl ? "ThirdParty" : "Employee"), $_SERVER["PHP_SELF"], "s.nom", '', $urladd, '', $sortfield, $sortorder); print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $urladd, 'class="right"', $sortfield, $sortorder); print_liste_field_titre(''); print "\n"; @@ -509,11 +517,15 @@ if ($id > 0 || $ref) { print $ligne->LibStatut($obj->statut, 2); print ''.$obj->rowid.''; print ''; - - $thirdparty = new Societe($db); - $thirdparty->fetch($obj->socid); + if (!$salaryBonPl) { + $thirdparty = new Societe($db); + $thirdparty->fetch($obj->socid); + } else { + $userSalary = new User($db); + $userSalary->fetch($obj->fk_user); + } print '\n"; print '\n"; diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 813455b4061..8f0eea7e2ab 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -28,13 +28,14 @@ */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; -require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php'; @@ -225,16 +226,18 @@ class BonPrelevement extends CommonObject * @param string $number bank account number * @param string $number_key number key of account number * @param string $type 'debit-order' or 'bank-transfer' + * @param string $sourcetype 'salary' for invoice of salary * @return int >0 if OK, <0 if KO */ - public function AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type = 'debit-order') + public function AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type = 'debit-order', $sourcetype = '') { // phpcs:enable $result = 0; $line_id = 0; // Add lines - $result = $this->addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key); + $result = $this->addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype); + if ($result == 0) { if ($line_id > 0) { @@ -242,7 +245,11 @@ class BonPrelevement extends CommonObject if ($type != 'bank-transfer') { $sql .= "fk_facture"; } else { - $sql .= "fk_facture_fourn"; + if (!empty($sourcetype)) { + $sql .= "fk_salary"; + } else { + $sql .= "fk_facture_fourn"; + } } $sql .= ",fk_prelevement_lignes"; $sql .= ") VALUES ("; @@ -281,9 +288,10 @@ class BonPrelevement extends CommonObject * @param string $code_guichet code of bank's office * @param string $number bank account number * @param string $number_key number key of account number + * @param string $sourcetype check if is salary invoice * @return int >0 if OK, <0 if KO */ - public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key) + public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype = '') { $result = -1; $concat = 0; @@ -295,7 +303,11 @@ class BonPrelevement extends CommonObject $sql = "SELECT rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes"; $sql .= " WHERE fk_prelevement_bons = ".((int) $this->id); - $sql .= " AND fk_soc =".((int) $client_id); + if (empty($sourcetype)) { + $sql .= " AND fk_soc =".((int) $client_id); + } else { + $sql .= " AND fk_user =".((int) $client_id); + } $sql .= " AND code_banque = '".$this->db->escape($code_banque)."'"; $sql .= " AND code_guichet = '".$this->db->escape($code_guichet)."'"; $sql .= " AND number = '".$this->db->escape($number)."'"; @@ -319,17 +331,18 @@ class BonPrelevement extends CommonObject $sql .= ", code_guichet"; $sql .= ", number"; $sql .= ", cle_rib"; + $sql .= (!empty($sourcetype) ? ", fk_user" : ""); $sql .= ") VALUES ("; $sql .= $this->id; - $sql .= ", ".((int) $client_id); + $sql .= ", ".(empty($sourcetype) ? ((int) $client_id) : 0); $sql .= ", '".$this->db->escape($client_nom)."'"; $sql .= ", ".((float) price2num($amount)); $sql .= ", '".$this->db->escape($code_banque)."'"; $sql .= ", '".$this->db->escape($code_guichet)."'"; $sql .= ", '".$this->db->escape($number)."'"; $sql .= ", '".$this->db->escape($number_key)."'"; + $sql .= (!empty($sourcetype) ? ", ". ((int) $client_id) : ''); $sql .= ")"; - if ($this->db->query($sql)) { $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_lignes"); $result = 0; @@ -676,17 +689,17 @@ class BonPrelevement extends CommonObject */ $sql = "SELECT "; if ($this->type == 'bank-transfer') { - $sql .= " pf.fk_facture_fourn"; + $sql .= " p.fk_facture_fourn"; } else { - $sql .= " pf.fk_facture"; + $sql .= " p.fk_facture"; } if ($amounts) { $sql .= ", SUM(pl.amount)"; } $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl"; - $sql .= " , ".MAIN_DB_PREFIX."prelevement as pf"; - $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid"; + $sql .= " , ".MAIN_DB_PREFIX."prelevement as p"; + $sql .= " WHERE p.fk_prelevement_lignes = pl.rowid"; $sql .= " AND pl.fk_prelevement_bons = p.rowid"; $sql .= " AND p.rowid = ".((int) $this->id); $sql .= " AND p.entity = ".((int) $conf->entity); @@ -730,33 +743,42 @@ class BonPrelevement extends CommonObject * Returns amount waiting for direct debit payment or credit transfer payment * * @param string $mode 'direct-debit' or 'bank-transfer' + * @param string $type for type=salary * @return double global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { - $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; + $sql .= ($type !== 'salary' ? " AND f.fk_statut = ".Facture::STATUS_VALIDATED : " AND s.paye = ".Salary::STATUS_UNPAID); } - if ($mode != 'bank-transfer') { - $sql .= " AND f.rowid = pd.fk_facture"; + if ($type !== 'salary') { + if ($mode != 'bank-transfer') { + $sql .= " AND f.rowid = pd.fk_facture"; + } else { + $sql .= " AND f.rowid = pd.fk_facture_fourn"; + } } else { - $sql .= " AND f.rowid = pd.fk_facture_fourn"; + $sql .= " AND s.rowid = pd.fk_salary"; } - $sql .= " AND f.paye = 0"; + $sql .= ($type !== 'salary' ? " AND f.paye = 0" : ""); $sql .= " AND pd.traite = 0"; $sql .= " AND pd.ext_payment_id IS NULL"; - $sql .= " AND f.total_ttc > 0"; + $sql .= ($type !== 'salary' ? " AND f.total_ttc > 0" : ""); $resql = $this->db->query($sql); if ($resql) { @@ -778,11 +800,16 @@ class BonPrelevement extends CommonObject * Get number of invoices waiting for payment * * @param string $mode 'direct-debit' or 'bank-transfer' + * @param string $type for salary invoice * @return int NbFactureAPrelever($mode); + if ($type === 'salary') { + return $this->NbFactureAPrelever($mode, 1); + } else { + return $this->NbFactureAPrelever($mode); + } } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -790,39 +817,60 @@ class BonPrelevement extends CommonObject * Get number of invoices to pay * * @param string $type 'direct-debit' or 'bank-transfer' + * @param int $forsalary 0= for facture & facture_supplier, 1=for salary * @return int global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { - $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; - } - if ($type == 'bank-transfer') { - $sql .= " AND f.rowid = pd.fk_facture_fourn"; + if ($forsalary == 1) { + $sql .= " WHERE s.entity IN (".getEntity('invoice').")"; + if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { + $sql .= " AND s.paye = 0"; + } } else { - $sql .= " AND f.rowid = pd.fk_facture"; + $sql .= " WHERE f.entity IN (".getEntity('invoice').")"; + if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { + $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; + } + } + if ($forsalary == 1) { + $sql .= " AND s.rowid = pd.fk_salary"; + } else { + if ($type == 'bank-transfer') { + $sql .= " AND f.rowid = pd.fk_facture_fourn"; + } else { + $sql .= " AND f.rowid = pd.fk_facture"; + } } $sql .= " AND pd.traite = 0"; $sql .= " AND pd.ext_payment_id IS NULL"; - $sql .= " AND f.total_ttc > 0"; + if (!$forsalary == 1) { + $sql .= " AND f.total_ttc > 0"; + } else { + $sql .= " AND s.paye = 0"; + } dol_syslog(get_class($this)."::NbFactureAPrelever"); $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); - $this->db->free($resql); return $obj->nb; @@ -897,7 +945,6 @@ class BonPrelevement extends CommonObject $factures_result = array(); $factures_prev_id = array(); $factures_errors = array(); - if (!$error) { dol_syslog(__METHOD__." Read invoices for did=".((int) $did), LOG_DEBUG); @@ -909,36 +956,52 @@ class BonPrelevement extends CommonObject } $sql .= ", pd.code_banque, pd.code_guichet, pd.number, pd.cle_rib"; $sql .= ", pd.amount"; - $sql .= ", s.nom as name"; - $sql .= ", f.ref, sr.bic, sr.iban_prefix, sr.frstrecur"; + if ($sourcetype != 'salary') { + $sql .= ", s.nom as name"; + $sql .= ", f.ref, sr.bic, sr.iban_prefix, sr.frstrecur"; + } else { + $sql .= ", CONCAT(s.firstname,' ',s.lastname) as name"; + $sql .= ", f.ref, sr.bic, sr.iban_prefix, 'FRST' as frstrecur"; + } if ($sourcetype != 'salary') { if ($type != 'bank-transfer') { $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "prelevement_demande as pd ON f.rowid = pd.fk_facture"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_demande as pd ON f.rowid = pd.fk_facture"; } else { $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "prelevement_demande as pd ON f.rowid = pd.fk_facture_fourn"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_demande as pd ON f.rowid = pd.fk_facture_fourn"; } - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_rib as sr ON s.rowid = sr.fk_soc AND sr.default_rib = 1"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_rib as sr ON s.rowid = sr.fk_soc AND sr.default_rib = 1"; } else { $sql .= " FROM ".MAIN_DB_PREFIX."salary as f"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "prelevement_demande as pd ON f.rowid = pd.fk_salary"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as s ON s.rowid = f.fk_user"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user_rib as sr ON s.rowid = sr.fk_user"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_demande as pd ON f.rowid = pd.fk_salary"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as s ON s.rowid = f.fk_user"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user_rib as sr ON s.rowid = sr.fk_user"; // TODO Add AND sr.default_rib = 1 here + } + if ($sourcetype != 'salary') { + if ($type != 'bank-transfer') { + $sql .= " WHERE f.entity IN (".getEntity('invoice').')'; + } else { + $sql .= " WHERE f.entity IN (".getEntity('supplier_invoice').')'; + } + } else { + $sql .= " WHERE f.entity IN (".getEntity('salary').')'; } - $sql .= " WHERE f.entity IN (".getEntity('invoice').')'; if ($sourcetype != 'salary') { $sql .= " AND f.fk_statut = 1"; // Invoice validated $sql .= " AND f.paye = 0"; $sql .= " AND f.total_ttc > 0"; } else { + //$sql .= " AND f.fk_statut = 1"; // Invoice validated $sql .= " AND f.paye = 0"; $sql .= " AND f.amount > 0"; } $sql .= " AND pd.traite = 0"; $sql .= " AND pd.ext_payment_id IS NULL"; - $sql .= " AND sr.type = 'ban' "; + if ($sourcetype != 'salary') { + $sql .= " AND sr.type = 'ban'"; // TODO Add AND sr.type = 'ban' for users too + } if ($did > 0) { $sql .= " AND pd.rowid = ".((int) $did); } @@ -949,8 +1012,9 @@ class BonPrelevement extends CommonObject $i = 0; while ($i < $num) { - $row = $this->db->fetch_row($resql); + $row = $this->db->fetch_row($resql); // TODO Replace with fetch_object() $factures[$i] = $row; // All fields + if ($row[7] == 0) { $error++; dol_syslog(__METHOD__." Read invoices/salary error Found a null amount", LOG_ERR); @@ -959,6 +1023,7 @@ class BonPrelevement extends CommonObject } $i++; } + $this->db->free($resql); dol_syslog(__METHOD__." Read invoices/salary, ".$i." invoices/salary to withdraw", LOG_DEBUG); } else { @@ -970,10 +1035,14 @@ class BonPrelevement extends CommonObject } if (!$error) { + // Make some checks + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; + require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; - $soc = new Societe($this->db); + $tmpsoc = new Societe($this->db); + $tmpuser = new User($this->db); // Check BAN $i = 0; @@ -1018,13 +1087,30 @@ class BonPrelevement extends CommonObject //dol_syslog(__METHOD__."::RIB is ok", LOG_DEBUG); } else { if ($type != 'bank-transfer') { + $tmpsoc->id = $fac[2]; + $tmpsoc->name = $fac[8]; $invoice_url = "".$fac[9].""; - } else { - $invoice_url = "".$fac[9].""; + $this->invoice_in_error[$fac[0]] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0); + $this->thirdparty_in_error[$tmpsoc->id] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0); + $error++; } - dol_syslog(__METHOD__ . " Check BAN Error on default bank number IBAN/BIC for thirdparty reported by verif() " . $fac->fk_soc . " " . $soc->name, LOG_WARNING); - $this->invoice_in_error[$fac[0]] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $soc->getNomUrl(0); - $this->thirdparty_in_error[$soc->id] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $soc->getNomUrl(0); + if ($type == 'bank-transfer' && $sourcetype != 'salary') { + $tmpsoc->id = $fac[2]; + $tmpsoc->name = $fac[8]; + $invoice_url = "".$fac[9].""; + $this->invoice_in_error[$fac[0]] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0); + $this->thirdparty_in_error[$tmpsoc->id] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0); + $error++; + } + if ($type == 'bank-transfer' && $sourcetype == 'salary') { + $tmpuser->id = $fac[2]; + $tmpuser->firstname = $fac[8]; + $salary_url = "".$fac[0].""; + $this->invoice_in_error[$fac[0]] = "Error on default bank number IBAN/BIC for salary " . $salary_url . " for employee " . $tmpuser->getNomUrl(0); + $this->thirdparty_in_error[$tmpuser->id] = "Error on default bank number IBAN/BIC for salary " . $salary_url . " for employee " . $tmpuser->getNomUrl(0); + $error++; + } + dol_syslog(__METHOD__ . " Check BAN Error on default bank number IBAN/BIC reported by verif(): " . join(', ', $fac), LOG_WARNING); } } else { dol_syslog(__METHOD__ . " Check BAN Failed to read company", LOG_WARNING); @@ -1063,7 +1149,6 @@ class BonPrelevement extends CommonObject print $langs->trans("ModeWarning"); // "Option for real mode was not set, we stop after this simulation\n"; } } - if ($ok) { /* * We are in real mode. @@ -1128,6 +1213,8 @@ class BonPrelevement extends CommonObject $sql .= ")"; $resql = $this->db->query($sql); + + if ($resql) { $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons"); $this->id = $prev_id; @@ -1143,17 +1230,9 @@ class BonPrelevement extends CommonObject } if (!$error) { - /* - if ($type != 'bank-transfer') { - $fact = new Facture($this->db); - } else { - $fact = new FactureFournisseur($this->db); - } - */ - // Add lines for the bon if (count($factures_prev) > 0) { - foreach ($factures_prev as $fac) { // Add a link in database for each invoice + foreach ($factures_prev as $fac) { // Add a link in database for each invoice ro salary // Fetch invoice /* $result = $fact->fetch($fac[0]); @@ -1180,7 +1259,9 @@ class BonPrelevement extends CommonObject * $fac[11] : IBAN * $fac[12] : frstrcur */ - $ri = $this->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type); + + $ri = $this->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type, $sourcetype); + if ($ri <> 0) { $error++; } @@ -1227,18 +1308,14 @@ class BonPrelevement extends CommonObject $this->raison_sociale = $account->proprio; } - $this->factures = $factures_prev_id; $this->context['factures_prev'] = $factures_prev; - // Generation of direct debit or credit transfer file $this->filename (May be a SEPA file for european countries) // This also set the property $this->total with amount that is included into file if ($sourcetype == 'salary') { $userid = $this->context['factures_prev'][0][2]; - $result = $this->generate($format, $executiondate, $type, $fk_bank_account, $userid); - } else { - $result = $this->generate($format, $executiondate, $type); } + $result = $this->generate($format, $executiondate, $type, $fk_bank_account, $userid); if ($result < 0) { //var_dump($this->error); //var_dump($this->invoice_in_error); @@ -1247,7 +1324,7 @@ class BonPrelevement extends CommonObject } dol_syslog(__METHOD__." Bank order file has been generated under filename ".$this->filename, LOG_DEBUG); } - //var_dump($this->total);exit; + /* * Update total defined after generation of file @@ -1257,8 +1334,8 @@ class BonPrelevement extends CommonObject $sql .= " SET amount = ".price2num($this->total); $sql .= " WHERE rowid = ".((int) $this->id); $sql .= " AND entity = ".((int) $conf->entity); - $resql = $this->db->query($sql); + if (!$resql) { $error++; dol_syslog(__METHOD__." Error update total: ".$this->db->error(), LOG_ERR); @@ -1281,7 +1358,7 @@ class BonPrelevement extends CommonObject if (!$error) { $this->db->commit(); - return count($factures_prev); + return count($factures_prev); // The error of failed lines are into $this->invoice_in_error and $this->thirdparty_in_error } else { $this->db->rollback(); return -1; @@ -1606,18 +1683,18 @@ class BonPrelevement extends CommonObject $sql = "SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,"; $sql .= " pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,"; - $sql .= " f.ref as reffac, pf.fk_facture as idfac,"; + $sql .= " f.ref as reffac, p.fk_facture as idfac,"; $sql .= " rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum"; $sql .= " FROM"; $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; $sql .= " ".MAIN_DB_PREFIX."facture as f,"; - $sql .= " ".MAIN_DB_PREFIX."prelevement as pf,"; + $sql .= " ".MAIN_DB_PREFIX."prelevement as p,"; $sql .= " ".MAIN_DB_PREFIX."societe as soc,"; $sql .= " ".MAIN_DB_PREFIX."c_country as c,"; $sql .= " ".MAIN_DB_PREFIX."societe_rib as rib"; $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $this->id); - $sql .= " AND pl.rowid = pf.fk_prelevement_lignes"; - $sql .= " AND pf.fk_facture = f.rowid"; + $sql .= " AND pl.rowid = p.fk_prelevement_lignes"; + $sql .= " AND p.fk_facture = f.rowid"; $sql .= " AND f.fk_soc = soc.rowid"; $sql .= " AND soc.fk_pays = c.rowid"; $sql .= " AND rib.fk_soc = f.fk_soc"; @@ -1721,11 +1798,11 @@ class BonPrelevement extends CommonObject /* * Section Creditor (sepa Crediteurs bloc lines) */ - // add condition for traiting sourcetype TODO if (!empty($user_dest)) { $sql = "SELECT u.rowid as userId, c.code as country_code, CONCAT(u.firstname,' ',u.lastname) as nom,"; $sql .= " pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,"; - $sql .= " s.rowid as idSalary,rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum"; + $sql .= " s.ref as reffac, p.fk_salary as idfac,"; + $sql .= " rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, '' as rum, '' as date_rum"; $sql .= " FROM"; $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; $sql .= " ".MAIN_DB_PREFIX."salary as s,"; @@ -1742,18 +1819,18 @@ class BonPrelevement extends CommonObject } else { $sql = "SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,"; $sql .= " pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,"; - $sql .= " f.ref as reffac, pf.fk_facture_fourn as idfac, f.ref_supplier as fac_ref_supplier,"; + $sql .= " f.ref as reffac, f.ref_supplier as fac_ref_supplier, p.fk_facture_fourn as idfac,"; $sql .= " rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum"; $sql .= " FROM"; $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; $sql .= " ".MAIN_DB_PREFIX."facture_fourn as f,"; - $sql .= " ".MAIN_DB_PREFIX."prelevement as pf,"; + $sql .= " ".MAIN_DB_PREFIX."prelevement as p,"; $sql .= " ".MAIN_DB_PREFIX."societe as soc,"; $sql .= " ".MAIN_DB_PREFIX."c_country as c,"; $sql .= " ".MAIN_DB_PREFIX."societe_rib as rib"; $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $this->id); - $sql .= " AND pl.rowid = pf.fk_prelevement_lignes"; - $sql .= " AND pf.fk_facture_fourn = f.rowid"; + $sql .= " AND pl.rowid = p.fk_prelevement_lignes"; + $sql .= " AND p.fk_facture_fourn = f.rowid"; $sql .= " AND f.fk_soc = soc.rowid"; $sql .= " AND soc.fk_pays = c.rowid"; $sql .= " AND rib.fk_soc = f.fk_soc"; @@ -1768,7 +1845,6 @@ class BonPrelevement extends CommonObject $num = $this->db->num_rows($resql); while ($i < $num) { $obj = $this->db->fetch_object($resql); - if (!empty($cachearraytotestduplicate[$obj->idfac])) { $this->error = $langs->trans('ErrorCompanyHasDuplicateDefaultBAN', $obj->socid); $this->invoice_in_error[$obj->idfac] = $this->error; @@ -1841,10 +1917,10 @@ class BonPrelevement extends CommonObject $sql .= " FROM"; $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; $sql .= " ".MAIN_DB_PREFIX."facture as f,"; - $sql .= " ".MAIN_DB_PREFIX."prelevement as pf"; + $sql .= " ".MAIN_DB_PREFIX."prelevement as p"; $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $this->id); - $sql .= " AND pl.rowid = pf.fk_prelevement_lignes"; - $sql .= " AND pf.fk_facture = f.rowid"; + $sql .= " AND pl.rowid = p.fk_prelevement_lignes"; + $sql .= " AND p.fk_facture = f.rowid"; // Lines $i = 0; @@ -1867,10 +1943,10 @@ class BonPrelevement extends CommonObject $sql .= " FROM"; $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; $sql .= " ".MAIN_DB_PREFIX."facture_fourn as f,"; - $sql .= " ".MAIN_DB_PREFIX."prelevement as pf"; + $sql .= " ".MAIN_DB_PREFIX."prelevement as p"; $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $this->id); - $sql .= " AND pl.rowid = pf.fk_prelevement_lignes"; - $sql .= " AND pf.fk_facture_fourn = f.rowid"; + $sql .= " AND pl.rowid = p.fk_prelevement_lignes"; + $sql .= " AND p.fk_facture_fourn = f.rowid"; // Lines $i = 0; $resql = $this->db->query($sql); @@ -2009,8 +2085,8 @@ class BonPrelevement extends CommonObject * @param string $row_cg pl.code_guichet AS cg, Not used for SEPA * @param string $row_cc pl.number AS cc, Not used for SEPA * @param string $row_somme pl.amount AS somme, - * @param string $row_ref Invoice ref (f.ref) - * @param string $row_idfac pf.fk_facture AS idfac, + * @param string $row_ref Invoice ref (f.ref) or Salary ref + * @param string $row_idfac p.fk_facture AS idfac or p.fk_facture_fourn or p.fk_salary, * @param string $row_iban rib.iban_prefix AS iban, * @param string $row_bic rib.bic AS bic, * @param string $row_datec rib.datec, @@ -2085,7 +2161,7 @@ class BonPrelevement extends CommonObject $XML_DEBITOR .= ' '.$CrLf; return $XML_DEBITOR; } else { - // SEPA Paiement Information of seller for Credit Transfer + // SEPA Payment Information of seller for Credit Transfer $XML_CREDITOR = ''; $XML_CREDITOR .= ' '.$CrLf; $XML_CREDITOR .= ' '.$CrLf; @@ -2333,8 +2409,8 @@ class BonPrelevement extends CommonObject $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; - $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS), ' ')).''.$CrLf; - $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN), ' ')).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf;*/ $XML_SEPA_INFO .= ' SLEV'.$CrLf; // Field "Responsible of fees". Must be SLEV @@ -2399,8 +2475,8 @@ class BonPrelevement extends CommonObject $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; - $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS), ' ')).''.$CrLf; - $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN), ' ')).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf;*/ $XML_SEPA_INFO .= ' SLEV'.$CrLf; // Field "Responsible of fees". Must be SLEV @@ -2647,4 +2723,38 @@ class BonPrelevement extends CommonObject $return .= ''; return $return; } + + /** + * Check if is bon prelevement for salary invoice + * + * @return int 1 if OK, O if K0 + */ + public function checkIfSalaryBonPrelevement() + { + if (!empty($this->id)) { + $id = $this->id; + } else { + return 0; + } + if ($id) { + $sql = "SELECT COUNT(*) AS nb FROM ".MAIN_DB_PREFIX."prelevement_lignes"; + $sql .= " WHERE fk_prelevement_bons = ".((int) $id); + $sql .= " AND fk_soc = 0"; + $sql .= " AND fk_user IS NOT NULL"; + + $num = 0; + $resql = $this->db->query($sql); + if ($resql) { + $obj = $this->db->fetch_object($resql); + $num = $obj->nb; + } + if ($num > 0) { + return 1; + } + } else { + dol_print_error($this->db); + } + + return 0; + } } diff --git a/htdocs/compta/prelevement/create.php b/htdocs/compta/prelevement/create.php index 2555ab9d37e..36b48ef5bde 100644 --- a/htdocs/compta/prelevement/create.php +++ b/htdocs/compta/prelevement/create.php @@ -1,6 +1,6 @@ - * Copyright (C) 2010-2020 Laurent Destailleur + * Copyright (C) 2010-2023 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2010-2012 Juanjo Menent * Copyright (C) 2018 Nicolas ZABOURI @@ -31,6 +31,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; @@ -41,14 +42,14 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Load translation files required by the page $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies', 'bills')); -$type = GETPOST('type', 'aZ09'); - // Get supervariables $action = GETPOST('action', 'aZ09'); $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list - $mode = GETPOST('mode', 'alpha') ?GETPOST('mode', 'alpha') : 'real'; + +$type = GETPOST('type', 'aZ09'); +$sourcetype = GETPOST('sourcetype', 'aZ09'); $format = GETPOST('format', 'aZ09'); $id_bankaccount = GETPOST('id_bankaccount', 'int'); $executiondate = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); @@ -69,10 +70,17 @@ if ($user->socid) { } if ($type == 'bank-transfer') { $result = restrictedArea($user, 'paymentbybanktransfer', '', '', ''); + + $permissiontoread = $user->hasRight('paymentbybanktransfer', 'read'); + $permissiontocreate = $user->hasRight('paymentbybanktransfer', 'create'); } else { $result = restrictedArea($user, 'prelevement', '', '', 'bons'); + + $permissiontoread = $user->hasRight('prelevement', 'bons', 'lire'); + $permissiontocreate = $user->hasRight('prelevement', 'bons', 'creer'); } + $error = 0; $option = ""; $mesg = ''; @@ -94,20 +102,20 @@ if ($reshook < 0) { if (empty($reshook)) { // Change customer bank information to withdraw + /* if ($action == 'modify') { for ($i = 1; $i < 9; $i++) { dolibarr_set_const($db, GETPOST("nom".$i), GETPOST("value".$i), 'chaine', 0, '', $conf->entity); } } - if ($action == 'create') { + */ + if ($action == 'create' && $permissiontocreate) { $default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT'); - //var_dump($default_account);var_dump($conf->global->$default_account);var_dump($id_bankaccount);exit; if ($id_bankaccount != getDolGlobalInt($default_account)) { $res = dolibarr_set_const($db, $default_account, $id_bankaccount, 'chaine', 0, '', $conf->entity); // Set as default } - require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $bank = new Account($db); $bank->fetch(getDolGlobalInt($default_account)); @@ -115,6 +123,7 @@ if (empty($reshook)) { /*if ((empty($bank->ics) && $type !== 'bank-transfer') || (empty($bank->ics_transfer) && $type === 'bank-transfer') ) {*/ + if (empty($bank->ics) && $type !== 'bank-transfer') { $errormessage = str_replace('{url}', $bank->getNomUrl(1, '', '', -1, 1), $langs->trans("ErrorICSmissing", '{url}')); setEventMessages($errormessage, null, 'errors'); @@ -127,16 +136,43 @@ if (empty($reshook)) { if (!$error) { // getDolGlobalString('PRELEVEMENT_CODE_BANQUE') and getDolGlobalString('PRELEVEMENT_CODE_GUICHET') should be empty (we don't use them anymore) - $result = $bprev->create(getDolGlobalString('PRELEVEMENT_CODE_BANQUE'), getDolGlobalString('PRELEVEMENT_CODE_GUICHET'), $mode, $format, $executiondate, 0, $type); - + $result = $bprev->create(getDolGlobalString('PRELEVEMENT_CODE_BANQUE'), getDolGlobalString('PRELEVEMENT_CODE_GUICHET'), $mode, $format, $executiondate, 0, $type, 0, 0, $sourcetype); if ($result < 0) { - setEventMessages($bprev->error, $bprev->errors, 'errors'); - } elseif ($result == 0) { - $mesg = $langs->trans("NoInvoiceCouldBeWithdrawed", $format); - setEventMessages($mesg, null, 'errors'); - $mesg .= '
'."\n"; - foreach ($bprev->invoice_in_error as $key => $val) { - $mesg .= ''.$val."
\n"; + $mesg = ''; + + if ($bprev->error || !empty($bprev->errors)) { + setEventMessages($bprev->error, $bprev->errors, 'errors'); + } else { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorsOnXLines", count($bprev->invoice_in_error)), null, 'warnings'); + } + + if (!empty($bprev->invoice_in_error)) { + foreach ($bprev->invoice_in_error as $key => $val) { + $mesg .= ''.$val."
\n"; + } + } + } elseif ($result == 0 || !empty($bprev->invoice_in_error)) { + $mesg = ''; + + if ($result == 0) { + if ($type != 'bank-transfer') { + $mesg = $langs->trans("NoInvoiceCouldBeWithdrawed", $format); + } + if ($type == 'bank-transfer' && $sourcetype != 'salary') { + $mesg = $langs->trans("NoInvoiceCouldBeWithdrawedSupplier", $format); + } + if ($type == 'bank-transfer' && $sourcetype == 'salary') { + $mesg = $langs->trans("NoSalariesCouldBeWithdrawed", $format); + } + setEventMessages($mesg, null, 'errors'); + } + + if (!empty($bprev->invoice_in_error)) { + $mesg .= '
'."\n"; + foreach ($bprev->invoice_in_error as $key => $val) { + $mesg .= ''.$val."
\n"; + } } } else { if ($type != 'bank-transfer') { @@ -154,6 +190,7 @@ if (empty($reshook)) { } } } + $objectclass = "BonPrelevement"; if ($type == 'bank-transfer') { $uploaddir = $conf->paymentbybanktransfer->dir_output; @@ -203,12 +240,23 @@ if ($type == 'bank-transfer') { llxHeader('', $title); -print load_fiche_titre($title); -print dol_get_fiche_head(); +$head = bon_prelevement_prepare_head($bprev, $bprev->nbOfInvoiceToPay($type), $bprev->nbOfInvoiceToPay($type, 'salary')); +if ($type) { + print dol_get_fiche_head($head, (!GETPOSTISSET('sourcetype') ? 'invoice' : 'salary'), $langs->trans("Invoices"), -1, $bprev->picto); +} else { + print load_fiche_titre($title); + print dol_get_fiche_head(); +} -$nb = $bprev->nbOfInvoiceToPay($type); -$pricetowithdraw = $bprev->SommeAPrelever($type); + +if ($sourcetype != 'salary') { + $nb = $bprev->nbOfInvoiceToPay($type); + $pricetowithdraw = $bprev->SommeAPrelever($type); +} else { + $nb = $bprev->nbOfInvoiceToPay($type, 'salary'); + $pricetowithdraw = $bprev->SommeAPrelever($type, 'salary'); +} if ($nb < 0) { dol_print_error($bprev->error); } @@ -218,6 +266,9 @@ $labeltoshow = $langs->trans("NbOfInvoiceToWithdraw"); if ($type == 'bank-transfer') { $labeltoshow = $langs->trans("NbOfInvoiceToPayByBankTransfer"); } +if ($sourcetype == 'salary') { + $labeltoshow = $langs->trans("NbOfInvoiceToPayByBankTransferForSalaries"); +} print '
'; print ''; print '
'; - print $thirdparty->getNomUrl(1); + print (!$salaryBonPl ? $thirdparty->getNomUrl(1) : $userSalary->getNomUrl(-1)); print "'.price($obj->amount)."
'.$labeltoshow.''; @@ -233,15 +284,14 @@ print '
'; print '
'; -if ($mesg) { - print $mesg; -} - print '
'."\n"; -print '
'; +print ''; +print ''; print ''; print ''; +print ''; + if ($nb) { if ($pricetowithdraw) { $title = $langs->trans('BankToReceiveWithdraw').': '; @@ -328,42 +378,65 @@ if ($nb) { print "
\n"; print "
\n"; -print ''; + +// Show errors or warnings +if ($mesg) { + print $mesg; + print '
'; +} + print '
'; /* * Invoices waiting for withdraw */ - -$sql = "SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,"; -if ($type == 'bank-transfer') { - $sql .= " f.ref_supplier,"; -} -$sql .= " pfd.rowid as request_row_id, pfd.date_demande, pfd.amount"; -if ($type == 'bank-transfer') { - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,"; +if ($sourcetype != 'salary') { + $sql = "SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,"; + if ($type == 'bank-transfer') { + $sql .= " f.ref_supplier,"; + } + $sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount"; + if ($type == 'bank-transfer') { + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,"; + } else { + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,"; + } + $sql .= " ".MAIN_DB_PREFIX."societe as s,"; + $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd"; + $sql .= " WHERE s.rowid = f.fk_soc"; + $sql .= " AND f.entity IN (".getEntity('invoice').")"; + if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { + $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; + } + //$sql .= " AND pd.amount > 0"; + $sql .= " AND f.total_ttc > 0"; // Avoid credit notes + $sql .= " AND pd.traite = 0"; + $sql .= " AND pd.ext_payment_id IS NULL"; + if ($type == 'bank-transfer') { + $sql .= " AND pd.fk_facture_fourn = f.rowid"; + } else { + $sql .= " AND pd.fk_facture = f.rowid"; + } + if ($socid > 0) { + $sql .= " AND f.fk_soc = ".((int) $socid); + } } else { - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,"; -} -$sql .= " ".MAIN_DB_PREFIX."societe as s,"; -$sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pfd"; -$sql .= " WHERE s.rowid = f.fk_soc"; -$sql .= " AND f.entity IN (".getEntity('invoice').")"; -if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { - $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; -} -//$sql .= " AND pfd.amount > 0"; -$sql .= " AND f.total_ttc > 0"; // Avoid credit notes -$sql .= " AND pfd.traite = 0"; -$sql .= " AND pfd.ext_payment_id IS NULL"; -if ($type == 'bank-transfer') { - $sql .= " AND pfd.fk_facture_fourn = f.rowid"; -} else { - $sql .= " AND pfd.fk_facture = f.rowid"; -} -if ($socid > 0) { - $sql .= " AND f.fk_soc = ".((int) $socid); + $sql = "SELECT s.ref, s.rowid, s.amount, CONCAT(u.lastname, ' ', u.firstname) as name, u.rowid as uid,"; + $sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."salary as s,"; + $sql .= " ".MAIN_DB_PREFIX."user as u,"; + $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd"; + $sql .= " WHERE s.fk_user = u.rowid"; + $sql .= " AND s.entity IN (".getEntity('salary').")"; + /*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { + $sql .= " AND s.fk_statut = ".Facture::STATUS_VALIDATED; + }*/ + $sql .= " AND s.amount > 0"; + $sql .= " AND pd.traite = 0"; + $sql .= " AND pd.ext_payment_id IS NULL"; + $sql .= " AND s.rowid = pd.fk_salary AND s.paye = ".Salary::STATUS_UNPAID; + $sql .= " AND pd.traite = 0"; } $nbtotalofrecords = ''; @@ -404,16 +477,26 @@ if ($resql) { if ($type != '') { print ''; } - $title = $langs->trans("InvoiceWaitingWithdraw"); - if ($type == 'bank-transfer') { - $title = $langs->trans("InvoiceWaitingPaymentByBankTransfer"); + $picto = 'bill'; + if ($type =='bank-transfer') { + if ($sourcetype != 'salary') { + $title = $langs->trans("InvoiceWaitingPaymentByBankTransfer"); + } else { + $title = $langs->trans("SalaryWaitingWithdraw"); + $picto = 'salary'; + } } - print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, '', '', $massactionbutton, $num, $nbtotalofrecords, 'bill', 0, '', '', $limit); + print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, '', '', $massactionbutton, $num, $nbtotalofrecords, $picto, 0, '', '', $limit); + $tradinvoice = "Invoice"; if ($type == 'bank-transfer') { - $tradinvoice = "SupplierInvoice"; + if ($sourcetype != 'salary') { + $tradinvoice = "SupplierInvoice"; + } else { + $tradinvoice = "RefSalary"; + } } print '
'; @@ -425,14 +508,31 @@ if ($resql) { print ''.$form->showCheckAddButtons('checkforselect', 1).''; } } + // Ref invoice or salary print ''.$langs->trans($tradinvoice).''; - if ($type == 'bank-transfer') { + // Ref supplier + if ($type == 'bank-transfer' && $sourcetype != 'salary') { print ''.$langs->trans("RefSupplier").''; } - print ''.$langs->trans("ThirdParty").''; + // Thirdparty or user + if ($sourcetype != 'salary') { + print ''.$langs->trans("ThirdParty").''; + } else { + print ''.$langs->trans("Employee").''; + } + // BAN print ''.$langs->trans("RIB").''; - print ''.$langs->trans("RUM").''; - print ''.$langs->trans("AmountTTC").''; + // RUM + if (empty($type) || $type == 'direc-debit') { + print ''.$langs->trans("RUM").''; + } + print ''; + if ($sourcetype == 'salary') { + print $langs->trans("Amount"); + } else { + print $langs->trans("AmountTTC"); + } + print ''; print ''.$langs->trans("DateRequest").''; // Action column if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { @@ -443,18 +543,29 @@ if ($resql) { print ''; if ($num) { - require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; + if ($sourcetype != 'salary') { + require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; + } else { + require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php'; + require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; + } while ($i < $num && $i < $limit) { $obj = $db->fetch_object($resql); + if ($sourcetype != 'salary') { + $bac = new CompanyBankAccount($db); // Must include the new in loop so the fetch is clean + $bac->fetch(0, $obj->socid); - $bac = new CompanyBankAccount($db); // Must include the new in loop so the fetch is clean - $bac->fetch(0, $obj->socid); - - $invoicestatic->id = $obj->rowid; - $invoicestatic->ref = $obj->ref; - $invoicestatic->ref_supplier = $obj->ref_supplier; + $invoicestatic->id = $obj->rowid; + $invoicestatic->ref = $obj->ref; + $invoicestatic->ref_supplier = $obj->ref_supplier; + } else { + $bac = new UserBankAccount($db); + $bac->fetch(0, '', $obj->uid); + $salary = new Salary($db); + $salary->fetch($obj->rowid); + } print ''; // Action column @@ -472,28 +583,39 @@ if ($resql) { // Ref invoice print ''; - print $invoicestatic->getNomUrl(1, 'withdraw'); + if ($sourcetype != 'salary') { + print $invoicestatic->getNomUrl(1, 'withdraw'); + } else { + print $salary->getNomUrl(1, 'withdraw'); + } print ''; - if ($type == 'bank-transfer') { + if ($type == 'bank-transfer' && $sourcetype != 'salary') { print ''; print dol_escape_htmltag($invoicestatic->ref_supplier); print ''; } // Thirdparty - print ''; - $thirdpartystatic->fetch($obj->socid); - print $thirdpartystatic->getNomUrl(1, 'ban'); - print ''; + if ($sourcetype != 'salary') { + print ''; + $thirdpartystatic->fetch($obj->socid); + print $thirdpartystatic->getNomUrl(1, 'ban'); + print ''; + } else { + print ''; + $user->fetch($obj->uid); + print $user->getNomUrl(-1); + print ''; + } - // RIB + // BAN print ''; if ($bac->id > 0) { if (!empty($bac->iban) || !empty($bac->bic)) { print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic; if ($bac->verif() <= 0) { - print img_warning('Error on default bank number for IBAN : '.$langs->trans($bac->error_message)); + print img_warning('Error on default bank number for IBAN : '.$langs->trans($bac->error)); } } else { print img_warning($langs->trans("IBANNotDefined")); @@ -504,20 +626,23 @@ if ($resql) { print ''; // RUM - print ''; - $rumtoshow = $thirdpartystatic->display_rib('rum'); - if ($rumtoshow) { - print $rumtoshow; - $format = $thirdpartystatic->display_rib('format'); - if ($type != 'bank-transfer') { - if ($format) { - print ' ('.$format.')'; + if (empty($type) || $type == 'direct-debit') { + print ''; + $rumtoshow = $thirdpartystatic->display_rib('rum'); + if ($rumtoshow) { + print $rumtoshow; + $format = $thirdpartystatic->display_rib('format'); + if ($type != 'bank-transfer') { + if ($format) { + print ' ('.$format.')'; + } } + } else { + print img_warning($langs->trans("NoBankAccountDefined")); } - } else { - print img_warning($langs->trans("NoBankAccountDefined")); + print ''; } - print ''; + // Amount print ''; print price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency); diff --git a/htdocs/compta/prelevement/demandes.php b/htdocs/compta/prelevement/demandes.php index 62eebd65aa3..f6337d27b1d 100644 --- a/htdocs/compta/prelevement/demandes.php +++ b/htdocs/compta/prelevement/demandes.php @@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; // Load translation files required by the page $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies')); @@ -44,6 +45,7 @@ $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') $type = GETPOST('type', 'aZ09'); +$sourcetype = GETPOST('sourcetype', 'aZ'); $search_facture = GETPOST('search_facture', 'alpha'); $search_societe = GETPOST('search_societe', 'alpha'); @@ -127,52 +129,79 @@ if ($type == 'bank-transfer') { } // List of requests - -$sql = "SELECT f.ref, f.rowid, f.total_ttc,"; -$sql .= " s.nom as name, s.rowid as socid,"; -$sql .= " pfd.date_demande as date_demande, pfd.amount, pfd.fk_user_demande"; -if ($type != 'bank-transfer') { - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,"; +if ($sourcetype != 'salary') { + $sql = "SELECT f.ref, f.rowid, f.total_ttc,"; + $sql .= " s.nom as name, s.rowid as socid,"; + $sql .= " pd.date_demande as date_demande, pd.amount, pd.fk_user_demande"; + if ($type != 'bank-transfer') { + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,"; + } else { + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,"; + } + $sql .= " ".MAIN_DB_PREFIX."societe as s,"; + $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd"; + if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + $sql .= " WHERE s.rowid = f.fk_soc"; + $sql .= " AND f.entity IN (".getEntity('invoice').")"; + if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); + } + if ($socid) { + $sql .= " AND f.fk_soc = ".((int) $socid); + } + if (!$status) { + $sql .= " AND pd.traite = 0"; + } + $sql .= " AND pd.ext_payment_id IS NULL"; + if ($status) { + $sql .= " AND pd.traite = ".((int) $status); + } + $sql .= " AND f.total_ttc > 0"; + if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { + $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; + } + if ($type != 'bank-transfer') { + $sql .= " AND pd.fk_facture = f.rowid"; + } else { + $sql .= " AND pd.fk_facture_fourn = f.rowid"; + } + if ($search_facture) { + $sql .= natural_search("f.ref", $search_facture); + } + if ($search_societe) { + $sql .= natural_search("s.nom", $search_societe); + } + $sql .= $db->order($sortfield, $sortorder); } else { - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,"; + $sql = "SELECT s.rowid,s.amount as total_ttc, pd.amount,"; + $sql .= " s.fk_user, pd.date_demande, pd.fk_salary, CONCAT(u.firstname,' ',u.lastname) as nom"; + $sql .= " FROM ".MAIN_DB_PREFIX."salary as s, ".MAIN_DB_PREFIX."user as u,"; + $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd"; + $sql .= " WHERE s.rowid = pd.fk_salary"; + $sql .= " AND u.rowid = s.fk_user"; + $sql .= " AND s.entity IN (".getEntity("salary").")"; + /*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { + $sql .= " AND s.statut = ".Salary::STATUS_UNPAID; + }*/ + if (!$status) { + $sql .= " AND pd.traite = 0"; + } + $sql .= " AND pd.ext_payment_id IS NULL"; + if ($status) { + $sql .= " AND pd.traite = ".((int) $status); + } + $sql .= " AND s.amount > 0"; + $sql .= " AND s.paye = ".Salary::STATUS_UNPAID; + if ($search_facture) { + $sql .= natural_search("s.rowid", $search_facture); + } + if ($search_societe) { + $sql .= natural_search("CONCAT(u.firstname,' ',u.lastname)", $search_societe); + } + //print $sql; } -$sql .= " ".MAIN_DB_PREFIX."societe as s,"; -$sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pfd"; -if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; -} -$sql .= " WHERE s.rowid = f.fk_soc"; -$sql .= " AND f.entity IN (".getEntity('invoice').")"; -if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); -} -if ($socid) { - $sql .= " AND f.fk_soc = ".((int) $socid); -} -if (!$status) { - $sql .= " AND pfd.traite = 0"; -} -$sql .= " AND pfd.ext_payment_id IS NULL"; -if ($status) { - $sql .= " AND pfd.traite = ".((int) $status); -} -$sql .= " AND f.total_ttc > 0"; -if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { - $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; -} -if ($type != 'bank-transfer') { - $sql .= " AND pfd.fk_facture = f.rowid"; -} else { - $sql .= " AND pfd.fk_facture_fourn = f.rowid"; -} -if ($search_facture) { - $sql .= natural_search("f.ref", $search_facture); -} -if ($search_societe) { - $sql .= natural_search("s.nom", $search_societe); -} -$sql .= $db->order($sortfield, $sortorder); - // Count total nb of records $nbtotalofrecords = ''; if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { @@ -204,8 +233,11 @@ $newcardbutton = ''.$langs->trans("Back").''; } - -print '
'; +if ($sourcetype != 'salary') { + print ''; +} else { + print ''; +} if ($optioncss != '') { print ''; } @@ -225,52 +257,86 @@ if ($type == 'bank-transfer') { $label = 'NewPaymentByBankTransfer'; $typefilter = 'type='.$type; } -$newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php'.($typefilter ? '?'.$typefilter : '')); +$newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php'.($typefilter ? '?'.$typefilter : '').($sourcetype ? '&sourcetype='.$sourcetype : '')); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit); +print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''; print ''; -print_liste_field_titre("Bill", $_SERVER["PHP_SELF"]); -print_liste_field_titre("Company", $_SERVER["PHP_SELF"]); -print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'right '); -print_liste_field_titre("DateRequest", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center '); -print_liste_field_titre(''); -print ''; - -print ''; +// Action column +if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; +} print ''; print ''; print ''; print ''; // Action column -print ''; +if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; +} print ''; +print ''; +if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print_liste_field_titre(''); +} +print_liste_field_titre(($sourcetype ? "RefSalary" : "Bill"), $_SERVER["PHP_SELF"]); +print_liste_field_titre(($sourcetype ? "Employee" :"Company"), $_SERVER["PHP_SELF"]); +print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'right '); +print_liste_field_titre("DateRequest", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center '); +if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print_liste_field_titre(''); +} +print ''; + +$userstatic = new User($db); +$salarystatic = new Salary($db); + $i = 0; while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); if (empty($obj)) { break; // Should not happen } - - $invoicestatic->fetch($obj->rowid); - + if ($sourcetype != 'salary') { + $invoicestatic->fetch($obj->rowid); + } else { + $salarystatic->fetch($obj->fk_salary); + $userstatic->fetch($obj->fk_user); + } print ''; + // Action column + if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + } + // Ref facture print ''; print ''; print ''; - print ''; + // Action column + if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + } print ''; $i++; } -print "
'; + $searchpicto = $form->showFilterButtons(); + print $searchpicto; + print ''; -$searchpicto = $form->showFilterButtons(); -print $searchpicto; -print ''; + $searchpicto = $form->showFilterButtons(); + print $searchpicto; + print '
'; - print $invoicestatic->getNomUrl(1, 'withdraw'); + if ($sourcetype != 'salary') { + print $invoicestatic->getNomUrl(1, 'withdraw'); + } else { + print $salarystatic->getNomUrl(1, 'withdraw'); + } print ''; - $thirdpartystatic->id = $obj->socid; - $thirdpartystatic->name = $obj->name; - print $thirdpartystatic->getNomUrl(1, 'customer'); + if ($sourcetype != 'salary') { + $thirdpartystatic->id = $obj->socid; + $thirdpartystatic->name = $obj->name; + print $thirdpartystatic->getNomUrl(1, 'customer'); + } else { + print $userstatic->getNomUrl(-1, 'accountancy'); + } print ''; @@ -281,13 +347,18 @@ while ($i < min($num, $limit)) { print ''.dol_print_date($db->jdate($obj->date_demande), 'day').'

"; +print ""; +print "
"; +print "
"; print '
'; diff --git a/htdocs/compta/prelevement/factures.php b/htdocs/compta/prelevement/factures.php index 3ccc00d2016..192a359a2c6 100644 --- a/htdocs/compta/prelevement/factures.php +++ b/htdocs/compta/prelevement/factures.php @@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.p require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; // Load translation files required by the page $langs->loadLangs(array('banks', 'categories', 'bills', 'companies', 'withdrawals', 'suppliers')); @@ -40,6 +41,7 @@ $langs->loadLangs(array('banks', 'categories', 'bills', 'companies', 'withdrawal $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $socid = GETPOST('socid', 'int'); +$userid = GETPOST('userid', 'int'); $type = GETPOST('type', 'aZ09'); // Load variable for pagination @@ -73,6 +75,7 @@ if ($user->socid > 0) { } $type = $object->type; +$salaryBonPl = $object->checkIfSalaryBonPrelevement(); if ($type == 'bank-transfer') { $result = restrictedArea($user, 'paymentbybanktransfer', '', '', ''); } else { @@ -199,43 +202,60 @@ if ($id > 0 || $ref) { } -// List of invoices -$sql = "SELECT pf.rowid, p.type,"; -$sql .= " f.rowid as facid, f.ref as ref, f.total_ttc,"; -if ($object->type == 'bank-transfer') { - $sql .= " f.ref_supplier,"; -} -$sql .= " s.rowid as socid, s.nom as name, pl.statut, pl.amount as amount_requested"; -$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; -$sql .= ", ".MAIN_DB_PREFIX."prelevement_lignes as pl"; -$sql .= ", ".MAIN_DB_PREFIX."prelevement as pf"; -if ($object->type != 'bank-transfer') { - $sql .= ", ".MAIN_DB_PREFIX."facture as f"; +// List of invoices or salaries +if ($salaryBonPl) { + $sql = "SELECT pf.rowid, p.type,"; + $sql .= " f.rowid as salaryid, f.ref as ref, f.amount,"; + $sql .= " u.rowid as userid, u.firstname, u.lastname, pl.statut as status, pl.amount as amount_requested"; + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."prelevement_lignes as pl ON pl.fk_prelevement_bons = p.rowid"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."prelevement as pf ON pf.fk_prelevement_lignes = pl.rowid"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as f ON f.rowid = pf.fk_salary AND f.entity IN (".getEntity('salary').")"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON f.fk_user = u.rowid"; + $sql .= " WHERE 1 = 1"; + if ($object->id > 0) { + $sql .= " AND p.rowid = ".((int) $object->id); + } + if ($userid > 0) { + $sql .= " AND u.rowid = ".((int) $userid); + } } else { - $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql = "SELECT pf.rowid, p.type,"; + $sql .= " f.rowid as facid, f.ref as ref, f.total_ttc,"; + if ($object->type == 'bank-transfer') { + $sql .= " f.ref_supplier,"; + } + $sql .= " s.rowid as socid, s.nom as name, pl.statut as status, pl.amount as amount_requested"; + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p,"; + $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; + $sql .= " ".MAIN_DB_PREFIX."prelevement as pf"; + if ($object->type != 'bank-transfer') { + $sql .= ", ".MAIN_DB_PREFIX."facture as f"; + } else { + $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f"; + } + $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid"; + $sql .= " AND pl.fk_prelevement_bons = p.rowid"; + $sql .= " AND f.fk_soc = s.rowid"; + if ($object->type != 'bank-transfer') { + $sql .= " AND pf.fk_facture = f.rowid"; + } else { + $sql .= " AND pf.fk_facture_fourn = f.rowid"; + } + if ($object->type != 'bank-transfer') { + $sql .= " AND f.entity IN (".getEntity('invoice').")"; + } else { + $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")"; + } + if ($object->id > 0) { + $sql .= " AND p.rowid = ".((int) $object->id); + } + if ($socid > 0) { + $sql .= " AND s.rowid = ".((int) $socid); + } + $sql .= $db->order($sortfield, $sortorder); } -$sql .= ", ".MAIN_DB_PREFIX."societe as s"; -$sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid"; -$sql .= " AND pl.fk_prelevement_bons = p.rowid"; -$sql .= " AND f.fk_soc = s.rowid"; -if ($object->type != 'bank-transfer') { - $sql .= " AND pf.fk_facture = f.rowid"; -} else { - $sql .= " AND pf.fk_facture_fourn = f.rowid"; -} -if ($object->type != 'bank-transfer') { - $sql .= " AND f.entity IN (".getEntity('invoice').")"; -} else { - $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")"; -} -if ($object->id > 0) { - $sql .= " AND p.rowid = ".((int) $object->id); -} -if ($socid > 0) { - $sql .= " AND s.rowid = ".((int) $socid); -} -$sql .= $db->order($sortfield, $sortorder); - // Count total nb of records $nbtotalofrecords = ''; if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { @@ -248,7 +268,6 @@ if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { } $sql .= $db->plimit($limit + 1, $offset); - $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); @@ -275,18 +294,18 @@ if ($resql) { $massactionbutton = ''; - print_barre_liste($langs->trans("Invoices"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit); + print_barre_liste(($salaryBonPl ? $langs->trans("Salaries") : $langs->trans("Invoices")), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit); print"\n\n"; print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''; print ''; - print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder); - if ($object->type == 'bank-transfer') { + print_liste_field_titre(($salaryBonPl ? "Salary" : "Bill"), $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder); + if ($object->type == 'bank-transfer' && !$salaryBonPl) { print_liste_field_titre("RefSupplierShort", $_SERVER["PHP_SELF"], "f.ref_supplier", '', $param, '', $sortfield, $sortorder); } - print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder); - print_liste_field_titre("AmountInvoice", $_SERVER["PHP_SELF"], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder); + print_liste_field_titre(($salaryBonPl ? "Employee" : "ThirdParty"), $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder); + print_liste_field_titre(($salaryBonPl ? "AmountSalary": "AmountInvoice"), $_SERVER["PHP_SELF"], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "pl.amount", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, 'align="center"', $sortfield, $sortorder); print_liste_field_titre(''); @@ -295,58 +314,66 @@ if ($resql) { $totalinvoices = 0; $totalamount_requested = 0; - $invoicetmpcustomer = new Facture($db); - $invoicetmpsupplier = new FactureFournisseur($db); + if ($salaryBonPl) { + $salarytmp = new Salary($db); + $usertmp = new User($db); + } else { + $invoicetmpcustomer = new Facture($db); + $invoicetmpsupplier = new FactureFournisseur($db); + } while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); - - if ($obj->type == 'bank-transfer') { - $invoicetmp = $invoicetmpsupplier; + if ($salaryBonPl) { + $salarytmp->fetch($obj->salaryid); + $usertmp->fetch($obj->userid); } else { - $invoicetmp = $invoicetmpcustomer; - } - $invoicetmp->fetch($obj->facid); + if ($obj->type == 'bank-transfer') { + $invoicetmp = $invoicetmpsupplier; + } else { + $invoicetmp = $invoicetmpcustomer; + } + $invoicetmp->fetch($obj->facid); - $thirdpartytmp->fetch($obj->socid); + $thirdpartytmp->fetch($obj->socid); + } print ''; + print '\n"; - if ($object->type == 'bank-transfer') { + if ($object->type == 'bank-transfer' && !$salaryBonPl) { print '\n"; } print '\n"; // Amount of invoice - print '\n"; + print '\n"; // Amount requested print '\n"; // Status of requests print '"; print ""; @@ -362,7 +389,7 @@ if ($resql) { if ($num > 0) { print ''; print ''; - if ($object->type == 'bank-transfer') { + if ($object->type == 'bank-transfer' && !$salaryBonPl) { print ''; } print ''; diff --git a/htdocs/compta/prelevement/list.php b/htdocs/compta/prelevement/list.php index b9f300ddfc1..302c4db24df 100644 --- a/htdocs/compta/prelevement/list.php +++ b/htdocs/compta/prelevement/list.php @@ -63,7 +63,7 @@ if (!$sortorder) { $sortorder = "DESC"; } if (!$sortfield) { - $sortfield = "p.datec"; + $sortfield = ($type == 'bank-transfer' ? "datec" : "p.datec"); } $search_line = GETPOST('search_line', 'alpha'); @@ -75,6 +75,7 @@ $statut = GETPOST('statut', 'int'); $bon = new BonPrelevement($db); $line = new LignePrelevement($db); $company = new Societe($db); +$userstatic = new User($db); $hookmanager->initHooks(array('withdrawalsreceiptslineslist')); @@ -115,7 +116,7 @@ if ($type == 'bank-transfer') { } $help_url = ''; -$sql = "SELECT p.rowid, p.ref, p.statut as status, p.datec"; +$sql = "SELECT p.rowid, p.ref, p.statut as status, p.datec"; $sql .= " , f.rowid as facid, f.ref as invoiceref, f.total_ttc"; $sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.email"; $sql .= " , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne"; @@ -143,11 +144,11 @@ $sql .= " AND f.entity IN (".getEntity('invoice').")"; if ($socid) { $sql .= " AND s.rowid = ".((int) $socid); } -if ($search_line) { - $sql .= " AND pl.rowid = '".$db->escape($search_line)."'"; -} if ($search_bon) { - $sql .= natural_search("p.ref", $search_bon); + $sql .= " AND pl.rowid = '".$db->escape($search_bon)."'"; +} +if ($search_line) { + $sql .= natural_search("p.ref", $search_line); } if ($type == 'bank-transfer') { if ($search_code) { @@ -161,13 +162,59 @@ if ($type == 'bank-transfer') { if ($search_company) { $sql .= natural_search("s.nom", $search_company); } +//get salary invoices +if ($type == 'bank-transfer') { + $sql .= " UNION"; + $sql .= " SELECT p.rowid, p.ref, p.statut as status, p.datec"; + $sql .= ", sl.rowid as facid, sl.ref as invoiceref, sl.amount"; + $sql .= ", u.rowid as socid, CONCAT(u.firstname, ' ', u.lastname) as name, u.ref_employee as code_client, NULL as code_fournisseur, u.email"; + $sql .= ", pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne"; + + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; + $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl"; + $sql .= " , ".MAIN_DB_PREFIX."prelevement as pf"; + $sql .= " , ".MAIN_DB_PREFIX."salary as sl"; + $sql .= " , ".MAIN_DB_PREFIX."user as u"; + + $sql .= " WHERE pl.fk_prelevement_bons = p.rowid"; + $sql .= " AND pf.fk_prelevement_lignes = pl.rowid"; + $sql .= " AND pf.fk_salary = sl.rowid"; + $sql .= " AND sl.fk_user = u.rowid"; + $sql .= " AND sl.entity IN (".getEntity('invoice').")"; + if ($socid) { + $sql .= " AND s.rowid = ".((int) $socid); + } + if ($search_bon) { + $sql .= " AND pl.rowid = '".$db->escape($search_bon)."'"; + } + if ($search_line) { + $sql .= natural_search("p.ref", $search_line); + } + if ($type == 'bank-transfer') { + if ($search_code) { + $sql .= natural_search("NULL", $search_code); + } + } else { + if ($search_code) { + $sql .= natural_search("s.code_client", $search_code); + } + } + if ($search_company) { + $sql .= natural_search(array("u.firstname","u.lastname"), $search_company); + } +} // Count total nb of records $nbtotalofrecords = ''; if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); - $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); + if ($type == 'bank-transfer') { + $sqlforcount = "SELECT COUNT(*) as nbtotalofrecords FROM (" . $sql . ") AS combined_results"; + } else { + $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); + $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); + } + $resql = $db->query($sqlforcount); if ($resql) { $objforcount = $db->fetch_object($resql); @@ -332,9 +379,9 @@ print_liste_field_titre($columntitle, $_SERVER["PHP_SELF"], "p.ref", '', $param, $totalarray['nbfield']++; print_liste_field_titre("Line", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder); $totalarray['nbfield']++; -print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "f.ref", '', $param, '', $sortfield, $sortorder); +print_liste_field_titre(($type == 'bank-transfer' ? "BillsAndSalaries" : "Bills"), $_SERVER["PHP_SELF"], "f.ref", '', $param, '', $sortfield, $sortorder); $totalarray['nbfield']++; -print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder); +print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder); $totalarray['nbfield']++; print_liste_field_titre($columntitlethirdparty, $_SERVER["PHP_SELF"], $columncodethirdparty, '', $param, '', $sortfield, $sortorder, 'center '); $totalarray['nbfield']++; @@ -367,7 +414,14 @@ while ($i < $imaxinloop) { $bon->total = $obj->amount; $object = $bon; + if ($object->checkIfSalaryBonPrelevement()) { + $userstatic->id = $obj->socid; + $userstatic->email = $obj->email; + $fullname = explode(' ', $obj->name); + $userstatic->firstname = $fullname[0]; + $userstatic->lastname = isset($fullname[1]) ? $fullname[1] : ''; + } $company->id = $obj->socid; $company->name = $obj->name; $company->email = $obj->email; @@ -427,18 +481,29 @@ while ($i < $imaxinloop) { $link_title = 'Invoice'; $link_picto = 'bill'; if ($type == 'bank-transfer') { - $link_to_bill = '/fourn/facture/card.php?facid='; - $link_title = 'SupplierInvoice'; - $link_picto = 'supplier_invoice'; + if ($bon->checkIfSalaryBonPrelevement()) { + $link_to_bill = '/salaries/card.php?id='; + $link_title = 'SalaryInvoice'; + $link_picto = 'salary'; + } else { + $link_to_bill = '/fourn/facture/card.php?facid='; + $link_title = 'SupplierInvoice'; + $link_picto = 'supplier_invoice'; + } } print ''; print img_object($langs->trans($link_title), $link_picto); - print ' '.$obj->invoiceref."\n"; + if (!$bon->checkIfSalaryBonPrelevement()) { + print ' '.$obj->invoiceref."\n"; + } else { + print ' '.(!empty($obj->invoiceref) ? $obj->invoiceref : $obj->facid)."\n"; + } print ''; print ''; print '\n"; diff --git a/htdocs/compta/prelevement/rejets.php b/htdocs/compta/prelevement/rejets.php index 4b30df4ffef..baed8076f6b 100644 --- a/htdocs/compta/prelevement/rejets.php +++ b/htdocs/compta/prelevement/rejets.php @@ -30,6 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; // Load translation files required by the page $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies')); @@ -88,8 +89,8 @@ $hookmanager->initHooks(array('withdrawalsreceiptsrejectedlist')); // List of invoices -$sql = "SELECT pl.rowid, pr.motif, p.ref, pl.statut"; -$sql .= " , s.rowid as socid, s.nom"; +$sql = "SELECT pl.rowid, pr.motif, p.ref, pl.statut, p.rowid as bonId"; +$sql .= " , s.rowid as socid, s.nom as name, p.datec"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; $sql .= " , ".MAIN_DB_PREFIX."prelevement_rejet as pr"; $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl"; @@ -106,9 +107,28 @@ if ($type == 'bank-transfer') { if ($socid) { $sql .= " AND s.rowid = ".((int) $socid); } +if ($type == 'bank-transfer') { + $sql .= " UNION"; + $sql .= " SELECT pl.rowid, pr.motif, p.ref, pl.statut, p.rowid as bonId"; + $sql .= " ,u.rowid as socid, CONCAT(u.firstname,' ', u.lastname) as name, p.datec"; + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; + $sql .= " , ".MAIN_DB_PREFIX."prelevement_rejet as pr"; + $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl"; + $sql .= " , ".MAIN_DB_PREFIX."user as u"; + $sql .= " WHERE pr.fk_prelevement_lignes = pl.rowid"; + $sql .= " AND pl.fk_prelevement_bons = p.rowid"; + $sql .= " AND pl.fk_user = u.rowid"; + $sql .= " AND p.entity = ".$conf->entity; + $sql .= " AND p.type = 'bank-transfer'"; + if ($socid) { + $sql .= " AND s.rowid = ".((int) $socid); + } +} +if ($type == 'bank-transfer') { + $sortfield = 'datec'; +} $sql .= $db->order($sortfield, $sortorder); $sql .= $db->plimit($limit + 1, $offset); - $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -125,9 +145,11 @@ if ($result) { print_liste_field_titre("Reason", $_SERVER["PHP_SELF"], "pr.motif", "", $param); print "\n"; + $bon = new BonPrelevement($db); if ($num) { while ($i < min($num, $limit)) { $obj = $db->fetch_object($result); + $bon->fetch($obj->bonId); print ''; @@ -135,8 +157,11 @@ if ($result) { print $line->LibStatut($obj->statut, 2).' '; print ''; print substr('000000'.$obj->rowid, -6).""; - - print '\n"; + if ($bon->checkIfSalaryBonPrelevement()) { + print '\n"; + } else { + print '\n"; + } print ''; diff --git a/htdocs/compta/prelevement/stats.php b/htdocs/compta/prelevement/stats.php index a3439266ce8..1ebee939615 100644 --- a/htdocs/compta/prelevement/stats.php +++ b/htdocs/compta/prelevement/stats.php @@ -125,12 +125,12 @@ if ($resql) { //print $st[$row[2]]; print ''; - print ''; print ''; print ''; print ''; print ''; @@ -229,17 +229,19 @@ if ($resql) { print ''; - print ''; - print ''; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 0a969dd3e79..584ece47079 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -74,11 +74,11 @@ $year = GETPOST('year', 'int'); // this is used for navigation previous/next. I if (empty($year)) { $year_current = dol_print_date(dol_now(), "%Y"); $month_current = dol_print_date(dol_now(), "%m"); - $year_start = $year_current - ($nbofyear - 1); + $year_start = $year_current; } else { $year_current = $year; $month_current = dol_print_date(dol_now(), "%m"); - $year_start = $year - $nbofyear + (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1); + $year_start = $year; } $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); @@ -88,14 +88,17 @@ if (empty($date_start) || empty($date_end)) { // We define date_start and date_e $q = GETPOST("q") ? GETPOST("q", 'int') : 0; if ($q == 0) { // We define date_start and date_end - $year_end = $year_start + $nbofyear - (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1); + $year_end = $year_start; $month_start = GETPOST("month") ? GETPOST("month", 'int') : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); if (!GETPOST('month')) { if (!$year && $month_start > $month_current) { $year_start--; $year_end--; } - $month_end = $month_start - 1; + if (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1) { + $month_end = $month_start - 1; + $year_end = $year_start + 1; + } if ($month_end < 1) { $month_end = 12; } diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index 0bc3ec45779..d9199baa03c 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -334,7 +334,7 @@ if (isModEnabled('project')) { $now = dol_now(); $title = $langs->trans("SocialContribution").' - '.$langs->trans("Card"); -$help_url = 'EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)'; +$help_url = 'EN:Module_Taxes_and_social_contributions|FR:Module_Taxes_et_charges_spéciales|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)'; llxHeader("", $title, $help_url); diff --git a/htdocs/compta/sociales/class/cchargesociales.class.php b/htdocs/compta/sociales/class/cchargesociales.class.php index 371c3ffeb68..0825f223f19 100644 --- a/htdocs/compta/sociales/class/cchargesociales.class.php +++ b/htdocs/compta/sociales/class/cchargesociales.class.php @@ -366,7 +366,7 @@ class Cchargesociales * @param int $fromid Id of object to clone * @return int New id of clone */ - public function createFromClone(User $user, $fromid) + /*public function createFromClone(User $user, $fromid) { dol_syslog(__METHOD__, LOG_DEBUG); @@ -406,7 +406,7 @@ class Cchargesociales return -1; } - } + }*/ /** * Return a link to the user card (with optionaly the picto) @@ -419,7 +419,7 @@ class Cchargesociales * @param string $morecss Add more css on link * @return string String with URL */ - public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '') + /*public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '') { global $langs, $conf, $db; global $dolibarr_main_authentication, $dolibarr_main_demo; @@ -446,7 +446,7 @@ class Cchargesociales } $result .= $link.$this->ref.$linkend; return $result; - } + }*/ /** * Return the label of the status @@ -454,10 +454,10 @@ class Cchargesociales * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto * @return string Label of status */ - public function getLibStatut($mode = 0) + /*public function getLibStatut($mode = 0) { return $this->LibStatut($this->status, $mode); - } + }*/ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index fb43c8a526a..ac32bbebecc 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -741,9 +741,9 @@ class ChargeSociales extends CommonObject $this->ref = 'SPECIMEN'; $this->specimen = 1; $this->paye = 0; - $this->date = dol_now(); - $this->date_ech = $this->date + 3600 * 24 * 30; - $this->periode = $this->date + 3600 * 24 * 30; + $this->date_creation = dol_now(); + $this->date_ech = $this->date_creation + 3600 * 24 * 30; + $this->periode = $this->date_creation + 3600 * 24 * 30; $this->amount = 100; $this->label = 'Social contribution label'; $this->type = 1; diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php index a798eee92bb..1020b4cec00 100644 --- a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -61,6 +61,26 @@ class PaymentSocialContribution extends CommonObject public $tms = ''; public $datep = ''; + /** + * @var string + */ + public $type_code; + + /** + * @var string + */ + public $type_label; + + /** + * @var int + */ + public $bank_account; + + /** + * @var int + */ + public $bank_line; + /** * @deprecated * @see $amount diff --git a/htdocs/compta/sociales/list.php b/htdocs/compta/sociales/list.php index 5594f92862e..dec468835fe 100644 --- a/htdocs/compta/sociales/list.php +++ b/htdocs/compta/sociales/list.php @@ -457,7 +457,7 @@ if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) { // Filter: Ref if (!empty($arrayfields['cs.rowid']['checked'])) { print ''; } @@ -634,7 +634,7 @@ $i = 0; $savnbfield = $totalarray['nbfield']; $totalarray = array(); $totalarray['nbfield'] = 0; -$totalarray['val'] = array(); +$totalarray['val'] = array('totalttcfield'=>0); $imaxinloop = ($limit ? min($num, $limit) : $num); while ($i < $imaxinloop) { $obj = $db->fetch_object($resql); @@ -800,7 +800,9 @@ while ($i < $imaxinloop) { print $bankstatic->getNomUrl(1); } print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Amount @@ -808,8 +810,6 @@ while ($i < $imaxinloop) { print ''; if (!$i) { $totalarray['nbfield']++; - } - if (!$i) { $totalarray['pos'][$totalarray['nbfield']] = 'totalttcfield'; } $totalarray['val']['totalttcfield'] += $obj->amount; diff --git a/htdocs/compta/tva/class/paymentvat.class.php b/htdocs/compta/tva/class/paymentvat.class.php index c7e59c640b5..a03d031e8c7 100644 --- a/htdocs/compta/tva/class/paymentvat.class.php +++ b/htdocs/compta/tva/class/paymentvat.class.php @@ -113,6 +113,26 @@ class PaymentVAT extends CommonObject */ public $datepaye; + /** + * @var string + */ + public $type_code; + + /** + * @var string + */ + public $type_label; + + /** + * @var int + */ + public $bank_account; + + /** + * @var int + */ + public $bank_line; + /** * @var integer|string paiementtype */ diff --git a/htdocs/compta/tva/class/tva.class.php b/htdocs/compta/tva/class/tva.class.php index c888f438f54..3ff2b6178e7 100644 --- a/htdocs/compta/tva/class/tva.class.php +++ b/htdocs/compta/tva/class/tva.class.php @@ -62,6 +62,26 @@ class Tva extends CommonObject public $type_payment; public $num_payment; + /** + * @var DateTime + */ + public $datec; + + /** + * @var int ID + */ + public $fk_type; + + /** + * @var int + */ + public $paye; + + /** + * @var int + */ + public $rappro; + /** * @var integer|string totalpaid */ diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 4907c57774a..21419bd3843 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -777,7 +777,7 @@ if (empty($reshook)) { $objectline->date_start_real = $date_start_real_update; $objectline->date_end = $date_end_update; $objectline->date_end_real = $date_end_real_update; - $objectline->fk_user_cloture = $user->id; + $objectline->user_closing_id = $user->id; //$objectline->fk_fournprice = $fk_fournprice; $objectline->pa_ht = $pa_ht; $objectline->rang = $objectline->rang; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index bb01930b9e0..2247bc0fec8 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -455,7 +455,7 @@ class Contrat extends CommonObject if ($contratline->statut != ContratLigne::STATUS_CLOSED) { $contratline->date_end_real = $now; $contratline->date_cloture = $now; // For backward compatibility - $contratline->fk_user_cloture = $user->id; + $contratline->user_closing_id = $user->id; $contratline->statut = ContratLigne::STATUS_CLOSED; $result = $contratline->close_line($user, $now, $comment, $notrigger); if ($result < 0) { @@ -556,6 +556,12 @@ class Contrat extends CommonObject if (!$resql) { $error++; $this->error = $this->db->lasterror(); } + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'contract/".$this->db->escape($this->newref)."'"; + $sql .= " WHERE filepath = 'contract/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (!$resql) { + $error++; $this->error = $this->db->lasterror(); + } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); @@ -660,15 +666,17 @@ class Contrat extends CommonObject } /** - * Load a contract from database + * Load a contract from database * - * @param int $id Id of contract to load - * @param string $ref Ref - * @param string $ref_customer Customer ref - * @param string $ref_supplier Supplier ref - * @return int <0 if KO, 0 if not found or if two records found for same ref, Id of contract if OK + * @param int $id Id of contract to load + * @param string $ref Ref + * @param string $ref_customer Customer ref + * @param string $ref_supplier Supplier ref + * @param int $noextrafields 0=Default to load extrafields, 1=No extrafields + * @param int $nolines 0=Default to load lines, 1=No lines + * @return int <0 if KO, 0 if not found or if two records found for same ref, Id of contract if OK */ - public function fetch($id, $ref = '', $ref_customer = '', $ref_supplier = '') + public function fetch($id, $ref = '', $ref_customer = '', $ref_supplier = '', $noextrafields = 0, $nolines = 0) { $sql = "SELECT rowid, statut as status, ref, fk_soc as thirdpartyid,"; $sql .= " ref_supplier, ref_customer,"; @@ -740,16 +748,23 @@ class Contrat extends CommonObject // Retrieve all extrafields // fetch optionals attributes and labels - $result = $this->fetch_optionals(); - - // Lines - if ($result >= 0 && !empty($this->table_element_line)) { - $result = $this->fetch_lines(); + if (empty($noextrafields)) { + $result = $this->fetch_optionals(); + if ($result < 0) { + $this->error = $this->db->lasterror(); + return -4; + } } - if ($result < 0) { - $this->error = $this->db->lasterror(); - return -3; + // Lines + if (empty($nolines)) { + if ($result >= 0 && !empty($this->table_element_line)) { + $result = $this->fetch_lines(); + if ($result < 0) { + $this->error = $this->db->lasterror(); + return -3; + } + } } return $this->id; @@ -775,11 +790,12 @@ class Contrat extends CommonObject * Load lines array into this->lines. * This set also nbofserviceswait, nbofservicesopened, nbofservicesexpired and nbofservicesclosed * - * @param int $only_services 0=Default, 1=Force only services (depending on setup, we may also have physical products in a contract) - * @param int $loadalsotranslation 0=Default, 1=Load also translations of product descriptions - * @return array|int Return array of contract lines + * @param int $only_services 0=Default for all, 1=Force only services (depending on setup, we may also have physical products in a contract) + * @param int $loadalsotranslation 0=Default to not load translations, 1=Load also translations of product descriptions + * @param int $noextrafields 0=Default to load extrafields, 1=Do not load the extrafields of lines + * @return array|int Return array of contract lines */ - public function fetch_lines($only_services = 0, $loadalsotranslation = 0) + public function fetch_lines($only_services = 0, $loadalsotranslation = 0, $noextrafields = 0) { // phpcs:enable $this->nbofservices = 0; @@ -895,7 +911,9 @@ class Contrat extends CommonObject // Retrieve all extrafields for contract line // fetch optionals attributes and labels - $line->fetch_optionals(); + if (empty($noextrafields)) { + $line->fetch_optionals(); + } // multilangs if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($objp->fk_product) && !empty($loadalsotranslation)) { @@ -2752,7 +2770,7 @@ class Contrat extends CommonObject // Load contract $object = new Contrat($this->db); $object->fetch($obj->rowid); // fetch also lines - $object->fetch_thirdparty(); + //$object->fetch_thirdparty(); if ($object->id <= 0) { $error++; @@ -2768,13 +2786,16 @@ class Contrat extends CommonObject $duration_unit = preg_replace('/\d/', '', $obj->duration); //var_dump($expirationdate.' '.$enddatetoscan); - // Test if there is pending invoice + // Load linked ->linkedObjects (objects linked) + // @TODO Comment this line and then make the search if there is n open invoice(s) by doing a dedicated SQL COUNT request to fill $contractcanceled. $object->fetchObjectLinked(null, '', null, '', 'OR', 1, 'sourcetype', 1); - if (is_array($object->linkedObjects['facture']) && count($object->linkedObjects['facture']) > 0) { - usort($object->linkedObjects['facture'], "cmp"); + // Test if there is at least 1 open invoice + if (isset($object->linkedObjects['facture']) && is_array($object->linkedObjects['facture']) && count($object->linkedObjects['facture']) > 0) { + // Sort array of linked invoices by ascending date + usort($object->linkedObjects['facture'], array('Contrat', 'contractCmpDate')); + //dol_sort_array($object->linkedObjects['facture'], 'date'); - //dol_sort_array($contract->linkedObjects['facture'], 'date'); $someinvoicenotpaid=0; foreach ($object->linkedObjects['facture'] as $idinvoice => $invoice) { if ($invoice->statut == Facture::STATUS_DRAFT) continue; // Draft invoice are not invoice not paid @@ -2785,7 +2806,7 @@ class Contrat extends CommonObject } if ($someinvoicenotpaid) { $this->output .= 'Contract '.$object->ref.' is qualified for renewal but there is '.$someinvoicenotpaid.' invoice(s) unpayed so we cancel renewal'."\n"; - $contractignored[$object->id]=$object->ref; + $contractignored[$object->id] = $object->ref; continue; } } @@ -2827,7 +2848,7 @@ class Contrat extends CommonObject $actioncomm->datep = $now; $actioncomm->datef = $now; $actioncomm->percentage = -1; // Not applicable - $actioncomm->socid = $object->thirdparty->id; + $actioncomm->socid = $object->socid; $actioncomm->authorid = $user->id; // User saving action $actioncomm->userownerid = $user->id; // Owner of action $actioncomm->fk_element = $object->id; @@ -2867,6 +2888,21 @@ class Contrat extends CommonObject return ($error ? 1: 0); } + /** + * Used to sort lines by date + * + * @param Object $a 1st element to test + * @param Object $b 2nd element to test + * @return int + */ + static public function contractCmpDate($a, $b) + { + if ($a->date == $b->date) { + return strcmp((string) $a->id, (string) $b->id); + } + return ($a->date < $b->date) ? -1 : 1; + } + /** * Return clicable link of object (with eventually picto) * @@ -3772,7 +3808,7 @@ class ContratLigne extends CommonObjectLine // Update object $this->date_cloture = $date_end_real; $this->date_end_real = $date_end_real; - $this->fk_user_cloture = $user->id; + $this->user_closing_id = $user->id; $this->commentaire = $comment; $error = 0; diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 07136bd760a..b6a02aac7f1 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -382,17 +382,27 @@ if ($action == 'confirm_delete' && !empty($permissiontodelete)) { exit; } + $db->begin(); + $result = $object->delete($user); if ($result > 0) { + $db->commit(); + // Delete OK setEventMessages("RecordDeleted", null, 'mesgs'); if (empty($noback)) { + if (empty($backurlforlist)) { + print 'Error backurlforlist is not defined'; + exit; + } header("Location: " . $backurlforlist); exit; } } else { + $db->rollback(); + $error++; if (!empty($object->errors)) { setEventMessages(null, $object->errors, 'errors'); diff --git a/htdocs/core/actions_extrafields.inc.php b/htdocs/core/actions_extrafields.inc.php index c694b382164..c2e63167f62 100644 --- a/htdocs/core/actions_extrafields.inc.php +++ b/htdocs/core/actions_extrafields.inc.php @@ -33,6 +33,7 @@ $param = GETPOST('param', 'alphanohtml'); $css = GETPOST('css', 'alphanohtml'); $cssview = GETPOST('cssview', 'alphanohtml'); $csslist = GETPOST('csslist', 'alphanohtml'); +$confirm = GETPOST('confirm', 'alpha'); if ($type == 'double' && strpos($extrasize, ',') === false) { $extrasize = '24,8'; @@ -47,6 +48,18 @@ if ($type == 'select') { $extrasize = ''; } +$listofreservedwords = array( + 'ADD', 'ALL', 'ALTER', 'ANALYZE', 'AND', 'AS', 'ASENSITIVE', 'BEFORE', 'BETWEEN', 'BINARY', 'BLOB', 'BOTH', 'CALL', 'CASCADE', 'CASE', 'CHANGE', 'CHAR', 'CHARACTER', 'CHECK', 'COLLATE', 'COLUMN', 'CONDITION', 'CONSTRAINT', 'CONTINUE', 'CONVERT', 'CREATE', 'CROSS', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', + 'CURSOR', 'DATABASE', 'DATABASES', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DECIMAL', 'DECLARE', 'DEFAULT', 'DELAYED', 'DELETE', 'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCT', 'DISTINCTROW', 'DOUBLE', 'DROP', 'DUAL', + 'EACH', 'ELSE', 'ELSEIF', 'ENCLOSED', 'ESCAPED', 'EXISTS', 'EXPLAIN', 'FALSE', 'FETCH', 'FLOAT', 'FLOAT4', 'FLOAT8', 'FORCE', 'FOREIGN', 'FULLTEXT', 'GRANT', 'GROUP', 'HAVING', 'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', + 'IGNORE', 'IGNORE_SERVER_IDS', 'INDEX', 'INFILE', 'INNER', 'INOUT', 'INSENSITIVE', 'INSERT', 'INT', 'INTEGER', 'INTERVAL', 'INTO', 'ITERATE', + 'KEYS', 'KEYWORD', 'LEADING', 'LEAVE', 'LEFT', 'LIKE', 'LIMIT', 'LINES', 'LOCALTIME', 'LOCALTIMESTAMP', 'LONGBLOB', 'LONGTEXT', 'MASTER_SSL_VERIFY_SERVER_CERT', 'MATCH', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MODIFIES', 'NATURAL', 'NOT', 'NO_WRITE_TO_BINLOG', 'NUMERIC', + 'ON', 'OPTION', 'OPTIONALLY', 'OUTER', 'OUTFILE', + 'PARTITION', 'POSITION', 'PRECISION', 'PRIMARY', 'PROCEDURE', 'PURGE', 'RANGE', 'READS', 'READ_WRITE', 'REAL', 'REFERENCES', 'REGEXP', 'RELEASE', 'RENAME', 'REPEAT', 'REQUIRE', 'RESTRICT', 'RETURN', 'REVOKE', 'RIGHT', 'RLIKE', + 'SCHEMAS', 'SECOND_MICROSECOND', 'SENSITIVE', 'SEPARATOR', 'SIGNAL', 'SMALLINT', 'SPATIAL', 'SPECIFIC', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SSL', 'STARTING', 'STRAIGHT_JOIN', + 'TABLE', 'TERMINATED', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TRAILING', 'TRIGGER', 'UNDO', 'UNIQUE', 'UNSIGNED', 'UPDATE', 'USAGE', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARYING', + 'WHEN', 'WHERE', 'WHILE', 'WRITE', 'XOR', 'YEAR_MONTH', 'ZEROFILL' +); // Add attribute if ($action == 'add') { @@ -140,7 +153,7 @@ if ($action == 'add') { // Check reserved keyword with more than 3 characters if (!$error) { - if (in_array(GETPOST('attrname', 'aZ09'), array('and', 'keyword', 'table', 'index', 'int', 'integer', 'float', 'double', 'real', 'position'))) { + if (in_array(strtoupper(GETPOST('attrname', 'aZ09')), $listofreservedwords)) { $error++; $langs->load("errors"); $mesg[] = $langs->trans("ErrorReservedKeyword", GETPOST('attrname', 'aZ09')); @@ -314,7 +327,7 @@ if ($action == 'update') { // Check reserved keyword with more than 3 characters if (!$error) { - if (in_array(GETPOST('attrname', 'aZ09'), array('and', 'keyword', 'table', 'index', 'integer', 'float', 'double', 'position')) && empty($conf->global->MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE)) { + if (in_array(strtoupper(GETPOST('attrname', 'aZ09')), $listofreservedwords) && empty($conf->global->MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE)) { $error++; $langs->load("errors"); $mesg[] = $langs->trans("ErrorReservedKeyword", GETPOST('attrname', 'aZ09')); @@ -399,7 +412,7 @@ if ($action == 'update') { } // Delete attribute -if ($action == 'delete') { +if ($action == 'confirm_delete' && $confirm == "yes") { if (GETPOSTISSET("attrname") && preg_match("/^\w[a-zA-Z0-9-_]*$/", GETPOST("attrname", 'aZ09'))) { $attributekey = GETPOST('attrname', 'aZ09'); diff --git a/htdocs/core/boxes/box_external_rss.php b/htdocs/core/boxes/box_external_rss.php index 8bc4943e50b..e442a4fb1db 100644 --- a/htdocs/core/boxes/box_external_rss.php +++ b/htdocs/core/boxes/box_external_rss.php @@ -200,7 +200,7 @@ class box_external_rss extends ModeleBoxes ); $this->info_box_contents[$line][2] = array( - 'td' => 'class="right nowrap"', + 'td' => 'class="right nowraponall"', 'text' => dol_escape_htmltag($date), ); } diff --git a/htdocs/core/boxes/box_members_by_tags.php b/htdocs/core/boxes/box_members_by_tags.php index 06499776ef2..dfec0bce8f6 100644 --- a/htdocs/core/boxes/box_members_by_tags.php +++ b/htdocs/core/boxes/box_members_by_tags.php @@ -219,7 +219,7 @@ class box_members_by_tags extends ModeleBoxes ); $this->info_box_contents[$line][] = array( 'td' => 'class="liste_total right"', - 'text' => $sumMembers['total']['members_pending'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now, 3), + 'text' => $sumMembers['total']['members_pending'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 0, 3), 'asis' => 1 ); $this->info_box_contents[$line][] = array( diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index cb40fc98beb..72030908578 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -170,7 +170,7 @@ class box_members_by_type extends ModeleBoxes ); $this->info_box_contents[$line][] = array( 'td' => 'class="right"', - 'text' => (isset($data['members_pending']) && $data['members_pending'] > 0 ? $data['members_pending'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now, 3), + 'text' => (isset($data['members_pending']) && $data['members_pending'] > 0 ? $data['members_pending'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 0, 3), 'asis' => 1, ); $this->info_box_contents[$line][] = array( @@ -219,7 +219,7 @@ class box_members_by_type extends ModeleBoxes ); $this->info_box_contents[$line][] = array( 'td' => 'class="liste_total right"', - 'text' => $sumMembers['total']['members_pending'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now, 3), + 'text' => $sumMembers['total']['members_pending'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 0, 3), 'asis' => 1 ); $this->info_box_contents[$line][] = array( diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 5e2a3b71210..fbd4db0883b 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -66,6 +66,16 @@ abstract class CommonInvoice extends CommonObject public $mode_reglement_id; public $mode_reglement_code; // Code in llx_c_paiement + /** + * @var string + */ + public $mode_reglement; + + /** + * @var double + */ + public $revenuestamp; + public $totalpaid; // duplicate with sumpayed public $totaldeposits; // duplicate with sumdeposit public $totalcreditnotes; // duplicate with sumcreditnote @@ -90,6 +100,34 @@ abstract class CommonInvoice extends CommonObject public $multicurrency_total_tva; public $multicurrency_total_ttc; + /** + * @var int + */ + public $stripechargedone; + + /** + * @var int + */ + public $stripechargeerror; + + /** + * Payment description + * @var string + */ + public $description; + + /** + * @var string + * @deprecated + * @see $ref_customer + */ + public $ref_client; + + /** + * @var int Situation cycle reference number + */ + public $situation_cycle_ref; + /** * ! Closing after partial payment: discount_vat, badsupplier, abandon * ! Closing when no payment: replaced, abandoned @@ -192,6 +230,7 @@ abstract class CommonInvoice extends CommonObject * * @param int $multicurrency Return multicurrency_amount instead of amount. -1=Return both. * @return float|int|array Amount of payment already done, <0 and set ->error if KO + * @see getSumDepositsUsed(), getSumCreditNotesUsed() */ public function getSommePaiement($multicurrency = 0) { @@ -236,12 +275,13 @@ abstract class CommonInvoice extends CommonObject } /** - * Return amount (with tax) of all deposits invoices used by invoice. - * Should always be empty, except if option FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is on for sale invoices (not recommended), - * of FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS is on for purchase invoices (not recommended). + * Return amount (with tax) of all deposits invoices used by invoice. + * Should always be empty, except if option FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is on for sale invoices (not recommended), + * of FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS is on for purchase invoices (not recommended). * - * @param int $multicurrency Return multicurrency_amount instead of amount - * @return float <0 and set ->error if KO, Sum of deposits amount otherwise + * @param int $multicurrency Return multicurrency_amount instead of amount + * @return float <0 and set ->error if KO, Sum of deposits amount otherwise + * @see getSommePaiement(), getSumCreditNotesUsed() */ public function getSumDepositsUsed($multicurrency = 0) { @@ -270,10 +310,11 @@ abstract class CommonInvoice extends CommonObject } /** - * Return amount (with tax) of all credit notes invoices + excess received used by invoice + * Return amount (with tax) of all credit notes invoices + excess received used by invoice * - * @param int $multicurrency Return multicurrency_amount instead of amount - * @return float <0 and set ->error if KO, Sum of credit notes and deposits amount otherwise + * @param int $multicurrency Return multicurrency_amount instead of amount + * @return float <0 and set ->error if KO, Sum of credit notes and deposits amount otherwise + * @see getSommePaiement(), getSumDepositsUsed() */ public function getSumCreditNotesUsed($multicurrency = 0) { @@ -642,7 +683,7 @@ abstract class CommonInvoice extends CommonObject * Return label of invoice subtype * * @param string $table table of invoice - * @return string Label of invoice subtype + * @return string|int Label of invoice subtype or -1 if error */ public function getSubtypeLabel($table = '') { @@ -661,13 +702,36 @@ abstract class CommonInvoice extends CommonObject } if (!empty($subtypeLabel)) { - print ' ' . $subtypeLabel; + return $subtypeLabel; + } + } else { + dol_print_error($this->db); + return -1; + } + } elseif ($table === 'facture_rec' || $table === 'facture_fourn_rec') { + $sql = "SELECT s.label FROM " . MAIN_DB_PREFIX . $table . " AS f"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "c_invoice_subtype AS s ON f.subtype = s.rowid"; + $sql .= " WHERE f.titre = '".$this->db->escape($this->titre)."'"; + + $resql = $this->db->query($sql); + + if ($resql) { + $subtypeLabel = ''; + + while ($obj = $this->db->fetch_object($resql)) { + $subtypeLabel = $obj->label; + } + + if (!empty($subtypeLabel)) { + return $subtypeLabel; } } else { dol_print_error($this->db); return -1; } } + + return ''; } /** diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index f96482038ee..a53e9cbaf0d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3913,7 +3913,7 @@ abstract class CommonObject * @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. + * @param int|string $loadalsoobjects Load also the array $this->linkedObjects. Use 0 to not load (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() */ @@ -6162,7 +6162,7 @@ abstract class CommonObject //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]); } if (!empty($extrafields->attributes[$this->table_element]['type'][$key]) && $extrafields->attributes[$this->table_element]['type'][$key] == 'password') { - if (preg_match('/^dolcrypt:/', $value)) { + if (!empty($value) && preg_match('/^dolcrypt:/', $value)) { $this->array_options["options_".$key] = dolDecrypt($value); } } @@ -7033,6 +7033,7 @@ abstract class CommonObject $param['options'] = array(); $type = $this->fields[$key]['type']; } + //var_dump($type); var_dump($param['options']); // Special case that force options and type ($type can be integer, varchar, ...) if (!empty($this->fields[$key]['arrayofkeyval']) && is_array($this->fields[$key]['arrayofkeyval'])) { @@ -7194,7 +7195,27 @@ abstract class CommonObject $out .= ''; if ($showempty) { diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index 5a1823c03c0..b1437575617 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -1576,7 +1576,7 @@ class FormTicket // Attached files if (!empty($this->withfile)) { $out = ''; - $out .= ''; + $out .= ''; $out .= ''; @@ -1682,7 +1682,7 @@ class FormTicket print '
'; - print $invoicetmp->getNomUrl(1); + print ($salaryBonPl ? $salarytmp->getNomUrl(1) : $invoicetmp->getNomUrl(1)); print "'; print dol_escape_htmltag($invoicetmp->ref_supplier); print "'; - print $thirdpartytmp->getNomUrl(1); + print ($salaryBonPl ? $usertmp->getNomUrl(-1) : $thirdpartytmp->getNomUrl(1)); print "'.price($obj->total_ttc)."'.price(($salaryBonPl ? $obj->amount :$obj->total_ttc))."'.price($obj->amount_requested)."'; - - if ($obj->statut == 0) { - print '-'; - } elseif ($obj->statut == 2) { + if ($obj->status == 0) { + print $langs->trans("StatusWaiting"); + } elseif ($obj->status == 2) { if ($obj->type == 'bank-transfer') { print $langs->trans("StatusDebited"); } else { print $langs->trans("StatusCredited"); } - } elseif ($obj->statut == 3) { + } elseif ($obj->status == 3) { print ''.$langs->trans("StatusRefused").''; } - print "
'.$langs->trans("Total").'  '; - print $company->getNomUrl(1); + + print (!$bon->checkIfSalaryBonPrelevement() ? $company->getNomUrl(1) : $userstatic->getNomUrl(1)); print "
'.$obj->nom."'.$obj->nom."'.$obj->nom."'.$rej->motifs[$obj->motif].''; + print ''; print $row[1]; print ''; - print round($row[1] / $nbtotal * 100, 2)." %"; + print price2num($row[1] / $nbtotal * 100, 2)." %"; print ''; @@ -138,7 +138,7 @@ if ($resql) { print ''; - print round($row[0] / $total * 100, 2)." %"; + print price2num($row[0] / $total * 100, 2)." %"; print '
'; print $Rejet->motifs[$row[2]]; + print ''.$row[1]; + print ''.$row[1]; + print ''; - print round($row[1] / $nbtotal * 100, 2)." %"; + print ''; + print price2num($row[1] / $nbtotal * 100, 2)." %"; print ''; print price($row[0]); print ''; - print round($row[0] / $total * 100, 2)." %"; + print price2num($row[0] / $total * 100, 2)." %"; print '
'; - print ''; + print ''; print ''.price($obj->amount).'
'.$langs->trans("MailFile").''.$langs->trans("MailFile").''; // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript $out .= ''."\n"; @@ -1662,7 +1662,7 @@ class FormTicket //$toolbarname = 'dolibarr_details'; $toolbarname = 'dolibarr_notes'; include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('message', $defaultmessage, '100%', 200, $toolbarname, '', false, $uselocalbrowser, getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_5, 70); + $doleditor = new DolEditor('message', $defaultmessage, '100%', 200, $toolbarname, '', false, $uselocalbrowser, getDolGlobalInt('FCKEDITOR_ENABLE_TICKET'), ROWS_5, '90%'); $doleditor->Create(); print '
'; - print '

'; + print '
'; print 'withfile == 2 && !empty($conf->use_javascript_ajax)) { @@ -1697,7 +1697,7 @@ class FormTicket print ''."\n"; - print "\n"; + print "
\n"; // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set if (!empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY)) { diff --git a/htdocs/core/class/timespent.class.php b/htdocs/core/class/timespent.class.php index 6455459ce24..afe3e4ac0e5 100644 --- a/htdocs/core/class/timespent.class.php +++ b/htdocs/core/class/timespent.class.php @@ -527,6 +527,12 @@ class TimeSpent extends CommonObject if (!$resql) { $error++; $this->error = $this->db->lasterror(); } + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'timespent/".$this->db->escape($this->newref)."'"; + $sql .= " WHERE filepath = 'timespent/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (!$resql) { + $error++; $this->error = $this->db->lasterror(); + } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php index cb54b1f4ef8..9e7e8841bb5 100644 --- a/htdocs/core/js/lib_head.js.php +++ b/htdocs/core/js/lib_head.js.php @@ -253,14 +253,15 @@ function dpChangeDay(dateFieldID, format) /* * ================================================================= - * Function: - * formatDate (javascript object Date(), format) Purpose: Returns a date in the - * output format specified. The format string can use the following tags: Field | - * Tags -------------+------------------------------- Year | yyyy (4 digits), yy - * (2 digits) Month | MM (2 digits) Day of Month | dd (2 digits) Hour (1-12) | - * hh (2 digits) Hour (0-23) | HH (2 digits) Minute | mm (2 digits) Second | ss - * (2 digits) Author: Laurent Destailleur Author: Matelli (see - * http://matelli.fr/showcases/patchs-dolibarr/update-date-input-in-action-form.html) + * Function: formatDate(javascript object Date(), format) + * Purpose: Returns a date in the output format specified. The format string can use the following tags: + * Year | yyyy (4 digits), yy (2 digits) + * Month | MM (2 digits) + * Day of Month | dd (2 digits) + * Hour (1-12) | hh (2 digits) Hour (0-23) | HH (2 digits) + * Minute | mm (2 digits) + * Second | ss (2 digits) + * Author: Laurent Destailleur Author: Matelli (see http://matelli.fr/showcases/patchs-dolibarr/update-date-input-in-action-form.html) * Licence: GPL * ================================================================== */ diff --git a/htdocs/core/lib/accounting.lib.php b/htdocs/core/lib/accounting.lib.php index 86f7770e27f..08ec7f062e3 100644 --- a/htdocs/core/lib/accounting.lib.php +++ b/htdocs/core/lib/accounting.lib.php @@ -280,7 +280,7 @@ function getDefaultDatesForTransfer() $pastmonthyear = 0; // Period by default on transfer (0: previous month | 1: current month | 2: fiscal year) - $periodbydefaultontransfer = (empty($conf->global->ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER) ? 0 : $conf->global->ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER); + $periodbydefaultontransfer = getDolGlobalInt('ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER', 0); if ($periodbydefaultontransfer == 2) { // fiscal year $sql = "SELECT date_start, date_end FROM ".MAIN_DB_PREFIX."accounting_fiscalyear"; $sql .= " WHERE date_start < '".$db->idate(dol_now())."' AND date_end > '".$db->idate(dol_now())."'"; diff --git a/htdocs/core/lib/barcode.lib.php b/htdocs/core/lib/barcode.lib.php index 717ed4af1c6..d6ad49d54da 100644 --- a/htdocs/core/lib/barcode.lib.php +++ b/htdocs/core/lib/barcode.lib.php @@ -511,3 +511,37 @@ function barcode_outimage($text, $bars, $scale = 1, $mode = "png", $total_y = 0, imagepng($im); } } + +/** + * Check if EAN13 code is valid + * + * @param string $ean Code + * @return bool + */ +function isAValidEAN13($ean) +{ + $sumEvenIndexes = 0; + $sumOddIndexes = 0; + + $eanAsArray = array_map('intval', str_split($ean)); + + if (!(count($eanAsArray) === 13)) { + return false; + }; + + for ($i = 0; $i < count($eanAsArray)-1; $i++) { + if ($i % 2 === 0) { + $sumOddIndexes += $eanAsArray[$i]; + } else { + $sumEvenIndexes += $eanAsArray[$i]; + } + } + + $rest = ($sumOddIndexes + (3 * $sumEvenIndexes)) % 10; + + if ($rest !== 0) { + $rest = 10 - $rest; + } + + return $rest === $eanAsArray[12]; +} diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 3d8439dcf07..680fc0517ec 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -857,6 +857,12 @@ function show_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatel $num = $db->num_rows($result); print ''; + if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + $selectedfields = (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); + print $selectedfields; + print ''; + } print ''.$langs->trans("Ref").''; print ''.$langs->trans("Name").''; print ''.$langs->trans("DateStart").''; @@ -865,10 +871,12 @@ function show_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatel print ''.$langs->trans("OpportunityStatusShort").''; print ''.$langs->trans("OpportunityProbabilityShort").''; print ''.$langs->trans("Status").''; - print ''; - $selectedfields = (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); - print $selectedfields; - print ''; + if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + $selectedfields = (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); + print $selectedfields; + print ''; + } print ''; if ($num > 0) { @@ -888,6 +896,17 @@ function show_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatel if ($user->hasRight('projet', 'lire') && $userAccess > 0) { print ''; + if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + if ($massactionbutton || $massaction) { + $selected = 0; + if (in_array($obj->id, $arrayofselected)) { + $selected = 1; + } + print ''; + } + print ''; + } // Ref print ''; print $projecttmp->getNomUrl(1, '', 0, '', '-', 0, 1, '', 'project:'.$_SERVER["PHP_SELF"].'?socid=__SOCID__'); @@ -922,7 +941,7 @@ function show_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatel // Action column if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { - print ''; + print ''; if ($massactionbutton || $massaction) { $selected = 0; if (in_array($obj->id, $arrayofselected)) { diff --git a/htdocs/core/lib/emailing.lib.php b/htdocs/core/lib/emailing.lib.php index 746e3cf13fe..84198e81340 100644 --- a/htdocs/core/lib/emailing.lib.php +++ b/htdocs/core/lib/emailing.lib.php @@ -61,6 +61,11 @@ function emailing_prepare_head(Mailing $object) $head[$h][2] = 'info'; $h++; + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/note.php?id=".$object->id; + $head[$h][1] = $langs->trans("Note"); + $head[$h][2] = 'note'; + $h++; + complete_head_from_modules($conf, $langs, $object, $head, $h, 'emailing'); complete_head_from_modules($conf, $langs, $object, $head, $h, 'emailing', 'remove'); diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index edb89290592..7f45bc2e4ab 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -941,10 +941,11 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayrep * @param int $overwriteifexists Overwrite file if exists (1 by default) * @param int $testvirus Do an antivirus test. Move is canceled if a virus is found. * @param int $indexdatabase Index new file into database. + * @param int $moreinfo Array with more information * @return boolean True if OK, false if KO * @see dol_move_uploaded_file() */ -function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1) +function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array()) { global $user, $db, $conf; $result = false; @@ -1036,10 +1037,31 @@ function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $te $ecmfile->filepath = $rel_dir; $ecmfile->filename = $filename; $ecmfile->label = md5_file(dol_osencode($destfile)); // $destfile is a full path to file - $ecmfile->fullpath_orig = $srcfile; - $ecmfile->gen_or_uploaded = 'unknown'; - $ecmfile->description = ''; // indexed content - $ecmfile->keywords = ''; // keyword content + $ecmfile->fullpath_orig = basename($srcfile); + $ecmfile->gen_or_uploaded = 'uploaded'; + if (!empty($moreinfo) && !empty($moreinfo['description'])) { + $ecmfile->description = $moreinfo['description']; // indexed content + } else { + $ecmfile->description = ''; // indexed content + } + if (!empty($moreinfo) && !empty($moreinfo['keywords'])) { + $ecmfile->keywords = $moreinfo['keywords']; // indexed content + } else { + $ecmfile->keywords = ''; // keyword content + } + if (!empty($moreinfo) && !empty($moreinfo['note_private'])) { + $ecmfile->note_private = $moreinfo['note_private']; + } + if (!empty($moreinfo) && !empty($moreinfo['note_public'])) { + $ecmfile->note_public = $moreinfo['note_public']; + } + if (!empty($moreinfo) && !empty($moreinfo['src_object_type'])) { + $ecmfile->src_object_type = $moreinfo['src_object_type']; + } + if (!empty($moreinfo) && !empty($moreinfo['src_object_id'])) { + $ecmfile->src_object_id = $moreinfo['src_object_id']; + } + $resultecm = $ecmfile->create($user); if ($resultecm < 0) { setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); @@ -1558,7 +1580,8 @@ function dol_delete_preview($object) } if (empty($dir)) { - return 'ErrorObjectNoSupportedByFunction'; + $object->error = $langs->trans('ErrorObjectNoSupportedByFunction'); + return 0; } $refsan = dol_sanitizeFileName($object->ref); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 412a3c89be7..5da65a33320 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1598,18 +1598,26 @@ function dol_escape_json($stringtoescape) } /** - * Returns text escaped for inclusion into a php string, build with double quotes " + * Returns text escaped for inclusion into a php string, build with double quotes " or ' * * @param string $stringtoescape String to escape + * @param string $stringforquotes 2=String for doublequotes, 1=String for simple quotes * @return string Escaped string for json content. */ -function dol_escape_php($stringtoescape) +function dol_escape_php($stringtoescape, $stringforquotes = 2) { if (is_null($stringtoescape)) { return ''; } - return str_replace('"', "'", $stringtoescape); + if ($stringforquotes == 2) { + return str_replace('"', "'", $stringtoescape); + } + if ($stringforquotes == 1) { + return str_replace("'", "\'", str_replace('"', "'", $stringtoescape)); + } + + return 'Bad parameter for stringforquotes in dol_escape_php'; } /** @@ -2241,6 +2249,7 @@ function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab $out .= "\n".'
'."\n"; } if (!empty($dragdropfile)) { + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $out .= dragAndDropFileUpload("dragDropAreaTabBar"); } $parameters = array('tabname' => $active, 'out' => $out); @@ -4305,6 +4314,10 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ $url = DOL_URL_ROOT; $theme = isset($conf->theme) ? $conf->theme : null; $path = 'theme/'.$theme; + if (empty($picto)) { + $picto = 'generic'; + } + // Define fullpathpicto to use into src if ($pictoisfullpath) { // Clean parameters @@ -4318,7 +4331,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ $moreatt = str_replace('class="'.$reg[1].'"', '', $moreatt); } } else { - $pictowithouttext = preg_replace('/(\.png|\.gif|\.svg)$/', '', $picto); + $pictowithouttext = preg_replace('/(\.png|\.gif|\.svg)$/', '', (is_null($picto) ? '' : $picto)); $pictowithouttext = str_replace('object_', '', $pictowithouttext); $pictowithouttext = str_replace('_nocolor', '', $pictowithouttext); @@ -5413,7 +5426,9 @@ function dol_print_error($db = '', $error = '', $errors = null) print 'This website or feature is currently temporarly not available or failed after a technical error.

This may be due to a maintenance operation. Current status of operation ('.dol_print_date(dol_now(), 'dayhourrfc').') are on next line...

'."\n"; print $langs->trans("DolibarrHasDetectedError").'. '; print $langs->trans("YouCanSetOptionDolibarrMainProdToZero"); - define("MAIN_CORE_ERROR", 1); + if (!defined("MAIN_CORE_ERROR")) { + define("MAIN_CORE_ERROR", 1); + } } dol_syslog("Error ".$syslog, LOG_ERR); @@ -5859,7 +5874,7 @@ function print_barre_liste($titre, $page, $file, $options = '', $sortfield = '', * @param int $totalnboflines Total number of records/lines for all pages (if known) * @param int $hideselectlimit Force to hide select limit * @param string $beforearrows HTML content to show before arrows. Must NOT contains '
  • ' tags. - * @param int $hidenavigation Force to hide the switch mode view and the navigation tool (select limit, arrows $betweenarrows and $afterarrows but not $beforearrows) + * @param int $hidenavigation Force to hide the switch mode view and the navigation tool (hide limit section, html in $betweenarrows and $afterarrows but not $beforearrows) * @return void */ function print_fleche_navigation($page, $file, $options = '', $nextpage = 0, $betweenarrows = '', $afterarrows = '', $limit = -1, $totalnboflines = 0, $hideselectlimit = 0, $beforearrows = '', $hidenavigation = 0) @@ -7620,19 +7635,20 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = ' } while ($oldstringtoclean != $out); // Check the limit of external links that are automatically executed in a Rich text content. We count: - // ' + // ', we can only accept " $reg = array(); - preg_match_all('/( getDolGlobalInt("MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) { - $out = 'TooManyLinksIntoHTMLString'; + $tmpout = preg_replace('/ getDolGlobalInt("MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) { + $out = 'ErrorTooManyLinksIntoHTMLString'; } // - if (!empty($conf->global->MAIN_DISALLOW_EXT_URL_INTO_DESCRIPTIONS) || $check == 'restricthtmlnolink') { - if ($nbextlink > 0) { - $out = 'ExternalLinksNotAllowed'; + if (!empty($conf->global->MAIN_DISALLOW_URL_INTO_DESCRIPTIONS) || $check == 'restricthtmlnolink') { + if ($nblinks > 0) { + $out = 'ErrorHTMLLinksNotAllowed'; } } @@ -8237,18 +8253,36 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $substitutionarray['__ATTENDEE_LASTNAME__'] = isset($object->lastname) ? $object->lastname : ''; } - if (is_object($object->project)) { - $substitutionarray['__PROJECT_ID__'] = (is_object($object->project) ? $object->project->id : ''); - $substitutionarray['__PROJECT_REF__'] = (is_object($object->project) ? $object->project->ref : ''); - $substitutionarray['__PROJECT_NAME__'] = (is_object($object->project) ? $object->project->title : ''); - } - if (is_object($object->projet)) { // Deprecated, for backward compatibility - $substitutionarray['__PROJECT_ID__'] = (is_object($object->projet) ? $object->projet->id : ''); - $substitutionarray['__PROJECT_REF__'] = (is_object($object->projet) ? $object->projet->ref : ''); - $substitutionarray['__PROJECT_NAME__'] = (is_object($object->projet) ? $object->projet->title : ''); - } if (is_object($object) && $object->element == 'project') { + $substitutionarray['__PROJECT_ID__'] = $object->id; + $substitutionarray['__PROJECT_REF__'] = $object->ref; $substitutionarray['__PROJECT_NAME__'] = $object->title; + } elseif (is_object($object)) { + $project = null; + if (!empty($object->project)) { + $project = $object->project; + } elseif (!empty($object->projet)) { // Deprecated, for backward compatibility + $project = $object->projet; + } + if (!is_null($project) && is_object($project)) { + $substitutionarray['__PROJECT_ID__'] = $project->id; + $substitutionarray['__PROJECT_REF__'] = $project->ref; + $substitutionarray['__PROJECT_NAME__'] = $project->title; + } else { + // can substitute variables for project : uses lazy load in "make_substitutions" method + $project_id = 0; + if (!empty($object->fk_project) && $object->fk_project > 0) { + $project_id = $object->fk_project; + } elseif (!empty($object->fk_projet) && $object->fk_projet > 0) { + $project_id = $object->fk_project; + } + if ($project_id > 0) { + // path:class:method:id + $substitutionarray['__PROJECT_ID__@lazyload'] = '/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id; + $substitutionarray['__PROJECT_REF__@lazyload'] = '/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id; + $substitutionarray['__PROJECT_NAME__@lazyload'] = '/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id; + } + } } if (is_object($object) && $object->element == 'shipping') { @@ -8525,6 +8559,9 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, '__PREVIOUS_YEAR__' => (string) ($tmp['year'] - 1), '__NEXT_DAY__' => (string) $tmp4['day'], '__NEXT_MONTH__' => (string) $tmp5['month'], + '__NEXT_MONTH_TEXT__' => $outputlangs->trans('Month'.sprintf("%02d", $tmp5['month'])), + '__NEXT_MONTH_TEXT_SHORT__' => $outputlangs->trans('MonthShort'.sprintf("%02d", $tmp5['month'])), + '__NEXT_MONTH_TEXT_MIN__' => $outputlangs->trans('MonthVeryShort'.sprintf("%02d", $tmp5['month'])), '__NEXT_YEAR__' => (string) ($tmp['year'] + 1), )); } @@ -8562,7 +8599,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, */ function make_substitutions($text, $substitutionarray, $outputlangs = null, $converttextinhtmlifnecessary = 0) { - global $conf, $langs; + global $conf, $db, $langs; if (!is_array($substitutionarray)) { return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions'; @@ -8680,6 +8717,53 @@ function make_substitutions($text, $substitutionarray, $outputlangs = null, $con $valuetouseforsubstitution = $tmpobj->$method($id, '__XXX__'); And make the replacement of "__XXX__@lazyload" with $valuetouseforsubstitution */ + $memory_object_list = array(); + foreach ($substitutionarray as $key => $value) { + $lazy_load_arr = array(); + if (preg_match('/(__[A-Z\_]+__)@lazyload$/', $key, $lazy_load_arr)) { + if (isset($lazy_load_arr[1]) && !empty($lazy_load_arr[1])) { + $key_to_substitute = $lazy_load_arr[1]; + if (preg_match('/' . preg_quote($key_to_substitute, '/') . '/', $text)) { + $param_arr = explode(':', $value); + // path:class:method:id + if (count($param_arr) == 4) { + $path = $param_arr[0]; + $class = $param_arr[1]; + $method = $param_arr[2]; + $id = (int) $param_arr[3]; + + // load class file and init object list in memory + if (!isset($memory_object_list[$class])) { + if (dol_is_file(DOL_DOCUMENT_ROOT . $path)) { + require_once DOL_DOCUMENT_ROOT . $path; + if (class_exists($class)) { + $memory_object_list[$class] = array( + 'list' => array(), + ); + } + } + } + + // fetch object and set substitution + if (isset($memory_object_list[$class]) && isset($memory_object_list[$class]['list'])) { + if (method_exists($class, $method)) { + if (!isset($memory_object_list[$class]['list'][$id])) { + $tmpobj = new $class($db); + $valuetouseforsubstitution = $tmpobj->$method($id, $key_to_substitute); + $memory_object_list[$class]['list'][$id] = $tmpobj; + } else { + $tmpobj = $memory_object_list[$class]['list'][$id]; + $valuetouseforsubstitution = $tmpobj->$method($id, $key_to_substitute, true); + } + + $text = str_replace("$key_to_substitute", "$valuetouseforsubstitution", $text); // We must keep the " to work when value is 123.5 for example + } + } + } + } + } + } + } return $text; } @@ -9609,7 +9693,8 @@ function picto_from_langcode($codelang, $moreatt = '', $notitlealt = 0) $flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1]; } - return img_picto_common($codelang, 'flags/'.strtolower($flagImage).'.png', $moreatt, 0, $notitlealt); + // return img_picto_common($codelang, 'flags/'.strtolower($flagImage).'.png', $moreatt, 0, $notitlealt); + return ''; } /** @@ -9883,6 +9968,21 @@ function complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $reg = array(); if ($mode == 'add' && !preg_match('/^\-/', $values[1])) { + $newtab = array(); + $postab = $h; + // detect if position set in $values[1] ie : +(2)mytab@mymodule (first tab is 0, second is one, ...) + $str = $values[1]; + $posstart = strpos($str, '('); + if ($posstart > 0) { + $posend = strpos($str, ')'); + if ($posstart > 0) { + $res1 = substr($str, $posstart + 1, $posend - $posstart -1); + if (is_numeric($res1)) { + $postab = (int) $res1; + $values[1] = '+' . substr($str, $posend + 1); + } + } + } if (count($values) == 6) { // new declaration with permissions: // $value='objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__' @@ -9932,9 +10032,9 @@ function complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, } } - $head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[5]), 1); - $head[$h][1] = $label; - $head[$h][2] = str_replace('+', '', $values[1]); + $newtab[0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[5]), 1); + $newtab[1] = $label; + $newtab[2] = str_replace('+', '', $values[1]); $h++; } } elseif (count($values) == 5) { // case deprecated @@ -9965,11 +10065,13 @@ function complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $label = $langs->trans($values[2]); } - $head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[4]), 1); - $head[$h][1] = $label; - $head[$h][2] = str_replace('+', '', $values[1]); + $newtab[0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[4]), 1); + $newtab[1] = $label; + $newtab[2] = str_replace('+', '', $values[1]); $h++; } + // set tab at its position + $head = array_merge(array_slice($head, 0, $postab), array($newtab), array_slice($head, $postab)); } elseif ($mode == 'remove' && preg_match('/^\-/', $values[1])) { if ($values[0] != $type) { continue; @@ -11374,8 +11476,10 @@ function dolGetButtonAction($label, $text = '', $actionType = 'default', $url = // If $url is an array, we must build a dropdown button if (is_array($url)) { + $out = ''; + if (count($url) > 1) { - $out = ''; + + print '

    '; + + if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { + $blocname = 'contacts'; + $title = $langs->trans('ContactsAddresses'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { + $blocname = 'notes'; + $title = $langs->trans('Notes'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + /* + * Lines + */ + + // Show object lines + $result = $object->getLinesArray(); + + print '
    + + + + + + '; + + if (!empty($conf->use_javascript_ajax) && $object->statut == SupplierProposal::STATUS_DRAFT) { + include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; + } + + print '
    '; + print ''; + + // Add free products/services form + global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax; + $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1; + $senderissupplier = 2; // $senderissupplier=2 is same than 1 but disable test on minimum qty. + if (!empty($conf->global->SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY)) { + $senderissupplier = 1; + } + + if (!empty($object->lines)) { + $object->printObjectLines($action, $soc, $mysoc, $lineid, $dateSelector); + } + + // Form to add new line + if ($object->statut == SupplierProposal::STATUS_DRAFT && $usercancreate) { + if ($action != 'editline') { + // Add products/services form + + $parameters = array(); + $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if (empty($reshook)) + $object->formAddObjectLine($dateSelector, $soc, $mysoc); + } + } + + print '
    '; + print '
    '; + print "
    \n"; + } print dol_get_fiche_end(); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index a817f992898..a203c0ac8a8 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -1442,6 +1442,12 @@ class SupplierProposal extends CommonObject if (!$resql) { $error++; $this->error = $this->db->lasterror(); } + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'supplier_proposal/".$this->db->escape($this->newref)."'"; + $sql .= " WHERE filepath = 'supplier_proposal/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (!$resql) { + $error++; $this->error = $this->db->lasterror(); + } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); @@ -1533,6 +1539,7 @@ class SupplierProposal extends CommonObject * @param double $remise Amount discount * @return int <0 if ko, >0 if ok */ + /* public function set_remise_percent($user, $remise) { // phpcs:enable @@ -1555,7 +1562,7 @@ class SupplierProposal extends CommonObject } return 0; } - + */ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** @@ -1615,7 +1622,7 @@ class SupplierProposal extends CommonObject if (!empty($note)) { $sql .= " note_private = '".$this->db->escape($note)."',"; } - $sql .= " date_cloture=NULL, fk_user_cloture=NULL"; + $sql .= " date_cloture = NULL, fk_user_cloture = NULL"; $sql .= " WHERE rowid = ".((int) $this->id); $this->db->begin(); @@ -2023,7 +2030,8 @@ class SupplierProposal extends CommonObject if (!$error) { // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive - $this->deleteEcmFiles(); + $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive + $this->deleteEcmFiles(1); // Deleting files physically is done later with the dol_delete_dir_recursive // We remove directory $ref = dol_sanitizeFileName($this->ref); @@ -2894,6 +2902,12 @@ class SupplierProposalLine extends CommonObjectLine */ public $product_label; + /** + * Custom label + * @var string + */ + public $label; + /** * Product description * @var string diff --git a/htdocs/takepos/admin/terminal.php b/htdocs/takepos/admin/terminal.php index 39699100941..2da691bf805 100644 --- a/htdocs/takepos/admin/terminal.php +++ b/htdocs/takepos/admin/terminal.php @@ -159,8 +159,9 @@ print ''; print ''.$langs->trans("CashDeskThirdPartyForSell").''; print ''; +print img_picto('', 'company', 'class="pictofixedwidth"'); $filter = '((s.client:IN:1,2,3) AND (s.status:=:1))'; -print $form->select_company(getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$terminaltouse), 'socid', $filter, 1, 0, 0, array(), 0); +print $form->select_company(getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$terminaltouse), 'socid', $filter, 1, 0, 0, array(), 0, 'maxwidth500 widthcentpercentminusx'); print ''; $atleastonefound = 0; @@ -168,7 +169,7 @@ if (isModEnabled("banque")) { print ''.$langs->trans("CashDeskBankAccountForSell").''; print ''; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); - print $form->select_comptes(getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse), 'CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse, 0, "courant=2", 1, '', 0, '', 1); + print $form->select_comptes(getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse), 'CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse, 0, "courant=2", 1, '', 0, 'maxwidth500 widthcentpercentminusxx', 1); print '
    '; if (getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse)) { $atleastonefound++; @@ -177,7 +178,7 @@ if (isModEnabled("banque")) { print ''.$langs->trans("CashDeskBankAccountForCheque").''; print ''; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); - print $form->select_comptes(getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_CHEQUE'.$terminaltouse), 'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$terminaltouse, 0, "courant=1", 1, '', 0, '', 1); + print $form->select_comptes(getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_CHEQUE'.$terminaltouse), 'CASHDESK_ID_BANKACCOUNT_CHEQUE'.$terminaltouse, 0, "courant=1", 1, '', 0, 'maxwidth500 widthcentpercentminusxx', 1); print ' '; if (getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_CHEQUE'.$terminaltouse)) { $atleastonefound++; @@ -186,7 +187,7 @@ if (isModEnabled("banque")) { print ''.$langs->trans("CashDeskBankAccountForCB").''; print ''; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); - print $form->select_comptes(getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_CB'.$terminaltouse), 'CASHDESK_ID_BANKACCOUNT_CB'.$terminaltouse, 0, "courant=1", 1, '', 0, '', 1); + print $form->select_comptes(getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_CB'.$terminaltouse), 'CASHDESK_ID_BANKACCOUNT_CB'.$terminaltouse, 0, "courant=1", 1, '', 0, 'maxwidth500 widthcentpercentminusxx', 1); print ' '; if (getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_CB'.$terminaltouse)) { $atleastonefound++; @@ -234,7 +235,7 @@ if (isModEnabled("banque")) { print ''.$langs->trans("CashDeskBankAccountForSumup").''; print ''; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); - print $form->select_comptes(getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_SUMUP'.$terminaltouse), 'CASHDESK_ID_BANKACCOUNT_SUMUP'.$terminaltouse, 0, "courant=1", 1, '', 0, '', 1); + print $form->select_comptes(getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_SUMUP'.$terminaltouse), 'CASHDESK_ID_BANKACCOUNT_SUMUP'.$terminaltouse, 0, "courant=1", 1, '', 0, 'maxwidth500 widthcentpercentminusxx', 1); print ' '; if (getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_SUMUP'.$terminaltouse)) { $atleastonefound++; @@ -254,7 +255,7 @@ if (isModEnabled("banque")) { } $cour = preg_match('/^LIQ.*/', $modep->code) ? 2 : 1; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); - print $form->select_comptes(getDolGlobalInt($name), $name, 0, "courant=".$cour, 1, '', 0, '', 1); + print $form->select_comptes(getDolGlobalInt($name), $name, 0, "courant=".$cour, 1, '', 0, 'maxwidth500 widthcentpercentminusxx', 1); print ' '; print ''; } @@ -263,15 +264,7 @@ if (isModEnabled("banque")) { if (isModEnabled('stock')) { print ''.$langs->trans("CashDeskDoNotDecreaseStock").''; // Force warehouse (this is not a default value) print ''; - if (!isModEnabled('productbatch') || getDolGlobalInt('CASHDESK_FORCE_DECREASE_STOCK')) { - print $form->selectyesno('CASHDESK_NO_DECREASE_STOCK'.$terminal, getDolGlobalInt('CASHDESK_NO_DECREASE_STOCK'.$terminal), 1); - } else { - if (getDolGlobalInt('CASHDESK_NO_DECREASE_STOCK'.$terminal)) { - $res = dolibarr_set_const($db, "CASHDESK_NO_DECREASE_STOCK".$terminal, 1, 'chaine', 0, '', $conf->entity); - } - print $langs->trans("Yes").'
    '; - print ''.$langs->trans('StockDecreaseForPointOfSaleDisabledbyBatch').''; - } + print $form->selectyesno('CASHDESK_NO_DECREASE_STOCK'.$terminal, getDolGlobalInt('CASHDESK_NO_DECREASE_STOCK'.$terminal), 1); print ''; $disabled = getDolGlobalString('CASHDESK_NO_DECREASE_STOCK'.$terminal); @@ -287,8 +280,8 @@ if (isModEnabled('stock')) { print ''; // Force warehouse (this is not a default value) print ''; if (!$disabled) { - print img_picto('', 'bank_account', 'class="pictofixedwidth"'); - print $formproduct->selectWarehouses(getDolGlobalString('CASHDESK_ID_WAREHOUSE'.$terminal), 'CASHDESK_ID_WAREHOUSE'.$terminal, '', 1, $disabled, 0, '', 0, 0, array(), 'maxwidth250'); + print img_picto('', 'stock', 'class="pictofixedwidth"'); + print $formproduct->selectWarehouses(getDolGlobalString('CASHDESK_ID_WAREHOUSE'.$terminal), 'CASHDESK_ID_WAREHOUSE'.$terminal, '', 1, $disabled, 0, '', 0, 0, array(), 'maxwidth500 widthcentpercentminusxx'); print ' '; } else { print ''.$langs->trans("StockDecreaseForPointOfSaleDisabled").''; @@ -359,7 +352,7 @@ if (getDolGlobalString('TAKEPOS_ADDON') == "terminal") { print ''; print $langs->trans("BillsNumberingModule"); print ''; - $array = array(0=>$langs->trans("Default")); + $array = array(0 => $langs->trans("Default")); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); foreach ($dirmodels as $reldir) { $dir = dol_buildpath($reldir."core/modules/facture/"); diff --git a/htdocs/takepos/ajax/ajax.php b/htdocs/takepos/ajax/ajax.php index 709c3ad42ef..4afe70c42c1 100644 --- a/htdocs/takepos/ajax/ajax.php +++ b/htdocs/takepos/ajax/ajax.php @@ -262,7 +262,11 @@ if ($action == 'getProducts') { $sql = 'SELECT p.rowid, p.ref, p.label, p.tosell, p.tobuy, p.barcode, p.price, p.price_ttc' ; if (getDolGlobalInt('TAKEPOS_PRODUCT_IN_STOCK') == 1) { - $sql .= ', ps.reel'; + if (getDolGlobalInt('CASHDESK_ID_WAREHOUSE'.$_SESSION['takeposterminal'])) { + $sql .= ', ps.reel'; + } else { + $sql .= ', SUM(ps.reel) as reel'; + } } /* this will be possible when field archive will be supported into llx_product_price if (getDolGlobalString('PRODUIT_MULTIPRICES')) { @@ -284,7 +288,9 @@ if ($action == 'getProducts') { if (getDolGlobalInt('TAKEPOS_PRODUCT_IN_STOCK') == 1) { $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'product_stock as ps'; $sql .= ' ON (p.rowid = ps.fk_product'; - $sql .= " AND ps.fk_entrepot = ".((int) getDolGlobalInt("CASHDESK_ID_WAREHOUSE".$_SESSION['takeposterminal'])); + if (getDolGlobalString('CASHDESK_ID_WAREHOUSE'.$_SESSION['takeposterminal'])) { + $sql .= " AND ps.fk_entrepot = ".((int) getDolGlobalInt("CASHDESK_ID_WAREHOUSE".$_SESSION['takeposterminal'])); + } $sql .= ')'; } @@ -300,7 +306,7 @@ if ($action == 'getProducts') { $sql .= ' AND EXISTS (SELECT cp.fk_product FROM '.MAIN_DB_PREFIX.'categorie_product as cp WHERE cp.fk_product = p.rowid AND cp.fk_categorie IN ('.$db->sanitize($filteroncategids).'))'; } $sql .= ' AND p.tosell = 1'; - if (getDolGlobalInt('TAKEPOS_PRODUCT_IN_STOCK') == 1) { + if (getDolGlobalInt('TAKEPOS_PRODUCT_IN_STOCK') == 1 && getDolGlobalInt('CASHDESK_ID_WAREHOUSE'.$_SESSION['takeposterminal'])) { $sql .= ' AND ps.reel > 0'; } $sql .= natural_search(array('ref', 'label', 'barcode'), $term); @@ -311,6 +317,17 @@ if ($action == 'getProducts') { $sql .= $hookmanager->resPrint; } + if (getDolGlobalInt('TAKEPOS_PRODUCT_IN_STOCK') == 1 && !getDolGlobalInt('CASHDESK_ID_WAREHOUSE'.$_SESSION['takeposterminal'])) { + $sql .= ' GROUP BY p.rowid, p.ref, p.label, p.tosell, p.tobuy, p.barcode, p.price, p.price_ttc'; + // Add fields from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); + if ($reshook >= 0) { + $sql .= $hookmanager->resPrint; + } + $sql .= ' HAVING SUM(ps.reel) > 0'; + } + // load only one page of products $sql.= $db->plimit($search_limit, $search_start); diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 3c9b24ea52a..42482814998 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -1441,9 +1441,7 @@ if (!empty($conf->global->TAKEPOS_WEIGHING_SCALE)) {
    -
    > +
    trans("NoLinesToBill", "TakePos"), null, 1); - } elseif (isModEnabled('stock') && getDolGlobalString($constantforkey) != "1") { + } elseif (isModEnabled('stock') && getDolGlobalString($constantforkey) != "1" && !isModEnabled('productbatch')) { $savconst = $conf->global->STOCK_CALCULATE_ON_BILL; if (isModEnabled('productbatch') && !getDolGlobalInt('CASHDESK_FORCE_DECREASE_STOCK')) { @@ -311,8 +311,25 @@ if (empty($reshook)) { } else { dol_htmloutput_errors($invoice->error, $invoice->errors, 1); } + // Update stock for batch products + if (isModEnabled('productbatch')) { + require_once DOL_DOCUMENT_ROOT . "/product/stock/class/mouvementstock.class.php"; + $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal"]; + foreach ($invoice->lines as $line) { + if ($line->batch && $line->fk_warehouse > 0) { + $prod_batch = new Productbatch($db); + $prod_batch->find(0, '', '', $line->batch, $line->fk_warehouse); + $mouvP = new MouvementStock($db); + $mouvP->origin = $invoice; + $mouvP->livraison($user, $line->fk_product, $conf->global->$constantforkey, $line->qty, $line->price, 'TakePOS', '', '', '', $prod_batch->batch, $line->batch); + } else { + $mouvP = new MouvementStock($db); + $mouvP->origin = $invoice; + $mouvP->livraison($user, $line->fk_product, $conf->global->$constantforkey, $line->qty, $line->price, 'TakePOS', '', '', ''); + } + } + } } - if ($action == 'creditnote' && $user->hasRight('facture', 'creer')) { $creditnote = new Facture($db); $creditnote->socid = $invoice->socid; @@ -509,6 +526,64 @@ if (empty($reshook)) { $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr); $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr); + if (isModEnabled('productbatch') && isModEnabled('stock')) { + $batch = GETPOST('batch', 'alpha'); + + if (!empty($batch)) { + $action="setbatch"; + } else { + $prod->load_stock('warehouseopen'); + $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal"]; + if ($prod->stock_warehouse[$conf->global->$constantforkey]->detail_batch!="") + if (is_object($prod->stock_warehouse[$conf->global->$constantforkey]) && count($prod->stock_warehouse[$conf->global->$constantforkey]->detail_batch)) { + foreach ($prod->stock_warehouse[$conf->global->$constantforkey]->detail_batch as $dbatch) { + $nbofsuggested++; + } + } + + echo ""; + + if ($nbofsuggested>0) { + echo "
    ".$langs->trans("SearchIntoBatch").": $nbofsuggested

    "; + foreach ($prod->stock_warehouse[$conf->global->$constantforkey]->detail_batch as $dbatch) { // $dbatch is instance of Productbatch + $batchStock = + $dbatch->qty; // To get a numeric + $deliverableQty = min($quantityToBeDelivered, $batchStock); + print ''; + print ''; + print ''; + } + print "
    '; + $staticwarehouse = new Entrepot($db); + if ($warehouse_id > 0) $staticwarehouse->fetch($conf->global->$constantforkey); + $detail = ''; + $detail .= $langs->trans("LotSerial").': '.$dbatch->batch; + if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { + //$detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby, "day"); + } + if (empty($conf->global->PRODUCT_DISABLE_EATBY)) { + //$detail .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby, "day"); + } + $detail .= ' - '.$langs->trans("Qty").': '.$dbatch->qty; + $detail .= " "; + $detail .= '
    '; + print $detail; + + $quantityToBeDelivered -= $deliverableQty; + if ($quantityToBeDelivered < 0) { + $quantityToBeDelivered = 0; + } + $subj++; + print '
    "; + exit; + } + } + } + if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $cat = new Categorie($db); @@ -786,6 +861,12 @@ if (empty($reshook)) { $invoice->fetch($placeid); } + if ($action=="setbatch") { + $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal"]; + $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set batch=".$db->escape($batch).", fk_warehouse=".getDolGlobalString($constantforkey)." where rowid=".((int) $idoflineadded); + $db->query($sql); + } + if ($action == "order" and $placeid != 0) { include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") { diff --git a/htdocs/takepos/pay.php b/htdocs/takepos/pay.php index 22d161a4bec..57ab0b4fb0e 100644 --- a/htdocs/takepos/pay.php +++ b/htdocs/takepos/pay.php @@ -261,7 +261,7 @@ if ($invoice->id > 0) { } $alreadypayed = (is_object($invoice) ? ($invoice->total_ttc - $remaintopay) : 0); -if (getDolGlobalInt('TAKEPOS_NUMPAD') == 0) { +if (!getDolGlobalInt("TAKEPOS_NUMPAD")) { print "var received='';"; } else { print "var received=0;"; @@ -273,7 +273,7 @@ if (getDolGlobalInt('TAKEPOS_NUMPAD') == 0) { function addreceived(price) { global->TAKEPOS_NUMPAD)) { + if (!getDolGlobalInt("TAKEPOS_NUMPAD")) { print 'received+=String(price);'."\n"; } else { print 'received+=parseFloat(price);'."\n"; @@ -348,7 +348,7 @@ if (getDolGlobalInt('TAKEPOS_NUMPAD') == 0) { parent.$.colorbox.close(); } else { - console.log("Amount is not comple, so we do NOT close popup and reload it."); + console.log("Amount is not complete, so we do NOT close popup and reload it."); location.reload(); } }); @@ -680,7 +680,7 @@ if (isModEnabled('stripe') && isset($keyforstripeterminalbank) && !empty($conf-> } $keyforsumupbank = "CASHDESK_ID_BANKACCOUNT_SUMUP".$_SESSION["takeposterminal"]; -if (getDolGlobalInt('TAKEPOS_ENABLE_SUMUP')) { +if (getDolGlobalInt("TAKEPOS_ENABLE_SUMUP")) { if (getDolGlobalString($keyforsumupbank)) { print ''; } else { diff --git a/htdocs/theme/common/flags/flag-sprite.png b/htdocs/theme/common/flags/flag-sprite.png new file mode 100644 index 00000000000..af4822a05e8 Binary files /dev/null and b/htdocs/theme/common/flags/flag-sprite.png differ diff --git a/htdocs/theme/eldy/badges.inc.php b/htdocs/theme/eldy/badges.inc.php index aae4e50fb29..43a78873655 100644 --- a/htdocs/theme/eldy/badges.inc.php +++ b/htdocs/theme/eldy/badges.inc.php @@ -229,7 +229,6 @@ _createStatusBadgeCss('4b', '', "STATUS4b"); */ function _createStatusBadgeCss($statusName, $statusVarNamePrefix = '', $commentLabel = '', $cssPrefix = '') { - global ${$statusVarNamePrefix.'badgeStatus'.$statusName}, ${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName}; if (!empty(${$statusVarNamePrefix.'badgeStatus'.$statusName})) { @@ -256,16 +255,21 @@ function _createStatusBadgeCss($statusName, $statusVarNamePrefix = '', $commentL $thisBadgeTextColor = '#777777'; } + // badge-statusX print $cssPrefix.".badge-status".$statusName." {\n"; print " color: ".$thisBadgeTextColor." !important;\n"; if (in_array((string) $statusName, $TBadgeBorderOnly)) { print " border-color: ".$thisBadgeBorderColor." !important;\n"; } - print " background-color: ".$thisBadgeBackgroundColor." !important;\n"; + if ($thisBadgeBackgroundColor != '') { + print " background-color: ".$thisBadgeBackgroundColor." !important;\n"; + } print "}\n"; print $cssPrefix.".font-status".$statusName." {\n"; - print " color: ".$thisBadgeBackgroundColor." !important;\n"; + if ($thisBadgeBackgroundColor != '') { + print " color: ".$thisBadgeBackgroundColor." !important;\n"; + } print "}\n"; print $cssPrefix.".badge-status".$statusName.".focus, ".$cssPrefix.".badge-status".$statusName.":focus {\n"; @@ -273,6 +277,7 @@ function _createStatusBadgeCss($statusName, $statusVarNamePrefix = '', $commentL print " box-shadow: 0 0 0 0.2rem ".colorHexToRgb($thisBadgeBackgroundColor, 0.5)." !important;\n"; print "}\n"; + // badge-statusX:focus print $cssPrefix.".badge-status".$statusName.":focus, ".$cssPrefix.".badge-status".$statusName.":hover {\n"; print " color: ".$thisBadgeTextColor." !important;\n"; //print " background-color: " . colorDarker($thisBadgeBackgroundColor, 10) . ";\n"; diff --git a/htdocs/theme/eldy/btn.inc.php b/htdocs/theme/eldy/btn.inc.php index 28ae22e9696..432da846840 100644 --- a/htdocs/theme/eldy/btn.inc.php +++ b/htdocs/theme/eldy/btn.inc.php @@ -251,12 +251,15 @@ a.btnTitle.btnTitleSelected { border-radius: 3px; position: relative; text-align: center; - /* color: #ffffff; - background-color: rgb(); */ font-size: 12px; text-decoration: none; box-shadow: none; } +/* The buttonplus isgrowing on hover (dont know why). This is to avoid to have the cellegrowing too */ +.btnTitlePlus:hover { + max-width: 24px; + max-height: 40px; +} .btnTitle.refused, a.btnTitle.refused, .btnTitle.refused:hover, a.btnTitle.refused:hover { color: #8a8a8a; diff --git a/htdocs/theme/eldy/flags-sprite.inc.php b/htdocs/theme/eldy/flags-sprite.inc.php new file mode 100644 index 00000000000..99e0b241761 --- /dev/null +++ b/htdocs/theme/eldy/flags-sprite.inc.php @@ -0,0 +1,1279 @@ + +/*