2008-08-12 20:20:18 +02:00
< ? php
2018-09-09 09:36:12 +02:00
/* Copyright ( C ) 2002 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
2020-03-26 02:13:34 +01:00
* Copyright ( C ) 2004 - 2020 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2005 Marc Barilley / Ocebo < marc @ ocebo . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2015 Regis Houssin < regis . houssin @ inodbox . com >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
* Copyright ( C ) 2010 - 2015 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2012 - 2013 Christophe Battarel < christophe . battarel @ altairis . fr >
* Copyright ( C ) 2012 - 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
* Copyright ( C ) 2012 - 2014 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
* Copyright ( C ) 2013 Jean - Francois FERRY < jfefe @ aternatik . fr >
* Copyright ( C ) 2013 - 2014 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
2019-09-17 09:38:08 +02:00
* Copyright ( C ) 2014 - 2019 Ferran Marcet < fmarcet @ 2 byte . es >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2015 - 2016 Marcos García < marcosgdf @ gmail . com >
2021-02-08 18:30:09 +01:00
* Copyright ( C ) 2018 - 2021 Frédéric France < frederic . france @ netlogic . fr >
2022-01-28 15:08:02 +01:00
* Copyright ( C ) 2022 Gauthier VERDOL < gauthier . verdol @ atm - consulting . fr >
2013-09-06 11:02:57 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2013-09-06 11:02:57 +02:00
*/
2008-08-12 20:20:18 +02:00
/**
2017-03-20 20:58:43 +01:00
* \file htdocs / compta / facture / card . php
2014-02-23 20:10:05 +01:00
* \ingroup facture
2014-03-19 23:49:07 +01:00
* \brief Page to create / see an invoice
2013-08-06 23:50:12 +02:00
*/
2014-03-19 23:49:07 +01:00
2017-03-20 20:58:43 +01:00
require '../../main.inc.php' ;
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture-rec.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formmargin.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'commande' )) {
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
2021-02-23 15:35:16 +01:00
}
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'project' )) {
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2013-06-14 22:33:01 +02:00
}
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2008-08-12 20:20:18 +02:00
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'variants' )) {
2017-02-08 12:37:38 +01:00
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductCombination.class.php' ;
2016-07-23 16:37:21 +02:00
}
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'accounting' )) {
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php' ;
2017-05-14 21:20:35 +02:00
}
2016-07-23 16:37:21 +02:00
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
2021-06-04 12:56:40 +02:00
$langs -> loadLangs ( array ( 'bills' , 'companies' , 'compta' , 'products' , 'banks' , 'main' , 'withdrawals' ));
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'incoterm' )) {
2021-02-23 21:09:01 +01:00
$langs -> load ( 'incoterm' );
}
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'margin' )) {
2021-02-23 21:09:01 +01:00
$langs -> load ( 'margins' );
}
2014-02-23 20:10:05 +01:00
2019-01-27 11:55:16 +01:00
$projectid = ( GETPOST ( 'projectid' , 'int' ) ? GETPOST ( 'projectid' , 'int' ) : 0 );
2014-02-23 20:10:05 +01:00
$id = ( GETPOST ( 'id' , 'int' ) ? GETPOST ( 'id' , 'int' ) : GETPOST ( 'facid' , 'int' )); // For backward compatibility
$ref = GETPOST ( 'ref' , 'alpha' );
$socid = GETPOST ( 'socid' , 'int' );
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2014-02-23 20:10:05 +01:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
2016-02-16 22:26:23 +01:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2014-02-23 20:10:05 +01:00
$lineid = GETPOST ( 'lineid' , 'int' );
$userid = GETPOST ( 'userid' , 'int' );
2019-01-27 11:55:16 +01:00
$search_ref = GETPOST ( 'sf_ref' , 'alpha' ) ? GETPOST ( 'sf_ref' , 'alpha' ) : GETPOST ( 'search_ref' , 'alpha' );
2014-02-23 20:10:05 +01:00
$search_societe = GETPOST ( 'search_societe' , 'alpha' );
$search_montant_ht = GETPOST ( 'search_montant_ht' , 'alpha' );
$search_montant_ttc = GETPOST ( 'search_montant_ttc' , 'alpha' );
$origin = GETPOST ( 'origin' , 'alpha' );
$originid = ( GETPOST ( 'originid' , 'int' ) ? GETPOST ( 'originid' , 'int' ) : GETPOST ( 'origin_id' , 'int' )); // For backward compatibility
2019-11-12 00:15:34 +01:00
$fac_rec = GETPOST ( 'fac_rec' , 'int' );
2021-12-02 15:56:34 +01:00
$facid = GETPOST ( 'facid' , 'int' );
$ref_client = GETPOST ( 'ref_client' , 'int' );
2021-11-16 14:09:18 +01:00
$rank = ( GETPOST ( 'rank' , 'int' ) > 0 ) ? GETPOST ( 'rank' , 'int' ) : - 1 ;
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
// PDF
2019-11-12 00:15:34 +01:00
$hidedetails = ( GETPOST ( 'hidedetails' , 'int' ) ? GETPOST ( 'hidedetails' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS ) ? 1 : 0 ));
$hidedesc = ( GETPOST ( 'hidedesc' , 'int' ) ? GETPOST ( 'hidedesc' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DESC ) ? 1 : 0 ));
$hideref = ( GETPOST ( 'hideref' , 'int' ) ? GETPOST ( 'hideref' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_REF ) ? 1 : 0 ));
2012-05-21 17:12:57 +02:00
2009-11-28 13:06:11 +01:00
// Nombre de ligne pour choix de produit/service predefinis
2014-02-23 20:10:05 +01:00
$NBLINES = 4 ;
2008-08-12 20:20:18 +02:00
2019-11-12 00:15:34 +01:00
$usehm = ( ! empty ( $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE ) ? $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE : 0 );
2008-10-02 00:24:31 +02:00
2014-02-23 20:10:05 +01:00
$object = new Facture ( $db );
2013-03-06 04:17:14 +01:00
$extrafields = new ExtraFields ( $db );
2008-08-12 20:20:18 +02:00
2020-02-19 01:23:54 +01:00
// Fetch optionals attributes and labels
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2012-07-02 19:30:37 +02:00
// Load object
2019-11-12 00:15:34 +01:00
if ( $id > 0 || ! empty ( $ref )) {
2020-01-16 02:48:24 +01:00
if ( $action != 'add' ) {
2021-06-29 16:33:24 +02:00
if ( empty ( $conf -> global -> INVOICE_USE_SITUATION )) {
$fetch_situation = false ;
} else {
$fetch_situation = true ;
}
$ret = $object -> fetch ( $id , $ref , '' , '' , $fetch_situation );
2020-01-16 02:48:24 +01:00
}
2012-05-10 19:26:44 +02:00
}
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2019-11-12 00:15:34 +01:00
$hookmanager -> initHooks ( array ( 'invoicecard' , 'globalcard' ));
2010-09-12 20:01:29 +02:00
2022-08-08 11:39:43 +02:00
$usercanread = $user -> hasRight ( " facture " , " lire " );
$usercancreate = $user -> hasRight ( " facture " , " creer " );
$usercanissuepayment = $user -> hasRight ( " facture " , " paiement " );
$usercandelete = $user -> hasRight ( " facture " , " supprimer " );
$usercancreatecontract = $user -> hasRight ( " contrat " , " creer " );
2019-11-12 00:15:34 +01:00
$usercanvalidate = (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && $usercancreate ) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> facture -> invoice_advance -> validate )));
2021-04-25 13:17:47 +02:00
$usercansend = ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> facture -> invoice_advance -> send )));
$usercanreopen = (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && $usercancreate ) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> facture -> invoice_advance -> reopen )));
if ( ! empty ( $conf -> global -> INVOICE_DISALLOW_REOPEN )) {
$usercanreopen = false ;
}
2019-11-12 00:15:34 +01:00
$usercanunvalidate = (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $usercancreate )) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> facture -> invoice_advance -> unvalidate )));
2018-11-14 14:59:36 +01:00
$usercanproductignorepricemin = (( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> produit -> ignore_price_min_advance )) || empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ));
2022-05-21 17:27:52 +02:00
$usercancreatemargin = ( ! empty ( $user -> rights -> margins -> creer ) ? $user -> rights -> margins -> creer : 0 );
$usercanreadallmargin = ( ! empty ( $user -> rights -> margins -> liretous ) ? $user -> rights -> margins -> liretous : 0 );
$usercancreatewithdrarequest = ( ! empty ( $user -> rights -> prelevement -> bons -> creer ) ? $user -> rights -> prelevement -> bons -> creer : 0 );
2018-11-14 14:59:36 +01:00
$permissionnote = $usercancreate ; // Used by the include of actions_setnotes.inc.php
2019-11-12 00:15:34 +01:00
$permissiondellink = $usercancreate ; // Used by the include of actions_dellink.inc.php
2018-11-14 14:59:36 +01:00
$permissiontoedit = $usercancreate ; // Used by the include of actions_lineupdonw.inc.php
2019-04-12 12:12:08 +02:00
$permissiontoadd = $usercancreate ; // Used by the include of actions_addupdatedelete.inc.php
2010-09-12 20:01:29 +02:00
2020-02-19 11:54:55 +01:00
// retained warranty invoice available type
2020-04-23 18:55:10 +02:00
$retainedWarrantyInvoiceAvailableType = array ();
if ( ! empty ( $conf -> global -> INVOICE_USE_RETAINED_WARRANTY )) {
2020-04-01 12:12:30 +02:00
$retainedWarrantyInvoiceAvailableType = explode ( '+' , $conf -> global -> INVOICE_USE_RETAINED_WARRANTY );
2020-02-19 11:54:55 +01:00
}
2020-01-19 15:19:07 +01:00
2018-10-29 18:19:40 +01:00
// Security check
2021-02-23 21:09:01 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2018-10-29 18:28:19 +01:00
$isdraft = (( $object -> statut == Facture :: STATUS_DRAFT ) ? 1 : 0 );
2022-03-30 18:41:45 +02:00
$result = restrictedArea ( $user , 'facture' , $object -> id , '' , '' , 'fk_soc' , 'rowid' , $isdraft );
2020-01-19 15:19:07 +01:00
2020-02-19 01:23:54 +01:00
2011-10-01 21:55:40 +02:00
/*
* Actions
*/
2008-08-12 20:20:18 +02:00
2014-02-23 20:10:05 +01:00
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 21:09:01 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2012-05-04 18:30:35 +02:00
2021-02-23 15:35:16 +01:00
if ( empty ( $reshook )) {
2021-09-02 21:35:36 +02:00
$backurlforlist = DOL_URL_ROOT . '/compta/facture/list.php' ;
if ( empty ( $backtopage ) || ( $cancel && empty ( $id ))) {
if ( empty ( $backtopage ) || ( $cancel && strpos ( $backtopage , '__ID__' ))) {
if ( empty ( $id ) && (( $action != 'add' && $action != 'create' ) || $cancel )) {
$backtopage = $backurlforlist ;
} else {
$backtopage = DOL_URL_ROOT . '/compta/facture/card.php?id=' . (( ! empty ( $id ) && $id > 0 ) ? $id : '__ID__' );
}
}
}
2021-02-23 15:35:16 +01:00
if ( $cancel ) {
2021-09-02 21:35:36 +02:00
if ( ! empty ( $backtopageforcancel )) {
header ( " Location: " . $backtopageforcancel );
exit ;
} elseif ( ! empty ( $backtopage )) {
2017-09-17 15:38:50 +02:00
header ( " Location: " . $backtopage );
exit ;
}
2019-11-12 00:15:34 +01:00
$action = '' ;
2017-09-17 15:38:50 +02:00
}
2016-04-24 18:55:19 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php' ; // Must be include, not include_once
2015-07-28 14:13:16 +02:00
2019-11-12 00:15:34 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php' ; // Must be include, not include_once
2015-07-28 14:13:16 +02:00
2019-11-12 00:15:34 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_lineupdown.inc.php' ; // Must be include, not include_once
2015-01-17 19:28:27 +01:00
// Action clone object
2021-04-26 14:30:44 +02:00
if ( $action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd ) {
2020-10-31 14:32:18 +01:00
$objectutil = dol_clone ( $object , 1 ); // To avoid to denaturate loaded object when setting some properties for clone. We use native clone to keep this->db valid.
$objectutil -> date = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'newdatemonth' , 'int' ), GETPOST ( 'newdateday' , 'int' ), GETPOST ( 'newdateyear' , 'int' ));
$objectutil -> socid = $socid ;
$result = $objectutil -> createFromClone ( $user , $id );
if ( $result > 0 ) {
2021-04-26 09:24:00 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $result );
exit ();
} else {
$langs -> load ( " errors " );
2021-06-25 16:40:39 +02:00
setEventMessages ( $objectutil -> error , $objectutil -> errors , 'errors' );
2021-04-26 09:24:00 +02:00
$action = '' ;
2020-10-31 14:32:18 +01:00
}
2021-04-27 01:17:26 +02:00
} elseif ( $action == 'reopen' && $usercanreopen ) {
2015-01-17 19:28:27 +01:00
$result = $object -> fetch ( $id );
2019-06-27 01:13:46 +02:00
if ( $object -> statut == Facture :: STATUS_CLOSED || ( $object -> statut == Facture :: STATUS_ABANDONED && ( $object -> close_code != 'replaced' || $object -> getIdReplacingInvoice () == 0 )) || ( $object -> statut == Facture :: STATUS_VALIDATED && $object -> paye == 1 )) { // ($object->statut == 1 && $object->paye == 1) should not happened but can be found when data are corrupted
2021-02-09 09:40:07 +01:00
$result = $object -> setUnpaid ( $user );
2014-02-23 20:10:05 +01:00
if ( $result > 0 ) {
2019-11-12 00:15:34 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $id );
2014-02-23 20:10:05 +01:00
exit ();
} else {
2015-11-15 07:47:35 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2013-04-20 00:10:20 +02:00
}
}
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'confirm_delete' && $confirm == 'yes' ) {
// Delete invoice
2015-01-17 19:28:27 +01:00
$result = $object -> fetch ( $id );
$object -> fetch_thirdparty ();
$idwarehouse = GETPOST ( 'idwarehouse' );
2008-11-20 22:30:23 +01:00
2015-01-17 19:28:27 +01:00
$qualified_for_stock_change = 0 ;
if ( empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
$qualified_for_stock_change = $object -> hasProductsOrServices ( 2 );
} else {
$qualified_for_stock_change = $object -> hasProductsOrServices ( 1 );
}
2008-11-20 22:30:23 +01:00
2019-11-12 00:15:34 +01:00
$isErasable = $object -> is_erasable ();
2018-10-29 14:56:00 +01:00
2018-11-14 14:59:36 +01:00
if (( $usercandelete && $isErasable > 0 )
2021-02-23 21:09:01 +01:00
|| ( $usercancreate && $isErasable == 1 )) {
2018-05-18 15:20:16 +02:00
$result = $object -> delete ( $user , 0 , $idwarehouse );
if ( $result > 0 ) {
2019-11-12 00:15:34 +01:00
header ( 'Location: ' . DOL_URL_ROOT . '/compta/facture/list.php?restore_lastsearch_values=1' );
2018-05-18 15:20:16 +02:00
exit ();
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2019-11-12 00:15:34 +01:00
$action = '' ;
2018-05-18 15:20:16 +02:00
}
2013-04-20 00:10:20 +02:00
}
2021-03-01 20:37:16 +01:00
} elseif ( $action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate ) {
// Delete line
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
$object -> fetch_thirdparty ();
2014-03-01 19:45:13 +01:00
2021-04-25 15:55:36 +02:00
$result = $object -> deleteline ( GETPOST ( 'lineid' , 'int' ));
2015-01-17 19:28:27 +01:00
if ( $result > 0 ) {
2021-11-17 12:10:12 +01:00
// reorder lines
$object -> line_order ( true );
2015-01-17 19:28:27 +01:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
2021-04-25 15:55:36 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' )) {
$newlang = GETPOST ( 'lang_id' );
2021-02-23 21:09:01 +01:00
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
2015-01-18 17:13:42 +01:00
$newlang = $object -> thirdparty -> default_lang ;
2021-02-23 21:09:01 +01:00
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $newlang )) {
2015-01-17 19:28:27 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
2018-02-08 12:53:26 +01:00
$outputlangs -> load ( 'products' );
2015-01-17 19:28:27 +01:00
}
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
$ret = $object -> fetch ( $id ); // Reload to get new records
2020-09-10 01:49:09 +02:00
$result = $object -> generateDocument ( $object -> model_pdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2015-01-17 19:28:27 +01:00
}
if ( $result >= 0 ) {
2019-11-12 00:15:34 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $id );
2015-01-17 19:28:27 +01:00
exit ();
}
} else {
2015-11-15 07:47:35 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-17 19:28:27 +01:00
$action = '' ;
}
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'unlinkdiscount' && $usercancreate ) {
// Delete link of credit note to invoice
2015-01-17 19:28:27 +01:00
$discount = new DiscountAbsolute ( $db );
2015-01-18 17:13:42 +01:00
$result = $discount -> fetch ( GETPOST ( " discountid " ));
2015-01-17 19:28:27 +01:00
$discount -> unlink_invoice ();
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'valid' && $usercancreate ) {
// Validation
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
2014-03-01 19:45:13 +01:00
2022-03-01 17:18:29 +01:00
if ( ! empty ( $conf -> global -> INVOICE_CHECK_POSTERIOR_DATE )) {
2022-05-16 21:01:48 +02:00
$last_of_type = $object -> willBeLastOfSameType ( true );
2022-03-01 17:18:29 +01:00
if ( empty ( $object -> date_validation ) && ! $last_of_type [ 0 ]) {
2022-03-02 12:53:44 +01:00
setEventMessages ( $langs -> transnoentities ( " ErrorInvoiceIsNotLastOfSameType " , $object -> ref , dol_print_date ( $object -> date , 'day' ), dol_print_date ( $last_of_type [ 1 ], 'day' )), null , 'errors' );
2022-03-24 11:09:39 +01:00
$action = '' ;
2022-03-01 17:18:29 +01:00
}
}
2015-01-17 19:28:27 +01:00
// On verifie signe facture
if ( $object -> type == Facture :: TYPE_CREDIT_NOTE ) {
// Si avoir, le signe doit etre negatif
if ( $object -> total_ht >= 0 ) {
2015-11-15 07:47:35 +01:00
setEventMessages ( $langs -> trans ( " ErrorInvoiceAvoirMustBeNegative " ), null , 'errors' );
2015-01-17 19:28:27 +01:00
$action = '' ;
}
} else {
2019-10-17 15:40:02 +02:00
// If not a credit note, amount with tax must be positive or nul.
// Note that amount excluding tax can be negative because you can have a invoice of 100 with vat of 20 that
// consumes a credit note of 100 with vat 0 (total with tax is 0 but without tax is -20).
// For some cases, credit notes can have a vat of 0 (for example when selling goods in France).
if ( empty ( $conf -> global -> FACTURE_ENABLE_NEGATIVE ) && $object -> total_ttc < 0 ) {
2015-11-15 07:47:35 +01:00
setEventMessages ( $langs -> trans ( " ErrorInvoiceOfThisTypeMustBePositive " ), null , 'errors' );
2015-01-17 19:28:27 +01:00
$action = '' ;
}
2020-01-19 15:19:07 +01:00
// Also negative lines should not be allowed on 'non Credit notes' invoices. A test is done when adding or updating lines but we must
// do it again in validation to avoid cases where invoice is created from another object that allow negative lines.
2020-03-04 00:38:04 +01:00
// Note that we can accept the negative line if sum with other lines with same vat makes total positive: Because all the lines will be merged together
2020-01-19 15:19:07 +01:00
// when converted into 'available credit' and we will get a positive available credit line.
// Note: Other solution if you want to add a negative line on invoice, is to create a discount for customer and consumme it (but this is possible on standard invoice only).
2020-03-04 00:38:04 +01:00
$array_of_total_ht_per_vat_rate = array ();
$array_of_total_ht_devise_per_vat_rate = array ();
2020-01-30 01:48:28 +01:00
foreach ( $object -> lines as $line ) {
2020-03-26 01:24:27 +01:00
//$vat_src_code_for_line = $line->vat_src_code; // TODO We chek sign of total per vat without taking into account the vat code because for the moment the vat code is lost/unknown when we add a down payment.
$vat_src_code_for_line = '' ;
2021-02-23 21:09:01 +01:00
if ( empty ( $array_of_total_ht_per_vat_rate [ $line -> tva_tx . '_' . $vat_src_code_for_line ])) {
$array_of_total_ht_per_vat_rate [ $line -> tva_tx . '_' . $vat_src_code_for_line ] = 0 ;
}
if ( empty ( $array_of_total_ht_devise_per_vat_rate [ $line -> tva_tx . '_' . $vat_src_code_for_line ])) {
$array_of_total_ht_devise_per_vat_rate [ $line -> tva_tx . '_' . $vat_src_code_for_line ] = 0 ;
}
2020-03-26 01:24:27 +01:00
$array_of_total_ht_per_vat_rate [ $line -> tva_tx . '_' . $vat_src_code_for_line ] += $line -> total_ht ;
$array_of_total_ht_devise_per_vat_rate [ $line -> tva_tx . '_' . $vat_src_code_for_line ] += $line -> multicurrency_total_ht ;
2020-01-19 15:19:07 +01:00
}
2020-03-04 00:38:04 +01:00
//var_dump($array_of_total_ht_per_vat_rate);exit;
2021-02-23 15:35:16 +01:00
foreach ( $array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue ) {
2021-08-10 10:23:56 +02:00
$tmp_total_ht = price2num ( $array_of_total_ht_per_vat_rate [ $vatrate ]);
$tmp_total_ht_devise = price2num ( $array_of_total_ht_devise_per_vat_rate [ $vatrate ]);
2020-01-19 15:19:07 +01:00
2021-02-23 15:35:16 +01:00
if (( $tmp_total_ht < 0 || $tmp_total_ht_devise < 0 ) && empty ( $conf -> global -> FACTURE_ENABLE_NEGATIVE_LINES )) {
2020-01-19 15:19:07 +01:00
if ( $object -> type == $object :: TYPE_DEPOSIT ) {
2020-06-19 14:50:33 +02:00
$langs -> load ( " errors " );
2020-01-19 15:19:07 +01:00
// Using negative lines on deposit lead to headach and blocking problems when you want to consume them.
setEventMessages ( $langs -> trans ( " ErrorLinesCantBeNegativeOnDeposits " ), null , 'errors' );
2020-06-19 14:50:33 +02:00
$error ++ ;
$action = '' ;
2020-01-19 15:19:07 +01:00
} else {
2020-06-19 14:50:33 +02:00
$tmpvatratetoshow = explode ( '_' , $vatrate );
$tmpvatratetoshow [ 0 ] = round ( $tmpvatratetoshow [ 0 ], 2 );
if ( $tmpvatratetoshow [ 0 ] != 0 ) {
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " ErrorLinesCantBeNegativeForOneVATRate " , $tmpvatratetoshow [ 0 ]), null , 'errors' );
$error ++ ;
$action = '' ;
}
2020-01-19 15:19:07 +01:00
}
}
}
2012-05-06 02:27:09 +02:00
}
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'classin' && $usercancreate ) {
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
2022-02-22 23:44:56 +01:00
$object -> setProject ( GETPOST ( 'projectid' , 'int' ));
2021-02-23 15:35:16 +01:00
} elseif ( $action == 'setmode' && $usercancreate ) {
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
$result = $object -> setPaymentMethods ( GETPOST ( 'mode_reglement_id' , 'int' ));
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
2015-01-17 19:28:27 +01:00
dol_print_error ( $db , $object -> error );
2021-02-23 21:09:01 +01:00
}
2021-02-23 15:35:16 +01:00
} elseif ( $action == 'setretainedwarrantyconditions' && $user -> rights -> facture -> creer ) {
2020-10-31 14:32:18 +01:00
$object -> fetch ( $id );
$object -> retained_warranty_fk_cond_reglement = 0 ; // To clean property
$result = $object -> setRetainedWarrantyPaymentTerms ( GETPOST ( 'retained_warranty_fk_cond_reglement' , 'int' ));
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
dol_print_error ( $db , $object -> error );
}
2020-10-31 14:32:18 +01:00
$old_rw_date_lim_reglement = $object -> retained_warranty_date_limit ;
$new_rw_date_lim_reglement = $object -> calculate_date_lim_reglement ( $object -> retained_warranty_fk_cond_reglement );
2021-02-23 21:09:01 +01:00
if ( $new_rw_date_lim_reglement > $old_rw_date_lim_reglement ) {
$object -> retained_warranty_date_limit = $new_rw_date_lim_reglement ;
}
if ( $object -> retained_warranty_date_limit < $object -> date ) {
$object -> retained_warranty_date_limit = $object -> date ;
}
2020-10-31 14:32:18 +01:00
$result = $object -> update ( $user );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
dol_print_error ( $db , $object -> error );
}
2020-11-29 15:16:53 +01:00
} elseif ( $action == 'setretainedwarranty' && $user -> rights -> facture -> creer ) {
2020-10-31 14:32:18 +01:00
$object -> fetch ( $id );
$result = $object -> setRetainedWarranty ( GETPOST ( 'retained_warranty' , 'float' ));
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
2020-10-31 14:32:18 +01:00
dol_print_error ( $db , $object -> error );
2021-02-23 21:09:01 +01:00
}
2020-11-29 15:16:53 +01:00
} elseif ( $action == 'setretainedwarrantydatelimit' && $user -> rights -> facture -> creer ) {
2020-10-31 14:32:18 +01:00
$object -> fetch ( $id );
$result = $object -> setRetainedWarrantyDateLimit ( GETPOST ( 'retained_warranty_date_limit' , 'float' ));
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
2020-10-31 14:32:18 +01:00
dol_print_error ( $db , $object -> error );
2021-02-23 21:09:01 +01:00
}
2021-02-23 15:35:16 +01:00
} elseif ( $action == 'setmulticurrencycode' && $usercancreate ) { // Multicurrency Code
2016-01-23 16:01:55 +01:00
$result = $object -> setMulticurrencyCode ( GETPOST ( 'multicurrency_code' , 'alpha' ));
2021-02-23 15:35:16 +01:00
} elseif ( $action == 'setmulticurrencyrate' && $usercancreate ) { // Multicurrency rate
2016-12-10 22:07:25 +01:00
$result = $object -> setMulticurrencyRate ( price2num ( GETPOST ( 'multicurrency_tx' )), GETPOST ( 'calculation_mode' , 'int' ));
2020-11-29 15:16:53 +01:00
} elseif ( $action == 'setinvoicedate' && $usercancreate ) {
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
$old_date_lim_reglement = $object -> date_lim_reglement ;
2021-09-23 02:10:39 +02:00
$newdate = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'invoicedatemonth' , 'int' ), GETPOST ( 'invoicedateday' , 'int' ), GETPOST ( 'invoicedateyear' , 'int' ), 'tzserver' );
if ( empty ( $newdate )) {
2017-10-16 08:47:05 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Date " )), null , 'errors' );
2021-09-23 02:10:39 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $id . '&action=editinvoicedate&token=' . newToken ());
2017-10-16 08:47:05 +02:00
exit ;
2015-01-17 19:28:27 +01:00
}
2021-09-23 02:10:39 +02:00
if ( $newdate > ( dol_now ( 'tzuserrel' ) + ( empty ( $conf -> global -> INVOICE_MAX_FUTURE_DELAY ) ? 0 : $conf -> global -> INVOICE_MAX_FUTURE_DELAY ))) {
if ( empty ( $conf -> global -> INVOICE_MAX_FUTURE_DELAY )) {
setEventMessages ( $langs -> trans ( " WarningInvoiceDateInFuture " ), null , 'warnings' );
} else {
setEventMessages ( $langs -> trans ( " WarningInvoiceDateTooFarInFuture " ), null , 'warnings' );
}
}
$object -> date = $newdate ;
2015-01-17 19:28:27 +01:00
$new_date_lim_reglement = $object -> calculate_date_lim_reglement ();
2021-02-23 21:09:01 +01:00
if ( $new_date_lim_reglement > $old_date_lim_reglement ) {
$object -> date_lim_reglement = $new_date_lim_reglement ;
}
if ( $object -> date_lim_reglement < $object -> date ) {
$object -> date_lim_reglement = $object -> date ;
}
2015-01-17 19:28:27 +01:00
$result = $object -> update ( $user );
2020-04-07 14:06:08 +02:00
if ( $result < 0 ) {
dol_print_error ( $db , $object -> error );
}
2020-11-29 15:16:53 +01:00
} elseif ( $action == 'setdate_pointoftax' && $usercancreate ) {
2016-05-29 23:56:58 +02:00
$object -> fetch ( $id );
2021-09-23 02:10:39 +02:00
$date_pointoftax = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'date_pointoftaxmonth' , 'int' ), GETPOST ( 'date_pointoftaxday' , 'int' ), GETPOST ( 'date_pointoftaxyear' , 'int' ), 'tzserver' );
2019-11-12 00:15:34 +01:00
$object -> date_pointoftax = $date_pointoftax ;
2016-05-29 23:56:58 +02:00
$result = $object -> update ( $user );
2020-04-07 14:06:08 +02:00
if ( $result < 0 ) {
dol_print_error ( $db , $object -> error );
}
2021-02-23 15:35:16 +01:00
} elseif ( $action == 'setconditions' && $usercancreate ) {
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
$object -> cond_reglement_code = 0 ; // To clean property
$object -> cond_reglement_id = 0 ; // To clean property
2008-08-12 20:20:18 +02:00
2020-10-22 18:39:45 +02:00
$error = 0 ;
2020-10-23 03:41:26 +02:00
2020-10-22 18:28:27 +02:00
$db -> begin ();
2020-10-31 14:32:18 +01:00
if ( ! $error ) {
2020-10-22 18:39:45 +02:00
$result = $object -> setPaymentTerms ( GETPOST ( 'cond_reglement_id' , 'int' ));
if ( $result < 0 ) {
2020-10-31 14:32:18 +01:00
$error ++ ;
2020-10-22 18:39:45 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2020-10-22 18:28:27 +02:00
}
2020-10-23 03:41:26 +02:00
2020-10-31 14:32:18 +01:00
if ( ! $error ) {
2020-10-22 18:39:45 +02:00
$old_date_lim_reglement = $object -> date_lim_reglement ;
$new_date_lim_reglement = $object -> calculate_date_lim_reglement ();
2021-02-23 21:09:01 +01:00
if ( $new_date_lim_reglement > $old_date_lim_reglement ) {
$object -> date_lim_reglement = $new_date_lim_reglement ;
}
if ( $object -> date_lim_reglement < $object -> date ) {
$object -> date_lim_reglement = $object -> date ;
}
2020-10-22 18:39:45 +02:00
$result = $object -> update ( $user );
if ( $result < 0 ) {
2020-10-31 14:32:18 +01:00
$error ++ ;
2020-10-22 18:39:45 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
2020-10-23 03:41:26 +02:00
2020-10-22 18:39:45 +02:00
if ( $error ) {
2020-10-23 03:41:26 +02:00
$db -> rollback ();
2020-10-22 18:39:45 +02:00
} else {
$db -> commit ();
2020-04-07 14:06:08 +02:00
}
2021-02-23 15:35:16 +01:00
} elseif ( $action == 'setpaymentterm' && $usercancreate ) {
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
2022-02-22 23:44:56 +01:00
$object -> date_lim_reglement = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'paymenttermmonth' , 'int' ), GETPOST ( 'paymenttermday' , 'int' ), GETPOST ( 'paymenttermyear' , 'int' ));
2015-01-17 19:28:27 +01:00
if ( $object -> date_lim_reglement < $object -> date ) {
$object -> date_lim_reglement = $object -> calculate_date_lim_reglement ();
2015-11-15 07:47:35 +01:00
setEventMessages ( $langs -> trans ( " DatePaymentTermCantBeLowerThanObjectDate " ), null , 'warnings' );
2015-01-17 19:28:27 +01:00
}
$result = $object -> update ( $user );
2020-04-07 14:06:08 +02:00
if ( $result < 0 ) {
2015-01-17 19:28:27 +01:00
dol_print_error ( $db , $object -> error );
2020-04-07 14:06:08 +02:00
}
2021-02-23 15:35:16 +01:00
} elseif ( $action == 'setrevenuestamp' && $usercancreate ) {
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
$object -> revenuestamp = GETPOST ( 'revenuestamp' );
$result = $object -> update ( $user );
$object -> update_price ( 1 );
2020-04-07 14:06:08 +02:00
if ( $result < 0 ) {
2015-01-17 19:28:27 +01:00
dol_print_error ( $db , $object -> error );
2020-04-07 14:06:08 +02:00
} else {
// Define output language
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2020-04-07 14:06:08 +02:00
$outputlangs = $langs ;
$newlang = '' ;
2021-02-23 21:09:01 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
2020-04-07 14:06:08 +02:00
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
$outputlangs -> load ( 'products' );
}
2020-09-10 01:49:09 +02:00
$model = $object -> model_pdf ;
2020-04-07 14:06:08 +02:00
$ret = $object -> fetch ( $id ); // Reload to get new records
$result = $object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2020-04-07 14:06:08 +02:00
}
}
2022-08-29 12:01:36 +02:00
} elseif ( $action == 'set_incoterms' && isModEnabled ( 'incoterm' )) { // Set incoterm
2017-10-16 08:47:05 +02:00
$result = $object -> setIncoterms ( GETPOST ( 'incoterm_id' , 'int' ), GETPOST ( 'location_incoterms' , 'alpha' ));
2021-02-23 15:35:16 +01:00
} elseif ( $action == 'setbankaccount' && $usercancreate ) { // bank account
2019-11-12 00:15:34 +01:00
$result = $object -> setBankAccount ( GETPOST ( 'fk_account' , 'int' ));
2021-01-31 12:48:40 +01:00
} elseif ( $action == 'setremisepercent' && $usercancreate ) {
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
2021-09-08 22:00:16 +02:00
$result = $object -> setDiscount ( $user , price2num ( GETPOST ( 'remise_percent' ), '' , 2 ));
2021-01-31 12:48:40 +01:00
} elseif ( $action == " setabsolutediscount " && $usercancreate ) {
2022-03-30 18:41:45 +02:00
// We have POST[remise_id] or POST[remise_id_for_payment]
$db -> begin ();
2017-09-19 00:24:52 +02:00
// We use the credit to reduce amount of invoice
2020-03-26 02:21:50 +01:00
if ( GETPOST ( " remise_id " , 'int' ) > 0 ) {
2015-01-17 19:28:27 +01:00
$ret = $object -> fetch ( $id );
if ( $ret > 0 ) {
2020-03-26 02:21:50 +01:00
$result = $object -> insert_discount ( GETPOST ( " remise_id " , 'int' ));
2015-01-17 19:28:27 +01:00
if ( $result < 0 ) {
2015-11-15 07:47:35 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-17 19:28:27 +01:00
}
} else {
2022-03-30 18:41:45 +02:00
$error ++ ;
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2013-04-20 00:10:20 +02:00
}
}
2017-09-19 00:24:52 +02:00
// We use the credit to reduce remain to pay
2021-02-23 15:35:16 +01:00
if ( GETPOST ( " remise_id_for_payment " , 'int' ) > 0 ) {
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php' ;
2015-01-17 19:28:27 +01:00
$discount = new DiscountAbsolute ( $db );
2020-03-26 02:21:50 +01:00
$discount -> fetch ( GETPOST ( " remise_id_for_payment " , 'int' ));
2014-03-20 00:05:20 +01:00
2017-09-19 00:24:52 +02:00
//var_dump($object->getRemainToPay(0));
//var_dump($discount->amount_ttc);exit;
2022-03-30 18:41:45 +02:00
$remaintopay = $object -> getRemainToPay ( 0 );
if ( price2num ( $discount -> amount_ttc ) > price2num ( $remaintopay )) {
2017-09-19 00:24:52 +02:00
// TODO Split the discount in 2 automatically
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorDiscountLargerThanRemainToPaySplitItBefore " ), null , 'errors' );
}
2021-02-23 15:35:16 +01:00
if ( ! $error ) {
2017-09-19 00:24:52 +02:00
$result = $discount -> link_to_invoice ( 0 , $id );
if ( $result < 0 ) {
2022-03-30 18:41:45 +02:00
$error ++ ;
2017-09-19 00:24:52 +02:00
setEventMessages ( $discount -> error , $discount -> errors , 'errors' );
}
2013-04-20 00:10:20 +02:00
}
2022-03-30 18:41:45 +02:00
if ( ! $error ) {
$newremaintopay = $object -> getRemainToPay ( 0 );
if ( $newremaintopay == 0 ) {
$object -> setPaid ( $user );
}
}
2013-04-20 00:10:20 +02:00
}
2017-07-25 12:20:51 +02:00
2022-03-30 18:41:45 +02:00
if ( ! $error ) {
$db -> commit ();
} else {
$db -> rollback ();
2013-04-20 00:10:20 +02:00
}
2017-07-25 12:20:51 +02:00
2022-03-30 18:41:45 +02:00
if ( empty ( $error ) && empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2017-07-25 12:20:51 +02:00
$outputlangs = $langs ;
$newlang = '' ;
2021-02-23 21:09:01 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $newlang )) {
2017-07-25 12:20:51 +02:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$ret = $object -> fetch ( $id ); // Reload to get new records
2020-09-10 01:49:09 +02:00
$result = $object -> generateDocument ( $object -> model_pdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2017-07-25 12:20:51 +02:00
}
2021-02-23 15:35:16 +01:00
} elseif ( $action == 'setref' && $usercancreate ) {
2019-12-16 22:30:16 +01:00
$object -> fetch ( $id );
$object -> setValueFrom ( 'ref' , GETPOST ( 'ref' ), '' , null , '' , '' , $user , 'BILL_MODIFY' );
2021-02-23 15:35:16 +01:00
} elseif ( $action == 'setref_client' && $usercancreate ) {
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
2016-09-21 01:25:34 +02:00
$object -> set_ref_client ( GETPOST ( 'ref_client' ));
2021-03-01 20:37:16 +01:00
} elseif ( $action == 'confirm_valid' && $confirm == 'yes' && $usercanvalidate ) {
// Classify to validated
2019-01-27 11:55:16 +01:00
$idwarehouse = GETPOST ( 'idwarehouse' , 'int' );
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
$object -> fetch_thirdparty ();
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
// Check for warehouse
2021-02-23 15:35:16 +01:00
if ( $object -> type != Facture :: TYPE_DEPOSIT && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_BILL )) {
2019-05-20 12:47:02 +02:00
$qualified_for_stock_change = 0 ;
if ( empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
$qualified_for_stock_change = $object -> hasProductsOrServices ( 2 );
} else {
$qualified_for_stock_change = $object -> hasProductsOrServices ( 1 );
}
2019-05-20 12:50:00 +02:00
2021-02-23 15:35:16 +01:00
if ( $qualified_for_stock_change ) {
2019-11-12 00:15:34 +01:00
if ( ! $idwarehouse || $idwarehouse == - 1 ) {
2019-05-20 12:47:02 +02:00
$error ++ ;
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( " Warehouse " )), null , 'errors' );
$action = '' ;
}
2015-01-17 19:28:27 +01:00
}
2014-02-23 20:10:05 +01:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( ! $error ) {
2015-01-17 19:28:27 +01:00
$result = $object -> validate ( $user , '' , $idwarehouse );
2021-02-23 15:35:16 +01:00
if ( $result >= 0 ) {
2015-01-17 19:28:27 +01:00
// Define output language
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2015-01-18 17:13:42 +01:00
$outputlangs = $langs ;
$newlang = '' ;
2022-09-07 08:57:51 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
2021-02-23 21:09:01 +01:00
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
2022-09-07 08:57:51 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && empty ( $newlang )) {
2021-02-23 21:09:01 +01:00
$newlang = $object -> thirdparty -> default_lang ;
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $newlang )) {
2015-01-18 17:13:42 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
2018-02-08 12:53:26 +01:00
$outputlangs -> load ( 'products' );
2015-01-18 17:13:42 +01:00
}
2020-09-10 01:49:09 +02:00
$model = $object -> model_pdf ;
2020-11-01 17:01:26 +01:00
2015-01-17 19:28:27 +01:00
$ret = $object -> fetch ( $id ); // Reload to get new records
2014-12-25 23:08:07 +01:00
2015-01-18 17:13:42 +01:00
$result = $object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2015-01-17 19:28:27 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 21:09:01 +01:00
if ( count ( $object -> errors )) {
setEventMessages ( null , $object -> errors , 'errors' );
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2013-04-20 00:10:20 +02:00
}
2014-10-27 19:37:30 +01:00
}
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'confirm_modif' && $usercanunvalidate ) {
// Go back to draft status (unvalidate)
2019-01-27 11:55:16 +01:00
$idwarehouse = GETPOST ( 'idwarehouse' , 'int' );
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
$object -> fetch_thirdparty ();
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
// Check parameters
2021-02-23 15:35:16 +01:00
if ( $object -> type != Facture :: TYPE_DEPOSIT && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_BILL )) {
2019-05-20 12:47:02 +02:00
$qualified_for_stock_change = 0 ;
if ( empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
$qualified_for_stock_change = $object -> hasProductsOrServices ( 2 );
} else {
$qualified_for_stock_change = $object -> hasProductsOrServices ( 1 );
}
2019-05-20 12:50:00 +02:00
2021-02-23 15:35:16 +01:00
if ( $qualified_for_stock_change ) {
2019-11-12 00:15:34 +01:00
if ( ! $idwarehouse || $idwarehouse == - 1 ) {
2019-05-20 12:47:02 +02:00
$error ++ ;
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( " Warehouse " )), null , 'errors' );
$action = '' ;
}
2013-04-20 00:10:20 +02:00
}
}
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
if ( ! $error ) {
2022-02-28 19:45:53 +01:00
// We check if invoice has payments
2015-01-17 19:28:27 +01:00
$sql = 'SELECT pf.amount' ;
2019-11-12 00:15:34 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf' ;
2021-08-27 23:36:06 +02:00
$sql .= ' WHERE pf.fk_facture = ' . (( int ) $object -> id );
2015-01-17 19:28:27 +01:00
$result = $db -> query ( $sql );
if ( $result ) {
$i = 0 ;
$num = $db -> num_rows ( $result );
while ( $i < $num ) {
$objp = $db -> fetch_object ( $result );
2022-05-22 17:09:08 +02:00
$totalpaid += $objp -> amount ;
2019-11-12 00:15:34 +01:00
$i ++ ;
2015-01-17 19:28:27 +01:00
}
} else {
dol_print_error ( $db , '' );
}
2014-03-01 19:45:13 +01:00
2022-05-22 17:09:08 +02:00
$resteapayer = $object -> total_ttc - $totalpaid ;
2014-03-01 19:45:13 +01:00
2019-07-05 21:50:35 +02:00
// We check that invlice lines are transferred into accountancy
2015-01-17 19:28:27 +01:00
$ventilExportCompta = $object -> getVentilExportCompta ();
2014-10-27 19:37:30 +01:00
2015-01-17 19:28:27 +01:00
// On verifie si aucun paiement n'a ete effectue
2021-02-23 15:35:16 +01:00
if ( $ventilExportCompta == 0 ) {
2022-04-05 17:39:56 +02:00
if ( ! empty ( $conf -> global -> INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE ) || ( $resteapayer == $object -> total_ttc && empty ( $object -> paye ))) {
2019-11-12 00:15:34 +01:00
$result = $object -> setDraft ( $user , $idwarehouse );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2014-12-25 23:08:07 +01:00
2017-09-27 16:29:33 +02:00
// Define output language
2021-02-23 15:35:16 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2017-09-27 16:29:33 +02:00
$outputlangs = $langs ;
$newlang = '' ;
2021-02-23 21:09:01 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $newlang )) {
2017-09-27 16:29:33 +02:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
2018-02-08 12:58:47 +01:00
$outputlangs -> load ( 'products' );
2017-09-27 16:29:33 +02:00
}
2020-09-10 01:49:09 +02:00
$model = $object -> model_pdf ;
2017-09-27 16:29:33 +02:00
$ret = $object -> fetch ( $id ); // Reload to get new records
2014-12-25 23:08:07 +01:00
2017-09-27 16:29:33 +02:00
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
2015-01-17 19:28:27 +01:00
}
2013-04-20 00:10:20 +02:00
}
}
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'confirm_paid' && $confirm == 'yes' && $usercanissuepayment ) {
// Classify "paid"
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
2021-02-09 10:26:17 +01:00
$result = $object -> setPaid ( $user );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
} elseif ( $action == 'confirm_paid_partially' && $confirm == 'yes' && $usercanissuepayment ) {
// Classif "paid partialy"
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
2020-09-18 01:29:17 +02:00
$close_code = GETPOST ( " close_code " , 'restricthtml' );
$close_note = GETPOST ( " close_note " , 'restricthtml' );
2015-01-17 19:28:27 +01:00
if ( $close_code ) {
2021-02-09 10:26:17 +01:00
$result = $object -> setPaid ( $user , $close_code , $close_note );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2015-01-17 19:28:27 +01:00
} else {
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Reason " )), null , 'errors' );
2015-01-17 19:28:27 +01:00
}
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'confirm_canceled' && $confirm == 'yes' ) {
// Classify "abandoned"
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
2020-09-18 01:29:17 +02:00
$close_code = GETPOST ( " close_code " , 'restricthtml' );
$close_note = GETPOST ( " close_note " , 'restricthtml' );
2015-01-17 19:28:27 +01:00
if ( $close_code ) {
2021-02-09 13:10:11 +01:00
$result = $object -> setCanceled ( $user , $close_code , $close_note );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2015-01-17 19:28:27 +01:00
} else {
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Reason " )), null , 'errors' );
2015-01-17 19:28:27 +01:00
}
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'confirm_converttoreduc' && $confirm == 'yes' && $usercancreate ) {
// Convertir en reduc
2015-01-17 19:28:27 +01:00
$object -> fetch ( $id );
$object -> fetch_thirdparty ();
//$object->fetch_lines(); // Already done into fetch
2014-03-19 22:30:25 +01:00
2015-01-17 19:28:27 +01:00
// Check if there is already a discount (protection to avoid duplicate creation when resubmit post)
2019-11-12 00:15:34 +01:00
$discountcheck = new DiscountAbsolute ( $db );
$result = $discountcheck -> fetch ( 0 , $object -> id );
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
$canconvert = 0 ;
2021-02-23 21:09:01 +01:00
if ( $object -> type == Facture :: TYPE_DEPOSIT && empty ( $discountcheck -> id )) {
$canconvert = 1 ; // we can convert deposit into discount if deposit is payed (completely, partially or not at all) and not already converted (see real condition into condition used to show button converttoreduc)
}
if (( $object -> type == Facture :: TYPE_CREDIT_NOTE || $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_SITUATION ) && $object -> paye == 0 && empty ( $discountcheck -> id )) {
$canconvert = 1 ; // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc)
}
2021-02-23 15:35:16 +01:00
if ( $canconvert ) {
2015-01-17 19:28:27 +01:00
$db -> begin ();
2014-03-01 19:45:13 +01:00
2017-04-30 12:55:11 +02:00
$amount_ht = $amount_tva = $amount_ttc = array ();
2019-02-18 18:27:06 +01:00
$multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array ();
2017-06-07 16:44:04 +02:00
2017-04-30 12:55:11 +02:00
// Loop on each vat rate
2015-01-17 19:28:27 +01:00
$i = 0 ;
2021-02-23 15:35:16 +01:00
foreach ( $object -> lines as $line ) {
if ( $line -> product_type < 9 && $line -> total_ht != 0 ) { // Remove lines with product_type greater than or equal to 9 and no need to create discount if amount is null
2020-03-26 02:13:34 +01:00
$keyforvatrate = $line -> tva_tx . ( $line -> vat_src_code ? ' (' . $line -> vat_src_code . ')' : '' );
$amount_ht [ $keyforvatrate ] += $line -> total_ht ;
$amount_tva [ $keyforvatrate ] += $line -> total_tva ;
$amount_ttc [ $keyforvatrate ] += $line -> total_ttc ;
$multicurrency_amount_ht [ $keyforvatrate ] += $line -> multicurrency_total_ht ;
$multicurrency_amount_tva [ $keyforvatrate ] += $line -> multicurrency_total_tva ;
$multicurrency_amount_ttc [ $keyforvatrate ] += $line -> multicurrency_total_ttc ;
2019-02-18 18:27:06 +01:00
$i ++ ;
2015-02-07 23:33:37 +01:00
}
2013-04-20 00:10:20 +02:00
}
2014-03-01 19:45:13 +01:00
2020-01-01 19:04:14 +01:00
// If some payments were already done, we change the amount to pay using same prorate
2021-08-30 09:34:59 +02:00
if ( ! empty ( $conf -> global -> INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED ) && $object -> type == Facture :: TYPE_CREDIT_NOTE ) {
2020-01-30 01:48:28 +01:00
$alreadypaid = $object -> getSommePaiement (); // This can be not 0 if we allow to create credit to reuse from credit notes partially refunded.
2020-01-01 19:04:14 +01:00
if ( $alreadypaid && abs ( $alreadypaid ) < abs ( $object -> total_ttc )) {
$ratio = abs (( $object -> total_ttc - $alreadypaid ) / $object -> total_ttc );
2020-01-30 01:48:28 +01:00
foreach ( $amount_ht as $vatrate => $val ) {
2020-01-01 19:04:14 +01:00
$amount_ht [ $vatrate ] = price2num ( $amount_ht [ $vatrate ] * $ratio , 'MU' );
$amount_tva [ $vatrate ] = price2num ( $amount_tva [ $vatrate ] * $ratio , 'MU' );
$amount_ttc [ $vatrate ] = price2num ( $amount_ttc [ $vatrate ] * $ratio , 'MU' );
2020-03-26 02:13:34 +01:00
$multicurrency_amount_ht [ $vatrate ] = price2num ( $multicurrency_amount_ht [ $vatrate ] * $ratio , 'MU' );
$multicurrency_amount_tva [ $vatrate ] = price2num ( $multicurrency_amount_tva [ $vatrate ] * $ratio , 'MU' );
$multicurrency_amount_ttc [ $vatrate ] = price2num ( $multicurrency_amount_ttc [ $vatrate ] * $ratio , 'MU' );
2020-01-01 19:04:14 +01:00
}
}
}
//var_dump($amount_ht);var_dump($amount_tva);var_dump($amount_ttc);exit;
2015-01-17 19:28:27 +01:00
// Insert one discount by VAT rate category
$discount = new DiscountAbsolute ( $db );
2021-02-23 15:35:16 +01:00
if ( $object -> type == Facture :: TYPE_CREDIT_NOTE ) {
2015-01-17 19:28:27 +01:00
$discount -> description = '(CREDIT_NOTE)' ;
2021-02-23 15:35:16 +01:00
} elseif ( $object -> type == Facture :: TYPE_DEPOSIT ) {
2015-01-17 19:28:27 +01:00
$discount -> description = '(DEPOSIT)' ;
2021-02-23 15:35:16 +01:00
} elseif ( $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_REPLACEMENT || $object -> type == Facture :: TYPE_SITUATION ) {
2016-11-24 15:48:04 +01:00
$discount -> description = '(EXCESS RECEIVED)' ;
2021-02-23 15:35:16 +01:00
} else {
2015-11-15 07:47:35 +01:00
setEventMessages ( $langs -> trans ( 'CantConvertToReducAnInvoiceOfThisType' ), null , 'errors' );
2015-01-17 19:28:27 +01:00
}
$discount -> fk_soc = $object -> socid ;
$discount -> fk_facture_source = $object -> id ;
$error = 0 ;
2017-06-07 16:44:04 +02:00
2021-02-23 15:35:16 +01:00
if ( $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_REPLACEMENT || $object -> type == Facture :: TYPE_SITUATION ) {
2017-04-30 12:55:11 +02:00
// If we're on a standard invoice, we have to get excess received to create a discount in TTC without VAT
2017-06-07 16:44:04 +02:00
2019-01-23 15:09:57 +01:00
// Total payments
2017-06-09 09:25:15 +02:00
$sql = 'SELECT SUM(pf.amount) as total_paiements' ;
2019-11-12 00:15:34 +01:00
$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' ;
2021-08-27 23:36:06 +02:00
$sql .= ' WHERE pf.fk_facture = ' . (( int ) $object -> id );
2019-11-12 00:15:34 +01:00
$sql .= ' AND pf.fk_paiement = p.rowid' ;
$sql .= ' AND p.entity IN (' . getEntity ( 'invoice' ) . ')' ;
2016-11-24 15:48:04 +01:00
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( ! $resql ) {
dol_print_error ( $db );
}
2017-08-24 15:39:23 +02:00
2016-11-24 15:48:04 +01:00
$res = $db -> fetch_object ( $resql );
$total_paiements = $res -> total_paiements ;
2017-06-07 16:44:04 +02:00
2019-01-23 15:09:57 +01:00
// Total credit note and deposit
$total_creditnote_and_deposit = 0 ;
2020-10-31 14:32:18 +01:00
$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 " ;
2021-08-27 16:33:03 +02:00
$sql .= " WHERE fk_facture = " . (( int ) $object -> id );
2020-10-31 14:32:18 +01:00
$resql = $db -> query ( $sql );
if ( ! empty ( $resql )) {
while ( $obj = $db -> fetch_object ( $resql )) {
$total_creditnote_and_deposit += $obj -> amount_ttc ;
}
2021-02-23 15:35:16 +01:00
} else {
dol_print_error ( $db );
}
2019-01-23 15:09:57 +01:00
$discount -> amount_ht = $discount -> amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object -> total_ttc ;
2016-11-24 15:48:04 +01:00
$discount -> amount_tva = 0 ;
$discount -> tva_tx = 0 ;
2020-03-26 02:13:34 +01:00
$discount -> vat_src_code = '' ;
2015-01-17 19:28:27 +01:00
$result = $discount -> create ( $user );
2021-02-23 15:35:16 +01:00
if ( $result < 0 ) {
2015-01-17 19:28:27 +01:00
$error ++ ;
}
2017-04-30 12:55:11 +02:00
}
2021-02-23 15:35:16 +01:00
if ( $object -> type == Facture :: TYPE_CREDIT_NOTE || $object -> type == Facture :: TYPE_DEPOSIT ) {
foreach ( $amount_ht as $tva_tx => $xxx ) {
2016-11-24 15:48:04 +01:00
$discount -> amount_ht = abs ( $amount_ht [ $tva_tx ]);
$discount -> amount_tva = abs ( $amount_tva [ $tva_tx ]);
$discount -> amount_ttc = abs ( $amount_ttc [ $tva_tx ]);
2018-10-17 15:49:08 +02:00
$discount -> multicurrency_amount_ht = abs ( $multicurrency_amount_ht [ $tva_tx ]);
$discount -> multicurrency_amount_tva = abs ( $multicurrency_amount_tva [ $tva_tx ]);
$discount -> multicurrency_amount_ttc = abs ( $multicurrency_amount_ttc [ $tva_tx ]);
2020-03-26 02:13:34 +01:00
// Clean vat code
$reg = array ();
$vat_src_code = '' ;
2021-02-23 21:09:01 +01:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx , $reg )) {
2020-03-26 02:13:34 +01:00
$vat_src_code = $reg [ 1 ];
$tva_tx = preg_replace ( '/\s*\(.*\)/' , '' , $tva_tx ); // Remove code into vatrate.
}
2016-11-24 15:48:04 +01:00
$discount -> tva_tx = abs ( $tva_tx );
2020-04-23 18:55:10 +02:00
$discount -> vat_src_code = $vat_src_code ;
2017-06-07 16:44:04 +02:00
2016-11-24 15:48:04 +01:00
$result = $discount -> create ( $user );
2021-02-23 15:35:16 +01:00
if ( $result < 0 ) {
2016-11-24 15:48:04 +01:00
$error ++ ;
break ;
}
}
2015-01-17 19:28:27 +01:00
}
2021-02-23 15:35:16 +01:00
if ( empty ( $error )) {
2019-11-12 00:15:34 +01:00
if ( $object -> type != Facture :: TYPE_DEPOSIT ) {
2017-11-11 12:07:55 +01:00
// Classe facture
2021-02-09 10:26:17 +01:00
$result = $object -> setPaid ( $user );
2021-02-23 15:35:16 +01:00
if ( $result >= 0 ) {
2017-11-11 12:07:55 +01:00
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2017-11-11 12:07:55 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$db -> rollback ();
}
} else {
2015-01-17 19:28:27 +01:00
$db -> commit ();
}
2020-05-21 15:05:19 +02:00
} else {
2015-11-15 07:47:35 +01:00
setEventMessages ( $discount -> error , $discount -> errors , 'errors' );
2013-04-20 00:10:20 +02:00
$db -> rollback ();
}
}
2022-02-28 19:45:53 +01:00
} elseif ( $action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercanissuepayment ) {
2021-02-23 21:09:01 +01:00
// Delete payment
2017-12-03 11:59:16 +01:00
$object -> fetch ( $id );
2021-02-23 15:35:16 +01:00
if ( $object -> statut == Facture :: STATUS_VALIDATED && $object -> paye == 0 ) {
2017-12-03 11:59:16 +01:00
$paiement = new Paiement ( $db );
2021-12-16 12:33:45 +01:00
$result = $paiement -> fetch ( GETPOST ( 'paiement_id' , 'int' ));
2017-12-03 11:59:16 +01:00
if ( $result > 0 ) {
2019-11-12 00:15:34 +01:00
$result = $paiement -> delete (); // If fetch ok and found
2021-12-16 12:33:45 +01:00
if ( $result >= 0 ) {
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
exit ;
}
2017-12-03 11:59:16 +01:00
}
if ( $result < 0 ) {
setEventMessages ( $paiement -> error , $paiement -> errors , 'errors' );
}
}
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'add' && $usercancreate ) {
// Insert new invoice in database
2021-02-23 15:35:16 +01:00
if ( $socid > 0 ) {
$object -> socid = GETPOST ( 'socid' , 'int' );
}
2020-10-25 09:28:41 +01:00
$selectedLines = GETPOST ( 'toselect' , 'array' );
2014-03-01 19:45:13 +01:00
2022-05-03 16:18:52 +02:00
if ( GETPOST ( 'type' , 'int' ) === '' ) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Type " )), null , 'errors' );
}
2015-01-17 19:28:27 +01:00
$db -> begin ();
2019-01-17 19:27:26 +01:00
2015-01-17 19:28:27 +01:00
$error = 0 ;
2018-11-07 16:45:04 +01:00
$originentity = GETPOST ( 'originentity' );
2015-01-17 19:28:27 +01:00
// Fill array 'array_options' with data from add form
2019-10-06 14:41:52 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
2021-02-23 21:09:01 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2014-03-01 19:45:13 +01:00
2021-09-23 02:10:39 +02:00
$dateinvoice = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'remonth' , 'int' ), GETPOST ( 'reday' , 'int' ), GETPOST ( 'reyear' , 'int' ), 'tzserver' ); // If we enter the 02 january, we need to save the 02 january for server
$date_pointoftax = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'date_pointoftaxmonth' , 'int' ), GETPOST ( 'date_pointoftaxday' , 'int' ), GETPOST ( 'date_pointoftaxyear' , 'int' ), 'tzserver' );
2015-01-18 17:13:42 +01:00
// Replacement invoice
2021-02-23 15:35:16 +01:00
if ( GETPOST ( 'type' ) == Facture :: TYPE_REPLACEMENT ) {
2021-01-11 15:34:25 +01:00
if ( empty ( $dateinvoice )) {
2015-01-17 19:28:27 +01:00
$error ++ ;
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Date " )), null , 'errors' );
2020-01-16 02:48:24 +01:00
$action = 'create' ;
2021-09-23 02:10:39 +02:00
} elseif ( $dateinvoice > ( dol_get_last_hour ( dol_now ( 'tzuserrel' )) + ( empty ( $conf -> global -> INVOICE_MAX_FUTURE_DELAY ) ? 0 : $conf -> global -> INVOICE_MAX_FUTURE_DELAY ))) {
2021-01-11 15:34:25 +01:00
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorDateIsInFuture " ), null , 'errors' );
$action = 'create' ;
2015-01-17 19:28:27 +01:00
}
2014-03-01 19:45:13 +01:00
2021-01-11 15:16:01 +01:00
if ( ! ( GETPOST ( 'fac_replacement' , 'int' ) > 0 )) {
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ReplaceInvoice " )), null , 'errors' );
2020-01-16 02:48:24 +01:00
$action = 'create' ;
2015-01-17 19:28:27 +01:00
}
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
if ( ! $error ) {
2015-01-17 19:28:27 +01:00
// This is a replacement invoice
2021-01-11 15:16:01 +01:00
$result = $object -> fetch ( GETPOST ( 'fac_replacement' , 'int' ));
2015-01-17 19:28:27 +01:00
$object -> fetch_thirdparty ();
2019-11-12 00:15:34 +01:00
$object -> date = $dateinvoice ;
$object -> date_pointoftax = $date_pointoftax ;
2020-09-18 01:29:17 +02:00
$object -> note_public = trim ( GETPOST ( 'note_public' , 'restricthtml' ));
2022-06-16 15:31:07 +02:00
$object -> note_private = trim ( GETPOST ( 'note_private' , 'restricthtml' ));
2021-01-31 12:48:40 +01:00
$object -> ref_client = GETPOST ( 'ref_client' , 'alphanohtml' );
$object -> model_pdf = GETPOST ( 'model' , 'alphanohtml' );
2021-01-11 15:16:01 +01:00
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
$object -> cond_reglement_id = GETPOST ( 'cond_reglement_id' , 'int' );
$object -> mode_reglement_id = GETPOST ( 'mode_reglement_id' , 'int' );
2019-11-12 00:15:34 +01:00
$object -> fk_account = GETPOST ( 'fk_account' , 'int' );
2021-09-08 22:00:16 +02:00
$object -> remise_absolue = price2num ( GETPOST ( 'remise_absolue' ), 'MU' , 2 );
$object -> remise_percent = price2num ( GETPOST ( 'remise_percent' ), '' , 2 );
2019-11-12 00:15:34 +01:00
$object -> fk_incoterms = GETPOST ( 'incoterm_id' , 'int' );
2015-02-23 09:16:14 +01:00
$object -> location_incoterms = GETPOST ( 'location_incoterms' , 'alpha' );
2016-01-23 16:01:55 +01:00
$object -> multicurrency_code = GETPOST ( 'multicurrency_code' , 'alpha' );
2018-01-17 19:45:23 +01:00
$object -> multicurrency_tx = GETPOST ( 'originmulticurrency_tx' , 'int' );
2016-04-24 18:55:19 +02:00
2015-01-17 19:28:27 +01:00
// Proprietes particulieres a facture de remplacement
2021-01-11 15:16:01 +01:00
$object -> fk_facture_source = GETPOST ( 'fac_replacement' , 'int' );
2015-01-17 19:28:27 +01:00
$object -> type = Facture :: TYPE_REPLACEMENT ;
$id = $object -> createFromCurrent ( $user );
2015-01-18 17:13:42 +01:00
if ( $id <= 0 ) {
2015-11-15 07:47:35 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-18 17:13:42 +01:00
}
2014-07-20 01:09:43 +02:00
}
2013-04-20 00:10:20 +02:00
}
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
// Credit note invoice
2021-02-23 15:35:16 +01:00
if ( GETPOST ( 'type' ) == Facture :: TYPE_CREDIT_NOTE ) {
2021-01-11 15:34:25 +01:00
$sourceinvoice = GETPOST ( 'fac_avoir' , 'int' );
2021-02-23 15:35:16 +01:00
if ( ! ( $sourceinvoice > 0 ) && empty ( $conf -> global -> INVOICE_CREDIT_NOTE_STANDALONE )) {
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CorrectInvoice " )), null , 'errors' );
2020-01-16 02:48:24 +01:00
$action = 'create' ;
2015-01-17 19:28:27 +01:00
}
2014-03-01 19:45:13 +01:00
2021-01-11 15:34:25 +01:00
if ( empty ( $dateinvoice )) {
2018-09-04 10:37:29 +02:00
$error ++ ;
2019-05-29 09:51:45 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Date " )), null , 'errors' );
2020-01-16 02:48:24 +01:00
$action = 'create' ;
2021-09-23 02:10:39 +02:00
} elseif ( $dateinvoice > ( dol_get_last_hour ( dol_now ( 'tzuserrel' )) + ( empty ( $conf -> global -> INVOICE_MAX_FUTURE_DELAY ) ? 0 : $conf -> global -> INVOICE_MAX_FUTURE_DELAY ))) {
2021-01-11 15:34:25 +01:00
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorDateIsInFuture " ), null , 'errors' );
$action = 'create' ;
2015-01-17 19:28:27 +01:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 21:09:01 +01:00
if ( ! $error ) {
2019-06-03 11:37:04 +02:00
if ( ! empty ( $originentity )) {
2018-11-07 16:45:04 +01:00
$object -> entity = $originentity ;
}
2019-11-12 00:15:34 +01:00
$object -> socid = GETPOST ( 'socid' , 'int' );
2020-09-18 01:29:17 +02:00
$object -> ref = GETPOST ( 'ref' );
2019-11-12 00:15:34 +01:00
$object -> date = $dateinvoice ;
$object -> date_pointoftax = $date_pointoftax ;
2020-09-18 01:29:17 +02:00
$object -> note_public = trim ( GETPOST ( 'note_public' , 'restricthtml' ));
2022-06-16 15:31:07 +02:00
$object -> note_private = trim ( GETPOST ( 'note_private' , 'restricthtml' ));
2020-09-18 01:29:17 +02:00
$object -> ref_client = GETPOST ( 'ref_client' );
$object -> model_pdf = GETPOST ( 'model' );
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
2021-01-31 12:48:40 +01:00
$object -> cond_reglement_id = 0 ; // No payment term for a credit note
$object -> mode_reglement_id = GETPOST ( 'mode_reglement_id' , 'int' );
2019-11-12 00:15:34 +01:00
$object -> fk_account = GETPOST ( 'fk_account' , 'int' );
2021-01-31 12:48:40 +01:00
$object -> remise_absolue = price2num ( GETPOST ( 'remise_absolue' ), 'MU' );
2021-09-08 22:00:16 +02:00
$object -> remise_percent = price2num ( GETPOST ( 'remise_percent' ), '' , 2 );
2019-11-12 00:15:34 +01:00
$object -> fk_incoterms = GETPOST ( 'incoterm_id' , 'int' );
2015-02-23 09:16:14 +01:00
$object -> location_incoterms = GETPOST ( 'location_incoterms' , 'alpha' );
2016-01-23 16:01:55 +01:00
$object -> multicurrency_code = GETPOST ( 'multicurrency_code' , 'alpha' );
2018-01-17 19:45:23 +01:00
$object -> multicurrency_tx = GETPOST ( 'originmulticurrency_tx' , 'int' );
2016-08-10 09:47:25 +02:00
2015-01-17 19:28:27 +01:00
// Proprietes particulieres a facture avoir
2015-07-08 14:32:57 +02:00
$object -> fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice : '' ;
2015-01-17 19:28:27 +01:00
$object -> type = Facture :: TYPE_CREDIT_NOTE ;
2014-03-01 19:45:13 +01:00
2018-03-23 12:24:47 +01:00
$facture_source = new Facture ( $db ); // fetch origin object
2021-02-23 15:35:16 +01:00
if ( $facture_source -> fetch ( $object -> fk_facture_source ) > 0 ) {
if ( $facture_source -> type == Facture :: TYPE_SITUATION ) {
2020-10-31 14:32:18 +01:00
$object -> situation_counter = $facture_source -> situation_counter ;
$object -> situation_cycle_ref = $facture_source -> situation_cycle_ref ;
$facture_source -> fetchPreviousNextSituationInvoice ();
}
2018-03-23 12:24:47 +01:00
}
2022-02-02 14:03:09 +01:00
2015-01-17 19:28:27 +01:00
$id = $object -> create ( $user );
2021-05-13 10:28:14 +02:00
if ( $id < 0 ) {
2021-05-13 10:26:09 +02:00
$error ++ ;
2021-05-13 10:28:14 +02:00
} else {
// copy internal contacts
if ( $object -> copy_linked_contact ( $facture_source , 'internal' ) < 0 ) {
$error ++ ;
} elseif ( $facture_source -> socid == $object -> socid ) {
// copy external contacts if same company
if ( $object -> copy_linked_contact ( $facture_source , 'external' ) < 0 ) {
$error ++ ;
}
}
2021-05-13 10:26:09 +02:00
}
2014-03-01 19:45:13 +01:00
2020-06-07 18:36:58 +02:00
// NOTE: Pb with situation invoice
// NOTE: fields total on situation invoice are stored as cumulative values on total of lines (bad) but delta on invoice total
// NOTE: fields total on credit note are stored as delta both on total of lines and on invoice total (good)
// NOTE: fields situation_percent on situation invoice are stored as cumulative values on lines (bad)
// NOTE: fields situation_percent on credit note are stored as delta on lines (good)
2021-02-23 21:09:01 +01:00
if ( GETPOST ( 'invoiceAvoirWithLines' , 'int' ) == 1 && $id > 0 ) {
if ( ! empty ( $facture_source -> lines )) {
2017-10-16 08:47:05 +02:00
$fk_parent_line = 0 ;
2021-02-23 21:09:01 +01:00
foreach ( $facture_source -> lines as $line ) {
2018-02-20 12:48:28 +01:00
// Extrafields
2020-04-23 13:21:39 +02:00
if ( method_exists ( $line , 'fetch_optionals' )) {
2018-02-20 12:48:28 +01:00
// load extrafields
$line -> fetch_optionals ();
}
2017-10-16 08:47:05 +02:00
// Reset fk_parent_line for no child products and special product
if (( $line -> product_type != 9 && empty ( $line -> fk_parent_line )) || $line -> product_type == 9 ) {
$fk_parent_line = 0 ;
}
2018-05-23 08:16:24 +02:00
2021-02-23 15:35:16 +01:00
if ( $facture_source -> type == Facture :: TYPE_SITUATION ) {
2020-10-31 14:32:18 +01:00
$source_fk_prev_id = $line -> fk_prev_id ; // temporary storing situation invoice fk_prev_id
$line -> fk_prev_id = $line -> id ; // The new line of the new credit note we are creating must be linked to the situation invoice line it is created from
2021-02-23 15:35:16 +01:00
if ( ! empty ( $facture_source -> tab_previous_situation_invoice )) {
2020-10-31 14:32:18 +01:00
// search the last standard invoice in cycle and the possible credit note between this last and facture_source
// TODO Move this out of loop of $facture_source->lines
$tab_jumped_credit_notes = array ();
$lineIndex = count ( $facture_source -> tab_previous_situation_invoice ) - 1 ;
$searchPreviousInvoice = true ;
2021-02-23 15:35:16 +01:00
while ( $searchPreviousInvoice ) {
if ( $facture_source -> tab_previous_situation_invoice [ $lineIndex ] -> type == Facture :: TYPE_SITUATION || $lineIndex < 1 ) {
2020-10-31 14:32:18 +01:00
$searchPreviousInvoice = false ; // find, exit;
break ;
} else {
if ( $facture_source -> tab_previous_situation_invoice [ $lineIndex ] -> type == Facture :: TYPE_CREDIT_NOTE ) {
$tab_jumped_credit_notes [ $lineIndex ] = $facture_source -> tab_previous_situation_invoice [ $lineIndex ] -> id ;
}
$lineIndex -- ; // go to previous invoice in cycle
}
}
$maxPrevSituationPercent = 0 ;
2021-02-23 15:35:16 +01:00
foreach ( $facture_source -> tab_previous_situation_invoice [ $lineIndex ] -> lines as $prevLine ) {
if ( $prevLine -> id == $source_fk_prev_id ) {
2020-10-31 14:32:18 +01:00
$maxPrevSituationPercent = max ( $maxPrevSituationPercent , $prevLine -> situation_percent );
//$line->subprice = $line->subprice - $prevLine->subprice;
$line -> total_ht = $line -> total_ht - $prevLine -> total_ht ;
$line -> total_tva = $line -> total_tva - $prevLine -> total_tva ;
$line -> total_ttc = $line -> total_ttc - $prevLine -> total_ttc ;
$line -> total_localtax1 = $line -> total_localtax1 - $prevLine -> total_localtax1 ;
$line -> total_localtax2 = $line -> total_localtax2 - $prevLine -> total_localtax2 ;
$line -> multicurrency_subprice = $line -> multicurrency_subprice - $prevLine -> multicurrency_subprice ;
$line -> multicurrency_total_ht = $line -> multicurrency_total_ht - $prevLine -> multicurrency_total_ht ;
$line -> multicurrency_total_tva = $line -> multicurrency_total_tva - $prevLine -> multicurrency_total_tva ;
$line -> multicurrency_total_ttc = $line -> multicurrency_total_ttc - $prevLine -> multicurrency_total_ttc ;
}
}
// prorata
$line -> situation_percent = $maxPrevSituationPercent - $line -> situation_percent ;
//print 'New line based on invoice id '.$facture_source->tab_previous_situation_invoice[$lineIndex]->id.' fk_prev_id='.$source_fk_prev_id.' will be fk_prev_id='.$line->fk_prev_id.' '.$line->total_ht.' '.$line->situation_percent.'<br>';
// If there is some credit note between last situation invoice and invoice used for credit note generation (note: credit notes are stored as delta)
$maxPrevSituationPercent = 0 ;
foreach ( $tab_jumped_credit_notes as $index => $creditnoteid ) {
2021-02-23 15:35:16 +01:00
foreach ( $facture_source -> tab_previous_situation_invoice [ $index ] -> lines as $prevLine ) {
if ( $prevLine -> fk_prev_id == $source_fk_prev_id ) {
2020-10-31 14:32:18 +01:00
$maxPrevSituationPercent = $prevLine -> situation_percent ;
$line -> total_ht -= $prevLine -> total_ht ;
$line -> total_tva -= $prevLine -> total_tva ;
$line -> total_ttc -= $prevLine -> total_ttc ;
$line -> total_localtax1 -= $prevLine -> total_localtax1 ;
$line -> total_localtax2 -= $prevLine -> total_localtax2 ;
$line -> multicurrency_subprice -= $prevLine -> multicurrency_subprice ;
$line -> multicurrency_total_ht -= $prevLine -> multicurrency_total_ht ;
$line -> multicurrency_total_tva -= $prevLine -> multicurrency_total_tva ;
$line -> multicurrency_total_ttc -= $prevLine -> multicurrency_total_ttc ;
}
}
}
// prorata
$line -> situation_percent += $maxPrevSituationPercent ;
//print 'New line based on invoice id '.$facture_source->tab_previous_situation_invoice[$lineIndex]->id.' fk_prev_id='.$source_fk_prev_id.' will be fk_prev_id='.$line->fk_prev_id.' '.$line->total_ht.' '.$line->situation_percent.'<br>';
}
2018-03-19 15:50:56 +01:00
}
2017-10-16 08:47:05 +02:00
$line -> fk_facture = $object -> id ;
$line -> fk_parent_line = $fk_parent_line ;
$line -> subprice = - $line -> subprice ; // invert price for object
2019-11-12 00:15:34 +01:00
$line -> pa_ht = $line -> pa_ht ; // we choosed to have buy/cost price always positive, so no revert of sign here
2017-10-16 08:47:05 +02:00
$line -> total_ht = - $line -> total_ht ;
$line -> total_tva = - $line -> total_tva ;
$line -> total_ttc = - $line -> total_ttc ;
$line -> total_localtax1 = - $line -> total_localtax1 ;
$line -> total_localtax2 = - $line -> total_localtax2 ;
$line -> multicurrency_subprice = - $line -> multicurrency_subprice ;
$line -> multicurrency_total_ht = - $line -> multicurrency_total_ht ;
$line -> multicurrency_total_tva = - $line -> multicurrency_total_tva ;
$line -> multicurrency_total_ttc = - $line -> multicurrency_total_ttc ;
2022-02-02 14:03:09 +01:00
$line -> context [ 'createcreditnotefrominvoice' ] = 1 ;
2019-11-12 00:15:34 +01:00
$result = $line -> insert ( 0 , 1 ); // When creating credit note with same lines than source, we must ignore error if discount alreayd linked
2017-10-16 08:47:05 +02:00
$object -> lines [] = $line ; // insert new line in current object
// Defined the new fk_parent_line
2022-09-16 15:03:53 +02:00
if ( $result > 0 && $line -> product_type == 9 ) {
2017-10-16 08:47:05 +02:00
$fk_parent_line = $result ;
}
}
$object -> update_price ( 1 );
}
2013-04-20 00:10:20 +02:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( GETPOST ( 'invoiceAvoirWithPaymentRestAmount' , 'int' ) == 1 && $id > 0 ) {
if ( $facture_source -> fetch ( $object -> fk_facture_source ) > 0 ) {
2022-05-22 17:09:08 +02:00
$totalpaid = $facture_source -> getSommePaiement ();
2017-10-16 08:47:05 +02:00
$totalcreditnotes = $facture_source -> getSumCreditNotesUsed ();
$totaldeposits = $facture_source -> getSumDepositsUsed ();
2022-05-22 17:09:08 +02:00
$remain_to_pay = abs ( $facture_source -> total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits );
2017-10-16 08:47:05 +02:00
2019-01-27 11:55:16 +01:00
$object -> addline ( $langs -> trans ( 'invoiceAvoirLineWithPaymentRestAmount' ), $remain_to_pay , 1 , 0 , 0 , 0 , 0 , 0 , '' , '' , 'TTC' );
2017-10-16 08:47:05 +02:00
}
}
2018-03-27 16:04:56 +02:00
// Add link between credit note and origin
2020-05-29 16:18:27 +02:00
if ( ! empty ( $object -> fk_facture_source ) && $id > 0 ) {
2018-03-27 16:04:56 +02:00
$facture_source -> fetch ( $object -> fk_facture_source );
2018-04-24 11:48:26 +02:00
$facture_source -> fetchObjectLinked ();
2018-03-27 16:04:56 +02:00
2019-11-12 00:15:34 +01:00
if ( ! empty ( $facture_source -> linkedObjectsIds )) {
foreach ( $facture_source -> linkedObjectsIds as $sourcetype => $TIds ) {
2018-04-24 11:48:26 +02:00
$object -> add_object_linked ( $sourcetype , current ( $TIds ));
}
}
2018-03-27 16:04:56 +02:00
}
2015-01-17 19:28:27 +01:00
}
2014-02-23 20:10:05 +01:00
}
2014-03-01 19:45:13 +01:00
2016-07-28 19:02:23 +02:00
// Standard invoice or Deposit invoice, created from a Predefined template invoice
2021-02-23 15:35:16 +01:00
if (( GETPOST ( 'type' ) == Facture :: TYPE_STANDARD || GETPOST ( 'type' ) == Facture :: TYPE_DEPOSIT ) && GETPOST ( 'fac_rec' , 'int' ) > 0 ) {
2021-01-11 15:34:25 +01:00
if ( empty ( $dateinvoice )) {
2015-01-17 19:28:27 +01:00
$error ++ ;
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Date " )), null , 'errors' );
2020-01-16 02:48:24 +01:00
$action = 'create' ;
2021-09-23 02:10:39 +02:00
} elseif ( $dateinvoice > ( dol_get_last_hour ( dol_now ( 'tzuserrel' )) + ( empty ( $conf -> global -> INVOICE_MAX_FUTURE_DELAY ) ? 0 : $conf -> global -> INVOICE_MAX_FUTURE_DELAY ))) {
2021-01-11 15:34:25 +01:00
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorDateIsInFuture " ), null , 'errors' );
$action = 'create' ;
2015-01-17 19:28:27 +01:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( ! $error ) {
2019-11-12 00:15:34 +01:00
$object -> socid = GETPOST ( 'socid' , 'int' );
2020-09-18 01:29:17 +02:00
$object -> type = GETPOST ( 'type' );
$object -> ref = GETPOST ( 'ref' );
2016-05-29 23:56:58 +02:00
$object -> date = $dateinvoice ;
$object -> date_pointoftax = $date_pointoftax ;
2020-09-18 01:29:17 +02:00
$object -> note_public = trim ( GETPOST ( 'note_public' , 'restricthtml' ));
$object -> note_private = trim ( GETPOST ( 'note_private' , 'restricthtml' ));
$object -> ref_client = GETPOST ( 'ref_client' );
2020-10-31 14:32:18 +01:00
$object -> model_pdf = GETPOST ( 'model' );
2020-09-18 01:29:17 +02:00
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
$object -> cond_reglement_id = ( GETPOST ( 'type' ) == 3 ? 1 : GETPOST ( 'cond_reglement_id' ));
$object -> mode_reglement_id = GETPOST ( 'mode_reglement_id' , 'int' );
2019-11-12 00:15:34 +01:00
$object -> fk_account = GETPOST ( 'fk_account' , 'int' );
2020-09-18 01:29:17 +02:00
$object -> amount = price2num ( GETPOST ( 'amount' ));
2021-01-31 12:48:40 +01:00
$object -> remise_absolue = price2num ( GETPOST ( 'remise_absolue' ), 'MU' );
2021-09-08 22:00:16 +02:00
$object -> remise_percent = price2num ( GETPOST ( 'remise_percent' ), '' , 2 );
2019-11-12 00:15:34 +01:00
$object -> fk_incoterms = GETPOST ( 'incoterm_id' , 'int' );
2016-04-24 18:55:19 +02:00
$object -> location_incoterms = GETPOST ( 'location_incoterms' , 'alpha' );
2016-01-23 16:01:55 +01:00
$object -> multicurrency_code = GETPOST ( 'multicurrency_code' , 'alpha' );
2018-01-17 19:45:23 +01:00
$object -> multicurrency_tx = GETPOST ( 'originmulticurrency_tx' , 'int' );
2016-08-10 09:47:25 +02:00
2015-01-17 19:28:27 +01:00
// Source facture
2018-01-17 19:45:23 +01:00
$object -> fac_rec = GETPOST ( 'fac_rec' , 'int' );
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
$id = $object -> create ( $user ); // This include recopy of links from recurring invoice and recurring invoice lines
2015-01-17 19:28:27 +01:00
}
2014-02-23 20:10:05 +01:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 14:48:54 +01:00
// Standard or deposit invoice, not from a Predefined template invoice
2021-02-23 15:35:16 +01:00
if (( GETPOST ( 'type' ) == Facture :: TYPE_STANDARD || GETPOST ( 'type' ) == Facture :: TYPE_DEPOSIT || GETPOST ( 'type' ) == Facture :: TYPE_PROFORMA || ( GETPOST ( 'type' ) == Facture :: TYPE_SITUATION && ! GETPOST ( 'situations' ))) && GETPOST ( 'fac_rec' ) <= 0 ) {
2021-02-23 14:48:54 +01:00
$typeamount = GETPOST ( 'typedeposit' , 'aZ09' );
$valuestandardinvoice = price2num ( str_replace ( '%' , '' , GETPOST ( 'valuestandardinvoice' , 'alpha' )), 'MU' );
$valuedeposit = price2num ( str_replace ( '%' , '' , GETPOST ( 'valuedeposit' , 'alpha' )), 'MU' );
if ( GETPOST ( 'socid' , 'int' ) < 1 ) {
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Customer " )), null , 'errors' );
2020-01-16 02:48:24 +01:00
$action = 'create' ;
2014-11-14 16:43:49 +01:00
}
2021-01-11 15:34:25 +01:00
if ( empty ( $dateinvoice )) {
2015-01-17 19:28:27 +01:00
$error ++ ;
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Date " )), null , 'errors' );
2020-01-16 02:48:24 +01:00
$action = 'create' ;
2021-09-23 02:10:39 +02:00
} elseif ( $dateinvoice > ( dol_get_last_hour ( dol_now ( 'tzuserrel' )) + ( empty ( $conf -> global -> INVOICE_MAX_FUTURE_DELAY ) ? 0 : $conf -> global -> INVOICE_MAX_FUTURE_DELAY ))) {
2021-01-11 15:34:25 +01:00
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorDateIsInFuture " ), null , 'errors' );
$action = 'create' ;
2015-01-17 19:28:27 +01:00
}
2014-03-01 19:45:13 +01:00
2016-08-10 09:47:25 +02:00
2021-02-23 14:48:54 +01:00
if ( GETPOST ( 'type' ) == Facture :: TYPE_STANDARD ) {
if ( $valuestandardinvoice < 0 || $valuestandardinvoice > 100 ) {
setEventMessages ( $langs -> trans ( " ErrorAPercentIsRequired " ), null , 'errors' );
$error ++ ;
$action = 'create' ;
}
} elseif ( GETPOST ( 'type' ) == Facture :: TYPE_DEPOSIT ) {
2021-02-23 15:35:16 +01:00
if ( $typeamount && ! empty ( $origin ) && ! empty ( $originid )) {
2021-02-23 14:48:54 +01:00
if ( $typeamount == 'amount' && $valuedeposit <= 0 ) {
setEventMessages ( $langs -> trans ( " ErrorAnAmountWithoutTaxIsRequired " ), null , 'errors' );
$error ++ ;
$action = 'create' ;
}
if ( $typeamount == 'variable' && $valuedeposit <= 0 ) {
setEventMessages ( $langs -> trans ( " ErrorAPercentIsRequired " ), null , 'errors' );
$error ++ ;
$action = 'create' ;
}
if ( $typeamount == 'variablealllines' && $valuedeposit <= 0 ) {
setEventMessages ( $langs -> trans ( " ErrorAPercentIsRequired " ), null , 'errors' );
$error ++ ;
$action = 'create' ;
}
}
}
2016-08-10 09:47:25 +02:00
2021-02-23 15:35:16 +01:00
if ( ! $error ) {
2015-01-17 19:28:27 +01:00
// Si facture standard
2019-11-12 00:15:34 +01:00
$object -> socid = GETPOST ( 'socid' , 'int' );
2015-01-17 19:28:27 +01:00
$object -> type = GETPOST ( 'type' );
2020-09-18 01:29:17 +02:00
$object -> ref = GETPOST ( 'ref' );
2015-01-17 19:28:27 +01:00
$object -> date = $dateinvoice ;
2019-11-12 00:15:34 +01:00
$object -> date_pointoftax = $date_pointoftax ;
2020-09-18 01:29:17 +02:00
$object -> note_public = trim ( GETPOST ( 'note_public' , 'restricthtml' ));
$object -> note_private = trim ( GETPOST ( 'note_private' , 'restricthtml' ));
$object -> ref_client = GETPOST ( 'ref_client' );
$object -> model_pdf = GETPOST ( 'model' );
2021-05-19 15:11:47 +02:00
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
2020-09-18 01:41:42 +02:00
$object -> cond_reglement_id = ( GETPOST ( 'type' ) == 3 ? 1 : GETPOST ( 'cond_reglement_id' ));
2020-09-18 01:29:17 +02:00
$object -> mode_reglement_id = GETPOST ( 'mode_reglement_id' );
2019-11-12 00:15:34 +01:00
$object -> fk_account = GETPOST ( 'fk_account' , 'int' );
2020-09-18 01:29:17 +02:00
$object -> amount = price2num ( GETPOST ( 'amount' ));
2021-01-31 12:48:40 +01:00
$object -> remise_absolue = price2num ( GETPOST ( 'remise_absolue' ), 'MU' );
2021-09-08 22:00:16 +02:00
$object -> remise_percent = price2num ( GETPOST ( 'remise_percent' ), '' , 2 );
2019-11-12 00:15:34 +01:00
$object -> fk_incoterms = GETPOST ( 'incoterm_id' , 'int' );
2015-02-23 09:16:14 +01:00
$object -> location_incoterms = GETPOST ( 'location_incoterms' , 'alpha' );
2016-01-23 16:01:55 +01:00
$object -> multicurrency_code = GETPOST ( 'multicurrency_code' , 'alpha' );
2018-01-17 19:45:23 +01:00
$object -> multicurrency_tx = GETPOST ( 'originmulticurrency_tx' , 'int' );
2015-01-17 19:28:27 +01:00
2021-02-23 14:48:54 +01:00
if ( GETPOST ( 'type' ) == Facture :: TYPE_SITUATION ) {
2015-01-18 18:44:22 +01:00
$object -> situation_counter = 1 ;
$object -> situation_final = 0 ;
$object -> situation_cycle_ref = $object -> newCycle ();
2020-02-19 11:54:55 +01:00
}
2019-08-29 00:45:02 +02:00
2020-04-23 18:55:10 +02:00
if ( in_array ( $object -> type , $retainedWarrantyInvoiceAvailableType )) {
2020-04-15 11:09:34 +02:00
$object -> retained_warranty = GETPOST ( 'retained_warranty' , 'int' );
$object -> retained_warranty_fk_cond_reglement = GETPOST ( 'retained_warranty_fk_cond_reglement' , 'int' );
2020-05-21 15:05:19 +02:00
} else {
2020-04-15 11:09:34 +02:00
$object -> retained_warranty = 0 ;
$object -> retained_warranty_fk_cond_reglement = 0 ;
}
2019-08-29 00:45:02 +02:00
2020-10-31 14:32:18 +01:00
$retained_warranty_date_limit = GETPOST ( 'retained_warranty_date_limit' );
2021-02-23 14:48:54 +01:00
if ( ! empty ( $retained_warranty_date_limit ) && dol_stringtotime ( $retained_warranty_date_limit )) {
$object -> retained_warranty_date_limit = dol_stringtotime ( $retained_warranty_date_limit );
2020-10-31 14:32:18 +01:00
}
$object -> retained_warranty_date_limit = ! empty ( $object -> retained_warranty_date_limit ) ? $object -> retained_warranty_date_limit : $object -> calculate_date_lim_reglement ( $object -> retained_warranty_fk_cond_reglement );
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
$object -> fetch_thirdparty ();
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
// If creation from another object of another module (Example: origin=propal, originid=1)
2021-02-23 15:35:16 +01:00
if ( ! empty ( $origin ) && ! empty ( $originid )) {
2021-02-23 14:48:54 +01:00
$regs = array ();
2015-01-17 19:28:27 +01:00
// Parse element/subelement (ex: project_task)
2015-01-18 17:13:42 +01:00
$element = $subelement = $origin ;
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , $origin , $regs )) {
2021-02-23 14:48:54 +01:00
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
2015-01-17 19:28:27 +01:00
}
2014-09-29 20:39:19 +02:00
2015-01-17 19:28:27 +01:00
// For compatibility
if ( $element == 'order' ) {
$element = $subelement = 'commande' ;
}
if ( $element == 'propal' ) {
$element = 'comm/propal' ;
$subelement = 'propal' ;
}
if ( $element == 'contract' ) {
$element = $subelement = 'contrat' ;
}
if ( $element == 'inter' ) {
$element = $subelement = 'ficheinter' ;
}
if ( $element == 'shipping' ) {
$element = $subelement = 'expedition' ;
}
2014-03-01 19:45:13 +01:00
2015-01-18 17:13:42 +01:00
$object -> origin = $origin ;
$object -> origin_id = $originid ;
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
// Possibility to add external linked objects with hooks
2015-01-18 17:13:42 +01:00
$object -> linked_objects [ $object -> origin ] = $object -> origin_id ;
// link with order if it is a shipping invoice
2021-02-23 21:09:01 +01:00
if ( $object -> origin == 'shipping' ) {
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php' ;
2015-01-18 17:13:42 +01:00
$exp = new Expedition ( $db );
$exp -> fetch ( $object -> origin_id );
$exp -> fetchObjectLinked ();
2017-12-02 15:03:14 +01:00
if ( is_array ( $exp -> linkedObjectsIds [ 'commande' ]) && count ( $exp -> linkedObjectsIds [ 'commande' ]) > 0 ) {
2019-11-12 00:15:34 +01:00
foreach ( $exp -> linkedObjectsIds [ 'commande' ] as $key => $value ) {
2015-09-12 23:42:48 +02:00
$object -> linked_objects [ 'commande' ] = $value ;
}
}
2015-01-18 17:13:42 +01:00
}
2014-09-29 20:39:19 +02:00
2021-02-23 15:35:16 +01:00
if ( is_array ( $_POST [ 'other_linked_objects' ]) && ! empty ( $_POST [ 'other_linked_objects' ])) {
2015-01-17 19:28:27 +01:00
$object -> linked_objects = array_merge ( $object -> linked_objects , $_POST [ 'other_linked_objects' ]);
}
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
$id = $object -> create ( $user ); // This include class to add_object_linked() and add add_contact()
2017-06-07 16:44:04 +02:00
2021-02-23 15:35:16 +01:00
if ( $id > 0 ) {
2019-11-12 00:15:34 +01:00
dol_include_once ( '/' . $element . '/class/' . $subelement . '.class.php' );
2016-02-25 01:00:13 +01:00
$classname = ucfirst ( $subelement );
$srcobject = new $classname ( $db );
2019-11-12 00:15:34 +01:00
dol_syslog ( " Try to find source object origin= " . $object -> origin . " originid= " . $object -> origin_id . " to add lines or deposit lines " );
2016-02-25 01:00:13 +01:00
$result = $srcobject -> fetch ( $object -> origin_id );
2016-07-19 07:46:27 +02:00
2021-02-23 14:48:54 +01:00
// If deposit invoice - down payment with 1 line (fixed amount or percent)
2021-02-23 15:35:16 +01:00
if ( GETPOST ( 'type' ) == Facture :: TYPE_DEPOSIT && in_array ( $typeamount , array ( 'amount' , 'variable' ))) {
2021-02-23 14:48:54 +01:00
// Define the array $amountdeposit
2017-02-07 11:09:18 +01:00
$amountdeposit = array ();
2021-02-23 15:35:16 +01:00
if ( ! empty ( $conf -> global -> MAIN_DEPOSIT_MULTI_TVA )) {
if ( $typeamount == 'amount' ) {
$amount = $valuedeposit ;
} else {
$amount = $srcobject -> total_ttc * ( $valuedeposit / 100 );
}
2017-06-07 16:44:04 +02:00
2017-02-07 11:09:18 +01:00
$TTotalByTva = array ();
2021-02-23 15:35:16 +01:00
foreach ( $srcobject -> lines as & $line ) {
2021-02-23 21:09:01 +01:00
if ( ! empty ( $line -> special_code )) {
continue ;
}
2019-11-12 00:15:34 +01:00
$TTotalByTva [ $line -> tva_tx ] += $line -> total_ttc ;
2017-02-07 11:09:18 +01:00
}
2017-06-07 16:44:04 +02:00
2021-02-23 15:35:16 +01:00
foreach ( $TTotalByTva as $tva => & $total ) {
2017-02-07 11:09:18 +01:00
$coef = $total / $srcobject -> total_ttc ; // Calc coef
$am = $amount * $coef ;
$amount_ttc_diff += $am ;
$amountdeposit [ $tva ] += $am / ( 1 + $tva / 100 ); // Convert into HT for the addline
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 15:35:16 +01:00
if ( $typeamount == 'amount' ) {
2017-05-05 14:49:25 +02:00
$amountdeposit [ 0 ] = $valuedeposit ;
2021-02-23 15:35:16 +01:00
} elseif ( $typeamount == 'variable' ) {
if ( $result > 0 ) {
2017-02-07 11:09:18 +01:00
$totalamount = 0 ;
$lines = $srcobject -> lines ;
2019-11-12 00:15:34 +01:00
$numlines = count ( $lines );
2021-02-23 21:09:01 +01:00
for ( $i = 0 ; $i < $numlines ; $i ++ ) {
2019-11-12 00:15:34 +01:00
$qualified = 1 ;
2021-02-23 15:35:16 +01:00
if ( empty ( $lines [ $i ] -> qty )) {
$qualified = 0 ; // We discard qty=0, it is an option
}
if ( ! empty ( $lines [ $i ] -> special_code )) {
$qualified = 0 ; // We discard special_code (frais port, ecotaxe, option, ...)
}
2019-11-12 00:15:34 +01:00
if ( $qualified ) {
2019-03-11 11:19:32 +01:00
$totalamount += $lines [ $i ] -> total_ht ; // Fixme : is it not for the customer ? Shouldn't we take total_ttc ?
$tva_tx = $lines [ $i ] -> tva_tx ;
$amountdeposit [ $tva_tx ] += ( $lines [ $i ] -> total_ht * $valuedeposit ) / 100 ;
}
2017-02-07 11:09:18 +01:00
}
2019-11-12 00:15:34 +01:00
if ( $totalamount == 0 ) {
2017-05-05 14:49:25 +02:00
$amountdeposit [ 0 ] = 0 ;
2017-02-07 11:09:18 +01:00
}
} else {
setEventMessages ( $srcobject -> error , $srcobject -> errors , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-01-17 19:28:27 +01:00
}
}
2017-06-07 16:44:04 +02:00
2017-02-07 11:09:18 +01:00
$amount_ttc_diff = $amountdeposit [ 0 ];
2015-01-17 19:28:27 +01:00
}
2020-02-06 14:15:41 +01:00
2021-02-23 21:09:01 +01:00
foreach ( $amountdeposit as $tva => $amount ) {
2021-02-23 15:35:16 +01:00
if ( empty ( $amount )) {
continue ;
}
2019-03-13 15:58:58 +01:00
2020-02-06 14:15:41 +01:00
$arraylist = array (
'amount' => 'FixAmount' ,
'variable' => 'VarAmount'
);
2019-11-30 16:14:16 +01:00
$descline = '(DEPOSIT)' ;
2018-07-06 12:45:20 +02:00
//$descline.= ' - '.$langs->trans($arraylist[$typeamount]);
2019-11-12 00:15:34 +01:00
if ( $typeamount == 'amount' ) {
$descline .= ' (' . price ( $valuedeposit , '' , $langs , 0 , - 1 , - 1 , ( ! empty ( $object -> multicurrency_code ) ? $object -> multicurrency_code : $conf -> currency )) . ')' ;
} elseif ( $typeamount == 'variable' ) {
$descline .= ' (' . $valuedeposit . '%)' ;
2017-07-25 11:32:41 +02:00
}
2019-03-21 18:22:17 +01:00
2019-11-12 00:15:34 +01:00
$descline .= ' - ' . $srcobject -> ref ;
2017-02-07 11:09:18 +01:00
$result = $object -> addline (
2021-02-23 21:09:01 +01:00
$descline ,
$amount , // subprice
1 , // quantity
$tva , // vat rate
0 , // localtax1_tx
0 , // localtax2_tx
( empty ( $conf -> global -> INVOICE_PRODUCTID_DEPOSIT ) ? 0 : $conf -> global -> INVOICE_PRODUCTID_DEPOSIT ), // fk_product
0 , // remise_percent
0 , // date_start
0 , // date_end
0 ,
$lines [ $i ] -> info_bits , // info_bits
0 ,
'HT' ,
0 ,
0 , // product_type
1 ,
$lines [ $i ] -> special_code ,
$object -> origin ,
0 ,
0 ,
0 ,
2022-05-03 15:57:17 +02:00
0 ,
'' ,
0 ,
100 ,
0 ,
null ,
0 ,
'' ,
1
2021-02-23 21:09:01 +01:00
);
2017-02-07 11:09:18 +01:00
}
2017-06-07 16:44:04 +02:00
2017-02-07 11:09:18 +01:00
$diff = $object -> total_ttc - $amount_ttc_diff ;
2017-06-07 16:44:04 +02:00
2021-02-23 15:35:16 +01:00
if ( ! empty ( $conf -> global -> MAIN_DEPOSIT_MULTI_TVA ) && $diff != 0 ) {
2017-02-07 11:09:18 +01:00
$object -> fetch_lines ();
2017-05-11 11:41:00 +02:00
$subprice_diff = $object -> lines [ 0 ] -> subprice - $diff / ( 1 + $object -> lines [ 0 ] -> tva_tx / 100 );
2017-02-07 11:09:18 +01:00
$object -> updateline ( $object -> lines [ 0 ] -> id , $object -> lines [ 0 ] -> desc , $subprice_diff , $object -> lines [ 0 ] -> qty , $object -> lines [ 0 ] -> remise_percent , $object -> lines [ 0 ] -> date_start , $object -> lines [ 0 ] -> date_end , $object -> lines [ 0 ] -> tva_tx , 0 , 0 , 'HT' , $object -> lines [ 0 ] -> info_bits , $object -> lines [ 0 ] -> product_type , 0 , 0 , 0 , $object -> lines [ 0 ] -> pa_ht , $object -> lines [ 0 ] -> label , 0 , array (), 100 );
}
2014-05-25 05:01:14 +02:00
}
2020-02-06 14:15:41 +01:00
2021-02-23 14:48:54 +01:00
// standard invoice, credit note, or down payment from a percent of all lines
2021-02-23 21:09:01 +01:00
if ( GETPOST ( 'type' ) != Facture :: TYPE_DEPOSIT || ( GETPOST ( 'type' ) == Facture :: TYPE_DEPOSIT && $typeamount == 'variablealllines' )) {
2021-02-23 15:35:16 +01:00
if ( $result > 0 ) {
2013-04-20 17:10:03 +02:00
$lines = $srcobject -> lines ;
2021-02-23 15:35:16 +01:00
if ( empty ( $lines ) && method_exists ( $srcobject , 'fetch_lines' )) {
2015-01-17 19:28:27 +01:00
$srcobject -> fetch_lines ();
$lines = $srcobject -> lines ;
2013-04-20 00:10:20 +02:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 14:48:54 +01:00
// If we create a standard invoice with a percent, we change amount by changing the qty
if ( GETPOST ( 'type' ) == Facture :: TYPE_STANDARD && $valuestandardinvoice > 0 && $valuestandardinvoice < 100 ) {
if ( is_array ( $lines )) {
foreach ( $lines as $line ) {
// We keep ->subprice and ->pa_ht, but we change the qty
$line -> qty = price2num ( $line -> qty * $valuestandardinvoice / 100 , 'MS' );
}
}
}
// If we create a down payment with a percent on all lines, we change amount by changing the qty
if ( GETPOST ( 'type' ) == Facture :: TYPE_DEPOSIT && $typeamount == 'variablealllines' ) {
2020-02-06 14:15:41 +01:00
if ( is_array ( $lines )) {
2020-03-12 12:45:44 +01:00
foreach ( $lines as $line ) {
2020-02-06 14:15:41 +01:00
// We keep ->subprice and ->pa_ht, but we change the qty
$line -> qty = price2num ( $line -> qty * $valuedeposit / 100 , 'MS' );
}
}
}
2019-11-12 00:15:34 +01:00
$fk_parent_line = 0 ;
$num = count ( $lines );
2020-10-25 09:28:41 +01:00
2021-02-23 15:35:16 +01:00
for ( $i = 0 ; $i < $num ; $i ++ ) {
if ( ! in_array ( $lines [ $i ] -> id , $selectedLines )) {
continue ; // Skip unselected lines
}
2020-10-25 09:28:41 +01:00
2015-01-18 17:13:42 +01:00
// Don't add lines with qty 0 when coming from a shipment including all order lines
2021-02-23 15:35:16 +01:00
if ( $srcobject -> element == 'shipping' && $conf -> global -> SHIPMENT_GETS_ALL_ORDER_PRODUCTS && $lines [ $i ] -> qty == 0 ) {
continue ;
}
2019-06-02 12:27:32 +02:00
// Don't add closed lines when coming from a contract (Set constant to '0,5' to exclude also inactive lines)
2021-02-23 15:35:16 +01:00
if ( ! isset ( $conf -> global -> CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE )) {
$conf -> global -> CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE = '5' ;
}
if ( $srcobject -> element == 'contrat' && in_array ( $lines [ $i ] -> statut , explode ( ',' , $conf -> global -> CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE ))) {
continue ;
}
2015-01-18 17:13:42 +01:00
2019-11-12 00:15:34 +01:00
$label = ( ! empty ( $lines [ $i ] -> label ) ? $lines [ $i ] -> label : '' );
$desc = ( ! empty ( $lines [ $i ] -> desc ) ? $lines [ $i ] -> desc : $lines [ $i ] -> libelle );
2021-02-23 21:09:01 +01:00
if ( $object -> situation_counter == 1 ) {
$lines [ $i ] -> situation_percent = 0 ;
}
2015-01-17 19:28:27 +01:00
2021-02-23 21:09:01 +01:00
if ( $lines [ $i ] -> subprice < 0 && empty ( $conf -> global -> INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN )) {
2015-01-17 19:28:27 +01:00
// Negative line, we create a discount line
$discount = new DiscountAbsolute ( $db );
$discount -> fk_soc = $object -> socid ;
2015-01-18 17:13:42 +01:00
$discount -> amount_ht = abs ( $lines [ $i ] -> total_ht );
$discount -> amount_tva = abs ( $lines [ $i ] -> total_tva );
$discount -> amount_ttc = abs ( $lines [ $i ] -> total_ttc );
$discount -> tva_tx = $lines [ $i ] -> tva_tx ;
2015-01-17 19:28:27 +01:00
$discount -> fk_user = $user -> id ;
$discount -> description = $desc ;
2021-12-01 12:10:14 +01:00
$discount -> multicurrency_subprice = abs ( $lines [ $i ] -> multicurrency_subprice );
$discount -> multicurrency_amount_ht = abs ( $lines [ $i ] -> multicurrency_total_ht );
$discount -> multicurrency_amount_tva = abs ( $lines [ $i ] -> multicurrency_total_tva );
$discount -> multicurrency_amount_ttc = abs ( $lines [ $i ] -> multicurrency_total_ttc );
2021-08-03 18:32:22 +02:00
2015-01-17 19:28:27 +01:00
$discountid = $discount -> create ( $user );
if ( $discountid > 0 ) {
$result = $object -> insert_discount ( $discountid ); // This include link_to_invoice
} else {
2015-11-18 16:05:41 +01:00
setEventMessages ( $discount -> error , $discount -> errors , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-01-17 19:28:27 +01:00
break ;
}
2014-02-23 20:10:05 +01:00
} else {
2015-01-17 19:28:27 +01:00
// Positive line
2015-01-18 17:13:42 +01:00
$product_type = ( $lines [ $i ] -> product_type ? $lines [ $i ] -> product_type : 0 );
2015-01-17 19:28:27 +01:00
// Date start
$date_start = false ;
2021-02-23 15:35:16 +01:00
if ( $lines [ $i ] -> date_debut_prevue ) {
2015-01-18 17:13:42 +01:00
$date_start = $lines [ $i ] -> date_debut_prevue ;
2021-02-23 15:35:16 +01:00
}
if ( $lines [ $i ] -> date_debut_reel ) {
2015-01-18 17:13:42 +01:00
$date_start = $lines [ $i ] -> date_debut_reel ;
2021-02-23 15:35:16 +01:00
}
if ( $lines [ $i ] -> date_start ) {
2015-01-18 17:13:42 +01:00
$date_start = $lines [ $i ] -> date_start ;
2021-02-23 15:35:16 +01:00
}
2015-01-17 19:28:27 +01:00
2021-02-23 15:35:16 +01:00
// Date end
2015-01-17 19:28:27 +01:00
$date_end = false ;
2021-02-23 15:35:16 +01:00
if ( $lines [ $i ] -> date_fin_prevue ) {
2015-01-18 17:13:42 +01:00
$date_end = $lines [ $i ] -> date_fin_prevue ;
2021-02-23 15:35:16 +01:00
}
if ( $lines [ $i ] -> date_fin_reel ) {
2015-01-18 17:13:42 +01:00
$date_end = $lines [ $i ] -> date_fin_reel ;
2021-02-23 15:35:16 +01:00
}
if ( $lines [ $i ] -> date_end ) {
2015-01-18 17:13:42 +01:00
$date_end = $lines [ $i ] -> date_end ;
2021-02-23 15:35:16 +01:00
}
2015-01-17 19:28:27 +01:00
2021-02-23 15:35:16 +01:00
// Reset fk_parent_line for no child products and special product
2015-01-18 17:13:42 +01:00
if (( $lines [ $i ] -> product_type != 9 && empty ( $lines [ $i ] -> fk_parent_line )) || $lines [ $i ] -> product_type == 9 ) {
2015-01-17 19:28:27 +01:00
$fk_parent_line = 0 ;
}
// Extrafields
2020-04-23 13:21:39 +02:00
if ( method_exists ( $lines [ $i ], 'fetch_optionals' )) {
2020-03-27 16:02:58 +01:00
$lines [ $i ] -> fetch_optionals ();
2015-02-28 04:59:27 +01:00
$array_options = $lines [ $i ] -> array_options ;
2015-01-17 19:28:27 +01:00
}
2017-05-02 21:27:56 +02:00
$tva_tx = $lines [ $i ] -> tva_tx ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $lines [ $i ] -> vat_src_code ) && ! preg_match ( '/\(/' , $tva_tx )) {
$tva_tx .= ' (' . $lines [ $i ] -> vat_src_code . ')' ;
}
2017-06-07 16:44:04 +02:00
2017-05-02 21:27:56 +02:00
// View third's localtaxes for NOW and do not use value from origin.
2020-01-01 21:54:47 +01:00
// TODO Is this really what we want ? Yes if source is template invoice but what if proposal or order ?
2017-05-02 21:27:56 +02:00
$localtax1_tx = get_localtax ( $tva_tx , 1 , $object -> thirdparty );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $object -> thirdparty );
2015-01-17 19:28:27 +01:00
2020-10-31 14:32:18 +01:00
$result = $object -> addline (
2021-02-23 21:09:01 +01:00
$desc ,
$lines [ $i ] -> subprice ,
$lines [ $i ] -> qty ,
$tva_tx ,
$localtax1_tx ,
$localtax2_tx ,
$lines [ $i ] -> fk_product ,
$lines [ $i ] -> remise_percent ,
$date_start ,
$date_end ,
0 ,
$lines [ $i ] -> info_bits ,
$lines [ $i ] -> fk_remise_except ,
'HT' ,
0 ,
$product_type ,
$lines [ $i ] -> rang ,
$lines [ $i ] -> special_code ,
$object -> origin ,
$lines [ $i ] -> rowid ,
$fk_parent_line ,
$lines [ $i ] -> fk_fournprice ,
$lines [ $i ] -> pa_ht ,
$label ,
$array_options ,
$lines [ $i ] -> situation_percent ,
$lines [ $i ] -> fk_prev_id ,
2022-05-03 15:57:17 +02:00
$lines [ $i ] -> fk_unit ,
0 ,
'' ,
1
2018-05-27 15:04:12 +02:00
);
2015-01-17 19:28:27 +01:00
if ( $result > 0 ) {
$lineid = $result ;
} else {
$lineid = 0 ;
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-01-17 19:28:27 +01:00
break ;
}
// Defined the new fk_parent_line
2022-09-16 15:03:53 +02:00
if ( $result > 0 && $lines [ $i ] -> product_type == 9 ) {
2015-01-17 19:28:27 +01:00
$fk_parent_line = $result ;
}
2013-04-20 17:10:03 +02:00
}
2013-04-20 00:10:20 +02:00
}
2014-02-23 20:10:05 +01:00
} else {
2015-11-15 07:47:35 +01:00
setEventMessages ( $srcobject -> error , $srcobject -> errors , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2013-04-20 00:10:20 +02:00
}
2013-04-20 17:10:03 +02:00
}
2016-07-19 07:46:27 +02:00
2022-05-03 15:57:17 +02:00
$object -> update_price ( 1 , 'auto' , 0 , $mysoc );
2016-02-25 01:00:13 +01:00
// Now we create same links to contact than the ones found on origin object
2017-09-11 13:39:03 +02:00
/* Useless , already into the create
2016-02-25 16:27:28 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN ))
2016-02-25 01:00:13 +01:00
{
2021-02-23 21:09:01 +01:00
$originforcontact = $object -> origin ;
$originidforcontact = $object -> origin_id ;
if ( $originforcontact == 'shipping' ) // shipment and order share the same contacts. If creating from shipment we take data of order
{
$originforcontact = $srcobject -> origin ;
$originidforcontact = $srcobject -> origin_id ;
}
$sqlcontact = " SELECT code, fk_socpeople FROM " . MAIN_DB_PREFIX . " element_contact as ec, " . MAIN_DB_PREFIX . " c_type_contact as ctc " ;
2021-03-30 17:53:25 +02:00
$sqlcontact .= " WHERE element_id = " . (( int ) $originidforcontact ) . " AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = ' " . $db -> escape ( $originforcontact ) . " ' " ;
2021-02-23 21:09:01 +01:00
$resqlcontact = $db -> query ( $sqlcontact );
if ( $resqlcontact )
{
while ( $objcontact = $db -> fetch_object ( $resqlcontact ))
{
//print $objcontact->code.'-'.$objcontact->fk_socpeople."\n";
$object -> add_contact ( $objcontact -> fk_socpeople , $objcontact -> code );
}
}
else dol_print_error ( $resqlcontact );
2017-09-11 13:39:03 +02:00
} */
2016-08-10 09:47:25 +02:00
2016-02-25 16:27:28 +01:00
// Hooks
$parameters = array ( 'objFrom' => $srcobject );
$reshook = $hookmanager -> executeHooks ( 'createFrom' , $parameters , $object , $action ); // Note that $action and $object may have been
// modified by hook
2021-02-23 21:09:01 +01:00
if ( $reshook < 0 ) {
2017-10-16 08:47:05 +02:00
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
$error ++ ;
2016-07-19 07:46:27 +02:00
}
2015-01-17 19:28:27 +01:00
} else {
2015-11-15 07:47:35 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2016-02-25 16:27:28 +01:00
$error ++ ;
2014-05-25 05:01:14 +02:00
}
2020-05-21 15:05:19 +02:00
} else { // If some invoice's lines coming from page
2015-01-17 19:28:27 +01:00
$id = $object -> create ( $user );
2019-11-12 00:15:34 +01:00
for ( $i = 1 ; $i <= $NBLINES ; $i ++ ) {
2021-02-04 10:58:07 +01:00
if ( GETPOST ( 'idprod' . $i , 'int' )) {
2015-01-17 19:28:27 +01:00
$product = new Product ( $db );
2021-02-04 10:58:07 +01:00
$product -> fetch ( GETPOST ( 'idprod' . $i , 'int' ));
$startday = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'date_start' . $i . 'month' ), GETPOST ( 'date_start' . $i . 'day' ), GETPOST ( 'date_start' . $i . 'year' ));
$endday = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'date_end' . $i . 'month' ), GETPOST ( 'date_end' . $i . 'day' ), GETPOST ( 'date_end' . $i . 'year' ));
2022-05-03 15:57:17 +02:00
$result = $object -> addline ( $product -> description , $product -> price , price2num ( GETPOST ( 'qty' . $i ), 'MS' ), $product -> tva_tx , $product -> localtax1_tx , $product -> localtax2_tx , GETPOST ( 'idprod' . $i , 'int' ), price2num ( GETPOST ( 'remise_percent' . $i ), '' , 2 ), $startday , $endday , 0 , 0 , '' , $product -> price_base_type , $product -> price_ttc , $product -> type , - 1 , 0 , '' , 0 , 0 , null , 0 , '' , 0 , 100 , '' , $product -> fk_unit , 0 , '' , 1 );
2015-01-17 19:28:27 +01:00
}
2013-04-20 00:10:20 +02:00
}
2022-05-03 15:57:17 +02:00
$object -> update_price ( 1 , 'auto' , 0 , $mysoc );
2013-04-20 00:10:20 +02:00
}
}
}
2014-03-01 19:45:13 +01:00
2018-03-12 12:27:40 +01:00
// Situation invoices
2021-02-23 15:35:16 +01:00
if ( GETPOST ( 'type' ) == Facture :: TYPE_SITUATION && GETPOST ( 'situations' )) {
2021-01-11 15:34:25 +01:00
if ( empty ( $dateinvoice )) {
2015-01-18 18:44:22 +01:00
$error ++ ;
2019-05-29 09:51:45 +02:00
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Date " ));
2020-10-31 14:32:18 +01:00
setEventMessages ( $mesg , null , 'errors' );
2021-09-23 02:10:39 +02:00
} elseif ( $dateinvoice > ( dol_get_last_hour ( dol_now ( 'tzuserrel' )) + ( empty ( $conf -> global -> INVOICE_MAX_FUTURE_DELAY ) ? 0 : $conf -> global -> INVOICE_MAX_FUTURE_DELAY ))) {
2021-01-11 15:34:25 +01:00
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorDateIsInFuture " ), null , 'errors' );
$action = 'create' ;
2015-01-18 18:44:22 +01:00
}
2014-03-01 19:45:13 +01:00
2021-01-11 15:19:47 +01:00
if ( ! ( GETPOST ( 'situations' , 'int' ) > 0 )) {
2015-01-18 18:44:22 +01:00
$error ++ ;
2019-05-29 09:51:45 +02:00
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " InvoiceSituation " ));
2020-10-31 14:32:18 +01:00
setEventMessages ( $mesg , null , 'errors' );
$action = 'create' ;
2015-01-18 18:44:22 +01:00
}
2014-03-01 19:45:13 +01:00
2015-01-18 18:44:22 +01:00
if ( ! $error ) {
2021-01-11 15:19:47 +01:00
$result = $object -> fetch ( GETPOST ( 'situations' , 'int' ));
$object -> fk_facture_source = GETPOST ( 'situations' , 'int' );
2015-01-18 18:44:22 +01:00
$object -> type = Facture :: TYPE_SITUATION ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $origin ) && ! empty ( $originid )) {
2020-04-24 15:57:08 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php' ;
2016-01-13 13:42:58 +01:00
$object -> origin = $origin ;
$object -> origin_id = $originid ;
2016-08-10 09:47:25 +02:00
2020-02-19 11:54:55 +01:00
// retained warranty
2021-02-23 21:09:01 +01:00
if ( ! empty ( $conf -> global -> INVOICE_USE_RETAINED_WARRANTY )) {
2020-10-31 14:32:18 +01:00
$retained_warranty = GETPOST ( 'retained_warranty' , 'int' );
2021-02-23 21:09:01 +01:00
if ( price2num ( $retained_warranty ) > 0 ) {
2020-10-31 14:32:18 +01:00
$object -> retained_warranty = price2num ( $retained_warranty );
}
2021-02-23 21:09:01 +01:00
if ( GETPOST ( 'retained_warranty_fk_cond_reglement' , 'int' ) > 0 ) {
2020-10-31 14:32:18 +01:00
$object -> retained_warranty_fk_cond_reglement = GETPOST ( 'retained_warranty_fk_cond_reglement' , 'int' );
}
$retained_warranty_date_limit = GETPOST ( 'retained_warranty_date_limit' );
if ( ! empty ( $retained_warranty_date_limit ) && $db -> jdate ( $retained_warranty_date_limit )) {
$object -> retained_warranty_date_limit = $db -> jdate ( $retained_warranty_date_limit );
}
$object -> retained_warranty_date_limit = ! empty ( $object -> retained_warranty_date_limit ) ? $object -> retained_warranty_date_limit : $object -> calculate_date_lim_reglement ( $object -> retained_warranty_fk_cond_reglement );
}
2020-02-19 11:54:55 +01:00
2021-02-23 21:09:01 +01:00
foreach ( $object -> lines as $i => & $line ) {
2016-01-13 13:42:58 +01:00
$line -> origin = $object -> origin ;
$line -> origin_id = $line -> id ;
2018-10-11 10:14:22 +02:00
$line -> fk_prev_id = $line -> id ;
2020-03-27 16:02:58 +01:00
$line -> fetch_optionals ();
2019-11-12 00:15:34 +01:00
$line -> situation_percent = $line -> get_prev_progress ( $object -> id ); // get good progress including credit note
2018-09-28 02:24:11 +02:00
2020-04-24 15:57:08 +02:00
// The $line->situation_percent has been modified, so we must recalculate all amounts
$tabprice = calcul_price_total ( $line -> qty , $line -> subprice , $line -> remise_percent , $line -> tva_tx , $line -> localtax1_tx , $line -> localtax2_tx , 0 , 'HT' , 0 , $line -> product_type , $mysoc , '' , $line -> situation_percent );
$line -> total_ht = $tabprice [ 0 ];
$line -> total_tva = $tabprice [ 1 ];
$line -> total_ttc = $tabprice [ 2 ];
$line -> total_localtax1 = $tabprice [ 9 ];
$line -> total_localtax2 = $tabprice [ 10 ];
$line -> multicurrency_total_ht = $tabprice [ 16 ];
$line -> multicurrency_total_tva = $tabprice [ 17 ];
$line -> multicurrency_total_ttc = $tabprice [ 18 ];
2018-05-14 14:55:33 +02:00
// Si fk_remise_except defini on vérifie si la réduction à déjà été appliquée
2021-02-23 21:09:01 +01:00
if ( $line -> fk_remise_except ) {
2020-10-31 14:32:18 +01:00
$discount = new DiscountAbsolute ( $line -> db );
$result = $discount -> fetch ( $line -> fk_remise_except );
2021-02-23 21:09:01 +01:00
if ( $result > 0 ) {
2020-10-31 14:32:18 +01:00
// Check if discount not already affected to another invoice
2021-02-23 21:09:01 +01:00
if ( $discount -> fk_facture_line > 0 ) {
2020-10-31 14:32:18 +01:00
$line -> fk_remise_except = 0 ;
}
}
2018-05-14 14:55:33 +02:00
}
2016-01-13 13:42:58 +01:00
}
}
2015-01-18 18:44:22 +01:00
$object -> fetch_thirdparty ();
2021-01-11 15:34:25 +01:00
$object -> date = $dateinvoice ;
2016-05-29 23:56:58 +02:00
$object -> date_pointoftax = $date_pointoftax ;
2020-09-18 01:29:17 +02:00
$object -> note_public = trim ( GETPOST ( 'note_public' , 'restricthtml' ));
$object -> note = trim ( GETPOST ( 'note' , 'restricthtml' ));
$object -> note_private = trim ( GETPOST ( 'note' , 'restricthtml' ));
2019-01-27 11:55:16 +01:00
$object -> ref_client = GETPOST ( 'ref_client' , 'alpha' );
2020-09-10 01:49:09 +02:00
$object -> model_pdf = GETPOST ( 'model' , 'alpha' );
2019-01-27 11:55:16 +01:00
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
$object -> cond_reglement_id = GETPOST ( 'cond_reglement_id' , 'int' );
$object -> mode_reglement_id = GETPOST ( 'mode_reglement_id' , 'int' );
2021-09-08 22:00:16 +02:00
$object -> remise_absolue = price2num ( GETPOST ( 'remise_absolue' ), 'MU' , 2 );
$object -> remise_percent = price2num ( GETPOST ( 'remise_percent' ), '' , 2 );
2015-01-18 18:44:22 +01:00
// Proprietes particulieres a facture de remplacement
$object -> situation_counter = $object -> situation_counter + 1 ;
$id = $object -> createFromCurrent ( $user );
2021-02-23 21:09:01 +01:00
if ( $id <= 0 ) {
2017-09-19 18:42:29 +02:00
$mesg = $object -> error ;
2020-05-21 15:05:19 +02:00
} else {
2017-09-19 18:42:29 +02:00
$nextSituationInvoice = new Facture ( $db );
$nextSituationInvoice -> fetch ( $id );
2020-04-24 15:57:08 +02:00
2017-09-19 18:42:29 +02:00
// create extrafields with data from create form
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $nextSituationInvoice -> table_element );
$ret = $extrafields -> setOptionalsFromPost ( null , $nextSituationInvoice );
2017-09-19 18:42:29 +02:00
if ( $ret > 0 ) {
$nextSituationInvoice -> insertExtraFields ();
}
}
2015-01-18 18:44:22 +01:00
}
}
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
// End of object creation, we show it
2021-02-23 21:09:01 +01:00
if ( $id > 0 && ! $error ) {
2015-01-17 19:28:27 +01:00
$db -> commit ();
2017-01-16 20:24:26 +01:00
// Define output language
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ) && count ( $object -> lines )) {
2017-01-16 20:24:26 +01:00
$outputlangs = $langs ;
$newlang = '' ;
2021-02-23 21:09:01 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $newlang )) {
2017-01-16 20:24:26 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
2018-02-08 12:53:26 +01:00
$outputlangs -> load ( 'products' );
2017-01-16 20:24:26 +01:00
}
2020-09-10 01:49:09 +02:00
$model = $object -> model_pdf ;
2017-01-16 20:24:26 +01:00
$ret = $object -> fetch ( $id ); // Reload to get new records
$result = $object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2017-01-16 20:24:26 +01:00
}
2019-11-12 00:15:34 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $id );
2015-01-17 19:28:27 +01:00
exit ();
2020-05-21 15:05:19 +02:00
} else {
2015-01-17 19:28:27 +01:00
$db -> rollback ();
$action = 'create' ;
2015-01-18 17:13:42 +01:00
$_GET [ " origin " ] = $_POST [ " origin " ];
$_GET [ " originid " ] = $_POST [ " originid " ];
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-17 19:28:27 +01:00
}
2021-02-28 12:59:58 +01:00
} elseif ( $action == 'addline' && GETPOST ( 'submitforalllines' , 'alpha' ) && GETPOST ( 'vatforalllines' , 'alpha' ) !== '' ) {
2020-07-06 22:48:22 +02:00
// Define vat_rate
$vat_rate = ( GETPOST ( 'vatforalllines' ) ? GETPOST ( 'vatforalllines' ) : 0 );
$vat_rate = str_replace ( '*' , '' , $vat_rate );
$localtax1_rate = get_localtax ( $vat_rate , 1 , $object -> thirdparty , $mysoc );
$localtax2_rate = get_localtax ( $vat_rate , 2 , $object -> thirdparty , $mysoc );
2020-07-07 01:29:31 +02:00
foreach ( $object -> lines as $line ) {
2020-07-06 22:48:22 +02:00
$result = $object -> updateline ( $line -> id , $line -> desc , $line -> subprice , $line -> qty , $line -> remise_percent , $line -> date_start , $line -> date_end , $vat_rate , $localtax1_rate , $localtax2_rate , 'HT' , $line -> info_bits , $line -> product_type , $line -> fk_parent_line , 0 , $line -> fk_fournprice , $line -> pa_ht , $line -> label , $line -> special_code , $line -> array_options , $line -> situation_percent , $line -> fk_unit , $line -> multicurrency_subprice );
}
2022-04-15 14:31:44 +02:00
} elseif ( $action == 'addline' && GETPOST ( 'submitforalllines' , 'alpha' ) && GETPOST ( 'remiseforalllines' , 'alpha' ) !== '' && $usercancreate ) {
// Define vat_rate
$remise_percent = ( GETPOST ( 'remiseforalllines' ) ? GETPOST ( 'remiseforalllines' ) : 0 );
$remise_percent = str_replace ( '*' , '' , $remise_percent );
foreach ( $object -> lines as $line ) {
$result = $object -> updateline ( $line -> id , $line -> desc , $line -> subprice , $line -> qty , $remise_percent , $line -> date_start , $line -> date_end , $line -> tva_tx , $line -> localtax1_tx , $line -> localtax2_tx , 'HT' , $line -> info_bits , $line -> product_type , $line -> fk_parent_line , 0 , $line -> fk_fournprice , $line -> pa_ht , $line -> label , $line -> special_code , $line -> array_options , $line -> situation_percent , $line -> fk_unit , $line -> multicurrency_subprice );
}
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'addline' && $usercancreate ) { // Add a new line
2015-01-17 19:28:27 +01:00
$langs -> load ( 'errors' );
$error = 0 ;
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
// Set if we used free entry or predefined product
2019-11-12 00:15:34 +01:00
$predef = '' ;
2020-10-28 16:37:41 +01:00
$product_desc = ( GETPOSTISSET ( 'dp_desc' ) ? GETPOST ( 'dp_desc' , 'restricthtml' ) : '' );
2021-03-02 23:09:55 +01:00
$price_ht = price2num ( GETPOST ( 'price_ht' ), 'MU' , 2 );
$price_ht_devise = price2num ( GETPOST ( 'multicurrency_price_ht' ), 'CU' , 2 );
2019-01-27 11:55:16 +01:00
$prod_entry_mode = GETPOST ( 'prod_entry_mode' , 'alpha' );
2021-02-23 21:09:01 +01:00
if ( $prod_entry_mode == 'free' ) {
2019-11-12 00:15:34 +01:00
$idprod = 0 ;
2019-01-27 11:55:16 +01:00
$tva_tx = ( GETPOST ( 'tva_tx' , 'alpha' ) ? GETPOST ( 'tva_tx' , 'alpha' ) : 0 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
$idprod = GETPOST ( 'idprod' , 'int' );
2015-01-17 19:28:27 +01:00
$tva_tx = '' ;
2013-06-10 16:05:41 +02:00
}
2014-03-01 19:45:13 +01:00
2021-09-08 22:00:16 +02:00
$qty = price2num ( GETPOST ( 'qty' . $predef ), 'MS' , 2 );
$remise_percent = price2num ( GETPOST ( 'remise_percent' . $predef ), '' , 2 );
2015-01-17 19:28:27 +01:00
// Extrafields
2019-10-06 14:41:52 +02:00
$extralabelsline = $extrafields -> fetch_name_optionals_label ( $object -> table_element_line );
$array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element_line , $predef );
2015-01-17 19:28:27 +01:00
// Unset extrafield
if ( is_array ( $extralabelsline )) {
// Get extra fields
foreach ( $extralabelsline as $key => $value ) {
2019-11-12 00:15:34 +01:00
unset ( $_POST [ " options_ " . $key . $predef ]);
2015-01-17 19:28:27 +01:00
}
}
2014-03-01 19:45:13 +01:00
2021-07-04 21:02:02 +02:00
if (( empty ( $idprod ) || $idprod < 0 ) && ( $price_ht < 0 ) && ( $qty < 0 )) {
2015-11-15 07:47:35 +01:00
setEventMessages ( $langs -> trans ( 'ErrorBothFieldCantBeNegative' , $langs -> transnoentitiesnoconv ( 'UnitPriceHT' ), $langs -> transnoentitiesnoconv ( 'Qty' )), null , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-01-17 19:28:27 +01:00
}
2021-02-23 21:09:01 +01:00
if ( ! $prod_entry_mode ) {
if ( GETPOST ( 'type' ) < 0 && ! GETPOST ( 'search_idprod' )) {
2017-10-16 08:47:05 +02:00
setEventMessages ( $langs -> trans ( 'ErrorChooseBetweenFreeEntryOrPredefinedProduct' ), null , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2017-10-16 08:47:05 +02:00
}
}
2021-07-04 21:02:02 +02:00
if ( $prod_entry_mode == 'free' && ( empty ( $idprod ) || $idprod < 0 ) && GETPOST ( 'type' ) < 0 ) {
2017-10-16 08:47:05 +02:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( 'Type' )), null , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-01-17 19:28:27 +01:00
}
2021-07-04 21:02:02 +02:00
if (( $prod_entry_mode == 'free' && ( empty ( $idprod ) || $idprod < 0 ) && (( $price_ht < 0 && empty ( $conf -> global -> FACTURE_ENABLE_NEGATIVE_LINES )) || $price_ht == '' ) && $price_ht_devise == '' ) && $object -> type != Facture :: TYPE_CREDIT_NOTE ) { // Unit price can be 0 but not ''
2021-02-23 21:09:01 +01:00
if ( $price_ht < 0 && empty ( $conf -> global -> FACTURE_ENABLE_NEGATIVE_LINES )) {
2018-09-04 10:37:29 +02:00
$langs -> load ( " errors " );
2020-01-19 15:19:07 +01:00
if ( $object -> type == $object :: TYPE_DEPOSIT ) {
// Using negative lines on deposit lead to headach and blocking problems when you want to consume them.
setEventMessages ( $langs -> trans ( " ErrorLinesCantBeNegativeOnDeposits " ), null , 'errors' );
} else {
setEventMessages ( $langs -> trans ( " ErrorFieldCantBeNegativeOnInvoice " , $langs -> transnoentitiesnoconv ( " UnitPriceHT " ), $langs -> transnoentitiesnoconv ( " CustomerAbsoluteDiscountShort " )), null , 'errors' );
}
2018-09-04 10:37:29 +02:00
$error ++ ;
2020-05-21 15:05:19 +02:00
} else {
2018-09-04 10:37:29 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " UnitPriceHT " )), null , 'errors' );
$error ++ ;
}
2015-01-17 19:28:27 +01:00
}
if ( $qty == '' ) {
2015-11-15 07:47:35 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( 'Qty' )), null , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-01-17 19:28:27 +01:00
}
2016-07-23 16:37:21 +02:00
if ( $prod_entry_mode == 'free' && empty ( $idprod ) && empty ( $product_desc )) {
2015-11-15 07:47:35 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( 'Description' )), null , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-01-17 19:28:27 +01:00
}
2015-01-18 17:13:42 +01:00
if ( $qty < 0 ) {
$langs -> load ( " errors " );
2015-11-15 07:47:35 +01:00
setEventMessages ( $langs -> trans ( 'ErrorQtyForCustomerInvoiceCantBeNegative' ), null , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-01-18 17:13:42 +01:00
}
2016-07-23 16:37:21 +02:00
2022-08-29 12:01:36 +02:00
if ( ! $error && isModEnabled ( 'variants' ) && $prod_entry_mode != 'free' ) {
2016-07-23 16:37:21 +02:00
if ( $combinations = GETPOST ( 'combinations' , 'array' )) {
//Check if there is a product with the given combination
$prodcomb = new ProductCombination ( $db );
if ( $res = $prodcomb -> fetchByProductCombination2ValuePairs ( $idprod , $combinations )) {
$idprod = $res -> fk_product_child ;
2020-05-21 15:05:19 +02:00
} else {
2018-07-24 18:28:56 +02:00
setEventMessages ( $langs -> trans ( 'ErrorProductCombinationNotFound' ), null , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2016-07-23 16:37:21 +02:00
}
}
}
2021-07-04 21:02:02 +02:00
if ( ! $error && ( $qty >= 0 ) && ( ! empty ( $product_desc ) || ( ! empty ( $idprod ) && $idprod > 0 ))) {
2015-01-17 19:28:27 +01:00
$ret = $object -> fetch ( $id );
if ( $ret < 0 ) {
dol_print_error ( $db , $object -> error );
exit ();
}
$ret = $object -> fetch_thirdparty ();
// Clean parameters
2019-11-12 00:15:34 +01:00
$date_start = dol_mktime ( GETPOST ( 'date_start' . $predef . 'hour' ), GETPOST ( 'date_start' . $predef . 'min' ), GETPOST ( 'date_start' . $predef . 'sec' ), GETPOST ( 'date_start' . $predef . 'month' ), GETPOST ( 'date_start' . $predef . 'day' ), GETPOST ( 'date_start' . $predef . 'year' ));
$date_end = dol_mktime ( GETPOST ( 'date_end' . $predef . 'hour' ), GETPOST ( 'date_end' . $predef . 'min' ), GETPOST ( 'date_end' . $predef . 'sec' ), GETPOST ( 'date_end' . $predef . 'month' ), GETPOST ( 'date_end' . $predef . 'day' ), GETPOST ( 'date_end' . $predef . 'year' ));
2015-01-17 19:28:27 +01:00
$price_base_type = ( GETPOST ( 'price_base_type' , 'alpha' ) ? GETPOST ( 'price_base_type' , 'alpha' ) : 'HT' );
// Define special_code for special lines
$special_code = 0 ;
2022-02-22 23:44:56 +01:00
// if (!GETPOST(qty)) $special_code=3; // Options should not exists on invoices
2015-01-17 19:28:27 +01:00
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
2017-03-04 21:45:19 +01:00
// Ecrase $tva_tx par celui du produit
2015-01-17 19:28:27 +01:00
// Ecrase $base_price_type par celui du produit
2015-02-26 14:15:33 +01:00
// Replaces $fk_unit with the product's
2021-07-04 21:02:02 +02:00
if ( ! empty ( $idprod ) && $idprod > 0 ) {
2015-01-17 19:28:27 +01:00
$prod = new Product ( $db );
$prod -> fetch ( $idprod );
$label = (( GETPOST ( 'product_label' ) && GETPOST ( 'product_label' ) != $prod -> label ) ? GETPOST ( 'product_label' ) : '' );
2019-01-24 19:45:17 +01:00
// Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
2019-01-27 11:55:16 +01:00
$pqp = ( GETPOST ( 'pbq' , 'int' ) ? GETPOST ( 'pbq' , 'int' ) : 0 );
2016-07-19 07:46:27 +02:00
2019-01-24 19:45:17 +01:00
$datapriceofproduct = $prod -> getSellPrice ( $mysoc , $object -> thirdparty , $pqp );
2015-01-17 19:28:27 +01:00
2019-01-24 19:45:17 +01:00
$pu_ht = $datapriceofproduct [ 'pu_ht' ];
$pu_ttc = $datapriceofproduct [ 'pu_ttc' ];
$price_min = $datapriceofproduct [ 'price_min' ];
$price_base_type = $datapriceofproduct [ 'price_base_type' ];
$tva_tx = $datapriceofproduct [ 'tva_tx' ];
$tva_npr = $datapriceofproduct [ 'tva_npr' ];
2014-03-01 19:45:13 +01:00
2017-03-04 21:45:19 +01:00
$tmpvat = price2num ( preg_replace ( '/\s*\(.*\)/' , '' , $tva_tx ));
$tmpprodvat = price2num ( preg_replace ( '/\s*\(.*\)/' , '' , $prod -> tva_tx ));
2017-06-07 16:44:04 +02:00
2017-03-04 21:45:19 +01:00
// if price ht was forced (ie: from gui when calculated by margin rate and cost price). TODO Why this ?
2021-02-23 21:09:01 +01:00
if ( ! empty ( $price_ht ) || $price_ht === '0' ) {
2017-03-04 21:45:19 +01:00
$pu_ht = price2num ( $price_ht , 'MU' );
$pu_ttc = price2num ( $pu_ht * ( 1 + ( $tmpvat / 100 )), 'MU' );
2021-02-23 21:09:01 +01:00
} elseif ( $tmpvat != $tmpprodvat ) {
// On reevalue prix selon taux tva car taux tva transaction peut etre different
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
if ( $price_base_type != 'HT' ) {
2017-03-04 21:45:19 +01:00
$pu_ht = price2num ( $pu_ttc / ( 1 + ( $tmpvat / 100 )), 'MU' );
2020-05-21 15:05:19 +02:00
} else {
2017-03-04 21:45:19 +01:00
$pu_ttc = price2num ( $pu_ht * ( 1 + ( $tmpvat / 100 )), 'MU' );
2013-04-20 00:10:20 +02:00
}
2017-03-04 21:45:19 +01:00
}
2014-03-01 19:45:13 +01:00
2017-03-04 21:45:19 +01:00
$desc = '' ;
2014-03-01 19:45:13 +01:00
2017-03-04 21:45:19 +01:00
// Define output language
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE )) {
2017-03-04 21:45:19 +01:00
$outputlangs = $langs ;
$newlang = '' ;
2021-02-23 21:09:01 +01:00
if ( empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
2019-01-27 11:55:16 +01:00
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
2021-02-23 21:09:01 +01:00
}
if ( empty ( $newlang )) {
2017-03-04 21:45:19 +01:00
$newlang = $object -> thirdparty -> default_lang ;
2021-02-23 21:09:01 +01:00
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $newlang )) {
2017-03-04 21:45:19 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
2018-02-08 12:53:26 +01:00
$outputlangs -> load ( 'products' );
2013-04-20 00:10:20 +02:00
}
2014-11-14 16:43:49 +01:00
2019-11-12 00:15:34 +01:00
$desc = ( ! empty ( $prod -> multilangs [ $outputlangs -> defaultlang ] [ " description " ])) ? $prod -> multilangs [ $outputlangs -> defaultlang ] [ " description " ] : $prod -> description ;
2017-03-04 21:45:19 +01:00
} else {
$desc = $prod -> description ;
}
2020-10-25 19:13:09 +01:00
//If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time
2020-10-28 16:37:41 +01:00
if ( $product_desc == $desc && ! empty ( $conf -> global -> PRODUIT_AUTOFILL_DESC )) {
2020-10-25 19:13:09 +01:00
$product_desc = '' ;
}
2021-02-23 21:09:01 +01:00
if ( ! empty ( $product_desc ) && ! empty ( $conf -> global -> MAIN_NO_CONCAT_DESCRIPTION )) {
$desc = $product_desc ;
} else {
$desc = dol_concatdesc ( $desc , $product_desc , '' , ! empty ( $conf -> global -> MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION ));
}
2017-03-04 21:45:19 +01:00
// Add custom code and origin country into description
2019-11-12 00:15:34 +01:00
if ( empty ( $conf -> global -> MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE ) && ( ! empty ( $prod -> customcode ) || ! empty ( $prod -> country_code ))) {
2017-03-04 21:45:19 +01:00
$tmptxt = '(' ;
2017-12-08 10:41:14 +01:00
// Define output language
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE )) {
2017-12-08 10:41:14 +01:00
$outputlangs = $langs ;
$newlang = '' ;
2021-02-23 21:09:01 +01:00
if ( empty ( $newlang ) && GETPOST ( 'lang_id' , 'alpha' )) {
2019-01-27 11:55:16 +01:00
$newlang = GETPOST ( 'lang_id' , 'alpha' );
2021-02-23 21:09:01 +01:00
}
if ( empty ( $newlang )) {
2017-12-08 10:41:14 +01:00
$newlang = $object -> thirdparty -> default_lang ;
2021-02-23 21:09:01 +01:00
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $newlang )) {
2017-12-08 10:41:14 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
2017-12-08 11:00:23 +01:00
$outputlangs -> load ( 'products' );
2017-12-08 10:41:14 +01:00
}
2021-02-23 21:09:01 +01:00
if ( ! empty ( $prod -> customcode )) {
2019-11-12 00:15:34 +01:00
$tmptxt .= $outputlangs -> transnoentitiesnoconv ( " CustomCode " ) . ': ' . $prod -> customcode ;
2021-02-23 21:09:01 +01:00
}
if ( ! empty ( $prod -> customcode ) && ! empty ( $prod -> country_code )) {
2017-12-08 10:41:14 +01:00
$tmptxt .= ' - ' ;
2021-02-23 21:09:01 +01:00
}
if ( ! empty ( $prod -> country_code )) {
2019-11-12 00:15:34 +01:00
$tmptxt .= $outputlangs -> transnoentitiesnoconv ( " CountryOrigin " ) . ': ' . getCountry ( $prod -> country_code , 0 , $db , $outputlangs , 0 );
2021-02-23 21:09:01 +01:00
}
2017-12-08 10:41:14 +01:00
} else {
2021-02-23 21:09:01 +01:00
if ( ! empty ( $prod -> customcode )) {
2019-11-12 00:15:34 +01:00
$tmptxt .= $langs -> transnoentitiesnoconv ( " CustomCode " ) . ': ' . $prod -> customcode ;
2021-02-23 21:09:01 +01:00
}
if ( ! empty ( $prod -> customcode ) && ! empty ( $prod -> country_code )) {
2017-12-08 10:41:14 +01:00
$tmptxt .= ' - ' ;
2021-02-23 21:09:01 +01:00
}
if ( ! empty ( $prod -> country_code )) {
2019-11-12 00:15:34 +01:00
$tmptxt .= $langs -> transnoentitiesnoconv ( " CountryOrigin " ) . ': ' . getCountry ( $prod -> country_code , 0 , $db , $langs , 0 );
2021-02-23 21:09:01 +01:00
}
2017-12-08 10:41:14 +01:00
}
2017-03-04 21:45:19 +01:00
$tmptxt .= ')' ;
$desc = dol_concatdesc ( $desc , $tmptxt );
}
2014-11-14 16:43:49 +01:00
2015-01-17 19:28:27 +01:00
$type = $prod -> type ;
2015-02-26 14:15:33 +01:00
$fk_unit = $prod -> fk_unit ;
2015-01-17 19:28:27 +01:00
} else {
$pu_ht = price2num ( $price_ht , 'MU' );
$pu_ttc = price2num ( GETPOST ( 'price_ttc' ), 'MU' );
$tva_npr = ( preg_match ( '/\*/' , $tva_tx ) ? 1 : 0 );
$tva_tx = str_replace ( '*' , '' , $tva_tx );
2021-02-23 21:09:01 +01:00
if ( empty ( $tva_tx )) {
$tva_npr = 0 ;
}
2015-01-17 19:28:27 +01:00
$label = ( GETPOST ( 'product_label' ) ? GETPOST ( 'product_label' ) : '' );
$desc = $product_desc ;
$type = GETPOST ( 'type' );
2019-11-12 00:15:34 +01:00
$fk_unit = GETPOST ( 'units' , 'alpha' );
2015-01-17 19:28:27 +01:00
}
2022-09-07 13:58:24 +02:00
2022-09-07 08:56:02 +02:00
$pu_ht_devise = price2num ( $price_ht_devise , 'MU' );
2014-11-14 16:43:49 +01:00
2015-01-17 19:28:27 +01:00
// Margin
2019-11-12 00:15:34 +01:00
$fournprice = price2num ( GETPOST ( 'fournprice' . $predef ) ? GETPOST ( 'fournprice' . $predef ) : '' );
$buyingprice = price2num ( GETPOST ( 'buying_price' . $predef ) != '' ? GETPOST ( 'buying_price' . $predef ) : '' ); // If buying_price is '0', we must keep this value
2014-11-14 16:43:49 +01:00
2015-01-17 19:28:27 +01:00
// Local Taxes
2016-02-27 11:32:49 +01:00
$localtax1_tx = get_localtax ( $tva_tx , 1 , $object -> thirdparty , $mysoc , $tva_npr );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $object -> thirdparty , $mysoc , $tva_npr );
2016-07-19 07:46:27 +02:00
2015-01-17 19:28:27 +01:00
$info_bits = 0 ;
2021-02-23 21:09:01 +01:00
if ( $tva_npr ) {
2015-01-17 19:28:27 +01:00
$info_bits |= 0x01 ;
2021-02-23 21:09:01 +01:00
}
2014-11-14 16:43:49 +01:00
2019-12-09 13:40:26 +01:00
$price2num_pu_ht = price2num ( $pu_ht );
$price2num_remise_percent = price2num ( $remise_percent );
$price2num_price_min = price2num ( $price_min );
2021-02-23 21:09:01 +01:00
if ( empty ( $price2num_pu_ht )) {
$price2num_pu_ht = 0 ;
}
if ( empty ( $price2num_remise_percent )) {
$price2num_remise_percent = 0 ;
}
if ( empty ( $price2num_price_min )) {
$price2num_price_min = 0 ;
}
2019-12-09 13:40:26 +01:00
2019-12-18 15:20:36 +01:00
if ( $usercanproductignorepricemin && ( ! empty ( $price_min ) && ( $price2num_pu_ht * ( 1 - $price2num_remise_percent / 100 ) < $price2num_price_min ))) {
2015-01-17 19:28:27 +01:00
$mesg = $langs -> trans ( " CantBeLessThanMinPrice " , price ( price2num ( $price_min , 'MU' ), 0 , $langs , 0 , 0 , - 1 , $conf -> currency ));
2015-11-15 07:47:35 +01:00
setEventMessages ( $mesg , null , 'errors' );
2015-01-17 19:28:27 +01:00
} else {
2021-06-04 12:55:03 +02:00
// Add batchinfo if the detail_batch array is defined
2021-06-04 12:57:43 +02:00
if ( ! empty ( $conf -> productbatch -> enabled ) && ! empty ( $lines [ $i ] -> detail_batch ) && is_array ( $lines [ $i ] -> detail_batch ) && ! empty ( $conf -> global -> INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS )) {
2021-06-04 12:56:40 +02:00
$langs -> load ( 'productbatch' );
2021-05-27 12:24:18 +02:00
foreach ( $lines [ $i ] -> detail_batch as $batchline ) {
2021-06-04 12:55:03 +02:00
$desc .= ' ' . $langs -> trans ( 'Batch' ) . ' ' . $batchline -> batch . ' ' . $langs -> trans ( 'printQty' , $batchline -> qty ) . ' ' ;
2021-05-27 12:24:18 +02:00
}
2021-05-27 12:20:42 +02:00
}
2021-05-27 12:24:18 +02:00
2015-01-17 19:28:27 +01:00
// Insert line
2022-03-10 10:02:57 +01:00
$result = $object -> addline ( $desc , $pu_ht , $qty , $tva_tx , $localtax1_tx , $localtax2_tx , $idprod , $remise_percent , $date_start , $date_end , 0 , $info_bits , '' , $price_base_type , $pu_ttc , $type , min ( $rank , count ( $object -> lines ) + 1 ), $special_code , '' , 0 , GETPOST ( 'fk_parent_line' ), $fournprice , $buyingprice , $label , $array_options , GETPOST ( 'progress' ), '' , $fk_unit , $pu_ht_devise );
2008-08-12 20:20:18 +02:00
2021-02-23 21:09:01 +01:00
if ( $result > 0 ) {
2019-05-20 14:41:47 +02:00
// Define output language and generate document
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2015-01-17 19:28:27 +01:00
$outputlangs = $langs ;
2015-01-18 17:13:42 +01:00
$newlang = '' ;
2022-09-07 13:58:24 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
2021-02-23 21:09:01 +01:00
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
2022-09-07 08:56:02 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && empty ( $newlang )) {
2021-02-23 21:09:01 +01:00
$newlang = $object -> thirdparty -> default_lang ;
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $newlang )) {
2015-01-17 19:28:27 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
2018-02-08 12:53:26 +01:00
$outputlangs -> load ( 'products' );
2013-04-20 17:10:03 +02:00
}
2020-09-10 01:49:09 +02:00
$model = $object -> model_pdf ;
2015-01-17 19:28:27 +01:00
$ret = $object -> fetch ( $id ); // Reload to get new records
2015-01-18 17:13:42 +01:00
2015-05-03 20:07:16 +02:00
$result = $object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2013-04-20 00:10:20 +02:00
}
2014-05-05 14:30:08 +02:00
2015-01-18 17:13:42 +01:00
unset ( $_POST [ 'prod_entry_mode' ]);
2015-01-17 19:28:27 +01:00
unset ( $_POST [ 'qty' ]);
unset ( $_POST [ 'type' ]);
unset ( $_POST [ 'remise_percent' ]);
unset ( $_POST [ 'price_ht' ]);
2016-04-12 14:10:27 +02:00
unset ( $_POST [ 'multicurrency_price_ht' ]);
2015-01-17 19:28:27 +01:00
unset ( $_POST [ 'price_ttc' ]);
unset ( $_POST [ 'tva_tx' ]);
unset ( $_POST [ 'product_ref' ]);
unset ( $_POST [ 'product_label' ]);
unset ( $_POST [ 'product_desc' ]);
unset ( $_POST [ 'fournprice' ]);
unset ( $_POST [ 'buying_price' ]);
unset ( $_POST [ 'np_marginRate' ]);
unset ( $_POST [ 'np_markRate' ]);
unset ( $_POST [ 'dp_desc' ]);
unset ( $_POST [ 'idprod' ]);
2015-02-26 14:15:33 +01:00
unset ( $_POST [ 'units' ]);
2015-01-17 19:28:27 +01:00
2017-10-16 08:47:05 +02:00
unset ( $_POST [ 'date_starthour' ]);
unset ( $_POST [ 'date_startmin' ]);
unset ( $_POST [ 'date_startsec' ]);
unset ( $_POST [ 'date_startday' ]);
unset ( $_POST [ 'date_startmonth' ]);
unset ( $_POST [ 'date_startyear' ]);
unset ( $_POST [ 'date_endhour' ]);
unset ( $_POST [ 'date_endmin' ]);
unset ( $_POST [ 'date_endsec' ]);
unset ( $_POST [ 'date_endday' ]);
unset ( $_POST [ 'date_endmonth' ]);
unset ( $_POST [ 'date_endyear' ]);
2015-01-18 18:44:22 +01:00
unset ( $_POST [ 'situations' ]);
unset ( $_POST [ 'progress' ]);
2014-02-23 20:10:05 +01:00
} else {
2015-11-15 07:47:35 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2013-04-20 00:10:20 +02:00
}
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
$action = '' ;
2013-04-20 00:10:20 +02:00
}
2013-06-10 16:05:41 +02:00
}
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'updateline' && $usercancreate && ! GETPOST ( 'cancel' , 'alpha' )) {
if ( ! $object -> fetch ( $id ) > 0 ) {
dol_print_error ( $db );
}
2015-01-17 19:28:27 +01:00
$object -> fetch_thirdparty ();
2014-03-01 19:45:13 +01:00
2013-04-20 00:10:20 +02:00
// Clean parameters
2015-01-17 19:28:27 +01:00
$date_start = '' ;
$date_end = '' ;
$date_start = dol_mktime ( GETPOST ( 'date_starthour' ), GETPOST ( 'date_startmin' ), GETPOST ( 'date_startsec' ), GETPOST ( 'date_startmonth' ), GETPOST ( 'date_startday' ), GETPOST ( 'date_startyear' ));
$date_end = dol_mktime ( GETPOST ( 'date_endhour' ), GETPOST ( 'date_endmin' ), GETPOST ( 'date_endsec' ), GETPOST ( 'date_endmonth' ), GETPOST ( 'date_endday' ), GETPOST ( 'date_endyear' ));
2020-09-18 01:29:17 +02:00
$description = dol_htmlcleanlastbr ( GETPOST ( 'product_desc' , 'restricthtml' ) ? GETPOST ( 'product_desc' , 'restricthtml' ) : GETPOST ( 'desc' , 'restricthtml' ));
2021-03-02 23:09:55 +01:00
$pu_ht = price2num ( GETPOST ( 'price_ht' ), '' , 2 );
2015-01-17 19:28:27 +01:00
$vat_rate = ( GETPOST ( 'tva_tx' ) ? GETPOST ( 'tva_tx' ) : 0 );
2015-01-18 17:13:42 +01:00
$qty = GETPOST ( 'qty' );
2021-03-02 23:09:55 +01:00
$pu_ht_devise = price2num ( GETPOST ( 'multicurrency_subprice' ), '' , 2 );
2016-08-10 09:47:25 +02:00
2015-01-17 19:28:27 +01:00
// Define info_bits
2014-02-23 20:10:05 +01:00
$info_bits = 0 ;
2021-02-23 21:09:01 +01:00
if ( preg_match ( '/\*/' , $vat_rate )) {
$info_bits |= 0x01 ;
}
2014-03-01 19:45:13 +01:00
2015-05-07 13:35:09 +02:00
// Define vat_rate
2015-01-17 19:28:27 +01:00
$vat_rate = str_replace ( '*' , '' , $vat_rate );
2015-01-18 17:13:42 +01:00
$localtax1_rate = get_localtax ( $vat_rate , 1 , $object -> thirdparty );
$localtax2_rate = get_localtax ( $vat_rate , 2 , $object -> thirdparty );
2015-01-17 19:28:27 +01:00
// Add buying price
$fournprice = price2num ( GETPOST ( 'fournprice' ) ? GETPOST ( 'fournprice' ) : '' );
2019-11-12 00:15:34 +01:00
$buyingprice = price2num ( GETPOST ( 'buying_price' ) != '' ? GETPOST ( 'buying_price' ) : '' ); // If buying_price is '0', we muste keep this value
2016-07-19 07:46:27 +02:00
2015-01-17 19:28:27 +01:00
// Extrafields
2019-10-06 14:41:52 +02:00
$extralabelsline = $extrafields -> fetch_name_optionals_label ( $object -> table_element_line );
$array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element_line );
2015-01-17 19:28:27 +01:00
// Unset extrafield
if ( is_array ( $extralabelsline )) {
// Get extra fields
foreach ( $extralabelsline as $key => $value ) {
2019-11-12 00:15:34 +01:00
unset ( $_POST [ " options_ " . $key ]);
2015-01-17 19:28:27 +01:00
}
2013-04-20 00:10:20 +02:00
}
2014-08-05 09:28:58 +02:00
2015-05-07 12:10:27 +02:00
// Define special_code for special lines
2022-02-28 18:13:29 +01:00
$special_code = GETPOST ( 'special_code' , 'int' );
if ( $special_code == 3 ) {
$special_code = 0 ; // Options should not exists on invoices
2021-02-23 21:09:01 +01:00
}
2015-05-07 12:10:27 +02:00
2015-01-18 18:44:22 +01:00
$line = new FactureLigne ( $db );
2020-01-16 10:12:39 +01:00
$line -> fetch ( GETPOST ( 'lineid' , 'int' ));
2016-03-12 20:49:38 +01:00
$percent = $line -> get_prev_progress ( $object -> id );
2021-06-29 19:14:03 +02:00
$progress = price2num ( GETPOST ( 'progress' , 'alpha' ));
2013-08-12 15:34:09 +02:00
2021-02-23 21:09:01 +01:00
if ( $object -> type == Facture :: TYPE_CREDIT_NOTE && $object -> situation_cycle_ref > 0 ) {
2020-10-31 14:32:18 +01:00
// in case of situation credit note
2021-06-29 16:33:24 +02:00
if ( $progress >= 0 ) {
2020-10-31 14:32:18 +01:00
$mesg = $langs -> trans ( " CantBeNullOrPositive " );
setEventMessages ( $mesg , null , 'warnings' );
$error ++ ;
$result = - 1 ;
2021-06-29 16:33:24 +02:00
} elseif ( $progress < $line -> situation_percent ) { // TODO : use a modified $line->get_prev_progress($object->id) result
2020-10-31 14:32:18 +01:00
$mesg = $langs -> trans ( " CantBeLessThanMinPercent " );
setEventMessages ( $mesg , null , 'warnings' );
$error ++ ;
$result = - 1 ;
2021-06-29 16:56:48 +02:00
} elseif ( $progress < $percent ) {
2021-06-28 11:38:34 +02:00
$mesg = '<div class="warning">' . $langs -> trans ( " CantBeLessThanMinPercent " ) . '</div>' ;
setEventMessages ( $mesg , null , 'warnings' );
$error ++ ;
$result = - 1 ;
2020-10-31 14:32:18 +01:00
}
2015-01-18 18:44:22 +01:00
}
2014-03-01 19:45:13 +01:00
2021-09-08 22:00:16 +02:00
$remise_percent = price2num ( GETPOST ( 'remise_percent' ), '' , 2 );
2015-01-17 19:28:27 +01:00
// Check minimum price
$productid = GETPOST ( 'productid' , 'int' );
2021-02-23 21:09:01 +01:00
if ( ! empty ( $productid )) {
2015-01-17 19:28:27 +01:00
$product = new Product ( $db );
$product -> fetch ( $productid );
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
$type = $product -> type ;
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
$price_min = $product -> price_min ;
2021-02-23 21:09:01 +01:00
if (( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) && ! empty ( $object -> thirdparty -> price_level )) {
2015-01-18 17:13:42 +01:00
$price_min = $product -> multiprices_min [ $object -> thirdparty -> price_level ];
2021-02-23 21:09:01 +01:00
}
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
$label = (( GETPOST ( 'update_label' ) && GETPOST ( 'product_label' )) ? GETPOST ( 'product_label' ) : '' );
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
// Check price is not lower than minimum (check is done only for standard or replacement invoices)
2021-09-08 22:00:16 +02:00
if ( $usercanproductignorepricemin && (( $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_REPLACEMENT ) && $price_min && ( price2num ( $pu_ht ) * ( 1 - $remise_percent / 100 ) < price2num ( $price_min )))) {
2015-11-15 07:47:35 +01:00
setEventMessages ( $langs -> trans ( " CantBeLessThanMinPrice " , price ( price2num ( $price_min , 'MU' ), 0 , $langs , 0 , 0 , - 1 , $conf -> currency )), null , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-01-17 19:28:27 +01:00
}
2014-02-23 20:10:05 +01:00
} else {
$type = GETPOST ( 'type' );
2015-01-17 19:28:27 +01:00
$label = ( GETPOST ( 'product_label' ) ? GETPOST ( 'product_label' ) : '' );
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
// Check parameters
if ( GETPOST ( 'type' ) < 0 ) {
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Type " )), null , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
2015-01-17 19:28:27 +01:00
}
}
2015-01-18 17:13:42 +01:00
if ( $qty < 0 ) {
$langs -> load ( " errors " );
2015-11-15 07:47:35 +01:00
setEventMessages ( $langs -> trans ( 'ErrorQtyForCustomerInvoiceCantBeNegative' ), null , 'errors' );
2018-09-04 10:37:29 +02:00
$error ++ ;
}
2021-02-23 21:09:01 +01:00
if (( empty ( $productid ) && (( $pu_ht < 0 && empty ( $conf -> global -> FACTURE_ENABLE_NEGATIVE_LINES )) || $pu_ht == '' ) && $pu_ht_devise == '' ) && $object -> type != Facture :: TYPE_CREDIT_NOTE ) { // Unit price can be 0 but not ''
if ( $pu_ht < 0 && empty ( $conf -> global -> FACTURE_ENABLE_NEGATIVE_LINES )) {
2018-09-04 10:37:29 +02:00
$langs -> load ( " errors " );
2020-01-19 15:19:07 +01:00
if ( $object -> type == $object :: TYPE_DEPOSIT ) {
// Using negative lines on deposit lead to headach and blocking problems when you want to consume them.
setEventMessages ( $langs -> trans ( " ErrorLinesCantBeNegativeOnDeposits " ), null , 'errors' );
} else {
setEventMessages ( $langs -> trans ( " ErrorFieldCantBeNegativeOnInvoice " , $langs -> transnoentitiesnoconv ( " UnitPriceHT " ), $langs -> transnoentitiesnoconv ( " CustomerAbsoluteDiscountShort " )), null , 'errors' );
}
2018-09-04 10:37:29 +02:00
$error ++ ;
2020-05-21 15:05:19 +02:00
} else {
2018-09-04 10:37:29 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " UnitPriceHT " )), null , 'errors' );
$error ++ ;
}
2015-01-18 17:13:42 +01:00
}
2014-03-01 19:45:13 +01:00
2018-09-04 10:37:29 +02:00
2015-01-17 19:28:27 +01:00
// Update line
2019-11-12 00:15:34 +01:00
if ( ! $error ) {
2021-02-23 21:09:01 +01:00
if ( empty ( $usercancreatemargin )) {
foreach ( $object -> lines as & $line ) {
2021-04-25 15:55:36 +02:00
if ( $line -> id == GETPOST ( 'lineid' , 'int' )) {
2016-12-15 12:01:46 +01:00
$fournprice = $line -> fk_fournprice ;
$buyingprice = $line -> pa_ht ;
break ;
}
}
}
2016-12-24 21:39:40 +01:00
2021-02-23 21:09:01 +01:00
$result = $object -> updateline (
GETPOST ( 'lineid' , 'int' ),
$description ,
$pu_ht ,
$qty ,
2021-09-08 22:00:16 +02:00
$remise_percent ,
2021-02-23 21:09:01 +01:00
$date_start ,
$date_end ,
$vat_rate ,
$localtax1_rate ,
$localtax2_rate ,
'HT' ,
$info_bits ,
$type ,
GETPOST ( 'fk_parent_line' , 'int' ),
0 ,
$fournprice ,
$buyingprice ,
$label ,
$special_code ,
$array_options ,
price2num ( GETPOST ( 'progress' , 'alpha' )),
GETPOST ( 'units' , 'alpha' ),
$pu_ht_devise
);
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
if ( $result >= 0 ) {
2014-02-23 20:10:05 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2013-04-20 00:10:20 +02:00
// Define output language
$outputlangs = $langs ;
2014-10-27 19:37:30 +01:00
$newlang = '' ;
2021-02-23 21:09:01 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
2019-01-27 11:55:16 +01:00
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
2021-02-23 21:09:01 +01:00
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
2014-08-01 16:17:31 +02:00
$newlang = $object -> thirdparty -> default_lang ;
2021-02-23 21:09:01 +01:00
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $newlang )) {
2014-02-23 20:10:05 +01:00
$outputlangs = new Translate ( " " , $conf );
2013-04-20 00:10:20 +02:00
$outputlangs -> setDefaultLang ( $newlang );
2018-02-08 12:53:26 +01:00
$outputlangs -> load ( 'products' );
2013-04-20 00:10:20 +02:00
}
2014-12-25 23:08:07 +01:00
2014-02-23 20:10:05 +01:00
$ret = $object -> fetch ( $id ); // Reload to get new records
2020-09-10 01:49:09 +02:00
$object -> generateDocument ( $object -> model_pdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2013-04-20 00:10:20 +02:00
}
2014-03-01 19:45:13 +01:00
2014-03-20 00:05:20 +01:00
unset ( $_POST [ 'qty' ]);
unset ( $_POST [ 'type' ]);
2015-01-17 19:28:27 +01:00
unset ( $_POST [ 'productid' ]);
2014-03-20 00:05:20 +01:00
unset ( $_POST [ 'remise_percent' ]);
unset ( $_POST [ 'price_ht' ]);
2016-04-12 14:10:27 +02:00
unset ( $_POST [ 'multicurrency_price_ht' ]);
2014-03-20 00:05:20 +01:00
unset ( $_POST [ 'price_ttc' ]);
unset ( $_POST [ 'tva_tx' ]);
unset ( $_POST [ 'product_ref' ]);
unset ( $_POST [ 'product_label' ]);
unset ( $_POST [ 'product_desc' ]);
unset ( $_POST [ 'fournprice' ]);
unset ( $_POST [ 'buying_price' ]);
unset ( $_POST [ 'np_marginRate' ]);
unset ( $_POST [ 'np_markRate' ]);
2015-01-18 18:44:22 +01:00
2014-03-20 00:05:20 +01:00
unset ( $_POST [ 'dp_desc' ]);
unset ( $_POST [ 'idprod' ]);
2015-02-26 14:15:33 +01:00
unset ( $_POST [ 'units' ]);
2014-05-05 17:59:43 +02:00
2017-10-16 08:47:05 +02:00
unset ( $_POST [ 'date_starthour' ]);
unset ( $_POST [ 'date_startmin' ]);
unset ( $_POST [ 'date_startsec' ]);
unset ( $_POST [ 'date_startday' ]);
unset ( $_POST [ 'date_startmonth' ]);
unset ( $_POST [ 'date_startyear' ]);
unset ( $_POST [ 'date_endhour' ]);
unset ( $_POST [ 'date_endmin' ]);
unset ( $_POST [ 'date_endsec' ]);
unset ( $_POST [ 'date_endday' ]);
unset ( $_POST [ 'date_endmonth' ]);
unset ( $_POST [ 'date_endyear' ]);
2014-11-14 16:43:49 +01:00
unset ( $_POST [ 'situations' ]);
unset ( $_POST [ 'progress' ]);
2014-02-23 20:10:05 +01:00
} else {
2015-11-15 07:47:35 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2013-04-20 00:10:20 +02:00
}
}
2022-02-22 23:44:56 +01:00
} elseif ( $action == 'updatealllines' && $usercancreate && GETPOST ( 'all_percent' ) == $langs -> trans ( 'Modifier' )) { // Update all lines of situation invoice
2021-02-23 21:09:01 +01:00
if ( ! $object -> fetch ( $id ) > 0 ) {
dol_print_error ( $db );
}
if ( GETPOST ( 'all_progress' ) != " " ) {
2020-10-31 14:32:18 +01:00
$all_progress = GETPOST ( 'all_progress' , 'int' );
2021-02-23 21:09:01 +01:00
foreach ( $object -> lines as $line ) {
2016-03-12 20:49:38 +01:00
$percent = $line -> get_prev_progress ( $object -> id );
2019-04-18 10:40:34 +02:00
if ( floatval ( $all_progress ) < floatval ( $percent )) {
2020-10-31 14:32:18 +01:00
$mesg = $langs -> trans ( " Line " ) . ' ' . $i . ' : ' . $langs -> trans ( " CantBeLessThanMinPercent " );
setEventMessages ( $mesg , null , 'warnings' );
2015-01-18 18:44:22 +01:00
$result = - 1 ;
2021-02-23 21:09:01 +01:00
} else {
2022-04-07 15:59:42 +02:00
$object -> update_percent ( $line , GETPOST ( 'all_progress' ), false );
2021-02-23 21:09:01 +01:00
}
2015-01-18 18:44:22 +01:00
}
2022-04-07 15:59:42 +02:00
$object -> update_price ( 1 );
2013-04-20 00:10:20 +02:00
}
2022-02-22 23:44:56 +01:00
} elseif ( $action == 'updateline' && $usercancreate && ! $cancel ) {
2020-01-16 10:12:39 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $id ); // To show again edited page
2015-01-17 19:28:27 +01:00
exit ();
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'confirm_situationout' && $confirm == 'yes' && $usercancreate ) {
// Outing situation invoice from cycle
2020-10-31 14:32:18 +01:00
$object -> fetch ( $id , '' , '' , '' , true );
2021-02-23 21:09:01 +01:00
if ( in_array ( $object -> statut , array ( Facture :: STATUS_CLOSED , Facture :: STATUS_VALIDATED ))
&& $object -> type == Facture :: TYPE_SITUATION
&& $usercancreate
&& ! $objectidnext
&& $object -> is_last_in_cycle ()
&& $usercanunvalidate
) {
$outingError = 0 ;
$newCycle = $object -> newCycle (); // we need to keep the "situation behavior" so we place it on a new situation cycle
if ( $newCycle > 1 ) {
// Search credit notes
$lastCycle = $object -> situation_cycle_ref ;
$lastSituationCounter = $object -> situation_counter ;
$linkedCreditNotesList = array ();
2020-10-31 14:32:18 +01:00
if ( count ( $object -> tab_next_situation_invoice ) > 0 ) {
foreach ( $object -> tab_next_situation_invoice as $next_invoice ) {
if ( $next_invoice -> type == Facture :: TYPE_CREDIT_NOTE
&& $next_invoice -> situation_counter == $object -> situation_counter
&& $next_invoice -> fk_facture_source == $object -> id
2021-02-23 21:09:01 +01:00
) {
2020-10-31 14:32:18 +01:00
$linkedCreditNotesList [] = $next_invoice -> id ;
}
}
}
2018-05-23 08:16:24 +02:00
2020-10-31 14:32:18 +01:00
$object -> situation_cycle_ref = $newCycle ;
$object -> situation_counter = 1 ;
$object -> situation_final = 0 ;
2021-02-23 21:09:01 +01:00
if ( $object -> update ( $user ) > 0 ) {
2020-10-31 14:32:18 +01:00
$errors = 0 ;
2021-02-23 21:09:01 +01:00
if ( count ( $linkedCreditNotesList ) > 0 ) {
2020-10-31 14:32:18 +01:00
// now, credit note must follow
2021-08-27 23:36:06 +02:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture' ;
$sql .= ' SET situation_cycle_ref = ' . (( int ) $newCycle );
2020-10-31 14:32:18 +01:00
$sql .= ' , situation_final=0' ;
2021-08-27 23:36:06 +02:00
$sql .= ' , situation_counter=' . (( int ) $object -> situation_counter );
2021-03-22 12:00:41 +01:00
$sql .= ' WHERE rowid IN (' . $db -> sanitize ( implode ( ',' , $linkedCreditNotesList )) . ')' ;
2020-10-31 14:32:18 +01:00
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( ! $resql ) {
$errors ++ ;
}
2020-10-31 14:32:18 +01:00
// Change each progression persent on each lines
2021-02-23 21:09:01 +01:00
foreach ( $object -> lines as $line ) {
2020-10-31 14:32:18 +01:00
// no traitement for special product
2021-02-23 21:09:01 +01:00
if ( $line -> product_type == 9 ) {
continue ;
}
2018-05-23 08:16:24 +02:00
2021-02-23 21:09:01 +01:00
if ( ! empty ( $object -> tab_previous_situation_invoice )) {
2020-10-31 14:32:18 +01:00
// search the last invoice in cycle
$lineIndex = count ( $object -> tab_previous_situation_invoice ) - 1 ;
$searchPreviousInvoice = true ;
2021-02-23 21:09:01 +01:00
while ( $searchPreviousInvoice ) {
if ( $object -> tab_previous_situation_invoice [ $lineIndex ] -> type == Facture :: TYPE_SITUATION || $lineIndex < 1 ) {
2020-10-31 14:32:18 +01:00
$searchPreviousInvoice = false ; // find, exit;
break ;
} else {
$lineIndex -- ; // go to previous invoice in cycle
}
}
$maxPrevSituationPercent = 0 ;
2021-02-23 21:09:01 +01:00
foreach ( $object -> tab_previous_situation_invoice [ $lineIndex ] -> lines as $prevLine ) {
if ( $prevLine -> id == $line -> fk_prev_id ) {
2020-10-31 14:32:18 +01:00
$maxPrevSituationPercent = max ( $maxPrevSituationPercent , $prevLine -> situation_percent );
}
}
2018-05-23 08:16:24 +02:00
2020-10-31 14:32:18 +01:00
$line -> situation_percent = $line -> situation_percent - $maxPrevSituationPercent ;
2021-02-23 21:09:01 +01:00
if ( $line -> update () < 0 ) {
$errors ++ ;
}
2020-10-31 14:32:18 +01:00
}
}
}
2021-02-23 21:09:01 +01:00
if ( ! $errors ) {
2020-10-31 14:32:18 +01:00
setEventMessages ( $langs -> trans ( 'Updated' ), '' , 'mesgs' );
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
} else {
setEventMessages ( $langs -> trans ( 'ErrorOutingSituationInvoiceCreditNote' ), array (), 'errors' );
}
} else {
setEventMessages ( $langs -> trans ( 'ErrorOutingSituationInvoiceOnUpdate' ), array (), 'errors' );
}
} else {
setEventMessages ( $langs -> trans ( 'ErrorFindNextSituationInvoice' ), array (), 'errors' );
}
}
2021-02-23 21:09:01 +01:00
} elseif ( $action == 'import_lines_from_object'
2020-10-31 14:32:18 +01:00
&& $usercancreate
&& $object -> statut == Facture :: STATUS_DRAFT
2021-02-23 21:09:01 +01:00
&& ( $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_REPLACEMENT || $object -> type == Facture :: TYPE_DEPOSIT || $object -> type == Facture :: TYPE_PROFORMA || $object -> type == Facture :: TYPE_SITUATION )) {
// add lines from objectlinked
2020-10-31 14:32:18 +01:00
$fromElement = GETPOST ( 'fromelement' );
$fromElementid = GETPOST ( 'fromelementid' );
$importLines = GETPOST ( 'line_checkbox' );
2021-02-23 21:09:01 +01:00
if ( ! empty ( $importLines ) && is_array ( $importLines ) && ! empty ( $fromElement ) && ctype_alpha ( $fromElement ) && ! empty ( $fromElementid )) {
if ( $fromElement == 'commande' ) {
2020-10-31 14:32:18 +01:00
dol_include_once ( '/' . $fromElement . '/class/' . $fromElement . '.class.php' );
$lineClassName = 'OrderLine' ;
2021-02-23 21:09:01 +01:00
} elseif ( $fromElement == 'propal' ) {
2020-10-31 14:32:18 +01:00
dol_include_once ( '/comm/' . $fromElement . '/class/' . $fromElement . '.class.php' );
$lineClassName = 'PropaleLigne' ;
}
$nextRang = count ( $object -> lines ) + 1 ;
$importCount = 0 ;
$error = 0 ;
2021-02-23 21:09:01 +01:00
foreach ( $importLines as $lineId ) {
2020-10-31 14:32:18 +01:00
$lineId = intval ( $lineId );
$originLine = new $lineClassName ( $db );
2021-02-23 21:09:01 +01:00
if ( intval ( $fromElementid ) > 0 && $originLine -> fetch ( $lineId ) > 0 ) {
2020-10-31 14:32:18 +01:00
$originLine -> fetch_optionals ();
$desc = $originLine -> desc ;
$pu_ht = $originLine -> subprice ;
$qty = $originLine -> qty ;
$txtva = $originLine -> tva_tx ;
$txlocaltax1 = $originLine -> localtax1_tx ;
$txlocaltax2 = $originLine -> localtax2_tx ;
$fk_product = $originLine -> fk_product ;
$remise_percent = $originLine -> remise_percent ;
$date_start = $originLine -> date_start ;
$date_end = $originLine -> date_end ;
$ventil = 0 ;
$info_bits = $originLine -> info_bits ;
$fk_remise_except = $originLine -> fk_remise_except ;
$price_base_type = 'HT' ;
$pu_ttc = 0 ;
$type = $originLine -> product_type ;
$rang = $nextRang ++ ;
$special_code = $originLine -> special_code ;
$origin = $originLine -> element ;
$origin_id = $originLine -> id ;
$fk_parent_line = 0 ;
$fk_fournprice = $originLine -> fk_fournprice ;
$pa_ht = $originLine -> pa_ht ;
$label = $originLine -> label ;
$array_options = $originLine -> array_options ;
if ( $object -> type == Facture :: TYPE_SITUATION ) {
$situation_percent = 0 ;
} else {
$situation_percent = 100 ;
}
$fk_prev_id = '' ;
$fk_unit = $originLine -> fk_unit ;
$pu_ht_devise = $originLine -> multicurrency_subprice ;
$res = $object -> addline ( $desc , $pu_ht , $qty , $txtva , $txlocaltax1 , $txlocaltax2 , $fk_product , $remise_percent , $date_start , $date_end , $ventil , $info_bits , $fk_remise_except , $price_base_type , $pu_ttc , $type , $rang , $special_code , $origin , $origin_id , $fk_parent_line , $fk_fournprice , $pa_ht , $label , $array_options , $situation_percent , $fk_prev_id , $fk_unit , $pu_ht_devise );
2018-04-10 12:03:01 +02:00
2020-10-31 14:32:18 +01:00
if ( $res > 0 ) {
$importCount ++ ;
} else {
$error ++ ;
}
} else {
$error ++ ;
}
}
2021-02-23 21:09:01 +01:00
if ( $error ) {
2020-10-31 14:32:18 +01:00
setEventMessages ( $langs -> trans ( 'ErrorsOnXLines' , $error ), null , 'errors' );
}
}
2018-02-22 15:19:20 +01:00
}
2018-04-10 12:03:01 +02:00
2017-09-17 15:38:50 +02:00
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php' ;
2013-09-23 12:31:10 +02:00
2015-01-18 17:13:42 +01:00
// Actions to send emails
2021-02-23 21:09:01 +01:00
if ( empty ( $id )) {
$id = $facid ;
}
2019-12-02 09:38:16 +01:00
$triggersendname = 'BILL_SENTBYMAIL' ;
2019-11-12 00:15:34 +01:00
$paramname = 'id' ;
$autocopy = 'MAIN_MAIL_AUTOCOPY_INVOICE_TO' ;
$trackid = 'inv' . $object -> id ;
2015-01-18 17:13:42 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php' ;
2010-01-13 11:30:33 +01:00
2017-10-16 08:47:05 +02:00
// Actions to build doc
2021-12-02 15:56:34 +01:00
$upload_dir = $conf -> facture -> multidir_output [ ! empty ( $object -> entity ) ? $object -> entity : $conf -> entity ];
2019-11-12 00:15:34 +01:00
$permissiontoadd = $usercancreate ;
2017-10-16 08:47:05 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php' ;
2016-08-10 09:47:25 +02:00
2014-03-01 19:45:13 +01:00
2016-06-24 12:50:50 +02:00
if ( $action == 'update_extras' ) {
2018-02-23 16:11:00 +01:00
$object -> oldcopy = dol_clone ( $object );
2015-09-12 17:28:32 +02:00
// Fill array 'array_options' with data from add form
2020-09-18 01:29:17 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object , GETPOST ( 'attribute' , 'restricthtml' ));
2021-02-23 21:09:01 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2015-09-12 17:28:32 +02:00
2021-02-23 21:09:01 +01:00
if ( ! $error ) {
2018-04-10 12:03:01 +02:00
// Actions on extra fields
$result = $object -> insertExtraFields ( 'BILL_MODIFY' );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
2018-04-10 12:03:01 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
2015-09-12 17:28:32 +02:00
}
2021-02-23 15:35:16 +01:00
if ( $error ) {
2015-09-12 17:28:32 +02:00
$action = 'edit_extras' ;
2021-02-23 15:35:16 +01:00
}
2013-04-20 17:10:03 +02:00
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ) && $usercancreate ) {
2015-09-12 17:28:32 +02:00
if ( $action == 'addcontact' ) {
2015-01-17 19:28:27 +01:00
$result = $object -> fetch ( $id );
2014-03-01 19:45:13 +01:00
2015-01-17 19:28:27 +01:00
if ( $result > 0 && $id > 0 ) {
$contactid = ( GETPOST ( 'userid' ) ? GETPOST ( 'userid' ) : GETPOST ( 'contactid' ));
2020-11-30 15:18:58 +01:00
$typeid = ( GETPOST ( 'typecontact' ) ? GETPOST ( 'typecontact' ) : GETPOST ( 'type' ));
$result = $object -> add_contact ( $contactid , $typeid , GETPOST ( " source " , 'aZ09' ));
2015-01-17 19:28:27 +01:00
}
2014-03-01 19:45:13 +01:00
2015-09-12 17:28:32 +02:00
if ( $result >= 0 ) {
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ();
2014-02-23 20:10:05 +01:00
} else {
2015-09-12 17:28:32 +02:00
if ( $object -> error == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
$langs -> load ( " errors " );
2015-11-15 07:47:35 +01:00
setEventMessages ( $langs -> trans ( " ErrorThisContactIsAlreadyDefinedAsThisType " ), null , 'errors' );
2015-09-12 17:28:32 +02:00
} else {
2015-11-15 07:47:35 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-09-12 17:28:32 +02:00
}
2013-04-20 17:10:03 +02:00
}
2021-03-01 20:37:16 +01:00
} elseif ( $action == 'swapstatut' ) {
// bascule du statut d'un contact
2015-09-12 17:28:32 +02:00
if ( $object -> fetch ( $id )) {
2021-03-29 15:07:23 +02:00
$result = $object -> swapContactStatus ( GETPOST ( 'ligne' , 'int' ));
2015-09-12 17:28:32 +02:00
} else {
dol_print_error ( $db );
2013-04-20 17:10:03 +02:00
}
2021-03-01 20:37:16 +01:00
} elseif ( $action == 'deletecontact' ) {
// Efface un contact
2015-09-12 17:28:32 +02:00
$object -> fetch ( $id );
$result = $object -> delete_contact ( $lineid );
2013-04-20 00:10:20 +02:00
2015-09-12 17:28:32 +02:00
if ( $result >= 0 ) {
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ();
} else {
dol_print_error ( $db );
2015-01-18 18:44:22 +01:00
}
}
2015-10-15 17:26:16 +02:00
2021-02-23 15:35:16 +01:00
if ( $error ) {
2015-10-15 17:26:16 +02:00
$action = 'edit_extras' ;
2021-02-23 15:35:16 +01:00
}
2014-02-23 20:10:05 +01:00
}
2013-04-20 17:10:03 +02:00
}
2008-08-12 20:20:18 +02:00
2014-03-19 23:49:07 +01:00
2013-04-20 17:10:03 +02:00
/*
* View
2014-03-19 22:30:25 +01:00
*/
2013-03-24 00:35:40 +01:00
2021-10-26 13:52:00 +02:00
2013-04-20 17:10:03 +02:00
$form = new Form ( $db );
2014-02-23 20:10:05 +01:00
$formother = new FormOther ( $db );
2013-04-20 17:10:03 +02:00
$formfile = new FormFile ( $db );
2015-10-03 19:05:13 +02:00
$formmargin = new FormMargin ( $db );
2019-10-20 20:47:39 +02:00
$soc = new Societe ( $db );
2019-11-12 00:15:34 +01:00
$paymentstatic = new Paiement ( $db );
2014-02-23 20:10:05 +01:00
$bankaccountstatic = new Account ( $db );
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'project' )) {
2021-02-23 21:09:01 +01:00
$formproject = new FormProjets ( $db );
}
2015-06-03 11:55:39 +02:00
2014-02-23 20:10:05 +01:00
$now = dol_now ();
2013-03-24 00:35:40 +01:00
2019-11-12 00:15:34 +01:00
$title = $langs -> trans ( 'InvoiceCustomer' ) . " - " . $langs -> trans ( 'Card' );
2021-02-23 15:35:16 +01:00
2021-03-19 09:36:49 +01:00
$help_url = " EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes " ;
llxHeader ( '' , $title , $help_url );
2010-07-25 23:23:57 +02:00
2016-02-29 15:43:00 +01:00
// Mode creation
2014-03-19 23:49:07 +01:00
2022-07-11 00:05:50 +02:00
if ( $action == 'create' ) {
2014-02-23 20:10:05 +01:00
$facturestatic = new Facture ( $db );
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $facturestatic -> table_element );
2014-03-01 19:45:13 +01:00
2020-04-25 13:49:44 +02:00
print load_fiche_titre ( $langs -> trans ( 'NewBill' ), '' , 'bill' );
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( $socid > 0 ) {
2014-02-23 20:10:05 +01:00
$res = $soc -> fetch ( $socid );
2021-02-23 15:35:16 +01:00
}
2014-03-01 19:45:13 +01:00
2016-01-23 16:01:55 +01:00
$currency_code = $conf -> currency ;
2022-01-10 19:28:57 +01:00
$fk_account = 0 ;
2016-08-10 09:47:25 +02:00
2014-06-28 19:47:51 +02:00
// Load objectsrc
2015-11-07 13:21:03 +01:00
$remise_absolue = 0 ;
2021-02-23 15:35:16 +01:00
if ( ! empty ( $origin ) && ! empty ( $originid )) {
2013-04-20 17:10:03 +02:00
// Parse element/subelement (ex: project_task)
$element = $subelement = $origin ;
2019-11-03 18:58:26 +01:00
$regs = array ();
2014-02-23 20:10:05 +01:00
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , $origin , $regs )) {
2019-12-22 13:19:14 +01:00
$element = $regs [ 1 ];
2019-11-03 18:58:26 +01:00
$subelement = $regs [ 2 ];
2014-02-23 20:10:05 +01:00
}
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
if ( $element == 'project' ) {
$projectid = $originid ;
2016-03-11 15:42:14 +01:00
2019-11-03 18:58:26 +01:00
if ( empty ( $cond_reglement_id )) {
2015-11-13 11:43:29 +01:00
$cond_reglement_id = $soc -> cond_reglement_id ;
}
2019-11-03 18:58:26 +01:00
if ( empty ( $mode_reglement_id )) {
2015-11-13 11:43:29 +01:00
$mode_reglement_id = $soc -> mode_reglement_id ;
}
2022-02-23 06:08:20 +01:00
if ( empty ( $fk_account )) {
$fk_account = $soc -> fk_account ;
}
2015-11-13 11:43:29 +01:00
if ( ! $remise_percent ) {
$remise_percent = $soc -> remise_percent ;
}
if ( ! $dateinvoice ) {
// Do not set 0 here (0 for a date is 1970)
2019-11-12 00:15:34 +01:00
$dateinvoice = ( empty ( $dateinvoice ) ? ( empty ( $conf -> global -> MAIN_AUTOFILL_DATE ) ? - 1 : '' ) : $dateinvoice );
2016-03-11 15:42:14 +01:00
}
2014-02-23 20:10:05 +01:00
} else {
2013-04-20 17:10:03 +02:00
// For compatibility
2014-02-23 20:10:05 +01:00
if ( $element == 'order' || $element == 'commande' ) {
2013-04-20 17:10:03 +02:00
$element = $subelement = 'commande' ;
}
2014-02-23 20:10:05 +01:00
if ( $element == 'propal' ) {
$element = 'comm/propal' ;
$subelement = 'propal' ;
2013-04-20 17:10:03 +02:00
}
if ( $element == 'contract' ) {
$element = $subelement = 'contrat' ;
}
if ( $element == 'shipping' ) {
$element = $subelement = 'expedition' ;
2013-04-20 00:10:20 +02:00
}
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
dol_include_once ( '/' . $element . '/class/' . $subelement . '.class.php' );
2014-03-01 19:45:13 +01:00
2013-04-20 17:10:03 +02:00
$classname = ucfirst ( $subelement );
$objectsrc = new $classname ( $db );
$objectsrc -> fetch ( $originid );
2021-02-23 21:09:01 +01:00
if ( empty ( $objectsrc -> lines ) && method_exists ( $objectsrc , 'fetch_lines' )) {
2014-02-23 20:10:05 +01:00
$objectsrc -> fetch_lines ();
2021-02-23 21:09:01 +01:00
}
2013-04-20 17:10:03 +02:00
$objectsrc -> fetch_thirdparty ();
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
$projectid = ( ! empty ( $projectid ) ? $projectid : $objectsrc -> fk_project );
$ref_client = ( ! empty ( $objectsrc -> ref_client ) ? $objectsrc -> ref_client : ( ! empty ( $objectsrc -> ref_customer ) ? $objectsrc -> ref_customer : '' ));
2014-03-01 19:45:13 +01:00
2014-12-28 12:34:21 +01:00
// only if socid not filled else it's allready done upper
2021-02-23 15:35:16 +01:00
if ( empty ( $socid )) {
2014-12-14 18:03:30 +01:00
$soc = $objectsrc -> thirdparty ;
2021-02-23 15:35:16 +01:00
}
2014-05-29 19:20:48 +02:00
2019-11-12 00:15:34 +01:00
$dateinvoice = ( empty ( $dateinvoice ) ? ( empty ( $conf -> global -> MAIN_AUTOFILL_DATE ) ? - 1 : '' ) : $dateinvoice );
2019-04-10 10:50:01 +02:00
if ( $element == 'expedition' ) {
2019-11-12 00:15:34 +01:00
$ref_client = ( ! empty ( $objectsrc -> ref_customer ) ? $objectsrc -> ref_customer : '' );
2019-04-10 10:50:01 +02:00
$elem = $subelem = $objectsrc -> origin ;
$expeoriginid = $objectsrc -> origin_id ;
dol_include_once ( '/' . $elem . '/class/' . $subelem . '.class.php' );
$classname = ucfirst ( $subelem );
$expesrc = new $classname ( $db );
$expesrc -> fetch ( $expeoriginid );
2019-11-12 00:15:34 +01:00
$cond_reglement_id = ( ! empty ( $expesrc -> cond_reglement_id ) ? $expesrc -> cond_reglement_id : ( ! empty ( $soc -> cond_reglement_id ) ? $soc -> cond_reglement_id : 1 ));
$mode_reglement_id = ( ! empty ( $expesrc -> mode_reglement_id ) ? $expesrc -> mode_reglement_id : ( ! empty ( $soc -> mode_reglement_id ) ? $soc -> mode_reglement_id : 0 ));
$fk_account = ( ! empty ( $expesrc -> fk_account ) ? $expesrc -> fk_account : ( ! empty ( $soc -> fk_account ) ? $soc -> fk_account : 0 ));
$remise_percent = ( ! empty ( $expesrc -> remise_percent ) ? $expesrc -> remise_percent : ( ! empty ( $soc -> remise_percent ) ? $soc -> remise_percent : 0 ));
$remise_absolue = ( ! empty ( $expesrc -> remise_absolue ) ? $expesrc -> remise_absolue : ( ! empty ( $soc -> remise_absolue ) ? $soc -> remise_absolue : 0 ));
2019-04-10 10:50:01 +02:00
2022-12-14 03:39:15 +01:00
if ( ! empty ( $conf -> multicurrency -> enabled )) {
2022-12-21 12:31:24 +01:00
$currency_code = ( ! empty ( $expesrc -> multicurrency_code ) ? $expesrc -> multicurrency_code : ( ! empty ( $soc -> multicurrency_code ) ? $soc -> multicurrency_code : $objectsrc -> multicurrency_code ));
$currency_tx = ( ! empty ( $expesrc -> multicurrency_tx ) ? $expesrc -> multicurrency_tx : ( ! empty ( $soc -> multicurrency_tx ) ? $soc -> multicurrency_tx : $objectsrc -> multicurrency_tx ));
2022-12-14 03:39:15 +01:00
}
2022-12-14 03:45:20 +01:00
2019-04-10 10:50:01 +02:00
//Replicate extrafields
2020-03-27 16:02:58 +01:00
$expesrc -> fetch_optionals ();
2019-11-12 00:15:34 +01:00
$object -> array_options = $expesrc -> array_options ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
$cond_reglement_id = ( ! empty ( $objectsrc -> cond_reglement_id ) ? $objectsrc -> cond_reglement_id : ( ! empty ( $soc -> cond_reglement_id ) ? $soc -> cond_reglement_id : 0 ));
$mode_reglement_id = ( ! empty ( $objectsrc -> mode_reglement_id ) ? $objectsrc -> mode_reglement_id : ( ! empty ( $soc -> mode_reglement_id ) ? $soc -> mode_reglement_id : 0 ));
$fk_account = ( ! empty ( $objectsrc -> fk_account ) ? $objectsrc -> fk_account : ( ! empty ( $soc -> fk_account ) ? $soc -> fk_account : 0 ));
$remise_percent = ( ! empty ( $objectsrc -> remise_percent ) ? $objectsrc -> remise_percent : ( ! empty ( $soc -> remise_percent ) ? $soc -> remise_percent : 0 ));
$remise_absolue = ( ! empty ( $objectsrc -> remise_absolue ) ? $objectsrc -> remise_absolue : ( ! empty ( $soc -> remise_absolue ) ? $soc -> remise_absolue : 0 ));
2019-04-10 10:50:01 +02:00
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2021-02-23 21:09:01 +01:00
if ( ! empty ( $objectsrc -> multicurrency_code )) {
$currency_code = $objectsrc -> multicurrency_code ;
}
if ( ! empty ( $conf -> global -> MULTICURRENCY_USE_ORIGIN_TX ) && ! empty ( $objectsrc -> multicurrency_tx )) {
$currency_tx = $objectsrc -> multicurrency_tx ;
}
2019-04-10 10:50:01 +02:00
}
2016-08-10 09:47:25 +02:00
2019-04-10 10:50:01 +02:00
// Replicate extrafields
2020-03-27 16:02:58 +01:00
$objectsrc -> fetch_optionals ();
2019-04-10 10:50:01 +02:00
$object -> array_options = $objectsrc -> array_options ;
}
2014-02-23 20:10:05 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2013-04-20 17:10:03 +02:00
$cond_reglement_id = $soc -> cond_reglement_id ;
$mode_reglement_id = $soc -> mode_reglement_id ;
2014-12-14 18:03:30 +01:00
$fk_account = $soc -> fk_account ;
2013-04-20 17:10:03 +02:00
$remise_percent = $soc -> remise_percent ;
$remise_absolue = 0 ;
2019-11-12 00:15:34 +01:00
$dateinvoice = ( empty ( $dateinvoice ) ? ( empty ( $conf -> global -> MAIN_AUTOFILL_DATE ) ? - 1 : '' ) : $dateinvoice ); // Do not set 0 here (0 for a date is 1970)
2016-08-10 09:47:25 +02:00
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'multicurrency' ) && ! empty ( $soc -> multicurrency_code )) {
2021-02-23 21:09:01 +01:00
$currency_code = $soc -> multicurrency_code ;
}
2014-02-23 20:10:05 +01:00
}
2017-06-07 16:44:04 +02:00
2020-05-22 08:01:29 +02:00
// when payment condition is empty (means not override by payment condition form a other object, like third-party), try to use default value
2020-05-23 21:07:47 +02:00
if ( empty ( $cond_reglement_id )) {
2021-05-11 21:31:43 +02:00
$cond_reglement_id = GETPOST ( " cond_reglement_id " , 'int' );
2020-05-22 08:01:29 +02:00
}
// when payment mode is empty (means not override by payment mode form a other object, like third-party), try to use default value
2020-05-23 21:07:47 +02:00
if ( empty ( $mode_reglement_id )) {
2021-05-11 21:31:43 +02:00
$mode_reglement_id = GETPOST ( " mode_reglement_id " , 'int' );
2020-05-22 08:01:29 +02:00
}
2020-05-22 08:08:12 +02:00
2022-02-23 06:08:20 +01:00
// when bank account is empty (means not override by payment mode form a other object, like third-party), try to use default value
2023-02-09 19:24:16 +01:00
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' );
}
2022-02-23 06:08:20 +01:00
2021-02-23 21:09:01 +01:00
if ( ! empty ( $soc -> id )) {
$absolute_discount = $soc -> getAvailableDiscounts ();
}
2019-11-12 00:15:34 +01:00
$note_public = $object -> getDefaultCreateValueFor ( 'note_public' , (( ! empty ( $origin ) && ! empty ( $originid ) && is_object ( $objectsrc ) && ! empty ( $conf -> global -> FACTURE_REUSE_NOTES_ON_CREATE_FROM )) ? $objectsrc -> note_public : null ));
$note_private = $object -> getDefaultCreateValueFor ( 'note_private' , (( ! empty ( $origin ) && ! empty ( $originid ) && is_object ( $objectsrc ) && ! empty ( $conf -> global -> FACTURE_REUSE_NOTES_ON_CREATE_FROM )) ? $objectsrc -> note_private : null ));
2017-06-07 16:44:04 +02:00
2020-05-23 21:07:47 +02:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2014-03-01 20:02:35 +01:00
print ajax_combobox ( 'fac_replacement' );
2013-04-20 17:10:03 +02:00
print ajax_combobox ( 'fac_avoir' );
2014-11-14 16:43:49 +01:00
print ajax_combobox ( 'situations' );
2013-04-20 17:10:03 +02:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( $origin == 'contrat' ) {
2017-10-16 08:47:05 +02:00
$langs -> load ( " admin " );
2019-11-12 00:15:34 +01:00
$text = $langs -> trans ( " ToCreateARecurringInvoice " );
$text .= ' ' . $langs -> trans ( " ToCreateARecurringInvoiceGene " , $langs -> transnoentitiesnoconv ( " MenuFinancial " ), $langs -> transnoentitiesnoconv ( " BillsCustomers " ), $langs -> transnoentitiesnoconv ( " ListOfTemplates " ));
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE )) {
2020-10-31 14:32:18 +01:00
$text .= ' ' . $langs -> trans ( " ToCreateARecurringInvoiceGeneAuto " , $langs -> transnoentitiesnoconv ( 'Module2300Name' ));
2017-10-16 08:47:05 +02:00
}
2022-03-23 17:12:25 +01:00
print info_admin ( $text , 0 , 0 , 0 , 'opacitymedium' ) . '<br>' ;
2016-03-03 10:42:49 +01:00
}
2016-08-10 09:47:25 +02:00
2020-11-03 02:17:51 +01:00
print '<form name="add" action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST" id="formtocreate" name="formtocreate">' ;
2020-03-24 13:10:35 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2013-04-20 17:10:03 +02:00
print '<input type="hidden" name="action" value="add">' ;
2021-02-23 21:09:01 +01:00
if ( $soc -> id > 0 ) {
print '<input type="hidden" name="socid" value="' . $soc -> id . '">' . " \n " ;
}
2018-12-02 14:31:45 +01:00
print '<input name="ref" type="hidden" value="provisoire">' ;
2019-11-12 00:15:34 +01:00
print '<input name="ref_client" type="hidden" value="' . $ref_client . '">' ;
2020-11-03 02:17:51 +01:00
print '<input name="force_cond_reglement_id" type="hidden" value="0">' ;
print '<input name="force_mode_reglement_id" type="hidden" value="0">' ;
print '<input name="force_fk_account" type="hidden" value="0">' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="origin" value="' . $origin . '">' ;
print '<input type="hidden" name="originid" value="' . $originid . '">' ;
print '<input type="hidden" name="originentity" value="' . GETPOST ( 'originentity' ) . '">' ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $currency_tx )) {
print '<input type="hidden" name="originmulticurrency_tx" value="' . $currency_tx . '">' ;
}
2016-08-10 09:47:25 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( '' );
2015-05-19 00:01:30 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2014-03-01 19:45:13 +01:00
2013-04-20 17:10:03 +02:00
// Ref
2021-02-24 10:24:15 +01:00
//print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans('Draft').'</td></tr>';
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
$exampletemplateinvoice = new FactureRec ( $db );
2019-11-05 15:46:48 +01:00
$invoice_predefined = new FactureRec ( $db );
2021-02-23 15:35:16 +01:00
if ( empty ( $origin ) && empty ( $originid ) && GETPOST ( 'fac_rec' , 'int' ) > 0 ) {
2019-11-05 15:46:48 +01:00
$invoice_predefined -> fetch ( GETPOST ( 'fac_rec' , 'int' ));
}
2014-03-01 19:45:13 +01:00
2013-09-21 10:53:46 +02:00
// Thirdparty
2021-02-23 15:35:16 +01:00
if ( $soc -> id > 0 && ( ! GETPOST ( 'fac_rec' , 'int' ) || ! empty ( $invoice_predefined -> frequency ))) {
2019-11-05 15:46:48 +01:00
// If thirdparty known and not a predefined invoiced without a recurring rule
2019-11-12 00:15:34 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Customer' ) . '</td>' ;
2013-08-06 23:50:12 +02:00
print '<td colspan="2">' ;
2022-06-25 16:24:55 +02:00
print $soc -> getNomUrl ( 1 , 'customer' );
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="socid" value="' . $soc -> id . '">' ;
2013-11-16 14:26:42 +01:00
// Outstanding Bill
2019-08-29 00:45:02 +02:00
$arrayoutstandingbills = $soc -> getOutstandingBills ();
$outstandingBills = $arrayoutstandingbills [ 'opened' ];
2021-02-23 14:48:54 +01:00
print ' - <span class="opacitymedium">' . $langs -> trans ( 'CurrentOutstandingBill' ) . ':</span> ' ;
2015-04-18 19:08:01 +02:00
print price ( $outstandingBills , '' , $langs , 0 , 0 , - 1 , $conf -> currency );
2021-02-23 21:09:01 +01:00
if ( $soc -> outstanding_limit != '' ) {
if ( $outstandingBills > $soc -> outstanding_limit ) {
print img_warning ( $langs -> trans ( " OutstandingBillReached " ));
}
2019-11-12 00:15:34 +01:00
print ' / ' . price ( $soc -> outstanding_limit , '' , $langs , 0 , 0 , - 1 , $conf -> currency );
2013-11-16 14:26:42 +01:00
}
2013-08-06 23:50:12 +02:00
print '</td>' ;
2019-11-12 00:15:34 +01:00
print '</tr>' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Customer' ) . '</td>' ;
2013-08-06 23:50:12 +02:00
print '<td colspan="2">' ;
2022-09-24 17:27:38 +02:00
print img_picto ( '' , 'company' ) . $form -> select_company ( $soc -> id , 'socid' , '((s.client = 1 OR s.client = 3) AND s.status = 1)' , 'SelectThirdParty' , 0 , 0 , null , 0 , 'minwidth300 widthcentpercentminusxx maxwidth500' );
2020-11-03 02:17:51 +01:00
// Option to reload page to retrieve customer informations.
2021-02-23 15:35:16 +01:00
if ( empty ( $conf -> global -> RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED )) {
2015-11-11 15:32:42 +01:00
print ' < script type = " text/javascript " >
$ ( document ) . ready ( function () {
$ ( " #socid " ) . change ( function () {
2020-11-03 02:17:51 +01:00
/*
console . log ( " Submit page " );
$ ( \ ' input [ name = " action " ] \ ' ) . val ( \ ' create\ ' );
$ ( \ ' input [ name = " force_cond_reglement_id " ] \ ' ) . val ( \ ' 1 \ ' );
$ ( \ ' input [ name = " force_mode_reglement_id " ] \ ' ) . val ( \ ' 1 \ ' );
$ ( \ ' input [ name = " force_fk_account " ] \ ' ) . val ( \ ' 1 \ ' );
$ ( " #formtocreate " ) . submit (); */
// For company change, we must reuse data of comany, not input already done, so we call a GET with action=create, not a POST submit.
console . log ( " We have changed the company - Reload page " );
2015-11-11 15:32:42 +01:00
var socid = $ ( this ) . val ();
2016-04-27 11:35:11 +02:00
var fac_rec = $ ( \ ' #fac_rec\').val();
window . location . href = " '. $_SERVER["PHP_SELF"] .'?action=create&socid= " + socid + " &fac_rec= " + fac_rec ;
2015-11-11 15:32:42 +01:00
});
2015-11-06 16:14:00 +01:00
});
2015-11-11 15:32:42 +01:00
</ script > ' ;
}
2021-02-23 21:09:01 +01:00
if ( ! GETPOST ( 'fac_rec' , 'int' )) {
print ' <a href="' . DOL_URL_ROOT . '/societe/card.php?action=create&client=3&fournisseur=0&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?action=create' ) . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs -> trans ( " AddThirdParty " ) . '"></span></a>' ;
}
2013-08-06 23:50:12 +02:00
print '</td>' ;
2019-11-12 00:15:34 +01:00
print '</tr>' . " \n " ;
2013-08-06 23:50:12 +02:00
}
2016-12-24 21:39:40 +01:00
2019-11-03 18:58:26 +01:00
// Overwrite some values if creation of invoice is from a predefined invoice
2021-02-23 15:35:16 +01:00
if ( empty ( $origin ) && empty ( $originid ) && GETPOST ( 'fac_rec' , 'int' ) > 0 ) {
2019-01-27 11:55:16 +01:00
$invoice_predefined -> fetch ( GETPOST ( 'fac_rec' , 'int' ));
2016-08-10 09:47:25 +02:00
2019-11-12 00:15:34 +01:00
$dateinvoice = $invoice_predefined -> date_when ; // To use next gen date by default later
2021-02-23 21:09:01 +01:00
if ( empty ( $projectid )) {
$projectid = $invoice_predefined -> fk_project ;
}
2017-10-16 08:47:05 +02:00
$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 ;
2016-07-19 07:46:27 +02:00
2021-02-23 21:09:01 +01:00
if ( ! empty ( $invoice_predefined -> multicurrency_code )) {
$currency_code = $invoice_predefined -> multicurrency_code ;
}
if ( ! empty ( $invoice_predefined -> multicurrency_tx )) {
$currency_tx = $invoice_predefined -> multicurrency_tx ;
}
2019-11-03 18:58:26 +01:00
2019-07-19 13:22:54 +02:00
$sql = 'SELECT r.rowid, r.titre as title, r.total_ttc' ;
2019-11-12 00:15:34 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture_rec as r' ;
2021-03-30 11:36:50 +02:00
$sql .= ' WHERE r.fk_soc = ' . (( int ) $invoice_predefined -> socid );
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
$resql = $db -> query ( $sql );
2021-02-23 15:35:16 +01:00
if ( $resql ) {
2013-04-20 17:10:03 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( $num > 0 ) {
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( 'CreateFromRepeatableInvoice' ) . '</td><td>' ;
2019-11-05 15:46:48 +01:00
//print '<input type="hidden" name="fac_rec" id="fac_rec" value="'.GETPOST('fac_rec', 'int').'">';
2019-11-12 00:15:34 +01:00
print '<select class="flat" id="fac_rec" name="fac_rec">' ; // We may want to change the template to use
2015-05-07 12:20:20 +02:00
print '<option value="0" selected></option>' ;
2021-02-23 15:35:16 +01:00
while ( $i < $num ) {
2013-04-20 17:10:03 +02:00
$objp = $db -> fetch_object ( $resql );
2019-11-12 00:15:34 +01:00
print '<option value="' . $objp -> rowid . '"' ;
2021-02-23 21:09:01 +01:00
if ( GETPOST ( 'fac_rec' , 'int' ) == $objp -> rowid ) {
2017-10-16 08:47:05 +02:00
print ' selected' ;
2019-11-03 18:58:26 +01:00
$exampletemplateinvoice -> fetch ( GETPOST ( 'fac_rec' , 'int' ));
2016-12-04 21:27:08 +01:00
}
2019-11-12 00:15:34 +01:00
print '>' . $objp -> title . ' (' . price ( $objp -> total_ttc ) . ' ' . $langs -> trans ( " TTC " ) . ')</option>' ;
$i ++ ;
2013-04-20 00:10:20 +02:00
}
2016-04-27 11:35:11 +02:00
print '</select>' ;
2022-05-03 16:18:52 +02:00
print ajax_combobox ( " fac_rec " );
2016-04-27 11:35:11 +02:00
// Option to reload page to retrieve customer informations. Note, this clear other input
2021-02-23 15:35:16 +01:00
if ( empty ( $conf -> global -> RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED )) {
2017-10-16 08:47:05 +02:00
print ' < script type = " text/javascript " >
2016-04-27 11:35:11 +02:00
$ ( document ) . ready ( function () {
$ ( " #fac_rec " ) . change ( function () {
2020-11-03 02:17:51 +01:00
console . log ( " We have changed the template invoice - Reload page " );
2016-04-27 11:35:11 +02:00
var fac_rec = $ ( this ) . val ();
var socid = $ ( \ ' #socid\').val();
2020-11-03 02:17:51 +01:00
// For template invoice change, we must reuse data of template, not input already done, so we call a GET with action=create, not a POST submit.
2016-04-27 11:35:11 +02:00
window . location . href = " '. $_SERVER["PHP_SELF"] .'?action=create&socid= " + socid + " &fac_rec= " + fac_rec ;
});
});
</ script > ' ;
2017-10-16 08:47:05 +02:00
}
2016-04-27 11:35:11 +02:00
print '</td></tr>' ;
2013-04-20 00:10:20 +02:00
}
2014-02-23 20:10:05 +01:00
$db -> free ( $resql );
} else {
dol_print_error ( $db );
}
2013-04-20 17:10:03 +02:00
}
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
print '<tr><td class="tdtop fieldrequired">' . $langs -> trans ( 'Type' ) . '</td><td colspan="2">' ;
print '<div class="tagtable">' . " \n " ;
2014-03-01 19:45:13 +01:00
2013-04-20 17:10:03 +02:00
// Standard invoice
2015-06-03 11:55:39 +02:00
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2022-05-03 16:18:52 +02:00
$tmp = '<input type="radio" id="radio_standard" name="type" value="0"' . ( GETPOST ( 'type' , 'int' ) ? '' : ' checked' ) . '> ' ;
2018-02-20 15:08:57 +01:00
$tmp = $tmp . '<label for="radio_standard" >' . $langs -> trans ( " InvoiceStandardAsk " ) . '</label>' ;
$desc = $form -> textwithpicto ( $tmp , $langs -> transnoentities ( " InvoiceStandardDesc " ), 1 , 'help' , '' , 0 , 3 );
2021-02-23 14:48:54 +01:00
print '<table class="nobordernopadding"><tr>' ;
print '<td>' ;
2013-04-20 17:10:03 +02:00
print $desc ;
2021-02-23 14:48:54 +01:00
print '</td>' ;
if ((( $origin == 'propal' ) || ( $origin == 'commande' )) && ( ! empty ( $originid ))) {
/* print '<td class="nowrap" style="padding-left: 5px">' ;
$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 '</td>' ; */
print '<td class="nowrap" style="padding-left: 15px">' ;
print '<span class="opacitymedium">' . $langs -> trans ( 'PercentOfOriginalObject' ) . '</span>:<input class="right" placeholder="100%" type="text" id="valuestandardinvoice" name="valuestandardinvoice" size="3" value="' . ( GETPOSTISSET ( 'valuestandardinvoice' ) ? GETPOST ( 'valuestandardinvoice' , 'alpha' ) : '100%' ) . '"/>' ;
print '</td>' ;
}
print '</tr></table>' ;
2015-06-03 11:55:39 +02:00
print '</div></div>' ;
2014-03-01 19:45:13 +01:00
2021-02-23 14:48:54 +01:00
if (( empty ( $origin )) || ((( $origin == 'propal' ) || ( $origin == 'commande' )) && ( ! empty ( $originid )))) {
// Deposit - Down payment
2021-02-23 15:35:16 +01:00
if ( empty ( $conf -> global -> INVOICE_DISABLE_DEPOSIT )) {
2017-10-16 08:47:05 +02:00
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2019-11-12 00:15:34 +01:00
$tmp = '<input type="radio" id="radio_deposit" name="type" value="3"' . ( GETPOST ( 'type' ) == 3 ? ' checked' : '' ) . '> ' ;
2021-11-29 15:09:18 +01:00
print ' < script type = " text/javascript " >
2016-08-31 18:35:15 +02:00
jQuery ( document ) . ready ( function () {
2021-02-23 14:48:54 +01:00
jQuery ( " #typestandardinvoice, #valuestandardinvoice " ) . click ( function () {
jQuery ( " #radio_standard " ) . prop ( " checked " , true );
});
2016-08-31 18:35:15 +02:00
jQuery ( " #typedeposit, #valuedeposit " ) . click ( function () {
jQuery ( " #radio_deposit " ) . prop ( " checked " , true );
});
2021-02-23 14:48:54 +01:00
jQuery ( " #typedeposit " ) . change ( function () {
console . log ( " We change type of down payment " );
jQuery ( " #radio_deposit " ) . prop ( " checked " , true );
setRadioForTypeOfIncoice ();
});
jQuery ( " #radio_standard, #radio_deposit, #radio_replacement, #radio_template " ) . change ( function () {
setRadioForTypeOfIncoice ();
});
function setRadioForTypeOfIncoice () {
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 );
}
};
2016-08-31 18:35:15 +02:00
});
</ script > ' ;
2017-06-07 16:44:04 +02:00
2018-02-20 15:08:57 +01:00
$tmp = $tmp . '<label for="radio_deposit" >' . $langs -> trans ( " InvoiceDeposit " ) . '</label>' ;
$desc = $form -> textwithpicto ( $tmp , $langs -> transnoentities ( " InvoiceDepositDesc " ), 1 , 'help' , '' , 0 , 3 );
2021-02-23 14:48:54 +01:00
print '<table class="nobordernopadding"><tr>' ;
print '<td>' ;
2017-10-16 08:47:05 +02:00
print $desc ;
print '</td>' ;
2021-02-23 15:35:16 +01:00
if (( $origin == 'propal' ) || ( $origin == 'commande' )) {
2021-02-23 14:48:54 +01:00
print '<td class="nowrap" style="padding-left: 15px">' ;
2020-02-06 14:15:41 +01:00
$arraylist = array (
'amount' => $langs -> transnoentitiesnoconv ( 'FixAmount' , $langs -> transnoentitiesnoconv ( 'Deposit' )),
'variable' => $langs -> transnoentitiesnoconv ( 'VarAmountOneLine' , $langs -> transnoentitiesnoconv ( 'Deposit' )),
'variablealllines' => $langs -> transnoentitiesnoconv ( 'VarAmountAllLines' )
);
2021-09-30 11:48:32 +02:00
$typedeposit = GETPOST ( 'typedeposit' , 'aZ09' );
$valuedeposit = GETPOST ( 'valuedeposit' , 'int' );
if ( empty ( $typedeposit ) && ! empty ( $objectsrc -> deposit_percent )) {
2022-05-09 15:57:10 +02:00
$origin_payment_conditions_deposit_percent = getDictionaryValue ( 'c_payment_term' , 'deposit_percent' , $objectsrc -> cond_reglement_id );
2021-09-30 11:48:32 +02:00
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 );
2017-10-16 08:47:05 +02:00
print '</td>' ;
2021-02-23 14:48:54 +01:00
print '<td class="nowrap" style="padding-left: 5px">' ;
2021-09-30 11:48:32 +02:00
print '<span class="opacitymedium paddingleft">' . $langs -> trans ( " AmountOrPercent " ) . '</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' . $valuedeposit . '"/>' ;
2021-02-23 14:48:54 +01:00
print '</td>' ;
2017-10-16 08:47:05 +02:00
}
2021-02-23 14:48:54 +01:00
print '</tr></table>' ;
2017-10-16 08:47:05 +02:00
print '</div></div>' ;
2021-02-23 21:09:01 +01:00
}
2013-04-20 17:10:03 +02:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( $socid > 0 ) {
if ( ! empty ( $conf -> global -> INVOICE_USE_SITUATION )) {
2015-06-03 11:55:39 +02:00
// First situation invoice
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2019-11-12 00:15:34 +01:00
$tmp = '<input id="radio_situation" type="radio" name="type" value="5"' . ( GETPOST ( 'type' ) == 5 ? ' checked' : '' ) . '> ' ;
2020-03-17 12:29:14 +01:00
$tmp = $tmp . '<label for="radio_situation" >' . $langs -> trans ( " InvoiceFirstSituationAsk " ) . '</label>' ;
2018-02-20 15:08:57 +01:00
$desc = $form -> textwithpicto ( $tmp , $langs -> transnoentities ( " InvoiceFirstSituationDesc " ), 1 , 'help' , '' , 0 , 3 );
2015-06-03 11:55:39 +02:00
print $desc ;
print '</div></div>' ;
// Next situation invoice
2020-05-25 00:20:00 +02:00
$opt = $form -> selectSituationInvoices ( GETPOST ( 'originid' , 'int' ), $socid );
2019-11-03 18:58:26 +01:00
2015-06-03 11:55:39 +02:00
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2020-05-25 00:20:00 +02:00
$tmp = '<input type="radio" name="type" value="5"' . ( GETPOST ( 'type' ) == 5 && GETPOST ( 'originid' , 'int' ) ? ' checked' : '' );
2021-02-23 15:35:16 +01:00
if ( $opt == ( '<option value ="0" selected>' . $langs -> trans ( 'NoSituations' ) . '</option>' ) || ( GETPOST ( 'origin' ) && GETPOST ( 'origin' ) != 'facture' && GETPOST ( 'origin' ) != 'commande' )) {
2019-11-12 00:15:34 +01:00
$tmp .= ' disabled' ;
2021-02-23 15:35:16 +01:00
}
2019-11-12 00:15:34 +01:00
$tmp .= '> ' ;
$text = '<label>' . $tmp . $langs -> trans ( " InvoiceSituationAsk " ) . '</label> ' ;
2019-11-03 18:58:26 +01:00
$text .= '<select class="flat" id="situations" name="situations"' ;
2021-02-23 21:09:01 +01:00
if ( $opt == ( '<option value ="0" selected>' . $langs -> trans ( 'NoSituations' ) . '</option>' ) || ( GETPOST ( 'origin' ) && GETPOST ( 'origin' ) != 'facture' && GETPOST ( 'origin' ) != 'commande' )) {
2019-11-03 18:58:26 +01:00
$text .= ' disabled' ;
2021-02-23 21:09:01 +01:00
}
2019-11-12 00:15:34 +01:00
$text .= '>' ;
2015-06-03 11:55:39 +02:00
$text .= $opt ;
$text .= '</select>' ;
2016-03-25 15:24:57 +01:00
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceSituationDesc " ), 1 , 'help' , '' , 0 , 3 );
2015-06-03 11:55:39 +02:00
print $desc ;
print '</div></div>' ;
2015-01-18 18:44:22 +01:00
}
2015-01-25 21:32:40 +01:00
2013-04-20 17:10:03 +02:00
// Replacement
2021-02-23 15:35:16 +01:00
if ( empty ( $conf -> global -> INVOICE_DISABLE_REPLACEMENT )) {
2019-09-17 09:38:08 +02:00
// Type de facture
$facids = $facturestatic -> list_replacable_invoices ( $soc -> id );
if ( $facids < 0 ) {
2021-06-08 12:01:05 +02:00
dol_print_error ( $db , $facturestatic -> error , $facturestatic -> errors );
2019-09-17 09:38:08 +02:00
exit ();
}
$options = " " ;
2020-01-16 10:12:39 +01:00
if ( is_array ( $facids )) {
2021-02-23 15:35:16 +01:00
foreach ( $facids as $facparam ) {
2020-01-16 10:12:39 +01:00
$options .= '<option value="' . $facparam [ 'id' ] . '"' ;
2021-06-30 15:06:16 +02:00
if ( $facparam [ 'id' ] == GETPOST ( 'fac_replacement' , 'int' )) {
2020-01-16 10:12:39 +01:00
$options .= ' selected' ;
2021-02-23 21:09:01 +01:00
}
2021-06-30 12:43:44 +02:00
$options .= '>' . $facparam [ 'ref' ];
$options .= ' (' . $facturestatic -> LibStatut ( $facparam [ 'paid' ], $facparam [ 'status' ], 0 , $facparam [ 'alreadypaid' ]) . ')' ;
2020-01-16 10:12:39 +01:00
$options .= '</option>' ;
}
2019-09-17 09:38:08 +02:00
}
2017-10-16 08:47:05 +02:00
print '<!-- replacement line -->' ;
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2019-11-12 00:15:34 +01:00
$tmp = '<input type="radio" name="type" id="radio_replacement" value="1"' . ( GETPOST ( 'type' ) == 1 ? ' checked' : '' );
2021-02-23 15:35:16 +01:00
if ( ! $options || $invoice_predefined -> id > 0 ) {
$tmp .= ' disabled' ;
}
2019-11-12 00:15:34 +01:00
$tmp .= '> ' ;
2021-11-29 15:09:18 +01:00
print ' < script type = " text/javascript " >
2016-08-31 18:35:15 +02:00
jQuery ( document ) . ready ( function () {
jQuery ( " #fac_replacement " ) . change ( function () {
jQuery ( " #radio_replacement " ) . prop ( " checked " , true );
});
});
</ script > ' ;
2019-11-12 00:15:34 +01:00
$text = '<label>' . $tmp . $langs -> trans ( " InvoiceReplacementAsk " ) . '</label>' ;
2017-10-16 08:47:05 +02:00
$text .= '<select class="flat" name="fac_replacement" id="fac_replacement"' ;
2021-02-23 15:35:16 +01:00
if ( ! $options || $invoice_predefined -> id > 0 ) {
2017-10-16 08:47:05 +02:00
$text .= ' disabled' ;
2021-02-23 15:35:16 +01:00
}
2017-10-16 08:47:05 +02:00
$text .= '>' ;
if ( $options ) {
$text .= '<option value="-1"> </option>' ;
$text .= $options ;
} else {
2019-11-12 00:15:34 +01:00
$text .= '<option value="-1">' . $langs -> trans ( " NoReplacableInvoice " ) . '</option>' ;
2017-10-16 08:47:05 +02:00
}
$text .= '</select>' ;
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceReplacementDesc " ), 1 , 'help' , '' , 0 , 3 );
print $desc ;
print '</div></div>' ;
2014-02-23 20:10:05 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 15:35:16 +01:00
if ( ! empty ( $conf -> global -> INVOICE_USE_SITUATION )) {
2020-10-31 14:32:18 +01:00
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
$tmp = '<input type="radio" name="type" id="radio_situation" value="0" disabled> ' ;
$text = '<label>' . $tmp . $langs -> trans ( " InvoiceFirstSituationAsk " ) . '</label> ' ;
$text .= '<span class="opacitymedium">(' . $langs -> trans ( " YouMustCreateInvoiceFromThird " ) . ')</span> ' ;
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceFirstSituationDesc " ), 1 , 'help' , '' , 0 , 3 );
print $desc ;
print '</div></div>' ;
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
$tmp = '<input type="radio" name="type" id="radio_situation" value="0" disabled> ' ;
$text = '<label>' . $tmp . $langs -> trans ( " InvoiceSituationAsk " ) . '</label> ' ;
$text .= '<span class="opacitymedium">(' . $langs -> trans ( " YouMustCreateInvoiceFromThird " ) . ')</span> ' ;
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceFirstSituationDesc " ), 1 , 'help' , '' , 0 , 3 );
print $desc ;
print '</div></div>' ;
}
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2019-11-12 00:15:34 +01:00
$tmp = '<input type="radio" name="type" id="radio_replacement" value="0" disabled> ' ;
$text = '<label>' . $tmp . $langs -> trans ( " InvoiceReplacement " ) . '</label> ' ;
2019-12-06 08:50:26 +01:00
$text .= '<span class="opacitymedium">(' . $langs -> trans ( " YouMustCreateInvoiceFromThird " ) . ')</span> ' ;
2016-03-25 15:24:57 +01:00
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceReplacementDesc " ), 1 , 'help' , '' , 0 , 3 );
2014-03-19 23:49:07 +01:00
print $desc ;
2015-06-03 11:55:39 +02:00
print '</div></div>' ;
2014-03-19 23:49:07 +01:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( empty ( $origin )) {
if ( $socid > 0 ) {
2017-10-16 08:47:05 +02:00
// Credit note
2021-02-23 15:35:16 +01:00
if ( empty ( $conf -> global -> INVOICE_DISABLE_CREDIT_NOTE )) {
2019-09-17 09:38:08 +02:00
// Show link for credit note
2019-11-12 00:15:34 +01:00
$facids = $facturestatic -> list_qualified_avoir_invoices ( $soc -> id );
2021-02-23 15:35:16 +01:00
if ( $facids < 0 ) {
2021-06-08 10:38:34 +02:00
dol_print_error ( $db , $facturestatic -> error , $facturestatic -> errors );
2019-09-17 09:38:08 +02:00
exit ;
}
$optionsav = " " ;
$newinvoice_static = new Facture ( $db );
2021-02-23 15:35:16 +01:00
foreach ( $facids as $key => $valarray ) {
2019-09-17 09:38:08 +02:00
$newinvoice_static -> id = $key ;
$newinvoice_static -> ref = $valarray [ 'ref' ];
$newinvoice_static -> statut = $valarray [ 'status' ];
$newinvoice_static -> type = $valarray [ 'type' ];
$newinvoice_static -> paye = $valarray [ 'paye' ];
2019-11-12 00:15:34 +01:00
$optionsav .= '<option value="' . $key . '"' ;
2021-02-23 21:09:01 +01:00
if ( $key == GETPOST ( 'fac_avoir' )) {
2019-09-17 09:38:08 +02:00
$optionsav .= ' selected' ;
2022-01-12 12:22:43 +01:00
// pre-filled extra fields with selected credit note
$newinvoice_static -> fetch_optionals ( $key );
$object -> array_options = $newinvoice_static -> array_options ;
2021-02-23 21:09:01 +01:00
}
2019-09-17 09:38:08 +02:00
$optionsav .= '>' ;
$optionsav .= $newinvoice_static -> ref ;
2019-11-12 00:15:34 +01:00
$optionsav .= ' (' . $newinvoice_static -> getLibStatut ( 1 , $valarray [ 'paymentornot' ]) . ')' ;
2019-09-17 09:38:08 +02:00
$optionsav .= '</option>' ;
}
2017-10-16 08:47:05 +02:00
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2019-11-12 00:15:34 +01:00
$tmp = '<input type="radio" id="radio_creditnote" name="type" value="2"' . ( GETPOST ( 'type' ) == 2 ? ' checked' : '' );
2021-02-23 15:35:16 +01:00
if (( ! $optionsav && empty ( $conf -> global -> INVOICE_CREDIT_NOTE_STANDALONE )) || $invoice_predefined -> id > 0 ) {
$tmp .= ' disabled' ;
}
2019-11-12 00:15:34 +01:00
$tmp .= '> ' ;
2017-10-16 08:47:05 +02:00
// Show credit note options only if we checked credit note
2021-11-29 15:09:18 +01:00
print ' < script type = " text/javascript " >
2016-08-31 18:35:15 +02:00
jQuery ( document ) . ready ( function () {
if ( ! jQuery ( " #radio_creditnote " ) . is ( " :checked " ))
{
jQuery ( " #credit_note_options " ) . hide ();
}
jQuery ( " #radio_creditnote " ) . click ( function () {
jQuery ( " #credit_note_options " ) . show ();
});
jQuery ( " #radio_standard, #radio_replacement, #radio_deposit " ) . click ( function () {
jQuery ( " #credit_note_options " ) . hide ();
});
});
</ script > ' ;
2019-11-12 00:15:34 +01:00
$text = '<label>' . $tmp . $langs -> transnoentities ( " InvoiceAvoirAsk " ) . '</label> ' ;
2017-10-16 08:47:05 +02:00
// $text.='<input type="text" value="">';
$text .= '<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"' ;
2021-02-23 15:35:16 +01:00
if ( ! $optionsav || $invoice_predefined -> id > 0 ) {
2017-10-16 08:47:05 +02:00
$text .= ' disabled' ;
2021-02-23 15:35:16 +01:00
}
2017-10-16 08:47:05 +02:00
$text .= '>' ;
if ( $optionsav ) {
$text .= '<option value="-1"></option>' ;
$text .= $optionsav ;
} else {
2019-11-12 00:15:34 +01:00
$text .= '<option value="-1">' . $langs -> trans ( " NoInvoiceToCorrect " ) . '</option>' ;
2017-10-16 08:47:05 +02:00
}
$text .= '</select>' ;
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceAvoirDesc " ), 1 , 'help' , '' , 0 , 3 );
print $desc ;
print '<div id="credit_note_options" class="clearboth">' ;
2019-11-12 00:15:34 +01:00
print ' <input type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="$(\'#credit_note_options input[type=checkbox]\').not(this).prop(\'checked\', false);" ' . ( GETPOST ( 'invoiceAvoirWithLines' , 'int' ) > 0 ? 'checked' : '' ) . ' /> <label for="invoiceAvoirWithLines">' . $langs -> trans ( 'invoiceAvoirWithLines' ) . " </label> " ;
print '<br> <input type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="$(\'#credit_note_options input[type=checkbox]\').not(this).prop(\'checked\', false);" ' . ( GETPOST ( 'invoiceAvoirWithPaymentRestAmount' , 'int' ) > 0 ? 'checked' : '' ) . ' /> <label for="invoiceAvoirWithPaymentRestAmount">' . $langs -> trans ( 'invoiceAvoirWithPaymentRestAmount' ) . " </label> " ;
2017-10-16 08:47:05 +02:00
print '</div>' ;
2020-10-31 14:32:18 +01:00
print '</div></div>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2015-06-03 11:55:39 +02:00
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> INVOICE_CREDIT_NOTE_STANDALONE )) {
$tmp = '<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ' ;
} else {
$tmp = '<input type="radio" name="type" id="radio_creditnote" value="2" > ' ;
}
2019-11-12 00:15:34 +01:00
$text = '<label>' . $tmp . $langs -> trans ( " InvoiceAvoir " ) . '</label> ' ;
2019-12-06 08:50:26 +01:00
$text .= '<span class="opacitymedium">(' . $langs -> trans ( " YouMustCreateInvoiceFromThird " ) . ')</span> ' ;
2016-03-25 15:24:57 +01:00
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceAvoirDesc " ), 1 , 'help' , '' , 0 , 3 );
2014-03-19 23:49:07 +01:00
print $desc ;
2019-11-12 00:15:34 +01:00
print '</div></div>' . " \n " ;
2014-02-23 20:10:05 +01:00
}
2013-04-20 17:10:03 +02:00
}
2017-06-07 16:44:04 +02:00
2016-04-24 18:11:19 +02:00
// Template invoice
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2019-11-12 00:15:34 +01:00
$tmp = '<input type="radio" name="type" id="radio_template" value="0" disabled> ' ;
$text = '<label>' . $tmp . $langs -> trans ( " RepeatableInvoice " ) . '</label> ' ;
2016-04-24 18:11:19 +02:00
//$text.= '('.$langs->trans("YouMustCreateStandardInvoiceFirst").') ';
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " YouMustCreateStandardInvoiceFirstDesc " ), 1 , 'help' , '' , 0 , 3 );
print $desc ;
print '</div></div>' ;
2016-08-10 09:47:25 +02:00
2015-06-03 11:55:39 +02:00
print '</div>' ;
2018-10-30 14:47:39 +01:00
2021-02-23 15:35:16 +01:00
if ( ! empty ( $conf -> global -> INVOICE_USE_DEFAULT_DOCUMENT )) { // Hidden conf
2020-10-31 14:32:18 +01:00
// 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 = '' ;
2021-02-23 15:35:16 +01:00
foreach ( $listtType as $type ) {
2020-10-31 14:32:18 +01:00
$thisTypeConfName = 'FACTURE_ADDON_PDF_' . $type ;
$curent = ! empty ( $conf -> global -> { $thisTypeConfName }) ? $conf -> global -> { $thisTypeConfName } : $conf -> global -> FACTURE_ADDON_PDF ;
$jsListType .= ( ! empty ( $jsListType ) ? ',' : '' ) . '"' . $type . '":"' . $curent . '"' ;
}
2021-11-29 15:09:18 +01:00
print ' < script type = " text/javascript " >
2018-10-02 15:51:17 +02:00
$ ( document ) . ready ( function () {
var listType = { '.$jsListType.' };
$ ( " [name= \ 'type \ ' " ) . change ( function () {
if ( $ ( this ) . prop ( " checked " ))
2018-02-20 15:08:57 +01:00
{
2018-10-02 15:51:17 +02:00
if (( $ ( this ) . val () in listType ))
{
$ ( " #model " ) . val ( listType [ $ ( this ) . val ()]);
}
else
{
$ ( " #model " ) . val ( " '. $conf->global ->FACTURE_ADDON_PDF.' " );
}
2018-02-20 15:08:57 +01:00
}
2018-10-02 15:51:17 +02:00
});
});
</ script > ' ;
}
2018-10-30 14:47:39 +01:00
2013-04-20 17:10:03 +02:00
print '</td></tr>' ;
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( $socid > 0 ) {
2013-04-20 17:10:03 +02:00
// Discounts for third party
2022-04-07 14:03:14 +02:00
print '<tr><td>' . $langs -> trans ( 'DiscountStillRemaining' ) . '</td><td colspan="2">' ;
2018-03-02 16:48:25 +01:00
$thirdparty = $soc ;
$discount_type = 0 ;
2020-01-06 17:19:49 +01:00
$backtopage = urlencode ( $_SERVER [ " PHP_SELF " ] . '?socid=' . $thirdparty -> id . '&action=' . $action . '&origin=' . GETPOST ( 'origin' , 'alpha' ) . '&originid=' . GETPOST ( 'originid' , 'int' ));
2018-03-02 16:48:25 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/object_discounts.tpl.php' ;
2012-06-09 19:16:31 +02:00
print '</td></tr>' ;
2013-04-20 17:10:03 +02:00
}
2014-03-01 19:45:13 +01:00
2021-09-23 02:10:39 +02:00
$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' );
2016-12-24 21:39:40 +01:00
2013-04-20 17:10:03 +02:00
// Date invoice
2019-11-12 00:15:34 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'DateInvoice' ) . '</td><td colspan="2">' ;
2021-01-11 15:34:25 +01:00
print $form -> selectDate ( $newdateinvoice ? $newdateinvoice : $dateinvoice , '' , '' , '' , '' , " add " , 1 , 1 );
2013-04-20 17:10:03 +02:00
print '</td></tr>' ;
2014-03-01 19:45:13 +01:00
2016-05-29 23:56:58 +02:00
// Date point of tax
2021-02-23 15:35:16 +01:00
if ( ! empty ( $conf -> global -> INVOICE_POINTOFTAX_DATE )) {
2019-11-12 00:15:34 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'DatePointOfTax' ) . '</td><td colspan="2">' ;
print $form -> selectDate ( $date_pointoftax ? $date_pointoftax : - 1 , 'date_pointoftax' , '' , '' , '' , " add " , 1 , 1 );
2016-05-29 23:56:58 +02:00
print '</td></tr>' ;
}
2016-08-10 09:47:25 +02:00
2013-04-20 17:10:03 +02:00
// Payment term
2019-11-12 00:15:34 +01:00
print '<tr><td class="nowrap fieldrequired">' . $langs -> trans ( 'PaymentConditionsShort' ) . '</td><td colspan="2">' ;
2020-01-06 17:19:49 +01:00
$form -> select_conditions_paiements ( GETPOSTISSET ( 'cond_reglement_id' ) ? GETPOST ( 'cond_reglement_id' , 'int' ) : $cond_reglement_id , 'cond_reglement_id' );
2013-04-20 17:10:03 +02:00
print '</td></tr>' ;
2014-03-01 19:45:13 +01:00
2019-08-29 00:45:02 +02:00
2021-12-02 15:56:34 +01:00
if ( ! empty ( $conf -> global -> INVOICE_USE_RETAINED_WARRANTY )) {
2020-04-15 10:52:28 +02:00
$rwStyle = 'display:none;' ;
2020-04-23 18:55:10 +02:00
if ( in_array ( GETPOST ( 'type' , 'int' ), $retainedWarrantyInvoiceAvailableType )) {
2020-04-15 10:48:45 +02:00
$rwStyle = '' ;
}
2020-02-19 11:54:55 +01:00
2020-04-15 10:52:28 +02:00
$retained_warranty = GETPOST ( 'retained_warranty' , 'int' );
2020-04-23 18:55:10 +02:00
if ( empty ( $retained_warranty )) {
if ( ! empty ( $objectsrc -> retained_warranty )) { // use previous situation value
2020-04-15 10:48:45 +02:00
$retained_warranty = $objectsrc -> retained_warranty ;
}
}
2020-04-23 18:55:10 +02:00
$retained_warranty_js_default = ! empty ( $retained_warranty ) ? $retained_warranty : $conf -> global -> INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT ;
2020-02-19 11:54:55 +01:00
2020-04-15 10:52:28 +02:00
print '<tr class="retained-warranty-line" style="' . $rwStyle . '" ><td class="nowrap">' . $langs -> trans ( 'RetainedWarranty' ) . '</td><td colspan="2">' ;
print '<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="' . $retained_warranty . '" step="0.01" min="0" max="100" />%' ;
2019-08-29 00:45:02 +02:00
2020-04-15 10:52:28 +02:00
// Retained warranty payment term
print '<tr class="retained-warranty-line" style="' . $rwStyle . '" ><td class="nowrap">' . $langs -> trans ( 'PaymentConditionsShortRetainedWarranty' ) . '</td><td colspan="2">' ;
$retained_warranty_fk_cond_reglement = GETPOST ( 'retained_warranty_fk_cond_reglement' , 'int' );
2020-04-23 18:55:10 +02:00
if ( empty ( $retained_warranty_fk_cond_reglement )) {
2020-04-15 10:48:45 +02:00
$retained_warranty_fk_cond_reglement = $conf -> global -> INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID ;
2020-04-23 18:55:10 +02:00
if ( ! empty ( $objectsrc -> retained_warranty_fk_cond_reglement )) { // use previous situation value
2020-04-15 10:48:45 +02:00
$retained_warranty_fk_cond_reglement = $objectsrc -> retained_warranty_fk_cond_reglement ;
2020-04-23 18:55:10 +02:00
} else {
2020-04-15 10:48:45 +02:00
$retained_warranty_fk_cond_reglement = $conf -> global -> INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID ;
}
}
2020-04-15 10:52:28 +02:00
$form -> select_conditions_paiements ( $retained_warranty_fk_cond_reglement , 'retained_warranty_fk_cond_reglement' , - 1 , 1 );
print '</td></tr>' ;
2020-02-19 11:54:55 +01:00
2021-11-29 15:09:18 +01:00
print ' < script type = " text/javascript " >
2020-04-15 10:52:28 +02:00
$ ( document ) . ready ( function () {
$ ( " [name= \ 'type \ '] " ) . change ( function () {
if ( $ ( this ) . prop ( " checked " ) && $ . inArray ( $ ( this ) . val (), '.json_encode($retainedWarrantyInvoiceAvailableType).' ) !== - 1 )
{
$ ( " .retained-warranty-line " ) . show ();
2021-05-20 09:22:55 +02:00
$ ( " #new-situation-invoice-retained-warranty " ) . val ( " '.floatval( $retained_warranty_js_default ).' " );
2020-04-15 10:52:28 +02:00
}
else {
$ ( " .retained-warranty-line " ) . hide ();
$ ( " #new-situation-invoice-retained-warranty " ) . val ( " " );
}
});
2020-04-15 10:44:07 +02:00
2020-10-21 14:49:51 +02:00
$ ( " [name= \ 'type \ ']:checked " ) . trigger ( " change " );
2020-04-15 10:52:28 +02:00
});
</ script > ' ;
2018-08-10 15:06:00 +02:00
}
2014-03-01 19:45:13 +01:00
2013-04-20 17:10:03 +02:00
// Payment mode
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( 'PaymentMode' ) . '</td><td colspan="2">' ;
2022-05-03 14:15:42 +02:00
print img_picto ( '' , 'payment' , 'class="pictofixedwidth"' );
print $form -> select_types_paiements ( GETPOSTISSET ( 'mode_reglement_id' ) ? GETPOST ( 'mode_reglement_id' ) : $mode_reglement_id , 'mode_reglement_id' , 'CRDT' , 0 , 1 , 0 , 0 , 1 , 'maxwidth200 widthcentpercentminusx' , 1 );
2013-04-20 17:10:03 +02:00
print '</td></tr>' ;
2014-03-01 19:45:13 +01:00
2017-10-16 08:47:05 +02:00
// Bank Account
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'banque' )) {
2020-08-28 13:08:04 +02:00
print '<tr><td>' . $langs -> trans ( 'BankAccount' ) . '</td><td colspan="2">' ;
2022-02-23 06:08:20 +01:00
print img_picto ( '' , 'bank_account' , 'class="pictofixedwidth"' );
2022-02-28 22:30:17 +01:00
print $form -> select_comptes (( $fk_account < 0 ? '' : $fk_account ), 'fk_account' , 0 , '' , 1 , '' , 0 , 'maxwidth200 widthcentpercentminusx' , 1 );
2020-08-28 13:08:04 +02:00
print '</td></tr>' ;
}
2014-07-07 17:59:04 +02:00
2013-04-20 17:10:03 +02:00
// Project
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'project' )) {
2013-04-20 17:10:03 +02:00
$langs -> load ( 'projects' );
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( 'Project' ) . '</td><td colspan="2">' ;
2021-05-19 15:00:44 +02:00
print img_picto ( '' , 'project' ) . $formproject -> select_projects (( $socid > 0 ? $socid : - 1 ), $projectid , 'projectid' , 0 , 0 , 1 , 1 , 0 , 0 , 0 , '' , 1 , 0 , 'maxwidth500 widthcentpercentminusxx' );
2019-12-06 08:50:26 +01:00
print ' <a href="' . DOL_URL_ROOT . '/projet/card.php?socid=' . $soc -> id . '&action=create&status=1&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?action=create&socid=' . $soc -> id . ( $fac_rec ? '&fac_rec=' . $fac_rec : '' )) . '"><span class="fa fa-plus-circle valignmiddle" title="' . $langs -> trans ( " AddProject " ) . '"></span></a>' ;
2013-04-20 00:10:20 +02:00
print '</td></tr>' ;
2013-04-20 17:10:03 +02:00
}
2014-03-01 19:45:13 +01:00
2015-02-23 09:16:14 +01:00
// Incoterms
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'incoterm' )) {
2015-02-23 09:16:14 +01:00
print '<tr>' ;
2021-12-02 15:56:34 +01:00
print '<td><label for="incoterm_id">' . $form -> textwithpicto ( $langs -> trans ( " IncotermLabel " ), ! empty ( $objectsrc -> label_incoterms ) ? $objectsrc -> label_incoterms : '' , 1 ) . '</label></td>' ;
2017-10-16 08:47:05 +02:00
print '<td colspan="2" class="maxwidthonsmartphone">' ;
$incoterm_id = GETPOST ( 'incoterm_id' );
$incoterm_location = GETPOST ( 'location_incoterms' );
2021-02-23 15:35:16 +01:00
if ( empty ( $incoterm_id )) {
2017-10-16 08:47:05 +02:00
$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 $form -> select_incoterms ( $incoterm_id , $incoterm_location );
2015-02-23 09:16:14 +01:00
print '</td></tr>' ;
}
2015-03-18 14:31:37 +01:00
2013-04-20 17:10:03 +02:00
// Other attributes
2021-12-02 15:56:34 +01:00
$parameters = array ( 'objectsrc' => ! empty ( $objectsrc ) ? $objectsrc : 0 , 'colspan' => ' colspan="2"' , 'cols' => '2' , 'socid' => $socid );
2017-06-07 16:44:04 +02:00
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2017-10-16 08:47:05 +02:00
print $hookmanager -> resPrint ;
2018-04-13 13:28:48 +02:00
if ( empty ( $reshook )) {
2020-11-23 16:40:31 +01:00
if ( ! empty ( $conf -> global -> THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE ) && ! empty ( $soc -> id )) {
2020-06-18 19:42:23 +02:00
// 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 );
}
};
2021-10-08 15:58:08 +02:00
print $object -> showOptionals ( $extrafields , 'create' , $parameters );
2013-04-20 17:10:03 +02:00
}
2014-03-01 19:45:13 +01:00
2015-06-03 11:55:39 +02:00
// Template to use by default
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( 'Model' ) . '</td>' ;
2016-02-15 00:58:51 +01:00
print '<td colspan="2">' ;
2021-05-19 15:00:44 +02:00
print img_picto ( '' , 'pdf' , 'class="pictofixedwidth"' );
2019-11-12 00:15:34 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php' ;
2014-02-23 20:10:05 +01:00
$liste = ModelePDFFactures :: liste_modeles ( $db );
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> global -> INVOICE_USE_DEFAULT_DOCUMENT )) {
2019-10-26 18:13:20 +02:00
// Hidden conf
2020-10-31 14:32:18 +01:00
$paramkey = 'FACTURE_ADDON_PDF_' . $object -> type ;
2021-01-15 14:02:18 +01:00
$preselected = ! empty ( $conf -> global -> $paramkey ) ? $conf -> global -> $paramkey : $conf -> global -> FACTURE_ADDON_PDF ;
2019-10-26 18:13:20 +02:00
} else {
2021-01-15 14:02:18 +01:00
$preselected = $conf -> global -> FACTURE_ADDON_PDF ;
2018-10-02 15:51:17 +02:00
}
2021-05-19 15:00:44 +02:00
print $form -> selectarray ( 'model' , $liste , $preselected , 0 , 0 , 0 , '' , 0 , 0 , 0 , '' , 'maxwidth200 widthcentpercentminusx' , 1 );
2013-04-20 17:10:03 +02:00
print " </td></tr> " ;
2014-03-01 19:45:13 +01:00
2016-01-23 16:01:55 +01:00
// Multicurrency
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2016-01-23 16:01:55 +01:00
print '<tr>' ;
2018-10-27 17:45:29 +02:00
print '<td>' . $form -> editfieldkey ( 'Currency' , 'multicurrency_code' , '' , $object , 0 ) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '<td colspan="2" class="maxwidthonsmartphone">' ;
2022-05-02 20:26:34 +02:00
print img_picto ( '' , 'currency' , 'class="pictofixedwidth"' );
2017-10-16 08:47:05 +02:00
print $form -> selectMultiCurrency ( $currency_code , 'multicurrency_code' );
2016-01-23 16:01:55 +01:00
print '</td></tr>' ;
}
2016-08-10 09:47:25 +02:00
2016-12-04 21:27:08 +01:00
// Help of substitution key
2019-11-12 00:15:34 +01:00
$htmltext = '' ;
2021-02-23 15:35:16 +01:00
if ( GETPOST ( 'fac_rec' , 'int' ) > 0 ) {
2021-01-11 15:34:25 +01:00
$dateexample = ( $newdateinvoice ? $newdateinvoice : $dateinvoice );
2021-02-23 21:09:01 +01:00
if ( empty ( $dateexample )) {
$dateexample = dol_now ();
}
2019-11-12 00:15:34 +01:00
$substitutionarray = array (
2017-10-16 08:47:05 +02:00
'__TOTAL_HT__' => $langs -> trans ( " AmountHT " ) . ' (' . $langs -> trans ( " Example " ) . ': ' . price ( $exampletemplateinvoice -> total_ht ) . ')' ,
'__TOTAL_TTC__' => $langs -> trans ( " AmountTTC " ) . ' (' . $langs -> trans ( " Example " ) . ': ' . price ( $exampletemplateinvoice -> total_ttc ) . ')' ,
2019-01-27 11:55:16 +01:00
'__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' ) . ')' ,
2017-10-16 08:47:05 +02:00
'__INVOICE_NEXT_MONTH_TEXT__' => $langs -> trans ( " TextNextMonthOfInvoice " ) . ' (' . $langs -> trans ( " Example " ) . ': ' . dol_print_date ( dol_time_plus_duree ( $dateexample , 1 , 'm' ), '%B' ) . ')' ,
2019-08-19 17:26:13 +02:00
'__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' ) . ')' ,
2019-01-27 11:55:16 +01:00
'__INVOICE_NEXT_YEAR__' => $langs -> trans ( " NextYearOfInvoice " ) . ' (' . $langs -> trans ( " Example " ) . ': ' . dol_print_date ( dol_time_plus_duree ( $dateexample , 1 , 'y' ), '%Y' ) . ')'
2017-10-16 08:47:05 +02:00
);
$htmltext = '<i>' . $langs -> trans ( " FollowingConstantsWillBeSubstituted " ) . ':<br>' ;
2021-02-23 15:35:16 +01:00
foreach ( $substitutionarray as $key => $val ) {
2019-11-12 00:15:34 +01:00
$htmltext .= $key . ' = ' . $langs -> trans ( $val ) . '<br>' ;
2017-10-16 08:47:05 +02:00
}
2019-11-12 00:15:34 +01:00
$htmltext .= '</i>' ;
2016-12-04 21:27:08 +01:00
}
2016-12-24 21:39:40 +01:00
2013-04-20 17:10:03 +02:00
// Public note
print '<tr>' ;
2017-04-11 20:07:35 +02:00
print '<td class="tdtop">' ;
2016-12-04 21:27:08 +01:00
print $form -> textwithpicto ( $langs -> trans ( 'NotePublic' ), $htmltext );
print '</td>' ;
2013-04-20 17:10:03 +02:00
print '<td valign="top" colspan="2">' ;
2020-11-30 14:54:44 +01:00
$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%' );
2013-04-20 17:10:03 +02:00
print $doleditor -> Create ( 1 );
2014-03-01 19:45:13 +01:00
2013-04-20 17:10:03 +02:00
// Private note
2021-02-23 15:35:16 +01:00
if ( empty ( $user -> socid )) {
2013-04-20 00:10:20 +02:00
print '<tr>' ;
2017-04-11 20:07:35 +02:00
print '<td class="tdtop">' ;
2016-12-04 21:27:08 +01:00
print $form -> textwithpicto ( $langs -> trans ( 'NotePrivate' ), $htmltext );
print '</td>' ;
2013-04-20 00:10:20 +02:00
print '<td valign="top" colspan="2">' ;
2020-11-30 14:54:44 +01:00
$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%' );
2013-04-20 00:10:20 +02:00
print $doleditor -> Create ( 1 );
2014-06-28 19:47:51 +02:00
// print '<textarea name="note_private" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'.</textarea>
print '</td></tr>' ;
2013-04-20 17:10:03 +02:00
}
2014-03-01 19:45:13 +01:00
2020-12-05 15:35:52 +01:00
// Lines from source (TODO Show them also when creating invoice from template invoice)
2021-02-23 15:35:16 +01:00
if ( ! empty ( $origin ) && ! empty ( $originid ) && is_object ( $objectsrc )) {
2021-02-23 14:48:54 +01:00
$langs -> loadLangs ( array ( 'orders' , 'propal' ));
2013-04-20 17:10:03 +02:00
// TODO for compatibility
2014-02-23 20:10:05 +01:00
if ( $origin == 'contrat' ) {
2013-04-20 17:10:03 +02:00
// Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
2014-02-23 20:10:05 +01:00
$objectsrc -> remise_absolue = $remise_absolue ;
$objectsrc -> remise_percent = $remise_percent ;
$objectsrc -> update_price ( 1 , - 1 , 1 );
2013-04-20 00:10:20 +02:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 14:48:54 +01:00
print " \n <!-- Show ref of origin " . $classname . " --> \n " ;
print '<input type="hidden" name="amount" value="' . $objectsrc -> total_ht . '">' . " \n " ;
print '<input type="hidden" name="total" value="' . $objectsrc -> total_ttc . '">' . " \n " ;
print '<input type="hidden" name="tva" value="' . $objectsrc -> total_tva . '">' . " \n " ;
2021-10-11 15:25:25 +02:00
// The commented lines below are fields already added as hidden parameters before
2021-10-05 11:18:42 +02:00
//print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
//print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
2014-03-01 19:45:13 +01:00
2018-07-02 16:22:40 +02:00
switch ( get_class ( $objectsrc )) {
2015-04-04 17:28:24 +02:00
case 'Propal' :
$newclassname = 'CommercialProposal' ;
break ;
case 'Commande' :
$newclassname = 'Order' ;
break ;
case 'Expedition' :
$newclassname = 'Sending' ;
break ;
case 'Contrat' :
$newclassname = 'Contract' ;
break ;
2015-04-12 12:03:59 +02:00
case 'Fichinter' :
$newclassname = 'Intervention' ;
break ;
2015-04-04 17:28:24 +02:00
default :
2018-07-02 16:46:30 +02:00
$newclassname = get_class ( $objectsrc );
2015-04-04 17:28:24 +02:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 14:48:54 +01:00
// Ref of origin
print '<tr><td>' . $langs -> trans ( $newclassname ) . '</td>' ;
print '<td colspan="2">' ;
print $objectsrc -> getNomUrl ( 1 );
2015-10-20 02:34:53 +02:00
// We check if Origin document (id and type is known) has already at least one invoice attached to it
2019-01-27 11:55:16 +01:00
$objectsrc -> fetchObjectLinked ( $originid , $origin , '' , 'facture' );
2021-02-23 15:35:16 +01:00
if ( is_array ( $objectsrc -> linkedObjects [ 'facture' ]) && count ( $objectsrc -> linkedObjects [ 'facture' ]) >= 1 ) {
2017-10-16 08:47:05 +02:00
setEventMessages ( 'WarningBillExist' , null , 'warnings' );
2021-02-23 14:48:54 +01:00
echo ' - ' . $langs -> trans ( 'LatestRelatedBill' ) . ' ' . end ( $objectsrc -> linkedObjects [ 'facture' ]) -> getNomUrl ( 1 );
2014-08-07 16:23:02 +02:00
}
echo '</td></tr>' ;
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( 'AmountHT' ) . '</td><td colspan="2">' . price ( $objectsrc -> total_ht ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'AmountVAT' ) . '</td><td colspan="2">' . price ( $objectsrc -> total_tva ) . " </td></tr> " ;
2021-02-23 15:35:16 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $objectsrc -> total_localtax1 != 0 ) { // Localtax1
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT1 " , $mysoc -> country_code ) . '</td><td colspan="2">' . price ( $objectsrc -> total_localtax1 ) . " </td></tr> " ;
2014-02-23 20:10:05 +01:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( $mysoc -> localtax2_assuj == " 1 " || $objectsrc -> total_localtax2 != 0 ) { // Localtax2
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT2 " , $mysoc -> country_code ) . '</td><td colspan="2">' . price ( $objectsrc -> total_localtax2 ) . " </td></tr> " ;
2014-02-23 20:10:05 +01:00
}
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( 'AmountTTC' ) . '</td><td colspan="2">' . price ( $objectsrc -> total_ttc ) . " </td></tr> " ;
2016-08-10 09:47:25 +02:00
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( 'MulticurrencyAmountHT' ) . '</td><td colspan="2">' . price ( $objectsrc -> multicurrency_total_ht ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'MulticurrencyAmountVAT' ) . '</td><td colspan="2">' . price ( $objectsrc -> multicurrency_total_tva ) . " </td></tr> " ;
print '<tr><td>' . $langs -> trans ( 'MulticurrencyAmountTTC' ) . '</td><td colspan="2">' . price ( $objectsrc -> multicurrency_total_ttc ) . " </td></tr> " ;
2016-01-23 16:01:55 +01:00
}
2015-06-03 11:55:39 +02:00
}
2014-03-01 19:45:13 +01:00
2013-04-20 17:10:03 +02:00
print " </table> \n " ;
2014-03-01 19:45:13 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-05-19 00:01:30 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ( " CreateDraft " );
2014-03-01 19:45:13 +01:00
2013-04-20 17:10:03 +02:00
// Show origin lines
2019-11-12 00:15:34 +01:00
if ( ! empty ( $origin ) && ! empty ( $originid ) && is_object ( $objectsrc )) {
2013-04-20 17:10:03 +02:00
print '<br>' ;
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
$title = $langs -> trans ( 'ProductsAndServices' );
2015-09-24 18:27:13 +02:00
print load_fiche_titre ( $title );
2014-03-01 19:45:13 +01:00
2022-04-07 11:18:56 +02:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2014-03-01 19:45:13 +01:00
2020-10-25 09:28:41 +01:00
$objectsrc -> printOriginLinesList ( '' , $selectedLines );
2014-03-01 19:45:13 +01:00
2013-04-20 17:10:03 +02:00
print '</table>' ;
2022-04-07 11:18:56 +02:00
print '</div>' ;
2013-04-20 00:10:20 +02:00
}
2014-03-01 19:45:13 +01:00
2020-10-25 09:28:41 +01:00
print " </form> \n " ;
2020-11-29 15:16:53 +01:00
} elseif ( $id > 0 || ! empty ( $ref )) {
2021-10-28 15:26:40 +02:00
if ( empty ( $object -> id )) {
$langs -> load ( 'errors' );
2021-10-31 14:33:44 +01:00
echo '<div class="error">' . $langs -> trans ( " ErrorRecordNotFound " ) . '</div>' ;
2021-10-28 15:26:40 +02:00
llxFooter ();
exit ;
}
2013-04-20 17:10:03 +02:00
/*
* Show object in view mode
2013-11-17 23:25:25 +01:00
*/
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
$result = $object -> fetch ( $id , $ref );
if ( $result <= 0 ) {
2021-06-08 10:38:34 +02:00
dol_print_error ( $db , $object -> error , $object -> errors );
2014-02-23 20:10:05 +01:00
exit ();
}
2014-03-01 19:45:13 +01:00
2013-04-20 17:10:03 +02:00
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2014-03-01 19:45:13 +01:00
2021-02-23 21:09:01 +01:00
if ( $user -> socid > 0 && $user -> socid != $object -> socid ) {
2019-06-04 12:21:27 +02:00
accessforbidden ( '' , 0 , 1 );
}
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
$result = $object -> fetch_thirdparty ();
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
$result = $soc -> fetch ( $object -> socid );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
dol_print_error ( $db );
}
2014-02-23 20:10:05 +01:00
$selleruserevenustamp = $mysoc -> useRevenueStamp ();
2014-03-01 19:45:13 +01:00
2022-05-22 17:09:08 +02:00
$totalpaid = $object -> getSommePaiement ();
2013-11-17 23:25:25 +01:00
$totalcreditnotes = $object -> getSumCreditNotesUsed ();
$totaldeposits = $object -> getSumDepositsUsed ();
2022-05-22 17:09:08 +02:00
//print "totalpaid=".$totalpaid." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits."
2014-02-23 20:10:05 +01:00
// selleruserrevenuestamp=".$selleruserevenustamp;
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// We can also use bcadd to avoid pb with floating points
// For example print 239.2 - 229.3 - 9.9; does not return 0.
2022-05-22 17:09:08 +02:00
// $resteapayer=bcadd($object->total_ttc,$totalpaid,$conf->global->MAIN_MAX_DECIMALS_TOT);
2014-02-23 20:10:05 +01:00
// $resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
2022-05-22 17:09:08 +02:00
$resteapayer = price2num ( $object -> total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits , 'MT' );
2014-03-01 19:45:13 +01:00
2021-10-15 09:07:48 +02:00
// Multicurrency
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2022-05-22 17:09:08 +02:00
$multicurrency_totalpaid = $object -> getSommePaiement ( 1 );
2021-10-15 09:07:48 +02:00
$multicurrency_totalcreditnotes = $object -> getSumCreditNotesUsed ( 1 );
$multicurrency_totaldeposits = $object -> getSumDepositsUsed ( 1 );
2022-05-22 17:09:08 +02:00
$multicurrency_resteapayer = price2num ( $object -> multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits , 'MT' );
2021-12-16 12:33:45 +01:00
// Code to fix case of corrupted data
2022-10-06 20:21:31 +02:00
// TODO We should not need this. Also data comes from a not reliable value of $object->multicurrency_total_ttc that may be wrong if it was
// calculated by summing lines that were in a currency for some of them and into another for others (lines from discount/down payment into another currency for example)
if ( $resteapayer == 0 && $multicurrency_resteapayer != 0 && $object -> multicurrency_code != $conf -> currency ) {
2021-12-16 12:33:45 +01:00
$resteapayer = price2num ( $multicurrency_resteapayer / $object -> multicurrency_tx , 'MT' );
}
2021-10-15 09:07:48 +02:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 21:09:01 +01:00
if ( $object -> paye ) {
2014-02-23 20:10:05 +01:00
$resteapayer = 0 ;
2017-12-05 12:31:57 +01:00
}
2014-02-23 20:10:05 +01:00
$resteapayeraffiche = $resteapayer ;
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS )) { // Never use this
2014-02-23 20:10:05 +01:00
$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 {
2018-02-19 17:32:59 +01:00
$filterabsolutediscount = " fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%') " ;
2017-10-13 01:03:33 +02:00
$filtercreditnote = " fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%') " ;
2014-02-23 20:10:05 +01:00
}
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
$absolute_discount = $soc -> getAvailableDiscounts ( '' , $filterabsolutediscount );
$absolute_creditnote = $soc -> getAvailableDiscounts ( '' , $filtercreditnote );
$absolute_discount = price2num ( $absolute_discount , 'MT' );
$absolute_creditnote = price2num ( $absolute_creditnote , 'MT' );
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
$author = new User ( $db );
2014-02-23 20:10:05 +01:00
if ( $object -> user_author ) {
2013-11-17 23:25:25 +01:00
$author -> fetch ( $object -> user_author );
}
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
$objectidnext = $object -> getIdReplacingInvoice ();
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
$head = facture_prepare_head ( $object );
2014-03-01 19:45:13 +01:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'compta' , $langs -> trans ( 'InvoiceCustomer' ), - 1 , 'bill' );
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
$formconfirm = '' ;
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Confirmation de la conversion de l'avoir en reduc
2014-02-23 20:10:05 +01:00
if ( $action == 'converttoreduc' ) {
2021-02-23 21:09:01 +01:00
if ( $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_SITUATION ) {
$type_fac = 'ExcessReceived' ;
} elseif ( $object -> type == Facture :: TYPE_CREDIT_NOTE ) {
$type_fac = 'CreditNote' ;
} elseif ( $object -> type == Facture :: TYPE_DEPOSIT ) {
$type_fac = 'Deposit' ;
}
2016-11-24 15:48:04 +01:00
$text = $langs -> trans ( 'ConfirmConvertToReduc' , strtolower ( $langs -> transnoentities ( $type_fac )));
2019-11-12 00:15:34 +01:00
$text .= '<br>' . $langs -> trans ( 'ConfirmConvertToReduc2' );
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $langs -> trans ( 'ConvertToReduc' ), $text , 'confirm_converttoreduc' , '' , " yes " , 2 );
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Confirmation to delete invoice
2014-02-23 20:10:05 +01:00
if ( $action == 'delete' ) {
$text = $langs -> trans ( 'ConfirmDeleteBill' , $object -> ref );
$formquestion = array ();
2014-03-01 19:45:13 +01:00
2021-02-23 21:09:01 +01:00
if ( $object -> type != Facture :: TYPE_DEPOSIT && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_BILL ) && $object -> statut >= 1 ) {
2019-05-20 12:47:02 +02:00
$qualified_for_stock_change = 0 ;
if ( empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
$qualified_for_stock_change = $object -> hasProductsOrServices ( 2 );
} else {
$qualified_for_stock_change = $object -> hasProductsOrServices ( 1 );
}
2019-05-20 12:50:00 +02:00
2021-02-23 21:09:01 +01:00
if ( $qualified_for_stock_change ) {
2019-05-20 12:47:02 +02:00
$langs -> load ( " stocks " );
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
2019-05-20 12:47:02 +02:00
$formproduct = new FormProduct ( $db );
$label = $object -> type == Facture :: TYPE_CREDIT_NOTE ? $langs -> trans ( " SelectWarehouseForStockDecrease " ) : $langs -> trans ( " SelectWarehouseForStockIncrease " );
2019-11-12 00:15:34 +01:00
$forcecombo = 0 ;
2021-02-23 21:09:01 +01:00
if ( $conf -> browser -> name == 'ie' ) {
$forcecombo = 1 ; // There is a bug in IE10 that make combo inside popup crazy
}
2019-05-20 12:47:02 +02:00
$formquestion = array (
// 'text' => $langs->trans("ConfirmClone"),
// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
// array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
2019-11-12 00:15:34 +01:00
array ( 'type' => 'other' , 'name' => 'idwarehouse' , 'label' => $label , 'value' => $formproduct -> selectWarehouses ( GETPOST ( 'idwarehouse' ) ? GETPOST ( 'idwarehouse' ) : 'ifone' , 'idwarehouse' , '' , 1 , 0 , 0 , $langs -> trans ( " NoStockAction " ), 0 , $forcecombo ))
2019-05-20 12:47:02 +02:00
);
2019-11-12 00:15:34 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $langs -> trans ( 'DeleteBill' ), $text , 'confirm_delete' , $formquestion , " yes " , 1 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $langs -> trans ( 'DeleteBill' ), $text , 'confirm_delete' , '' , 'no' , 1 );
2019-05-20 12:47:02 +02:00
}
2014-02-23 20:10:05 +01:00
} else {
2019-11-12 00:15:34 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $langs -> trans ( 'DeleteBill' ), $text , 'confirm_delete' , '' , 'no' , 1 );
2014-02-23 20:10:05 +01:00
}
}
2014-03-01 19:45:13 +01:00
2018-04-03 17:34:20 +02:00
// Confirmation to remove invoice from cycle
if ( $action == 'situationout' ) {
2021-02-23 21:09:01 +01:00
$text = $langs -> trans ( 'ConfirmRemoveSituationFromCycle' , $object -> ref );
$label = $langs -> trans ( " ConfirmOuting " );
$formquestion = array ();
// remove situation from cycle
if ( in_array ( $object -> statut , array ( Facture :: STATUS_CLOSED , Facture :: STATUS_VALIDATED ))
&& $usercancreate
&& ! $objectidnext
&& $object -> is_last_in_cycle ()
&& $usercanunvalidate
) {
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $label , $text , 'confirm_situationout' , $formquestion , " yes " , 1 );
2018-04-09 09:17:26 +02:00
}
2018-04-03 17:34:20 +02:00
}
2014-03-01 19:45:13 +01:00
2018-01-29 16:21:54 +01:00
// Confirmation of validation
2021-02-23 21:09:01 +01:00
if ( $action == 'valid' ) {
2018-01-29 16:21:54 +01:00
// we check object has a draft number
2013-11-17 23:25:25 +01:00
$objectref = substr ( $object -> ref , 1 , 4 );
2014-02-23 20:10:05 +01:00
if ( $objectref == 'PROV' ) {
$savdate = $object -> date ;
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> global -> FAC_FORCE_DATE_VALIDATION )) {
2014-02-23 20:10:05 +01:00
$object -> date = dol_now ();
$object -> date_lim_reglement = $object -> calculate_date_lim_reglement ();
2013-04-20 00:10:20 +02:00
}
2013-11-17 23:25:25 +01:00
$numref = $object -> getNextNumRef ( $soc );
2014-02-23 20:10:05 +01:00
// $object->date=$savdate;
} else {
2013-11-17 23:25:25 +01:00
$numref = $object -> ref ;
}
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
$text = $langs -> trans ( 'ConfirmValidateBill' , $numref );
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> notification -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php' ;
2014-02-23 20:10:05 +01:00
$notify = new Notify ( $db );
$text .= '<br>' ;
2015-03-18 21:44:57 +01:00
$text .= $notify -> confirmMessage ( 'BILL_VALIDATE' , $object -> socid , $object );
2014-02-23 20:10:05 +01:00
}
$formquestion = array ();
2014-03-01 19:45:13 +01:00
2021-02-23 21:09:01 +01:00
if ( $object -> type != Facture :: TYPE_DEPOSIT && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_BILL )) {
2019-05-20 12:47:02 +02:00
$qualified_for_stock_change = 0 ;
if ( empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
$qualified_for_stock_change = $object -> hasProductsOrServices ( 2 );
2013-11-17 23:25:25 +01:00
} else {
2019-05-20 12:47:02 +02:00
$qualified_for_stock_change = $object -> hasProductsOrServices ( 1 );
}
2019-05-20 12:50:00 +02:00
2021-02-23 21:09:01 +01:00
if ( $qualified_for_stock_change ) {
2019-05-20 12:47:02 +02:00
$langs -> load ( " stocks " );
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php' ;
2019-05-20 12:47:02 +02:00
$formproduct = new FormProduct ( $db );
$warehouse = new Entrepot ( $db );
$warehouse_array = $warehouse -> list_array ();
if ( count ( $warehouse_array ) == 1 ) {
$label = $object -> type == Facture :: TYPE_CREDIT_NOTE ? $langs -> trans ( " WarehouseForStockIncrease " , current ( $warehouse_array )) : $langs -> trans ( " WarehouseForStockDecrease " , current ( $warehouse_array ));
2019-11-12 00:15:34 +01:00
$value = '<input type="hidden" id="idwarehouse" name="idwarehouse" value="' . key ( $warehouse_array ) . '">' ;
2019-05-20 12:47:02 +02:00
} else {
$label = $object -> type == Facture :: TYPE_CREDIT_NOTE ? $langs -> trans ( " SelectWarehouseForStockIncrease " ) : $langs -> trans ( " SelectWarehouseForStockDecrease " );
2019-11-12 00:15:34 +01:00
$value = $formproduct -> selectWarehouses ( GETPOST ( 'idwarehouse' ) ? GETPOST ( 'idwarehouse' ) : 'ifone' , 'idwarehouse' , '' , 1 );
2019-05-20 12:47:02 +02:00
}
$formquestion = array (
// 'text' => $langs->trans("ConfirmClone"),
// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
// 1),
// array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
// => 1),
2019-11-12 00:15:34 +01:00
array ( 'type' => 'other' , 'name' => 'idwarehouse' , 'label' => $label , 'value' => $value ));
2013-04-20 00:10:20 +02:00
}
2013-11-17 23:25:25 +01:00
}
2021-02-23 21:09:01 +01:00
if ( $object -> type != Facture :: TYPE_CREDIT_NOTE && $object -> total_ttc < 0 ) { // Can happen only if $conf->global->FACTURE_ENABLE_NEGATIVE is on
2019-11-12 00:15:34 +01:00
$text .= '<br>' . img_warning () . ' ' . $langs -> trans ( " ErrorInvoiceOfThisTypeMustBePositive " );
2013-11-17 23:25:25 +01:00
}
2021-07-20 14:46:56 +02:00
// mandatoryPeriod
$nbMandated = 0 ;
2021-07-20 15:35:10 +02:00
foreach ( $object -> lines as $line ) {
2021-07-20 14:46:56 +02:00
$res = $line -> fetch_product ();
2021-07-20 15:35:10 +02:00
if ( $res > 0 ) {
if ( $line -> product -> isService () && $line -> product -> isMandatoryPeriod () && ( empty ( $line -> date_start ) || empty ( $line -> date_end ) )) {
2021-07-20 14:46:56 +02:00
$nbMandated ++ ;
break ;
}
}
}
if ( $nbMandated > 0 ) $text .= '<div><span class="clearboth nowraponall warning">' . $langs -> trans ( " mandatoryPeriodNeedTobeSetMsgValidate " ) . '</span></div>' ;
2019-11-12 00:15:34 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , $langs -> trans ( 'ValidateBill' ), $text , 'confirm_valid' , $formquestion , (( $object -> type != Facture :: TYPE_CREDIT_NOTE && $object -> total_ttc < 0 ) ? " no " : " yes " ), 2 );
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Confirm back to draft status
2014-02-23 20:10:05 +01:00
if ( $action == 'modif' ) {
$text = $langs -> trans ( 'ConfirmUnvalidateBill' , $object -> ref );
$formquestion = array ();
2014-03-01 19:45:13 +01:00
2021-02-23 21:09:01 +01:00
if ( $object -> type != Facture :: TYPE_DEPOSIT && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_BILL )) {
2019-05-20 12:47:02 +02:00
$qualified_for_stock_change = 0 ;
if ( empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
$qualified_for_stock_change = $object -> hasProductsOrServices ( 2 );
2013-11-17 23:25:25 +01:00
} else {
2019-05-20 12:47:02 +02:00
$qualified_for_stock_change = $object -> hasProductsOrServices ( 1 );
}
2019-05-20 12:50:00 +02:00
2021-02-23 21:09:01 +01:00
if ( $qualified_for_stock_change ) {
2019-05-20 12:47:02 +02:00
$langs -> load ( " stocks " );
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php' ;
2019-05-20 12:47:02 +02:00
$formproduct = new FormProduct ( $db );
$warehouse = new Entrepot ( $db );
$warehouse_array = $warehouse -> list_array ();
if ( count ( $warehouse_array ) == 1 ) {
$label = $object -> type == Facture :: TYPE_CREDIT_NOTE ? $langs -> trans ( " WarehouseForStockDecrease " , current ( $warehouse_array )) : $langs -> trans ( " WarehouseForStockIncrease " , current ( $warehouse_array ));
2019-11-12 00:15:34 +01:00
$value = '<input type="hidden" id="idwarehouse" name="idwarehouse" value="' . key ( $warehouse_array ) . '">' ;
2019-05-20 12:47:02 +02:00
} else {
$label = $object -> type == Facture :: TYPE_CREDIT_NOTE ? $langs -> trans ( " SelectWarehouseForStockDecrease " ) : $langs -> trans ( " SelectWarehouseForStockIncrease " );
2019-11-12 00:15:34 +01:00
$value = $formproduct -> selectWarehouses ( GETPOST ( 'idwarehouse' ) ? GETPOST ( 'idwarehouse' ) : 'ifone' , 'idwarehouse' , '' , 1 );
2019-05-20 12:47:02 +02:00
}
$formquestion = array (
// 'text' => $langs->trans("ConfirmClone"),
// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
// 1),
// array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
// => 1),
2019-11-12 00:15:34 +01:00
array ( 'type' => 'other' , 'name' => 'idwarehouse' , 'label' => $label , 'value' => $value ));
2019-05-20 12:47:02 +02:00
}
2013-04-20 17:10:03 +02:00
}
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , $langs -> trans ( 'UnvalidateBill' ), $text , 'confirm_modif' , $formquestion , " yes " , 1 );
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Confirmation du classement paye
2021-12-30 19:03:46 +01:00
if ( $action == 'paid' && ( $resteapayer <= 0 || ( ! empty ( $conf -> global -> INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID ) && $resteapayer == $object -> total_ttc ))) {
2019-11-12 00:15:34 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , $langs -> trans ( 'ClassifyPaid' ), $langs -> trans ( 'ConfirmClassifyPaidBill' , $object -> ref ), 'confirm_paid' , '' , " yes " , 1 );
2013-11-17 23:25:25 +01:00
}
2021-12-30 19:03:46 +01:00
if ( $action == 'paid' && $resteapayer > 0 && ( empty ( $conf -> global -> INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID ) || $resteapayer != $object -> total_ttc )) {
2020-11-29 15:16:53 +01:00
$close = array ();
2013-11-17 23:25:25 +01:00
// Code
2014-02-23 20:10:05 +01:00
$i = 0 ;
2019-12-22 13:19:14 +01:00
$close [ $i ][ 'code' ] = 'discount_vat' ; // escompte
2019-11-12 00:15:34 +01:00
$i ++ ;
2019-12-22 13:19:14 +01:00
$close [ $i ][ 'code' ] = 'badcustomer' ;
2019-11-12 00:15:34 +01:00
$i ++ ;
2021-08-26 04:37:03 +02:00
$close [ $i ][ 'code' ] = 'bankcharge' ;
$i ++ ;
2020-01-02 18:02:53 +01:00
$close [ $i ][ 'code' ] = 'other' ;
$i ++ ;
2013-11-17 23:25:25 +01:00
// Help
2014-02-23 20:10:05 +01:00
$i = 0 ;
2019-12-22 13:19:14 +01:00
$close [ $i ][ 'label' ] = $langs -> trans ( " HelpEscompte " ) . '<br><br>' . $langs -> trans ( " ConfirmClassifyPaidPartiallyReasonDiscountVatDesc " );
2019-11-12 00:15:34 +01:00
$i ++ ;
2019-12-22 13:19:14 +01:00
$close [ $i ][ 'label' ] = $langs -> trans ( " ConfirmClassifyPaidPartiallyReasonBadCustomerDesc " );
2019-11-12 00:15:34 +01:00
$i ++ ;
2021-08-26 04:37:03 +02:00
$close [ $i ][ 'label' ] = $langs -> trans ( " ConfirmClassifyPaidPartiallyReasonBankChargeDesc " );
$i ++ ;
2020-01-02 18:02:53 +01:00
$close [ $i ][ 'label' ] = $langs -> trans ( " Other " );
$i ++ ;
2013-11-17 23:25:25 +01:00
// Texte
2014-02-23 20:10:05 +01:00
$i = 0 ;
2019-12-22 13:19:14 +01:00
$close [ $i ][ 'reason' ] = $form -> textwithpicto ( $langs -> transnoentities ( " ConfirmClassifyPaidPartiallyReasonDiscount " , $resteapayer , $langs -> trans ( " Currency " . $conf -> currency )), $close [ $i ][ 'label' ], 1 );
2019-11-12 00:15:34 +01:00
$i ++ ;
2019-12-22 13:19:14 +01:00
$close [ $i ][ 'reason' ] = $form -> textwithpicto ( $langs -> transnoentities ( " ConfirmClassifyPaidPartiallyReasonBadCustomer " , $resteapayer , $langs -> trans ( " Currency " . $conf -> currency )), $close [ $i ][ 'label' ], 1 );
2019-11-12 00:15:34 +01:00
$i ++ ;
2021-08-26 04:37:03 +02:00
$close [ $i ][ 'reason' ] = $form -> textwithpicto ( $langs -> transnoentities ( " ConfirmClassifyPaidPartiallyReasonBankCharge " , $resteapayer , $langs -> trans ( " Currency " . $conf -> currency )), $close [ $i ][ 'label' ], 1 );
$i ++ ;
2020-01-02 18:02:53 +01:00
$close [ $i ][ 'reason' ] = $form -> textwithpicto ( $langs -> transnoentities ( " Other " ), $close [ $i ][ 'label' ], 1 );
$i ++ ;
2013-11-17 23:25:25 +01:00
// arrayreasons[code]=reason
2014-02-23 20:10:05 +01:00
foreach ( $close as $key => $val ) {
2020-11-29 15:16:53 +01:00
$arrayreasons [ $close [ $key ][ 'code' ]] = $close [ $key ][ 'reason' ];
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Cree un tableau formulaire
2019-11-12 00:15:34 +01:00
$formquestion = array ( 'text' => $langs -> trans ( " ConfirmClassifyPaidPartiallyQuestion " ), array ( 'type' => 'radio' , 'name' => 'close_code' , 'label' => $langs -> trans ( " Reason " ), 'values' => $arrayreasons ), array ( 'type' => 'text' , 'name' => 'close_note' , 'label' => $langs -> trans ( " Comment " ), 'value' => '' , 'morecss' => 'minwidth300' ));
2013-11-17 23:25:25 +01:00
// Paiement incomplet. On demande si motif = escompte ou autre
2022-07-05 14:02:47 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , $langs -> trans ( 'ClassifyPaid' ), $langs -> trans ( 'ConfirmClassifyPaidPartially' , $object -> ref ), 'confirm_paid_partially' , $formquestion , " yes " , 1 , 340 , 600 );
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Confirmation du classement abandonne
2014-02-23 20:10:05 +01:00
if ( $action == 'canceled' ) {
2013-11-17 23:25:25 +01:00
// S'il y a une facture de remplacement pas encore validee (etat brouillon),
// on ne permet pas de classer abandonner la facture.
2014-02-23 20:10:05 +01:00
if ( $objectidnext ) {
$facturereplacement = new Facture ( $db );
2013-11-17 23:25:25 +01:00
$facturereplacement -> fetch ( $objectidnext );
2014-02-23 20:10:05 +01:00
$statusreplacement = $facturereplacement -> statut ;
2013-04-20 17:10:03 +02:00
}
2014-02-23 20:10:05 +01:00
if ( $objectidnext && $statusreplacement == 0 ) {
2019-11-12 00:15:34 +01:00
print '<div class="error">' . $langs -> trans ( " ErrorCantCancelIfReplacementInvoiceNotValidated " ) . '</div>' ;
2014-02-23 20:10:05 +01:00
} else {
2013-04-20 17:10:03 +02:00
// Code
2019-12-22 13:19:14 +01:00
$close [ 1 ][ 'code' ] = 'badcustomer' ;
$close [ 2 ][ 'code' ] = 'abandon' ;
2013-04-20 17:10:03 +02:00
// Help
2019-12-22 13:19:14 +01:00
$close [ 1 ][ 'label' ] = $langs -> trans ( " ConfirmClassifyPaidPartiallyReasonBadCustomerDesc " );
$close [ 2 ][ 'label' ] = $langs -> trans ( " ConfirmClassifyAbandonReasonOtherDesc " );
2013-04-20 17:10:03 +02:00
// Texte
2019-12-22 13:19:14 +01:00
$close [ 1 ][ 'reason' ] = $form -> textwithpicto ( $langs -> transnoentities ( " ConfirmClassifyPaidPartiallyReasonBadCustomer " , $object -> ref ), $close [ 1 ][ 'label' ], 1 );
$close [ 2 ][ 'reason' ] = $form -> textwithpicto ( $langs -> transnoentities ( " ConfirmClassifyAbandonReasonOther " ), $close [ 2 ][ 'label' ], 1 );
2013-11-17 23:25:25 +01:00
// arrayreasons
2019-12-22 13:19:14 +01:00
$arrayreasons [ $close [ 1 ][ 'code' ]] = $close [ 1 ][ 'reason' ];
$arrayreasons [ $close [ 2 ][ 'code' ]] = $close [ 2 ][ 'reason' ];
2014-03-01 19:45:13 +01:00
2013-04-20 17:10:03 +02:00
// Cree un tableau formulaire
2019-11-12 00:15:34 +01:00
$formquestion = array ( 'text' => $langs -> trans ( " ConfirmCancelBillQuestion " ), array ( 'type' => 'radio' , 'name' => 'close_code' , 'label' => $langs -> trans ( " Reason " ), 'values' => $arrayreasons ), array ( 'type' => 'text' , 'name' => 'close_note' , 'label' => $langs -> trans ( " Comment " ), 'value' => '' , 'morecss' => 'minwidth300' ));
2014-03-01 19:45:13 +01:00
2022-08-13 12:03:41 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $langs -> trans ( 'CancelBill' ), $langs -> trans ( 'ConfirmCancelBill' , $object -> ref ), 'confirm_canceled' , $formquestion , " yes " , 1 , 270 );
2013-04-20 17:10:03 +02:00
}
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 21:09:01 +01:00
if ( $action == 'deletepayment' ) {
2017-12-03 11:59:16 +01:00
$payment_id = GETPOST ( 'paiement_id' );
2018-03-31 23:39:08 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&paiement_id=' . $payment_id , $langs -> trans ( 'DeletePayment' ), $langs -> trans ( 'ConfirmDeletePayment' ), 'confirm_delete_paiement' , '' , 'no' , 1 );
2017-12-03 11:59:16 +01:00
}
2013-11-17 23:25:25 +01:00
// Confirmation de la suppression d'une ligne produit
2014-02-23 20:10:05 +01:00
if ( $action == 'ask_deleteline' ) {
2019-11-12 00:15:34 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&lineid=' . $lineid , $langs -> trans ( 'DeleteProductLine' ), $langs -> trans ( 'ConfirmDeleteProductLine' ), 'confirm_deleteline' , '' , 'no' , 1 );
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Clone confirmation
2021-02-23 21:09:01 +01:00
if ( $action == 'clone' ) {
2013-11-17 23:25:25 +01:00
// Create an array for form
2014-02-23 20:10:05 +01:00
$formquestion = array (
2019-11-12 00:15:34 +01:00
array ( 'type' => 'other' , 'name' => 'socid' , 'label' => $langs -> trans ( " SelectThirdParty " ), 'value' => $form -> select_company ( $object -> socid , 'socid' , '(s.client=1 OR s.client=2 OR s.client=3)' , 1 )),
2020-10-31 14:32:18 +01:00
array ( 'type' => 'date' , 'name' => 'newdate' , 'label' => $langs -> trans ( " Date " ), 'value' => dol_now ())
2019-04-12 12:12:08 +02:00
);
// Ask confirmatio to clone
2019-11-12 00:15:34 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , $langs -> trans ( 'ToClone' ), $langs -> trans ( 'ConfirmCloneInvoice' , $object -> ref ), 'confirm_clone' , $formquestion , 'yes' , 1 , 250 );
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2021-02-23 21:09:01 +01:00
if ( $action == " remove_file_comfirm " ) {
2020-04-08 10:30:51 +02:00
$file = GETPOST ( 'file' , 'alpha' );
$formconfirm = $form -> formconfirm (
$_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&file=' . $file ,
$langs -> trans ( 'DeleteFileHeader' ),
$langs -> trans ( 'DeleteFileText' ) . " <br><br> " . $file ,
'remove_file' ,
'' ,
'no' ,
2021-02-23 21:09:01 +01:00
2
);
2020-04-08 10:30:51 +02:00
}
2020-04-08 10:50:16 +02:00
2018-08-30 11:27:48 +02:00
// Call Hook formConfirm
2020-02-03 03:32:31 +01:00
$parameters = array ( 'formConfirm' => $formconfirm , 'lineid' => $lineid , 'remainingtopay' => & $resteapayer );
2018-08-30 11:27:48 +02:00
$reshook = $hookmanager -> executeHooks ( 'formConfirm' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2021-02-23 21:09:01 +01:00
if ( empty ( $reshook )) {
$formconfirm .= $hookmanager -> resPrint ;
} elseif ( $reshook > 0 ) {
$formconfirm = $hookmanager -> resPrint ;
}
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Print form confirm
print $formconfirm ;
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Invoice content
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2016-09-29 07:01:58 +02:00
2019-11-12 00:15:34 +01:00
$morehtmlref = '<div class="refidno">' ;
2019-12-16 22:30:16 +01:00
// Ref invoice
2020-01-30 01:48:28 +01:00
if ( $object -> status == $object :: STATUS_DRAFT && ! $mysoc -> isInEEC () && ! empty ( $conf -> global -> INVOICE_ALLOW_FREE_REF )) {
2019-12-16 22:30:16 +01:00
$morehtmlref .= $form -> editfieldkey ( " Ref " , 'ref' , $object -> ref , $object , $usercancreate , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " Ref " , 'ref' , $object -> ref , $object , $usercancreate , 'string' , '' , null , null , '' , 1 );
$morehtmlref .= '<br>' ;
}
2016-09-21 01:25:34 +02:00
// Ref customer
2019-11-12 00:15:34 +01:00
$morehtmlref .= $form -> editfieldkey ( " RefCustomer " , 'ref_client' , $object -> ref_client , $object , $usercancreate , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " RefCustomer " , 'ref_client' , $object -> ref_client , $object , $usercancreate , 'string' , '' , null , null , '' , 1 );
2016-09-21 01:25:34 +02:00
// Thirdparty
2019-11-12 00:15:34 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 , 'customer' );
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_OTHER_LINK ) && $object -> thirdparty -> id > 0 ) {
$morehtmlref .= ' (<a href="' . DOL_URL_ROOT . '/compta/facture/list.php?socid=' . $object -> thirdparty -> id . '&search_societe=' . urlencode ( $object -> thirdparty -> name ) . '">' . $langs -> trans ( " OtherBills " ) . '</a>)' ;
}
2016-09-21 01:25:34 +02:00
// Project
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'project' )) {
2017-10-16 08:47:05 +02:00
$langs -> load ( " projects " );
2019-11-12 00:15:34 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2021-02-23 21:09:01 +01:00
if ( $usercancreate ) {
2019-10-26 18:13:20 +02:00
if ( $action != 'classify' ) {
2021-09-18 22:09:55 +02:00
$morehtmlref .= '<a class="editfielda" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=classify&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetProject' )) . '</a> : ' ;
2019-10-26 18:13:20 +02:00
}
if ( $action == 'classify' ) {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
2019-11-12 00:15:34 +01:00
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
2019-12-18 23:12:31 +01:00
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-12 00:15:34 +01:00
$morehtmlref .= $formproject -> select_projects ( $object -> socid , $object -> fk_project , 'projectid' , $maxlength , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
2019-10-26 18:13:20 +02:00
} else {
2019-11-12 00:15:34 +01:00
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
2019-10-26 18:13:20 +02:00
}
2017-10-16 08:47:05 +02:00
} else {
2019-11-12 00:15:34 +01:00
if ( ! empty ( $object -> fk_project )) {
2017-10-16 08:47:05 +02:00
$proj = new Project ( $db );
$proj -> fetch ( $object -> fk_project );
2021-10-29 09:40:38 +02:00
$morehtmlref .= ' : ' . $proj -> getNomUrl ( 1 );
if ( $proj -> title ) {
$morehtmlref .= ' - ' . $proj -> title ;
}
2017-10-16 08:47:05 +02:00
} else {
2019-11-12 00:15:34 +01:00
$morehtmlref .= '' ;
2017-10-16 08:47:05 +02:00
}
}
2016-09-21 01:25:34 +02:00
}
2019-11-12 00:15:34 +01:00
$morehtmlref .= '</div>' ;
2016-10-29 07:45:24 +02:00
2022-05-22 17:09:08 +02:00
$object -> totalpaid = $totalpaid ; // To give a chance to dol_banner_tab to use already paid amount to show correct status
2016-10-29 07:45:24 +02:00
2018-12-02 14:31:45 +01:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref , '' , 0 , '' , '' );
2016-10-29 07:45:24 +02:00
2016-09-21 01:25:34 +02:00
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2016-10-29 07:45:24 +02:00
2022-06-02 11:11:28 +02:00
print '<table class="border centpercent tableforfield">' ;
2016-10-29 07:45:24 +02:00
2013-11-17 23:25:25 +01:00
// Type
2019-12-22 13:19:14 +01:00
print '<tr><td class="titlefield fieldname_type">' . $langs -> trans ( 'Type' ) . '</td><td class="valuefield fieldname_type">' ;
2020-11-29 15:16:53 +01:00
print '<span class="badgeneutral">' ;
2013-11-17 23:25:25 +01:00
print $object -> getLibType ();
2020-11-29 15:16:53 +01:00
print '</span>' ;
2019-10-17 15:56:50 +02:00
if ( $object -> module_source ) {
2020-12-02 16:35:43 +01:00
print ' <span class="opacitymediumbycolor paddingleft">(' . $langs -> trans ( " POS " ) . ' ' . ucfirst ( $object -> module_source ) . ' - ' . $langs -> trans ( " Terminal " ) . ' ' . $object -> pos_source . ')</span>' ;
2019-10-17 15:56:50 +02:00
}
2014-02-26 01:03:26 +01:00
if ( $object -> type == Facture :: TYPE_REPLACEMENT ) {
2014-02-23 20:10:05 +01:00
$facreplaced = new Facture ( $db );
2013-11-17 23:25:25 +01:00
$facreplaced -> fetch ( $object -> fk_facture_source );
2022-06-02 11:11:28 +02:00
print ' <span class="opacitymediumbycolor paddingleft">' . $langs -> transnoentities ( " ReplaceInvoice " , $facreplaced -> getNomUrl ( 1 )) . '</span>' ;
2013-11-17 23:25:25 +01:00
}
2015-07-08 14:32:57 +02:00
if ( $object -> type == Facture :: TYPE_CREDIT_NOTE && ! empty ( $object -> fk_facture_source )) {
2014-02-23 20:10:05 +01:00
$facusing = new Facture ( $db );
2013-11-17 23:25:25 +01:00
$facusing -> fetch ( $object -> fk_facture_source );
2022-06-02 11:11:28 +02:00
print ' <span class="opacitymediumbycolor paddingleft">' . $langs -> transnoentities ( " CorrectInvoice " , $facusing -> getNomUrl ( 1 )) . '</span>' ;
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
$facidavoir = $object -> getListIdAvoirFromInvoice ();
if ( count ( $facidavoir ) > 0 ) {
2022-06-02 11:11:28 +02:00
print ' <span class="opacitymediumbycolor paddingleft">' . $langs -> transnoentities ( " InvoiceHasAvoir " );
2014-02-23 20:10:05 +01:00
$i = 0 ;
foreach ( $facidavoir as $id ) {
2021-02-23 21:09:01 +01:00
if ( $i == 0 ) {
2014-02-23 20:10:05 +01:00
print ' ' ;
2021-02-23 21:09:01 +01:00
} else {
print ',' ;
}
2014-02-23 20:10:05 +01:00
$facavoir = new Facture ( $db );
2013-11-17 23:25:25 +01:00
$facavoir -> fetch ( $id );
print $facavoir -> getNomUrl ( 1 );
2013-04-20 17:10:03 +02:00
}
2022-06-02 11:11:28 +02:00
print '</span>' ;
2013-11-17 23:25:25 +01:00
}
2014-02-23 20:10:05 +01:00
if ( $objectidnext > 0 ) {
$facthatreplace = new Facture ( $db );
2013-11-17 23:25:25 +01:00
$facthatreplace -> fetch ( $objectidnext );
2022-06-02 11:11:28 +02:00
print ' <span class="opacitymediumbycolor paddingleft">' . str_replace ( '{s1}' , $facthatreplace -> getNomUrl ( 1 ), $langs -> transnoentities ( " ReplacedByInvoice " , '{s1}' )) . '</span>' ;
2013-11-17 23:25:25 +01:00
}
2017-09-11 15:04:29 +02:00
if ( $object -> type == Facture :: TYPE_CREDIT_NOTE || $object -> type == Facture :: TYPE_DEPOSIT ) {
$discount = new DiscountAbsolute ( $db );
$result = $discount -> fetch ( 0 , $object -> id );
2019-11-12 00:15:34 +01:00
if ( $result > 0 ) {
2020-11-29 15:16:53 +01:00
print ' <span class="opacitymediumbycolor paddingleft">' ;
2021-02-17 11:54:34 +01:00
$s = $langs -> trans ( " CreditNoteConvertedIntoDiscount " , '{s1}' , '{s2}' );
$s = str_replace ( '{s1}' , $object -> getLibType ( 1 ), $s );
$s = str_replace ( '{s2}' , $discount -> getNomUrl ( 1 , 'discount' ), $s );
print $s ;
2020-11-28 19:13:17 +01:00
print '</span><br>' ;
2017-09-11 15:04:29 +02:00
}
}
2019-06-05 08:08:31 +02:00
2021-02-23 15:35:16 +01:00
if ( $object -> fk_fac_rec_source > 0 ) {
2019-12-06 13:48:24 +01:00
$tmptemplate = new FactureRec ( $db );
$result = $tmptemplate -> fetch ( $object -> fk_fac_rec_source );
if ( $result > 0 ) {
2020-11-29 15:16:53 +01:00
print ' <span class="opacitymediumbycolor paddingleft">' ;
2021-02-17 11:54:34 +01:00
$s = $langs -> transnoentities ( " GeneratedFromTemplate " , '{s1}' );
$s = str_replace ( '{s1}' , '<a href="' . DOL_URL_ROOT . '/compta/facture/card-rec.php?facid=' . $tmptemplate -> id . '">' . dol_escape_htmltag ( $tmptemplate -> ref ) . '</a>' , $s );
print $s ;
2020-11-28 19:13:17 +01:00
print '</span>' ;
2019-12-06 13:48:24 +01:00
}
2019-06-05 08:08:31 +02:00
}
2013-11-17 23:25:25 +01:00
print '</td></tr>' ;
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Relative and absolute discounts
2019-12-22 13:19:14 +01:00
print '<!-- Discounts -->' . " \n " ;
2022-04-07 14:03:14 +02:00
print '<tr><td>' . $langs -> trans ( 'DiscountStillRemaining' ) . '</td>' ;
print '<td>' ;
2018-03-02 16:48:25 +01:00
$thirdparty = $soc ;
$discount_type = 0 ;
2019-11-12 00:15:34 +01:00
$backtopage = urlencode ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id );
2018-03-02 16:48:25 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/object_discounts.tpl.php' ;
2013-11-17 23:25:25 +01:00
print '</td></tr>' ;
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Date invoice
print '<tr><td>' ;
2021-12-02 10:43:44 +01:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2016-08-31 06:27:35 +02:00
print $langs -> trans ( 'DateInvoice' );
2013-11-17 23:25:25 +01:00
print '</td>' ;
2021-02-23 15:35:16 +01:00
if ( $action != 'editinvoicedate' && ! empty ( $object -> brouillon ) && $usercancreate && empty ( $conf -> global -> FAC_FORCE_DATE_VALIDATION )) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editinvoicedate&token=' . newToken () . '&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetDate' ), 1 ) . '</a></td>' ;
2021-02-23 15:35:16 +01:00
}
2013-11-17 23:25:25 +01:00
print '</tr></table>' ;
2016-09-21 01:25:34 +02:00
print '</td><td>' ;
2014-03-01 19:45:13 +01:00
2020-10-10 07:19:13 +02:00
if ( $action == 'editinvoicedate' ) {
$form -> form_date ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> date , 'invoicedate' );
2014-02-23 20:10:05 +01:00
} else {
2020-11-29 15:16:53 +01:00
print '<span class="valuedate">' . dol_print_date ( $object -> date , 'day' ) . '</span>' ;
2013-11-17 23:25:25 +01:00
}
print '</td>' ;
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
print '</tr>' ;
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( ! empty ( $conf -> global -> INVOICE_POINTOFTAX_DATE )) {
2022-06-02 11:11:28 +02:00
// Date invoice point of tax
2016-05-29 23:56:58 +02:00
print '<tr><td>' ;
2021-12-02 10:43:44 +01:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2016-05-29 23:56:58 +02:00
print $langs -> trans ( 'DatePointOfTax' );
print '</td>' ;
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editdate_pointoftax&token=' . newToken () . '&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetDate' ), 1 ) . '</a></td>' ;
2016-05-29 23:56:58 +02:00
print '</tr></table>' ;
2016-09-21 01:25:34 +02:00
print '</td><td>' ;
2016-05-29 23:56:58 +02:00
if ( $action == 'editdate_pointoftax' ) {
2019-11-12 00:15:34 +01:00
$form -> form_date ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> date_pointoftax , 'date_pointoftax' );
2016-05-29 23:56:58 +02:00
} else {
2020-11-29 15:16:53 +01:00
print '<span class="valuedate">' . dol_print_date ( $object -> date_pointoftax , 'day' ) . '</span>' ;
2016-05-29 23:56:58 +02:00
}
print '</td></tr>' ;
2016-08-10 09:47:25 +02:00
}
2016-05-29 23:56:58 +02:00
2016-10-24 03:23:40 +02:00
// Payment term
2013-11-17 23:25:25 +01:00
print '<tr><td>' ;
2021-12-02 10:43:44 +01:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2013-11-17 23:25:25 +01:00
print $langs -> trans ( 'PaymentConditionsShort' );
print '</td>' ;
2021-02-23 15:35:16 +01:00
if ( $object -> type != Facture :: TYPE_CREDIT_NOTE && $action != 'editconditions' && $usercancreate ) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editconditions&token=' . newToken () . '&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetConditions' ), 1 ) . '</a></td>' ;
2021-02-23 15:35:16 +01:00
}
2013-11-17 23:25:25 +01:00
print '</tr></table>' ;
2016-09-21 01:25:34 +02:00
print '</td><td>' ;
2021-02-23 15:35:16 +01:00
if ( $object -> type != Facture :: TYPE_CREDIT_NOTE ) {
2014-02-23 20:10:05 +01:00
if ( $action == 'editconditions' ) {
2019-11-12 00:15:34 +01:00
$form -> form_conditions_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> cond_reglement_id , 'cond_reglement_id' );
2014-02-23 20:10:05 +01:00
} else {
2019-11-12 00:15:34 +01:00
$form -> form_conditions_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> cond_reglement_id , 'none' );
2013-11-17 23:25:25 +01:00
}
2014-02-23 20:10:05 +01:00
} else {
2013-11-17 23:25:25 +01:00
print ' ' ;
}
print '</td></tr>' ;
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Date payment term
print '<tr><td>' ;
2021-12-02 10:43:44 +01:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2013-11-17 23:25:25 +01:00
print $langs -> trans ( 'DateMaxPayment' );
print '</td>' ;
2021-02-23 15:35:16 +01:00
if ( $object -> type != Facture :: TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $usercancreate ) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editpaymentterm&token=' . newToken () . '&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetDate' ), 1 ) . '</a></td>' ;
2021-02-23 15:35:16 +01:00
}
2013-11-17 23:25:25 +01:00
print '</tr></table>' ;
2016-09-21 01:25:34 +02:00
print '</td><td>' ;
2021-02-23 15:35:16 +01:00
if ( $object -> type != Facture :: TYPE_CREDIT_NOTE ) {
2014-02-23 20:10:05 +01:00
if ( $action == 'editpaymentterm' ) {
2019-11-12 00:15:34 +01:00
$form -> form_date ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> date_lim_reglement , 'paymentterm' );
2014-02-23 20:10:05 +01:00
} else {
2020-11-29 15:16:53 +01:00
print '<span class="valuedate">' . dol_print_date ( $object -> date_lim_reglement , 'day' ) . '</span>' ;
2015-09-05 10:56:13 +02:00
if ( $object -> hasDelay ()) {
2014-02-23 20:10:05 +01:00
print img_warning ( $langs -> trans ( 'Late' ));
2015-09-05 10:56:13 +02:00
}
2014-02-23 20:10:05 +01:00
}
} else {
2013-11-17 23:25:25 +01:00
print ' ' ;
}
print '</td></tr>' ;
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Payment mode
print '<tr><td>' ;
2021-12-02 10:43:44 +01:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2013-11-17 23:25:25 +01:00
print $langs -> trans ( 'PaymentMode' );
print '</td>' ;
2021-02-23 15:35:16 +01:00
if ( $action != 'editmode' && $usercancreate ) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editmode&token=' . newToken () . '&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetMode' ), 1 ) . '</a></td>' ;
2021-02-23 15:35:16 +01:00
}
2013-11-17 23:25:25 +01:00
print '</tr></table>' ;
2016-09-21 01:25:34 +02:00
print '</td><td>' ;
2021-02-23 15:35:16 +01:00
if ( $action == 'editmode' ) {
2018-12-28 23:16:44 +01:00
$form -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> mode_reglement_id , 'mode_reglement_id' , 'CRDT' , 1 , 1 );
2020-05-21 15:05:19 +02:00
} else {
2014-09-07 12:22:04 +02:00
$form -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> mode_reglement_id , 'none' , 'CRDT' );
2013-11-17 23:25:25 +01:00
}
print '</td></tr>' ;
2014-07-07 17:59:04 +02:00
2016-01-23 16:01:55 +01:00
// Multicurrency
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2016-01-23 16:01:55 +01:00
// Multicurrency code
print '<tr>' ;
2016-02-15 00:58:51 +01:00
print '<td>' ;
2021-12-02 10:43:44 +01:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2018-10-27 17:45:29 +02:00
print $form -> editfieldkey ( 'Currency' , 'multicurrency_code' , '' , $object , 0 );
2016-01-23 16:01:55 +01:00
print '</td>' ;
2021-02-23 15:35:16 +01:00
if ( $usercancreate && $action != 'editmulticurrencycode' && ! empty ( $object -> brouillon )) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editmulticurrencycode&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetMultiCurrencyCode' ), 1 ) . '</a></td>' ;
2021-02-23 15:35:16 +01:00
}
2016-01-23 16:01:55 +01:00
print '</tr></table>' ;
2016-09-21 01:25:34 +02:00
print '</td><td>' ;
2019-11-12 00:15:34 +01:00
$htmlname = (( $usercancreate && $action == 'editmulticurrencycode' ) ? 'multicurrency_code' : 'none' );
$form -> form_multicurrency_code ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> multicurrency_code , $htmlname );
2016-01-23 16:01:55 +01:00
print '</td></tr>' ;
2016-08-10 09:47:25 +02:00
2019-11-03 17:48:16 +01:00
// Multicurrency rate
2021-02-23 21:09:01 +01:00
if ( $object -> multicurrency_code != $conf -> currency || $object -> multicurrency_tx != 1 ) {
2019-11-03 17:48:16 +01:00
print '<tr>' ;
print '<td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $form -> editfieldkey ( 'CurrencyRate' , 'multicurrency_tx' , '' , $object , 0 );
print '</td>' ;
2021-02-23 21:09:01 +01:00
if ( $usercancreate && $action != 'editmulticurrencyrate' && ! empty ( $object -> brouillon ) && $object -> multicurrency_code && $object -> multicurrency_code != $conf -> currency ) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editmulticurrencyrate&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetMultiCurrencyCode' ), 1 ) . '</a></td>' ;
2021-02-23 21:09:01 +01:00
}
2019-11-03 17:48:16 +01:00
print '</tr></table>' ;
print '</td><td>' ;
if ( $action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate' ) {
2019-11-12 00:15:34 +01:00
if ( $action == 'actualizemulticurrencyrate' ) {
2019-11-03 17:48:16 +01:00
list ( $object -> fk_multicurrency , $object -> multicurrency_tx ) = MultiCurrency :: getIdAndTxFromCode ( $object -> db , $object -> multicurrency_code );
}
2019-11-12 00:15:34 +01:00
$form -> form_multicurrency_rate ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> multicurrency_tx , ( $usercancreate ? 'multicurrency_tx' : 'none' ), $object -> multicurrency_code );
2019-11-03 17:48:16 +01:00
} else {
2019-11-12 00:15:34 +01:00
$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 ) {
2019-11-03 17:48:16 +01:00
print '<div class="inline-block"> ' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=actualizemulticurrencyrate">' . $langs -> trans ( " ActualizeCurrency " ) . '</a>' ;
print '</div>' ;
}
2017-04-12 11:30:33 +02:00
}
2019-11-03 17:48:16 +01:00
print '</td></tr>' ;
2017-04-12 11:30:33 +02:00
}
2016-01-23 16:01:55 +01:00
}
2014-07-07 17:59:04 +02:00
// Bank Account
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'banque' )) {
2020-08-28 12:53:30 +02:00
print '<tr><td class="nowrap">' ;
2021-12-02 10:43:44 +01:00
print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">' ;
2020-08-28 12:53:30 +02:00
print $langs -> trans ( 'BankAccount' );
print '<td>' ;
2021-02-23 21:09:01 +01:00
if (( $action != 'editbankaccount' ) && $usercancreate ) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editbankaccount&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetBankAccount' ), 1 ) . '</a></td>' ;
2021-02-23 21:09:01 +01:00
}
2020-08-28 12:53:30 +02:00
print '</tr></table>' ;
print '</td><td>' ;
2021-02-23 15:35:16 +01:00
if ( $action == 'editbankaccount' ) {
2020-08-28 12:53:30 +02:00
$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 " </td> " ;
print '</tr>' ;
2014-07-07 17:59:04 +02:00
}
2014-03-01 19:45:13 +01:00
2015-02-23 09:16:14 +01:00
// Incoterms
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'incoterm' )) {
2015-02-23 09:16:14 +01:00
print '<tr><td>' ;
2021-12-02 10:43:44 +01:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2017-10-16 08:47:05 +02:00
print $langs -> trans ( 'IncotermLabel' );
2019-02-04 13:57:38 +01:00
print '<td><td class="right">' ;
2021-02-23 21:09:01 +01:00
if ( $usercancreate ) {
2021-09-27 12:24:01 +02:00
print '<a class="editfielda" href="' . DOL_URL_ROOT . '/compta/facture/card.php?facid=' . $object -> id . '&action=editincoterm&token=' . newToken () . '">' . img_edit () . '</a>' ;
2021-02-23 21:09:01 +01:00
} else {
print ' ' ;
}
2017-10-16 08:47:05 +02:00
print '</td></tr></table>' ;
print '</td>' ;
print '<td>' ;
2021-02-23 15:35:16 +01:00
if ( $action != 'editincoterm' ) {
2019-06-25 13:00:02 +02:00
print $form -> textwithpicto ( $object -> display_incoterms (), $object -> label_incoterms , 1 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
print $form -> select_incoterms (( ! empty ( $object -> fk_incoterms ) ? $object -> fk_incoterms : '' ), ( ! empty ( $object -> location_incoterms ) ? $object -> location_incoterms : '' ), $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id );
2015-02-23 09:16:14 +01:00
}
2017-10-16 08:47:05 +02:00
print '</td></tr>' ;
2015-02-23 09:16:14 +01:00
}
2014-03-01 19:45:13 +01:00
2019-08-29 00:45:02 +02:00
2020-04-19 21:49:37 +02:00
if ( ! empty ( $object -> retained_warranty ) || ! empty ( $conf -> global -> INVOICE_USE_RETAINED_WARRANTY )) {
2020-10-31 14:32:18 +01:00
$displayWarranty = true ;
2020-04-19 21:49:37 +02:00
if ( ! in_array ( $object -> type , $retainedWarrantyInvoiceAvailableType ) && empty ( $object -> retained_warranty )) {
2020-04-14 14:11:12 +02:00
$displayWarranty = false ;
}
2019-08-29 00:45:02 +02:00
2020-05-21 01:52:25 +02:00
if ( $displayWarranty ) {
2020-02-19 11:54:55 +01:00
// Retained Warranty
print '<tr class="retained-warranty-lines" ><td>' ;
2023-01-03 02:33:59 +01:00
print '<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>' ;
2020-02-19 11:54:55 +01:00
print $langs -> trans ( 'RetainedWarranty' );
print '</td>' ;
2022-12-28 17:50:16 +01:00
if ( $action != 'editretainedwarranty' && $user -> rights -> facture -> creer && $object -> statut == Facture :: STATUS_DRAFT ) {
2021-09-27 12:24:01 +02:00
print '<td align="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editretainedwarranty&token=' . newToken () . '&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'setretainedwarranty' ), 1 ) . '</a></td>' ;
2020-10-31 14:32:18 +01:00
}
print '</tr></table>' ;
print '</td><td>' ;
2022-12-28 17:50:16 +01:00
if ( $action == 'editretainedwarranty' && $object -> statut == Facture :: STATUS_DRAFT ) {
2020-10-31 14:32:18 +01:00
print '<form id="retained-warranty-form" method="POST" action="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '">' ;
print '<input type="hidden" name="action" value="setretainedwarranty">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="' . $object -> retained_warranty . '" >' ;
print '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
print '</form>' ;
} else {
print price ( $object -> retained_warranty ) . '%' ;
}
print '</td></tr>' ;
// Retained warranty payment term
print '<tr class="retained-warranty-lines" ><td>' ;
print '<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'PaymentConditionsShortRetainedWarranty' );
print '</td>' ;
2022-12-28 17:50:16 +01:00
if ( $action != 'editretainedwarrantypaymentterms' && $user -> rights -> facture -> creer && $object -> statut == Facture :: STATUS_DRAFT ) {
2021-09-27 12:24:01 +02:00
print '<td align="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editretainedwarrantypaymentterms&token=' . newToken () . '&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'setPaymentConditionsShortRetainedWarranty' ), 1 ) . '</a></td>' ;
2020-10-31 14:32:18 +01:00
}
print '</tr></table>' ;
print '</td><td>' ;
$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 ;
}
2022-12-28 17:50:16 +01:00
if ( $action == 'editretainedwarrantypaymentterms' && $object -> statut == Facture :: STATUS_DRAFT ) {
2020-10-31 14:32:18 +01:00
//date('Y-m-d',$object->date_lim_reglement)
print '<form method="POST" action="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '">' ;
print '<input type="hidden" name="action" value="setretainedwarrantyconditions">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
$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 ;
$form -> select_conditions_paiements ( $retained_warranty_fk_cond_reglement , 'retained_warranty_fk_cond_reglement' , - 1 , 1 );
print '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
print '</form>' ;
} 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 '</td></tr>' ;
// Retained Warranty payment date limit
print '<tr class="retained-warranty-lines" ><td>' ;
print '<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'RetainedWarrantyDateLimit' );
print '</td>' ;
2022-12-28 17:50:16 +01:00
if ( $action != 'editretainedwarrantydatelimit' && $user -> rights -> facture -> creer && $object -> statut == Facture :: STATUS_DRAFT ) {
2021-09-27 12:24:01 +02:00
print '<td align="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editretainedwarrantydatelimit&token=' . newToken () . '&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'setretainedwarrantyDateLimit' ), 1 ) . '</a></td>' ;
2020-10-31 14:32:18 +01:00
}
print '</tr></table>' ;
print '</td><td>' ;
$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 ;
}
2022-12-28 17:50:16 +01:00
if ( $action == 'editretainedwarrantydatelimit' && $object -> statut == Facture :: STATUS_DRAFT ) {
2020-10-31 14:32:18 +01:00
//date('Y-m-d',$object->date_lim_reglement)
print '<form method="POST" action="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '">' ;
print '<input type="hidden" name="action" value="setretainedwarrantydatelimit">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input name="retained_warranty_date_limit" type="date" step="1" min="' . dol_print_date ( $object -> date , '%Y-%m-%d' ) . '" value="' . dol_print_date ( $defaultDate , '%Y-%m-%d' ) . '" >' ;
print '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
print '</form>' ;
} else {
print dol_print_date ( $object -> retained_warranty_date_limit , 'day' );
}
print '</td></tr>' ;
}
2018-08-08 17:36:39 +02:00
}
2019-08-29 00:45:02 +02:00
2014-10-14 17:00:06 +02:00
// Other attributes
2016-09-21 01:25:34 +02:00
$cols = 2 ;
2019-11-12 00:15:34 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2014-03-01 19:45:13 +01:00
2016-09-21 01:25:34 +02:00
print '</table>' ;
2016-10-29 07:45:24 +02:00
2016-09-21 01:25:34 +02:00
print '</div>' ;
print '<div class="fichehalfright">' ;
2017-06-07 16:44:04 +02:00
2020-09-15 11:18:21 +02:00
print '<!-- amounts -->' . " \n " ;
2021-12-02 10:43:44 +01:00
print '<div class="underbanner clearboth"></div>' . " \n " ;
print '<table class="border tableforfield centpercent">' ;
2017-06-07 16:44:04 +02:00
2020-09-15 11:18:21 +02:00
$sign = 1 ;
if ( ! empty ( $conf -> global -> INVOICE_POSITIVE_CREDIT_NOTE_SCREEN ) && $object -> type == $object :: TYPE_CREDIT_NOTE ) {
2020-10-31 14:32:18 +01:00
$sign = - 1 ; // We invert sign for output
2020-09-15 11:18:21 +02:00
}
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'multicurrency' ) && ( $object -> multicurrency_code != $conf -> currency )) {
2017-10-16 08:47:05 +02:00
// Multicurrency Amount HT
2019-11-12 00:15:34 +01:00
print '<tr><td class="titlefieldmiddle">' . $form -> editfieldkey ( 'MulticurrencyAmountHT' , 'multicurrency_total_ht' , '' , $object , 0 ) . '</td>' ;
2022-06-09 04:01:02 +02:00
print '<td class="nowrap right amountcard">' . price ( $sign * $object -> multicurrency_total_ht , '' , $langs , 0 , - 1 , - 1 , ( ! empty ( $object -> multicurrency_code ) ? $object -> multicurrency_code : $conf -> currency )) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '</tr>' ;
// Multicurrency Amount VAT
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $form -> editfieldkey ( 'MulticurrencyAmountVAT' , 'multicurrency_total_tva' , '' , $object , 0 ) . '</td>' ;
2022-06-09 04:01:02 +02:00
print '<td class="nowrap right amountcard">' . price ( $sign * $object -> multicurrency_total_tva , '' , $langs , 0 , - 1 , - 1 , ( ! empty ( $object -> multicurrency_code ) ? $object -> multicurrency_code : $conf -> currency )) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '</tr>' ;
// Multicurrency Amount TTC
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $form -> editfieldkey ( 'MulticurrencyAmountTTC' , 'multicurrency_total_ttc' , '' , $object , 0 ) . '</td>' ;
2022-06-09 04:01:02 +02:00
print '<td class="nowrap right amountcard">' . price ( $sign * $object -> multicurrency_total_ttc , '' , $langs , 0 , - 1 , - 1 , ( ! empty ( $object -> multicurrency_code ) ? $object -> multicurrency_code : $conf -> currency )) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '</tr>' ;
2016-10-24 03:23:40 +02:00
}
2016-10-29 07:45:24 +02:00
2016-09-21 01:25:34 +02:00
// Amount
2019-11-12 00:15:34 +01:00
print '<tr><td class="titlefieldmiddle">' . $langs -> trans ( 'AmountHT' ) . '</td>' ;
2022-06-09 04:01:02 +02:00
print '<td class="nowrap right amountcard">' . price ( $sign * $object -> total_ht , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2016-10-29 07:45:24 +02:00
2016-10-24 03:23:40 +02:00
// Vat
2022-06-09 04:01:02 +02:00
print '<tr><td>' . $langs -> trans ( 'AmountVAT' ) . '</td><td colspan="3" class="nowrap right amountcard">' . price ( $sign * $object -> total_tva , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2016-09-21 01:25:34 +02:00
print '</tr>' ;
2016-10-29 07:45:24 +02:00
2016-09-21 01:25:34 +02:00
// Amount Local Taxes
2021-02-23 15:35:16 +01:00
if (( $mysoc -> localtax1_assuj == " 1 " && $mysoc -> useLocalTax ( 1 )) || $object -> total_localtax1 != 0 ) { // Localtax1
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT1 " , $mysoc -> country_code ) . '</td>' ;
2022-06-09 04:01:02 +02:00
print '<td class="nowrap right amountcard">' . price ( $sign * $object -> total_localtax1 , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2016-09-21 01:25:34 +02:00
}
2021-02-23 15:35:16 +01:00
if (( $mysoc -> localtax2_assuj == " 1 " && $mysoc -> useLocalTax ( 2 )) || $object -> total_localtax2 != 0 ) { // Localtax2
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT2 " , $mysoc -> country_code ) . '</td>' ;
2022-06-09 04:01:02 +02:00
print '<td class="nowrap right amountcard">' . price ( $sign * $object -> total_localtax2 , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2016-09-21 01:25:34 +02:00
}
2016-10-29 07:45:24 +02:00
2016-09-21 01:25:34 +02:00
// Revenue stamp
2021-02-23 15:35:16 +01:00
if ( $selleruserevenustamp ) { // Test company use revenue stamp
2017-10-16 08:47:05 +02:00
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'RevenueStamp' );
print '</td>' ;
2021-02-23 15:35:16 +01:00
if ( $action != 'editrevenuestamp' && ! empty ( $object -> brouillon ) && $usercancreate ) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editrevenuestamp&token=' . newToken () . '&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetRevenuStamp' ), 1 ) . '</a></td>' ;
2017-10-16 08:47:05 +02:00
}
print '</tr></table>' ;
print '</td><td>' ;
if ( $action == 'editrevenuestamp' ) {
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="post">' ;
2020-03-24 13:10:35 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-16 08:47:05 +02:00
print '<input type="hidden" name="action" value="setrevenuestamp">' ;
2017-12-18 12:43:03 +01:00
print '<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="' . price2num ( $object -> revenuestamp ) . '">' ;
print $formother -> select_revenue_stamp ( '' , 'revenuestamp_type' , $mysoc -> country_code );
print ' → <span id="revenuestamp_span"></span>' ;
2021-09-16 11:33:42 +02:00
print ' <input type="submit" class="button buttongen button-save" value="' . $langs -> trans ( 'Modify' ) . '">' ;
2017-10-16 08:47:05 +02:00
print '</form>' ;
2017-12-18 12:43:03 +01:00
print " <script>
$ ( document ) . ready ( function (){
js_recalculate_revenuestamp ();
$ ( 'select[name=revenuestamp_type]' ) . on ( 'change' , function (){
js_recalculate_revenuestamp ();
});
});
function js_recalculate_revenuestamp (){
var valselected = $ ( 'select[name=revenuestamp_type]' ) . val ();
console . log ( 'Calculate revenue stamp from ' + valselected );
var revenue = 0 ;
if ( valselected . indexOf ( '%' ) == - 1 )
{
revenue = valselected ;
}
else
{
var revenue_type = parseFloat ( valselected );
2017-12-19 00:39:01 +01:00
var amount_net = " .round( $object->total_ht , 2). " ;
2017-12-18 12:43:03 +01:00
revenue = revenue_type * amount_net / 100 ;
revenue = revenue . toFixed ( 2 );
}
$ ( '#revenuestamp_val' ) . val ( revenue );
$ ( '#revenuestamp_span' ) . html ( revenue );
}
</ script > " ;
2017-10-16 08:47:05 +02:00
} else {
print price ( $object -> revenuestamp , 1 , '' , 1 , - 1 , - 1 , $conf -> currency );
}
print '</td></tr>' ;
2016-09-21 01:25:34 +02:00
}
2016-10-29 07:45:24 +02:00
2016-09-21 01:25:34 +02:00
// Total with tax
2022-06-09 04:01:02 +02:00
print '<tr><td>' . $langs -> trans ( 'AmountTTC' ) . '</td><td class="nowrap right amountcard">' . price ( $sign * $object -> total_ttc , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2016-10-29 07:45:24 +02:00
2016-09-21 01:25:34 +02:00
print '</table>' ;
2016-10-29 07:45:24 +02:00
2016-12-24 21:39:40 +01:00
2017-10-16 08:47:05 +02:00
$nbrows = 8 ;
$nbcols = 3 ;
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'project' )) {
2019-11-12 00:15:34 +01:00
$nbrows ++ ;
2021-02-23 15:35:16 +01:00
}
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'banque' )) {
2019-11-12 00:15:34 +01:00
$nbrows ++ ;
$nbcols ++ ;
2017-10-16 08:47:05 +02:00
}
2021-02-23 15:35:16 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $object -> total_localtax1 != 0 ) {
2019-11-12 00:15:34 +01:00
$nbrows ++ ;
2021-02-23 15:35:16 +01:00
}
if ( $mysoc -> localtax2_assuj == " 1 " || $object -> total_localtax2 != 0 ) {
2019-11-12 00:15:34 +01:00
$nbrows ++ ;
2021-02-23 15:35:16 +01:00
}
if ( $selleruserevenustamp ) {
2019-11-12 00:15:34 +01:00
$nbrows ++ ;
2021-02-23 15:35:16 +01:00
}
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2017-10-16 08:47:05 +02:00
$nbrows += 5 ;
2021-02-23 15:35:16 +01:00
}
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'incoterm' )) {
2017-10-16 08:47:05 +02:00
$nbrows += 1 ;
2021-02-23 15:35:16 +01:00
}
2017-10-16 08:47:05 +02:00
2018-05-16 15:55:42 +02:00
// List of previous situation invoices
2021-02-23 15:35:16 +01:00
if (( $object -> situation_cycle_ref > 0 ) && ! empty ( $conf -> global -> INVOICE_USE_SITUATION )) {
2022-03-12 16:04:00 +01:00
print '<!-- List of situation invoices -->' ;
2020-10-31 14:32:18 +01:00
print '<table class="noborder situationstable" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'ListOfSituationInvoices' ) . '</td>' ;
print '<td></td>' ;
print '<td class="center">' . $langs -> trans ( 'Situation' ) . '</td>' ;
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-23 21:09:01 +01:00
print '<td class="right"></td>' ;
}
2020-10-31 14:32:18 +01:00
print '<td class="right">' . $langs -> trans ( 'AmountHT' ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( 'AmountTTC' ) . '</td>' ;
print '<td width="18"> </td>' ;
print '</tr>' ;
$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 '<tr class="oddeven">' ;
print '<td>' . $prev_invoice -> getNomUrl ( 1 ) . '</td>' ;
print '<td></td>' ;
print '<td align="center" >' . (( $prev_invoice -> type == Facture :: TYPE_CREDIT_NOTE ) ? $langs -> trans ( 'situationInvoiceShortcode_AS' ) : $langs -> trans ( 'situationInvoiceShortcode_S' )) . $prev_invoice -> situation_counter . '</td>' ;
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-23 21:09:01 +01:00
print '<td class="right"></td>' ;
}
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $prev_invoice -> total_ht ) . '</span></td>' ;
print '<td class="right"><span class="amount">' . price ( $prev_invoice -> total_ttc ) . '</span></td>' ;
2020-10-31 14:32:18 +01:00
print '<td class="right">' . $prev_invoice -> getLibStatut ( 3 , $tmptotalpaidforthisinvoice ) . '</td>' ;
print '</tr>' ;
}
}
$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 '<tr class="oddeven">' ;
print '<td>' . $object -> getNomUrl ( 1 ) . '</td>' ;
print '<td></td>' ;
print '<td class="center">' . (( $object -> type == Facture :: TYPE_CREDIT_NOTE ) ? $langs -> trans ( 'situationInvoiceShortcode_AS' ) : $langs -> trans ( 'situationInvoiceShortcode_S' )) . $object -> situation_counter . '</td>' ;
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-23 21:09:01 +01:00
print '<td class="right"></td>' ;
}
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $object -> total_ht ) . '</span></td>' ;
print '<td class="right"><span class="amount">' . price ( $object -> total_ttc ) . '</span></td>' ;
2020-10-31 14:32:18 +01:00
print '<td class="right">' . $object -> getLibStatut ( 3 , $object -> getSommePaiement ()) . '</td>' ;
print '</tr>' ;
print '<tr class="oddeven">' ;
print '<td colspan="2" class="left"><b>' . $langs -> trans ( 'CurrentSituationTotal' ) . '</b></td>' ;
print '<td>' ;
$i = 0 ;
2021-02-23 15:35:16 +01:00
foreach ( $current_situation_counter as $sit ) {
2020-10-31 14:32:18 +01:00
$curSign = $sit > 0 ? '+' : '-' ;
$curType = $sit > 0 ? $langs -> trans ( 'situationInvoiceShortcode_S' ) : $langs -> trans ( 'situationInvoiceShortcode_AS' );
2021-02-23 21:09:01 +01:00
if ( $i > 0 ) {
print ' ' . $curSign . ' ' ;
}
2020-10-31 14:32:18 +01:00
print $curType . abs ( $sit );
$i ++ ;
}
print '</td>' ;
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-23 21:09:01 +01:00
print '<td></td>' ;
}
2020-10-31 14:32:18 +01:00
print '<td class="right"><b>' . price ( $total_global_ht ) . '</b></td>' ;
print '<td class="right"><b>' . price ( $total_global_ttc ) . '</b></td>' ;
print '<td width="18"> </td>' ;
print '</tr>' ;
if ( count ( $object -> tab_next_situation_invoice ) > 0 ) {
// List of next invoices
/* print '<tr class="liste_titre">' ;
2021-02-23 21:09:01 +01:00
print '<td>' . $langs -> trans ( 'ListOfNextSituationInvoices' ) . '</td>' ;
print '<td></td>' ;
print '<td></td>' ;
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'banque' )) print '<td class="right"></td>' ;
2021-02-23 21:09:01 +01:00
print '<td class="right">' . $langs -> trans ( 'AmountHT' ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( 'AmountTTC' ) . '</td>' ;
print '<td width="18"> </td>' ;
print '</tr>' ; */
2018-05-23 08:16:24 +02:00
2020-10-31 14:32:18 +01:00
$total_next_ht = $total_next_ttc = 0 ;
foreach ( $object -> tab_next_situation_invoice as $next_invoice ) {
2022-05-22 17:09:08 +02:00
$totalpaid = $next_invoice -> getSommePaiement ();
2020-10-31 14:32:18 +01:00
$total_next_ht += $next_invoice -> total_ht ;
$total_next_ttc += $next_invoice -> total_ttc ;
print '<tr class="oddeven">' ;
print '<td>' . $next_invoice -> getNomUrl ( 1 ) . '</td>' ;
print '<td></td>' ;
print '<td class="center">' . (( $next_invoice -> type == Facture :: TYPE_CREDIT_NOTE ) ? $langs -> trans ( 'situationInvoiceShortcode_AS' ) : $langs -> trans ( 'situationInvoiceShortcode_S' )) . $next_invoice -> situation_counter . '</td>' ;
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-23 21:09:01 +01:00
print '<td class="right"></td>' ;
}
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $next_invoice -> total_ht ) . '</span></td>' ;
print '<td class="right"><span class="amount">' . price ( $next_invoice -> total_ttc ) . '</span></td>' ;
2022-05-22 17:09:08 +02:00
print '<td class="right">' . $next_invoice -> getLibStatut ( 3 , $totalpaid ) . '</td>' ;
2020-10-31 14:32:18 +01:00
print '</tr>' ;
}
$total_global_ht += $total_next_ht ;
$total_global_ttc += $total_next_ttc ;
print '<tr class="oddeven">' ;
print '<td colspan="3" class="right"></td>' ;
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-23 21:09:01 +01:00
print '<td class="right"></td>' ;
}
2020-10-31 14:32:18 +01:00
print '<td class="right"><b>' . price ( $total_global_ht ) . '</b></td>' ;
print '<td class="right"><b>' . price ( $total_global_ttc ) . '</b></td>' ;
print '<td width="18"> </td>' ;
print '</tr>' ;
}
print '</table>' ;
2017-10-16 08:47:05 +02:00
}
2020-09-15 11:18:21 +02:00
$sign = 1 ;
2021-02-23 21:09:01 +01:00
if ( $object -> type == $object :: TYPE_CREDIT_NOTE ) {
$sign = - 1 ;
}
2017-10-16 08:47:05 +02:00
// List of payments already done
2017-12-03 11:59:16 +01:00
2022-03-12 16:04:00 +01:00
print '<!-- List of payments already done -->' ;
2017-11-24 14:23:25 +01:00
print '<div class="div-table-responsive-no-min">' ;
2022-02-10 13:01:47 +01:00
print '<table class="noborder paymenttable centpercent">' ;
2017-10-16 08:47:05 +02:00
print '<tr class="liste_titre">' ;
2019-11-12 00:15:34 +01:00
print '<td class="liste_titre">' . ( $object -> type == Facture :: TYPE_CREDIT_NOTE ? $langs -> trans ( " PaymentsBack " ) : $langs -> trans ( 'Payments' )) . '</td>' ;
2022-03-12 16:04:00 +01:00
print '<td class="liste_titre"><span class="hideonsmartphone">' . $langs -> trans ( 'Date' ) . '</span></td>' ;
print '<td class="liste_titre"><span class="hideonsmartphone">' . $langs -> trans ( 'Type' ) . '</span></td>' ;
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'banque' )) {
2022-03-12 16:04:00 +01:00
print '<td class="liste_titre"><span class="hideonsmartphone">' . $langs -> trans ( 'BankAccount' ) . '</span></td>' ;
2017-10-16 08:47:05 +02:00
}
2019-11-12 00:15:34 +01:00
print '<td class="liste_titre right">' . $langs -> trans ( 'Amount' ) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '<td class="liste_titre" width="18"> </td>' ;
print '</tr>' ;
// Payments already done (from payment on this invoice)
2020-01-16 10:12:39 +01:00
$sql = 'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,' ;
2017-10-16 08:47:05 +02:00
$sql .= ' c.code as payment_code, c.libelle as payment_label,' ;
$sql .= ' pf.amount,' ;
2022-04-08 17:13:41 +02:00
$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' ;
2019-11-12 00:15:34 +01:00
$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' ;
2021-08-27 23:36:06 +02:00
$sql .= ' WHERE pf.fk_facture = ' . (( int ) $object -> id ) . ' AND pf.fk_paiement = p.rowid' ;
2019-11-12 00:15:34 +01:00
$sql .= ' AND p.entity IN (' . getEntity ( 'invoice' ) . ')' ;
2017-10-16 08:47:05 +02:00
$sql .= ' ORDER BY p.datep, p.tms' ;
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
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 ;
2020-01-16 10:12:39 +01:00
$paymentstatic -> num_payment = $objp -> num_payment ;
2022-06-03 14:28:45 +02:00
$paymentstatic -> paiementcode = $objp -> payment_code ;
2017-10-16 08:47:05 +02:00
2021-02-19 22:12:03 +01:00
print '<tr class="oddeven"><td class="nowraponall">' ;
2017-10-16 08:47:05 +02:00
print $paymentstatic -> getNomUrl ( 1 );
print '</td>' ;
2020-12-30 22:53:21 +01:00
print '<td>' ;
$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 '</td>' ;
2019-11-12 00:15:34 +01:00
$label = ( $langs -> trans ( " PaymentType " . $objp -> payment_code ) != ( " PaymentType " . $objp -> payment_code )) ? $langs -> trans ( " PaymentType " . $objp -> payment_code ) : $objp -> payment_label ;
2020-01-16 10:12:39 +01:00
print '<td>' . $label . ' ' . $objp -> num_payment . '</td>' ;
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'banque' )) {
2017-10-16 08:47:05 +02:00
$bankaccountstatic -> id = $objp -> baid ;
$bankaccountstatic -> ref = $objp -> baref ;
$bankaccountstatic -> label = $objp -> baref ;
2017-05-14 21:20:35 +02:00
$bankaccountstatic -> number = $objp -> banumber ;
2022-04-08 17:13:41 +02:00
$bankaccountstatic -> currency_code = $objp -> bacurrency_code ;
2017-05-14 21:20:35 +02:00
2022-08-29 11:23:50 +02:00
if ( isModEnabled ( 'accounting' )) {
2017-05-15 05:11:00 +02:00
$bankaccountstatic -> account_number = $objp -> account_number ;
$accountingjournal = new AccountingJournal ( $db );
$accountingjournal -> fetch ( $objp -> fk_accountancy_journal );
2019-01-27 11:55:16 +01:00
$bankaccountstatic -> accountancy_journal = $accountingjournal -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
2017-05-15 05:11:00 +02:00
}
2017-05-14 21:20:35 +02:00
2021-02-19 22:12:03 +01:00
print '<td class="nowraponall">' ;
2021-02-23 15:35:16 +01:00
if ( $bankaccountstatic -> id ) {
2017-10-16 08:47:05 +02:00
print $bankaccountstatic -> getNomUrl ( 1 , 'transactions' );
2021-02-23 15:35:16 +01:00
}
2017-10-16 08:47:05 +02:00
print '</td>' ;
}
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $sign * $objp -> amount ) . '</span></td>' ;
2019-12-12 10:31:08 +01:00
print '<td class="center">' ;
2021-02-23 15:35:16 +01:00
if ( $object -> statut == Facture :: STATUS_VALIDATED && $object -> paye == 0 && $user -> socid == 0 ) {
2020-10-01 10:50:54 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=deletepayment&token=' . newToken () . '&paiement_id=' . $objp -> rowid . '">' ;
2017-12-03 11:59:16 +01:00
print img_delete ();
print '</a>' ;
}
print '</td>' ;
2017-10-16 08:47:05 +02:00
print '</tr>' ;
2019-11-12 00:15:34 +01:00
$i ++ ;
2017-10-16 08:47:05 +02:00
}
}
2021-02-23 15:35:16 +01:00
2017-10-16 08:47:05 +02:00
$db -> free ( $result );
} else {
dol_print_error ( $db );
}
if ( $object -> type != Facture :: TYPE_CREDIT_NOTE ) {
// Total already paid
2019-11-12 00:15:34 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
2020-11-29 15:16:53 +01:00
print '<span class="opacitymedium">' ;
if ( $object -> type != Facture :: TYPE_DEPOSIT ) {
2017-10-16 08:47:05 +02:00
print $langs -> trans ( 'AlreadyPaidNoCreditNotesNoDeposits' );
2020-11-29 15:16:53 +01:00
} else {
print $langs -> trans ( 'AlreadyPaid' );
}
2022-05-22 17:09:08 +02:00
print '</span></td><td class="right' . (( $totalpaid > 0 ) ? ' amountalreadypaid' : '' ) . '">' . price ( $totalpaid ) . '</td><td> </td></tr>' ;
2017-10-16 08:47:05 +02:00
$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 " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_remise_except as re " ;
2021-08-27 16:33:03 +02:00
$sql .= " WHERE fk_facture = " . (( int ) $object -> id );
2017-10-16 08:47:05 +02:00
$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 );
2019-11-12 00:15:34 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
2020-11-29 15:16:53 +01:00
print '<span class="opacitymedium">' ;
2021-02-23 21:09:01 +01:00
if ( $invoice -> type == Facture :: TYPE_CREDIT_NOTE ) {
2019-11-12 00:15:34 +01:00
print $langs -> trans ( " CreditNote " ) . ' ' ;
2021-02-23 21:09:01 +01:00
}
if ( $invoice -> type == Facture :: TYPE_DEPOSIT ) {
2019-11-12 00:15:34 +01:00
print $langs -> trans ( " Deposit " ) . ' ' ;
2021-02-23 21:09:01 +01:00
}
2017-10-16 08:47:05 +02:00
print $invoice -> getNomUrl ( 0 );
2020-11-29 15:16:53 +01:00
print '</span>' ;
print '</td>' ;
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $obj -> amount_ttc ) . '</span></td>' ;
2019-02-04 13:57:38 +01:00
print '<td class="right">' ;
2022-08-12 23:19:36 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=unlinkdiscount&token=' . newToken () . '&discountid=' . $obj -> rowid . '">' . img_delete () . '</a>' ;
2017-10-16 08:47:05 +02:00
print '</td></tr>' ;
2019-11-12 00:15:34 +01:00
$i ++ ;
2021-02-23 21:09:01 +01:00
if ( $invoice -> type == Facture :: TYPE_CREDIT_NOTE ) {
2017-10-16 08:47:05 +02:00
$creditnoteamount += $obj -> amount_ttc ;
2021-02-23 21:09:01 +01:00
}
if ( $invoice -> type == Facture :: TYPE_DEPOSIT ) {
2017-10-16 08:47:05 +02:00
$depositamount += $obj -> amount_ttc ;
2021-02-23 21:09:01 +01:00
}
2017-10-16 08:47:05 +02:00
}
} else {
dol_print_error ( $db );
}
// Paye partiellement 'escompte'
if (( $object -> statut == Facture :: STATUS_CLOSED || $object -> statut == Facture :: STATUS_ABANDONED ) && $object -> close_code == 'discount_vat' ) {
2019-11-12 00:15:34 +01:00
print '<tr><td colspan="' . $nbcols . '" class="nowrap right">' ;
2020-11-29 15:16:53 +01:00
print '<span class="opacitymedium">' ;
print $form -> textwithpicto ( $langs -> trans ( " Discount " ), $langs -> trans ( " HelpEscompte " ), - 1 );
print '</span>' ;
2022-05-22 17:09:08 +02:00
print '</td><td class="right"><span class="amount">' . price ( price2num ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaid , 'MT' )) . '</span></td><td> </td></tr>' ;
2017-10-16 08:47:05 +02:00
$resteapayeraffiche = 0 ;
2018-06-23 14:39:24 +02:00
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
2017-10-16 08:47:05 +02:00
}
// Paye partiellement ou Abandon 'badcustomer'
if (( $object -> statut == Facture :: STATUS_CLOSED || $object -> statut == Facture :: STATUS_ABANDONED ) && $object -> close_code == 'badcustomer' ) {
2019-11-12 00:15:34 +01:00
print '<tr><td colspan="' . $nbcols . '" class="nowrap right">' ;
2020-11-29 15:16:53 +01:00
print '<span class="opacitymedium">' ;
print $form -> textwithpicto ( $langs -> trans ( " Abandoned " ), $langs -> trans ( " HelpAbandonBadCustomer " ), - 1 );
print '</span>' ;
2022-05-22 17:09:08 +02:00
print '</td><td class="right">' . price ( price2num ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaid , 'MT' )) . '</td><td> </td></tr>' ;
2017-10-16 08:47:05 +02:00
// $resteapayeraffiche=0;
2018-06-23 14:39:24 +02:00
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
2017-10-16 08:47:05 +02:00
}
// Paye partiellement ou Abandon 'product_returned'
if (( $object -> statut == Facture :: STATUS_CLOSED || $object -> statut == Facture :: STATUS_ABANDONED ) && $object -> close_code == 'product_returned' ) {
2019-11-12 00:15:34 +01:00
print '<tr><td colspan="' . $nbcols . '" class="nowrap right">' ;
2020-11-29 15:16:53 +01:00
print '<span class="opacitymedium">' ;
print $form -> textwithpicto ( $langs -> trans ( " ProductReturned " ), $langs -> trans ( " HelpAbandonProductReturned " ), - 1 );
print '</span>' ;
2022-05-22 17:09:08 +02:00
print '</td><td class="right"><span class="amount">' . price ( price2num ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaid , 'MT' )) . '</span></td><td> </td></tr>' ;
2017-10-16 08:47:05 +02:00
$resteapayeraffiche = 0 ;
2018-06-23 14:39:24 +02:00
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
2017-10-16 08:47:05 +02:00
}
// Paye partiellement ou Abandon 'abandon'
if (( $object -> statut == Facture :: STATUS_CLOSED || $object -> statut == Facture :: STATUS_ABANDONED ) && $object -> close_code == 'abandon' ) {
2019-11-12 00:15:34 +01:00
print '<tr><td colspan="' . $nbcols . '" class="nowrap right">' ;
2017-10-16 08:47:05 +02:00
$text = $langs -> trans ( " HelpAbandonOther " );
2021-02-23 21:09:01 +01:00
if ( $object -> close_note ) {
2019-11-12 00:15:34 +01:00
$text .= '<br><br><b>' . $langs -> trans ( " Reason " ) . '</b>:' . $object -> close_note ;
2021-02-23 21:09:01 +01:00
}
2020-11-29 15:16:53 +01:00
print '<span class="opacitymedium">' ;
print $form -> textwithpicto ( $langs -> trans ( " Abandoned " ), $text , - 1 );
print '</span>' ;
2022-05-22 17:09:08 +02:00
print '</td><td class="right"><span class="amount">' . price ( price2num ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaid , 'MT' )) . '</span></td><td> </td></tr>' ;
2017-10-16 08:47:05 +02:00
$resteapayeraffiche = 0 ;
2018-06-23 14:39:24 +02:00
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
2017-10-16 08:47:05 +02:00
}
// Billed
2020-11-29 15:16:53 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
print '<span class="opacitymedium">' ;
print $langs -> trans ( " Billed " );
print '</td><td class="right">' . price ( $object -> total_ttc ) . '</td><td> </td></tr>' ;
2017-10-16 08:47:05 +02:00
// Remainder to pay
2019-11-12 00:15:34 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
2020-11-29 15:16:53 +01:00
print '<span class="opacitymedium">' ;
2019-03-19 10:27:36 +01:00
print $langs -> trans ( 'RemainderToPay' );
2021-02-23 15:35:16 +01:00
if ( $resteapayeraffiche < 0 ) {
2021-11-08 02:57:21 +01:00
print ' (' . $langs -> trans ( 'NegativeIfExcessReceived' ) . ')' ;
2021-02-23 15:35:16 +01:00
}
2020-11-29 15:16:53 +01:00
print '</span>' ;
print '</td>' ;
2021-08-28 16:38:17 +02:00
print '<td class="right' . ( $resteapayeraffiche ? ' amountremaintopay' : ( ' ' . $cssforamountpaymentcomplete )) . '">' . price ( $resteapayeraffiche ) . '</td><td> </td></tr>' ;
2017-10-16 08:47:05 +02:00
2021-08-16 03:39:09 +02:00
// Remainder to pay Multicurrency
2021-08-16 03:47:49 +02:00
if ( $object -> multicurrency_code != $conf -> currency || $object -> multicurrency_tx != 1 ) {
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
print '<span class="opacitymedium">' ;
2021-11-08 03:09:30 +01:00
print $langs -> trans ( 'RemainderToPayMulticurrency' );
if ( $resteapayeraffiche < 0 ) {
print ' (' . $langs -> trans ( 'NegativeIfExcessReceived' ) . ')' ;
2021-08-26 04:25:32 +02:00
}
2021-08-16 03:47:49 +02:00
print '</span>' ;
print '</td>' ;
2022-08-12 23:19:36 +02:00
print '<td class="right' . ( $resteapayeraffiche ? ' amountremaintopay' : ( ' ' . $cssforamountpaymentcomplete )) . '">' ;
//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 )) . '</td><td> </td></tr>' ;
2021-08-16 03:47:49 +02:00
}
2018-08-10 15:06:00 +02:00
// Retained warranty : usualy use on construction industry
2019-11-12 00:15:34 +01:00
if ( ! empty ( $object -> situation_final ) && ! empty ( $object -> retained_warranty ) && $displayWarranty ) {
2020-10-31 14:32:18 +01:00
// Billed - retained warranty
2021-02-23 15:35:16 +01:00
if ( $object -> type == Facture :: TYPE_SITUATION ) {
2020-10-31 14:32:18 +01:00
$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 ;
}
$billedWithRetainedWarranty = $object -> total_ttc - $retainedWarranty ;
print '<tr><td colspan="' . $nbcols . '" align="right">' . $langs -> trans ( " ToPayOn " , dol_print_date ( $object -> date_lim_reglement , 'day' )) . ' :</td><td align="right">' . price ( $billedWithRetainedWarranty ) . '</td><td> </td></tr>' ;
// retained warranty
print '<tr><td colspan="' . $nbcols . '" align="right">' ;
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 ' :</td><td align="right">' . price ( $retainedWarranty ) . '</td><td> </td></tr>' ;
2018-08-08 17:36:39 +02:00
}
2021-02-23 15:35:16 +01:00
} else { // Credit note
2021-11-08 02:57:21 +01:00
$resteapayeraffiche = $resteapayer ;
2019-11-12 00:15:34 +01:00
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
2017-10-16 08:47:05 +02:00
// Total already paid back
2019-11-12 00:15:34 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
2021-11-08 02:57:21 +01:00
print '<span class="opacitymedium">' . $langs -> trans ( 'AlreadyPaidBack' ) . '</span>' ;
2022-05-22 17:09:08 +02:00
print '</td><td class="right"><span class="amount">' . price ( $sign * $totalpaid ) . '</span></td><td> </td></tr>' ;
2017-10-16 08:47:05 +02:00
// Billed
2021-11-08 02:57:21 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right"><span class="opacitymedium">' . $langs -> trans ( " Billed " ) . '</span></td><td class="right">' . price ( $sign * $object -> total_ttc ) . '</td><td> </td></tr>' ;
2017-10-16 08:47:05 +02:00
// Remainder to pay back
2019-11-12 00:15:34 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
2021-11-08 02:57:21 +01:00
print '<span class="opacitymedium">' . $langs -> trans ( 'RemainderToPayBack' );
2021-02-23 21:09:01 +01:00
if ( $resteapayeraffiche > 0 ) {
2021-11-08 02:57:21 +01:00
print ' (' . $langs -> trans ( 'NegativeIfExcessRefunded' ) . ')' ;
2021-02-23 21:09:01 +01:00
}
2021-11-08 02:57:21 +01:00
print '</span></td>' ;
2019-11-12 00:15:34 +01:00
print '<td class="right' . ( $resteapayeraffiche ? ' amountremaintopayback' : ( ' ' . $cssforamountpaymentcomplete )) . '">' . price ( $sign * $resteapayeraffiche ) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '<td class="nowrap"> </td></tr>' ;
2021-08-26 04:29:45 +02:00
2021-08-26 04:25:32 +02:00
// Remainder to pay back Multicurrency
if ( $object -> multicurrency_code != $conf -> currency || $object -> multicurrency_tx != 1 ) {
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
2021-11-08 03:09:30 +01:00
print '<span class="opacitymedium">' . $langs -> trans ( 'RemainderToPayBackMulticurrency' );
if ( $resteapayeraffiche > 0 ) {
print ' (' . $langs -> trans ( 'NegativeIfExcessRefunded' ) . ')' ;
2021-08-26 04:25:32 +02:00
}
print '</span>' ;
print '</td>' ;
2021-08-28 16:38:17 +02:00
print '<td class="right' . ( $resteapayeraffiche ? ' amountremaintopayback' : ( ' ' . $cssforamountpaymentcomplete )) . '">' . ( ! empty ( $object -> multicurrency_code ) ? $object -> multicurrency_code : $conf -> currency ) . ' ' . price ( price2num ( $sign * $object -> multicurrency_tx * $resteapayeraffiche , 'MT' )) . '</td><td> </td></tr>' ;
2021-08-26 04:25:32 +02:00
}
2017-10-16 08:47:05 +02:00
// Sold credit note
2019-02-04 13:57:38 +01:00
// print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans('TotalTTC').' :</td>';
// print '<td class="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>'.price($sign *
2017-10-16 08:47:05 +02:00
// $object->total_ttc).'</b></td><td> </td></tr>';
}
print '</table>' ;
2017-11-24 14:23:25 +01:00
print '</div>' ;
2016-10-29 07:45:24 +02:00
2016-09-21 01:25:34 +02:00
// Margin Infos
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'margin' )) {
2017-10-16 08:47:05 +02:00
$formmargin -> displayMarginInfos ( $object );
2016-09-21 01:25:34 +02:00
}
2014-03-01 19:45:13 +01:00
2016-09-21 01:25:34 +02:00
print '</div>' ;
print '</div>' ;
2016-10-29 07:45:24 +02:00
2022-04-07 14:03:14 +02:00
print '<div class="clearboth"></div><br><br>' ;
2016-10-29 07:45:24 +02:00
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB )) {
2013-11-17 23:25:25 +01:00
$blocname = 'contacts' ;
$title = $langs -> trans ( 'ContactsAddresses' );
2019-11-12 00:15:34 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_NOTES_TAB )) {
2013-11-17 23:25:25 +01:00
$blocname = 'notes' ;
$title = $langs -> trans ( 'Notes' );
2019-11-12 00:15:34 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Lines
$result = $object -> getLinesArray ();
2014-03-01 19:45:13 +01:00
2014-11-14 16:43:49 +01:00
// Show global modifiers
2021-02-23 15:35:16 +01:00
if ( ! empty ( $conf -> global -> INVOICE_USE_SITUATION )) {
if ( $object -> situation_cycle_ref && $object -> statut == 0 ) {
2020-10-31 14:32:18 +01:00
print '<!-- Area to change globally the situation percent -->' . " \n " ;
2017-05-10 16:10:14 +02:00
print '<div class="div-table-responsive">' ;
2017-06-07 16:44:04 +02:00
2019-11-12 00:15:34 +01:00
print '<form name="updatealllines" id="updatealllines" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '#updatealllines" method="POST">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '" />' ;
2015-06-03 11:55:39 +02:00
print '<input type="hidden" name="action" value="updatealllines" />' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '" />' ;
2017-06-07 16:44:04 +02:00
2017-05-15 15:05:42 +02:00
print '<table id="tablelines_all_progress" class="noborder noshadow" width="100%">' ;
2017-06-07 16:44:04 +02:00
2017-05-11 09:04:14 +02:00
print '<tr class="liste_titre nodrag nodrop">' ;
2015-06-03 11:55:39 +02:00
2018-09-25 17:26:57 +02:00
// Adds a line numbering column
2015-06-03 11:55:39 +02:00
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
print '<td align="center" width="5"> </td>' ;
}
2019-11-12 00:15:34 +01:00
print '<td class="minwidth500imp">' . $langs -> trans ( 'ModifyAllLines' ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( 'Progress' ) . '</td>' ;
2015-06-03 11:55:39 +02:00
print '<td> </td>' ;
print " </tr> \n " ;
2019-04-30 16:44:11 +02:00
print '<tr class="nodrag nodrop">' ;
2018-09-25 17:26:57 +02:00
// Adds a line numbering column
2015-06-03 11:55:39 +02:00
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
2020-10-31 14:32:18 +01:00
print '<td align="center" width="5"> </td>' ;
2015-06-03 11:55:39 +02:00
}
print '<td> </td>' ;
2019-02-04 13:57:38 +01:00
print '<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>' ;
2021-08-24 17:04:17 +02:00
print '<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>' ;
2015-06-03 11:55:39 +02:00
print '</tr>' ;
2017-06-07 16:44:04 +02:00
2017-05-10 16:10:14 +02:00
print '</table>' ;
2017-06-07 16:44:04 +02:00
2015-06-03 11:55:39 +02:00
print '</form>' ;
2017-06-07 16:44:04 +02:00
2017-05-10 16:10:14 +02:00
print '</div>' ;
2015-06-03 11:55:39 +02:00
}
2015-01-18 18:44:22 +01:00
}
2015-01-25 21:32:40 +01:00
2021-07-04 21:14:46 +02:00
print ' <form name="addproduct" id="addproduct" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . (( $action != 'editline' ) ? '' : '#line_' . GETPOST ( 'lineid' , 'int' )) . ' " method= " POST " >
2020-03-24 13:10:35 +01:00
< input type = " hidden " name = " token " value = " ' . newToken().' " >
2019-11-12 00:15:34 +01:00
< input type = " hidden " name = " action " value = " ' . (( $action != 'editline') ? 'addline' : 'updateline').' " >
2017-05-10 16:10:14 +02:00
< input type = " hidden " name = " mode " value = " " >
2021-07-04 21:14:46 +02:00
< input type = " hidden " name = " page_y " value = " " >
2019-11-12 00:15:34 +01:00
< input type = " hidden " name = " id " value = " ' . $object->id .' " >
2017-05-10 16:10:14 +02:00
' ;
2017-06-07 16:44:04 +02:00
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && $object -> statut == 0 ) {
include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php' ;
2017-05-10 16:10:14 +02:00
}
2017-06-07 16:44:04 +02:00
2017-10-13 12:14:57 +02:00
print '<div class="div-table-responsive-no-min">' ;
2017-05-10 16:10:14 +02:00
print '<table id="tablelines" class="noborder noshadow" width="100%">' ;
2017-06-07 16:44:04 +02:00
2013-11-17 23:25:25 +01:00
// Show object lines
2020-04-21 14:14:49 +02:00
if ( ! empty ( $object -> lines )) {
2014-02-23 20:10:05 +01:00
$ret = $object -> printObjectLines ( $action , $mysoc , $soc , $lineid , 1 );
2020-04-21 14:14:49 +02:00
}
2014-03-01 19:45:13 +01:00
2014-05-05 14:30:08 +02:00
// Form to add new line
2021-02-23 15:35:16 +01:00
if ( $object -> statut == 0 && $usercancreate && $action != 'valid' && $action != 'editline' ) {
if ( $action != 'editline' && $action != 'selectlines' ) {
2013-11-17 23:25:25 +01:00
// Add free products/services
2014-03-01 19:45:13 +01:00
2014-05-05 14:30:08 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formAddObjectLine' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2021-04-29 15:32:15 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
if ( empty ( $reshook ))
2021-04-29 17:36:45 +02:00
$object -> formAddObjectLine ( 1 , $mysoc , $soc );
2013-11-17 23:25:25 +01:00
}
}
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
print " </table> \n " ;
2017-10-16 08:47:05 +02:00
print " </div> " ;
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
print " </form> \n " ;
2014-03-01 19:45:13 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2014-03-01 19:45:13 +01:00
2014-04-23 13:14:55 +02:00
// Actions buttons
2021-02-23 15:35:16 +01:00
if ( $action != 'prerelance' && $action != 'presend' && $action != 'valid' && $action != 'editline' ) {
2014-01-24 11:15:25 +01:00
print '<div class="tabsAction">' ;
2014-03-01 19:45:13 +01:00
2014-02-23 20:10:05 +01:00
$parameters = array ();
2016-10-29 07:45:24 +02:00
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2014-02-23 20:10:05 +01:00
if ( empty ( $reshook )) {
2022-03-04 17:03:40 +01:00
$params = array (
'attr' => array (
'title' => '' ,
'class' => 'classfortooltip'
)
);
2013-11-17 23:25:25 +01:00
// Editer une facture deja validee, sans paiement effectue et pas exporte en compta
2021-02-23 15:35:16 +01:00
if ( $object -> statut == Facture :: STATUS_VALIDATED ) {
2019-10-04 10:31:57 +02:00
// We check if lines of invoice are not already transfered into accountancy
2013-11-17 23:25:25 +01:00
$ventilExportCompta = $object -> getVentilExportCompta ();
2014-03-01 19:45:13 +01:00
2021-02-23 15:35:16 +01:00
if ( $ventilExportCompta == 0 ) {
2022-04-05 17:39:56 +02:00
if ( ! empty ( $conf -> global -> INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE ) || ( $resteapayer == price2num ( $object -> total_ttc , 'MT' , 1 ) && empty ( $object -> paye ))) {
2021-02-23 15:35:16 +01:00
if ( ! $objectidnext && $object -> is_last_in_cycle ()) {
if ( $usercanunvalidate ) {
2022-04-05 17:39:56 +02:00
print dolGetButtonAction ( $langs -> trans ( 'Modify' ), '' , 'default' , $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=modif&token=' . newToken (), '' , true , $params );
2017-09-27 16:29:33 +02:00
} else {
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'NotEnoughPermissions' );
2022-04-05 17:39:56 +02:00
print dolGetButtonAction ( $langs -> trans ( 'Modify' ), '' , 'default' , $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=modif&token=' . newToken (), '' , false , $params );
2017-09-27 16:29:33 +02:00
}
2019-01-27 10:49:34 +01:00
} elseif ( ! $object -> is_last_in_cycle ()) {
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'NotLastInCycle' );
print dolGetButtonAction ( $langs -> trans ( 'Modify' ), '' , 'default' , '#' , '' , false , $params );
2014-02-23 20:10:05 +01:00
} else {
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'DisabledBecauseReplacedInvoice' );
print dolGetButtonAction ( $langs -> trans ( 'Modify' ), '' , 'default' , '#' , '' , false , $params );
2013-04-20 00:10:20 +02:00
}
2013-04-20 17:10:03 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'DisabledBecauseDispatchedInBookkeeping' );
print dolGetButtonAction ( $langs -> trans ( 'Modify' ), '' , 'default' , '#' , '' , false , $params );
2017-09-27 16:29:33 +02:00
}
2013-11-17 23:25:25 +01:00
}
2017-06-07 16:44:04 +02:00
2016-11-28 17:38:20 +01:00
$discount = new DiscountAbsolute ( $db );
$result = $discount -> fetch ( 0 , $object -> id );
2017-06-07 16:44:04 +02:00
2021-12-16 12:33:45 +01:00
// Reopen an invoice
2014-03-19 22:59:10 +01:00
if ((( $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_REPLACEMENT )
|| ( $object -> type == Facture :: TYPE_CREDIT_NOTE && empty ( $discount -> id ))
2021-07-29 06:23:12 +02:00
|| ( $object -> type == Facture :: TYPE_DEPOSIT && empty ( $discount -> id ))
|| ( $object -> type == Facture :: TYPE_SITUATION && empty ( $discount -> id )))
2019-10-04 10:31:57 +02:00
&& ( $object -> statut == Facture :: STATUS_CLOSED || $object -> statut == Facture :: STATUS_ABANDONED || ( $object -> statut == 1 && $object -> paye == 1 )) // Condition ($object->statut == 1 && $object->paye == 1) should not happened but can be found due to corrupted data
2021-02-23 21:09:01 +01:00
&& (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && $usercancreate ) || $usercanreopen )) { // A paid invoice (partially or completely)
if ( $object -> close_code != 'replaced' || ( ! $objectidnext )) { // Not replaced by another invoice or replaced but the replacement invoice has been deleted
2022-03-09 16:41:26 +01:00
print dolGetButtonAction ( $langs -> trans ( 'ReOpen' ), '' , 'default' , $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=reopen&token=' . newToken (), '' , true , $params );
2014-02-23 20:10:05 +01:00
} else {
2022-03-09 16:41:26 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( " DisabledBecauseReplacedInvoice " );
print dolGetButtonAction ( $langs -> trans ( 'ReOpen' ), '' , 'default' , '#' , '' , false , $params );
2013-11-17 23:25:25 +01:00
}
}
2014-03-01 19:45:13 +01:00
2022-01-13 22:29:48 +01:00
// Create contract
if ( ! empty ( $conf -> global -> CONTRACT_CREATE_FROM_INVOICE )) {
2022-05-27 16:40:18 +02:00
if ( ! empty ( $conf -> contrat -> enabled ) && $object -> statut == Facture :: STATUS_VALIDATED ) {
2022-01-13 22:29:48 +01:00
$langs -> load ( " contracts " );
if ( $usercancreatecontract ) {
print '<a class="butAction" href="' . DOL_URL_ROOT . '/contrat/card.php?action=create&origin=' . $object -> element . '&originid=' . $object -> id . '&socid=' . $object -> socid . '">' . $langs -> trans ( 'AddContract' ) . '</a>' ;
}
}
}
2013-11-17 23:25:25 +01:00
// Validate
2019-11-12 00:15:34 +01:00
if ( $object -> statut == Facture :: STATUS_DRAFT && count ( $object -> lines ) > 0 && ((( $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_REPLACEMENT || $object -> type == Facture :: TYPE_DEPOSIT || $object -> type == Facture :: TYPE_PROFORMA || $object -> type == Facture :: TYPE_SITUATION ) && ( ! empty ( $conf -> global -> FACTURE_ENABLE_NEGATIVE ) || $object -> total_ttc >= 0 )) || ( $object -> type == Facture :: TYPE_CREDIT_NOTE && $object -> total_ttc <= 0 ))) {
2021-02-23 21:09:01 +01:00
if ( $usercanvalidate ) {
2022-03-04 17:03:40 +01:00
print dolGetButtonAction ( $langs -> trans ( 'Validate' ), '' , 'default' , $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=valid&token=' . newToken (), '' , true , $params );
2013-11-17 23:25:25 +01:00
}
}
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// Send by mail
2020-04-10 01:37:04 +02:00
if ( empty ( $user -> socid )) {
if (( $object -> statut == Facture :: STATUS_VALIDATED || $object -> statut == Facture :: STATUS_CLOSED ) || ! empty ( $conf -> global -> FACTURE_SENDBYEMAIL_FOR_ALL_STATUS )) {
if ( $objectidnext ) {
print '<span class="butActionRefused classfortooltip" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'SendMail' ) . '</span>' ;
} else {
if ( $usercansend ) {
2022-03-04 17:03:40 +01:00
print dolGetButtonAction ( $langs -> trans ( 'SendMail' ), '' , 'default' , $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=presend&mode=init#formmailbeforetitle' , '' , true , $params );
2021-02-23 21:09:01 +01:00
} else {
2022-03-04 17:03:40 +01:00
print dolGetButtonAction ( $langs -> trans ( 'SendMail' ), '' , 'default' , '#' , '' , false , $params );
2021-02-23 21:09:01 +01:00
}
2020-04-10 01:37:04 +02:00
}
2013-11-17 23:25:25 +01:00
}
}
2014-03-01 19:45:13 +01:00
2017-02-10 10:43:54 +01:00
// Request a direct debit order
2021-02-23 15:35:16 +01:00
if ( $object -> statut > Facture :: STATUS_DRAFT && $object -> paye == 0 && $num == 0 ) {
if ( $resteapayer > 0 ) {
if ( $usercancreatewithdrarequest ) {
if ( ! $objectidnext && $object -> close_code != 'replaced' ) { // Not replaced by another invoice
2018-01-04 14:35:02 +01:00
print '<a class="butAction" href="' . DOL_URL_ROOT . '/compta/facture/prelevement.php?facid=' . $object -> id . '" title="' . dol_escape_htmltag ( $langs -> trans ( " MakeWithdrawRequest " )) . '">' . $langs -> trans ( " MakeWithdrawRequest " ) . '</a>' ;
} else {
2019-11-12 00:15:34 +01:00
print '<span class="butActionRefused classfortooltip" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'MakeWithdrawRequest' ) . '</span>' ;
2018-01-04 14:35:02 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2018-11-13 21:40:17 +01:00
//print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("MakeWithdrawRequest").'</a>';
2017-10-16 08:47:05 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2018-11-13 21:40:17 +01:00
//print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$langs->trans("MakeWithdrawRequest").'</a>';
2017-10-16 08:47:05 +02:00
}
2013-11-17 23:25:25 +01:00
}
2017-06-07 16:44:04 +02:00
2019-05-14 12:00:58 +02:00
// POS Ticket
2022-08-29 12:01:36 +02:00
if ( isModEnabled ( 'takepos' ) && $object -> module_source == 'takepos' ) {
2020-10-31 14:32:18 +01:00
$langs -> load ( " cashdesk " );
$receipt_url = DOL_URL_ROOT . " /takepos/receipt.php " ;
2021-11-22 02:35:55 +01:00
print '<a target="_blank" rel="noopener noreferrer" class="butAction" href="' . $receipt_url . '?facid=' . (( int ) $object -> id ) . '">' . $langs -> trans ( 'POSTicket' ) . '</a>' ;
2019-05-14 12:00:58 +02:00
}
2013-11-17 23:25:25 +01:00
// Create payment
2018-11-14 14:59:36 +01:00
if ( $object -> type != Facture :: TYPE_CREDIT_NOTE && $object -> statut == 1 && $object -> paye == 0 && $usercanissuepayment ) {
2014-02-23 20:10:05 +01:00
if ( $objectidnext ) {
2019-11-12 00:15:34 +01:00
print '<span class="butActionRefused classfortooltip" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'DoPayment' ) . '</span>' ;
2014-02-23 20:10:05 +01:00
} else {
2021-12-16 12:33:45 +01:00
if ( $object -> type == Facture :: TYPE_DEPOSIT && $resteapayer == 0 ) {
// For down payment, we refuse to receive more than amount to pay.
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'DisabledBecauseRemainderToPayIsZero' );
print dolGetButtonAction ( $langs -> trans ( 'DoPayment' ), '' , 'default' , '#' , '' , false , $params );
2021-12-16 12:33:45 +01:00
} else {
// Sometimes we can receive more, so we accept to enter more and will offer a button to convert into discount (but it is not a credit note, just a prepayment done)
2022-03-04 17:03:40 +01:00
//print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/paiement.php?facid='.$object->id.'&action=create&accountid='.$object->fk_account.'">'.$langs->trans('DoPayment').'</a>';
print dolGetButtonAction ( $langs -> trans ( 'DoPayment' ), '' , 'default' , DOL_URL_ROOT . '/compta/paiement.php?facid=' . $object -> id . '&action=create&accountid=' . $object -> fk_account , '' , true , $params );
2021-12-16 12:33:45 +01:00
}
2013-11-17 23:25:25 +01:00
}
}
2014-03-01 19:45:13 +01:00
2022-05-22 17:09:08 +02:00
$sumofpayment = $totalpaid ;
$sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits ;
2021-12-16 12:33:45 +01:00
2013-11-17 23:25:25 +01:00
// Reverse back money or convert to reduction
2020-02-12 12:09:03 +01:00
if ( $object -> type == Facture :: TYPE_CREDIT_NOTE || $object -> type == Facture :: TYPE_DEPOSIT || $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_SITUATION ) {
2013-11-17 23:25:25 +01:00
// For credit note only
2021-02-23 15:35:16 +01:00
if ( $object -> type == Facture :: TYPE_CREDIT_NOTE && $object -> statut == Facture :: STATUS_VALIDATED && $object -> paye == 0 && $usercanissuepayment ) {
if ( $resteapayer == 0 ) {
2019-10-16 14:02:13 +02:00
print '<span class="butActionRefused classfortooltip" title="' . $langs -> trans ( " DisabledBecauseRemainderToPayIsZero " ) . '">' . $langs -> trans ( 'DoPaymentBack' ) . '</span>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
print '<a class="butAction" href="' . DOL_URL_ROOT . '/compta/paiement.php?facid=' . $object -> id . '&action=create&accountid=' . $object -> fk_account . '">' . $langs -> trans ( 'DoPaymentBack' ) . '</a>' ;
2014-03-19 22:30:25 +01:00
}
2013-11-17 23:25:25 +01:00
}
2014-03-19 22:30:25 +01:00
2016-11-24 15:48:04 +01:00
// For standard invoice with excess received
2021-02-23 21:09:01 +01:00
if (( $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_SITUATION ) && $object -> statut == Facture :: STATUS_VALIDATED && empty ( $object -> paye ) && $resteapayer < 0 && $usercancreate && empty ( $discount -> id )) {
2019-11-12 00:15:34 +01:00
print '<a class="butAction' . ( $conf -> use_javascript_ajax ? ' reposition' : '' ) . '" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=converttoreduc">' . $langs -> trans ( 'ConvertExcessReceivedToReduc' ) . '</a>' ;
2016-11-24 15:48:04 +01:00
}
2013-11-17 23:25:25 +01:00
// For credit note
2020-03-04 00:38:04 +01:00
if ( $object -> type == Facture :: TYPE_CREDIT_NOTE && $object -> statut == Facture :: STATUS_VALIDATED && $object -> paye == 0 && $usercancreate
2021-12-16 12:33:45 +01:00
&& ( ! empty ( $conf -> global -> INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED ) || $sumofpayment == 0 )
2020-01-01 19:04:14 +01:00
) {
2019-11-12 00:15:34 +01:00
print '<a class="butAction' . ( $conf -> use_javascript_ajax ? ' reposition' : '' ) . '" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=converttoreduc" title="' . dol_escape_htmltag ( $langs -> trans ( " ConfirmConvertToReduc2 " )) . '">' . $langs -> trans ( 'ConvertToReduc' ) . '</a>' ;
2013-11-17 23:25:25 +01:00
}
2022-07-05 20:59:42 +02:00
// For down payment invoice (deposit)
2021-12-23 10:09:20 +01:00
if ( $object -> type == Facture :: TYPE_DEPOSIT && $usercancreate && $object -> statut > Facture :: STATUS_DRAFT && empty ( $discount -> id )) {
2022-07-05 20:59:42 +02:00
if ( price2num ( $object -> total_ttc , 'MT' ) == price2num ( $sumofpaymentall , 'MT' ) || ( $object -> type == Facture :: STATUS_ABANDONED && in_array ( $object -> close_code , array ( 'bankcharge' , 'discount_vat' , 'other' )))) {
2021-12-16 12:33:45 +01:00
// We can close a down payment only if paid amount is same than amount of down payment (by definition)
print '<a class="butAction' . ( $conf -> use_javascript_ajax ? ' reposition' : '' ) . '" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=converttoreduc">' . $langs -> trans ( 'ConvertToReduc' ) . '</a>' ;
} else {
print '<span class="butActionRefused" title="' . $langs -> trans ( " AmountPaidMustMatchAmountOfDownPayment " ) . '">' . $langs -> trans ( 'ConvertToReduc' ) . '</span>' ;
}
2013-11-17 23:25:25 +01:00
}
}
2014-03-01 19:45:13 +01:00
2014-03-19 22:30:25 +01:00
// Classify paid
2021-11-02 16:43:09 +01:00
if ( $object -> statut == Facture :: STATUS_VALIDATED && $object -> paye == 0 && $usercanissuepayment && (
2021-12-30 19:03:46 +01:00
( $object -> type != Facture :: TYPE_CREDIT_NOTE && $object -> type != Facture :: TYPE_DEPOSIT && ( $resteapayer <= 0 || ( ! empty ( $conf -> global -> INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID ) && $object -> total_ttc == $resteapayer ))) ||
2021-11-02 16:43:09 +01:00
( $object -> type == Facture :: TYPE_CREDIT_NOTE && $resteapayer >= 0 ) ||
2021-12-19 00:36:22 +01:00
( $object -> type == Facture :: TYPE_DEPOSIT && $object -> total_ttc > 0 )
2021-11-02 16:43:09 +01:00
)
2021-02-23 21:09:01 +01:00
) {
2021-12-23 10:09:20 +01:00
if ( $object -> type == Facture :: TYPE_DEPOSIT && price2num ( $object -> total_ttc , 'MT' ) != price2num ( $sumofpaymentall , 'MT' )) {
2021-12-16 12:33:45 +01:00
// We can close a down payment only if paid amount is same than amount of down payment (by definition)
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'AmountPaidMustMatchAmountOfDownPayment' );
print dolGetButtonAction ( $langs -> trans ( 'ClassifyPaid' ), '' , 'default' , '#' , '' , false , $params );
2021-12-16 12:53:46 +01:00
} else {
2022-03-04 17:03:40 +01:00
print dolGetButtonAction ( $langs -> trans ( 'ClassifyPaid' ), '' , 'default' , $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=paid' , '' , true , $params );
2021-12-16 12:33:45 +01:00
}
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2021-04-06 09:15:34 +02:00
// Classify 'closed not completely paid' (possible if validated and not yet filed paid)
2021-12-30 19:03:46 +01:00
if ( $object -> statut == Facture :: STATUS_VALIDATED && $object -> paye == 0 && $resteapayer > 0 && ( empty ( $conf -> global -> INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID ) || $resteapayer != $object -> total_ttc ) && $usercanissuepayment ) {
2022-05-22 17:09:08 +02:00
if ( $totalpaid > 0 || $totalcreditnotes > 0 ) {
2013-11-17 23:25:25 +01:00
// If one payment or one credit note was linked to this invoice
2019-11-12 00:15:34 +01:00
print '<a class="butAction' . ( $conf -> use_javascript_ajax ? ' reposition' : '' ) . '" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=paid">' . $langs -> trans ( 'ClassifyPaidPartially' ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> INVOICE_CAN_NEVER_BE_CANCELED )) {
if ( $objectidnext ) {
2019-11-12 00:15:34 +01:00
print '<span class="butActionRefused classfortooltip" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'ClassifyCanceled' ) . '</span>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
print '<a class="butAction' . ( $conf -> use_javascript_ajax ? ' reposition' : '' ) . '" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=canceled">' . $langs -> trans ( 'ClassifyCanceled' ) . '</a>' ;
2016-03-24 11:38:05 +01:00
}
2013-04-20 00:10:20 +02:00
}
2013-11-17 23:25:25 +01:00
}
}
2014-03-01 19:45:13 +01:00
2015-07-08 14:01:30 +02:00
// Create a credit note
2021-07-02 16:14:12 +02:00
if (( $object -> type == Facture :: TYPE_STANDARD || ( $object -> type == Facture :: TYPE_DEPOSIT && empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS )) || $object -> type == Facture :: TYPE_PROFORMA ) && $object -> statut > 0 && $usercancreate ) {
2021-02-23 15:35:16 +01:00
if ( ! $objectidnext ) {
2020-05-29 16:18:27 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?socid=' . $object -> socid . '&fac_avoir=' . $object -> id . '&action=create&type=2' . ( $object -> fk_project > 0 ? '&projectid=' . $object -> fk_project : '' ) . ( $object -> entity > 0 ? '&originentity=' . $object -> entity : '' ) . '">' . $langs -> trans ( " CreateCreditNote " ) . '</a>' ;
2015-07-08 14:01:30 +02:00
}
}
2014-03-01 19:45:13 +01:00
2018-03-22 11:19:39 +01:00
// For situation invoice with excess received
2018-07-24 17:49:10 +02:00
if ( $object -> statut > Facture :: STATUS_DRAFT
2020-01-19 19:10:10 +01:00
&& $object -> type == Facture :: TYPE_SITUATION
2022-05-22 17:09:08 +02:00
&& ( $object -> total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits ) > 0
2020-10-31 14:32:18 +01:00
&& $usercancreate
&& ! $objectidnext
&& $object -> is_last_in_cycle ()
&& $conf -> global -> INVOICE_USE_SITUATION_CREDIT_NOTE
2021-02-23 21:09:01 +01:00
) {
2021-02-23 15:35:16 +01:00
if ( $usercanunvalidate ) {
2020-10-31 14:32:18 +01:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?socid=' . $object -> socid . '&fac_avoir=' . $object -> id . '&invoiceAvoirWithLines=1&action=create&type=2' . ( $object -> fk_project > 0 ? '&projectid=' . $object -> fk_project : '' ) . '">' . $langs -> trans ( " CreateCreditNote " ) . '</a>' ;
} else {
print '<span class="butActionRefused classfortooltip" title="' . $langs -> trans ( " NotEnoughPermissions " ) . '">' . $langs -> trans ( " CreateCreditNote " ) . '</span>' ;
}
2018-03-22 11:19:39 +01:00
}
2018-05-23 08:16:24 +02:00
2020-01-16 02:48:24 +01:00
// Clone
2021-02-23 21:09:01 +01:00
if (( $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_DEPOSIT || $object -> type == Facture :: TYPE_PROFORMA ) && $usercancreate ) {
2022-03-04 17:03:40 +01:00
print dolGetButtonAction ( $langs -> trans ( 'ToClone' ), '' , 'default' , $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=clone&object=invoice' , '' , true , $params );
2020-01-16 02:48:24 +01:00
}
// Clone as predefined / Create template
2021-02-23 21:09:01 +01:00
if (( $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_DEPOSIT || $object -> type == Facture :: TYPE_PROFORMA ) && $object -> statut == 0 && $usercancreate ) {
if ( ! $objectidnext && count ( $object -> lines ) > 0 ) {
2022-03-04 17:03:40 +01:00
print dolGetButtonAction ( $langs -> trans ( 'ChangeIntoRepeatableInvoice' ), '' , 'default' , DOL_URL_ROOT . '/compta/facture/card-rec.php?facid=' . $object -> id . '&action=create' , '' , true , $params );
2020-01-16 02:48:24 +01:00
}
}
2019-10-04 10:31:57 +02:00
// Remove situation from cycle
2020-12-16 10:54:32 +01:00
if ( in_array ( $object -> statut , array ( Facture :: STATUS_CLOSED , Facture :: STATUS_VALIDATED ))
2021-02-23 21:09:01 +01:00
&& $object -> type == Facture :: TYPE_SITUATION
&& $usercancreate
&& ! $objectidnext
&& $object -> situation_counter > 1
&& $object -> is_last_in_cycle ()
2018-11-14 14:59:36 +01:00
&& $usercanunvalidate
2021-02-23 21:09:01 +01:00
) {
2021-02-23 15:35:16 +01:00
if (( $object -> total_ttc - $totalcreditnotes ) == 0 ) {
2020-10-31 14:32:18 +01:00
print '<a id="butSituationOut" class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=situationout">' . $langs -> trans ( " RemoveSituationFromCycle " ) . '</a>' ;
} else {
print '<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " DisabledBecauseNotEnouthCreditNote " ) . '" >' . $langs -> trans ( " RemoveSituationFromCycle " ) . '</a>' ;
}
2018-04-03 15:12:44 +02:00
}
2018-05-23 08:16:24 +02:00
2016-02-11 10:39:01 +01:00
// Create next situation invoice
2018-11-14 14:59:36 +01:00
if ( $usercancreate && ( $object -> type == 5 ) && ( $object -> statut == 1 || $object -> statut == 2 )) {
2014-11-14 16:43:49 +01:00
if ( $object -> is_last_in_cycle () && $object -> situation_final != 1 ) {
2019-11-12 00:15:34 +01:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=create&type=5&origin=facture&originid=' . $object -> id . '&socid=' . $object -> socid . '" >' . $langs -> trans ( 'CreateNextSituationInvoice' ) . '</a>' ;
2019-01-27 10:49:34 +01:00
} elseif ( ! $object -> is_last_in_cycle ()) {
2019-11-12 00:15:34 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " DisabledBecauseNotLastInCycle " ) . '">' . $langs -> trans ( 'CreateNextSituationInvoice' ) . '</a>' ;
2014-11-14 16:43:49 +01:00
} else {
2019-11-12 00:15:34 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " DisabledBecauseFinal " ) . '">' . $langs -> trans ( 'CreateNextSituationInvoice' ) . '</a>' ;
2014-11-14 16:43:49 +01:00
}
}
2013-11-17 23:25:25 +01:00
// Delete
2018-10-29 14:35:42 +01:00
$isErasable = $object -> is_erasable ();
2022-03-04 17:03:40 +01:00
$params = array (
'attr' => array (
'title' => '' ,
'class' => 'classfortooltip'
)
);
2021-02-23 21:09:01 +01:00
if ( $usercandelete || ( $usercancreate && $isErasable == 1 )) { // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions)
2022-03-04 17:03:40 +01:00
$enableDelete = false ;
$deleteHref = '#' ;
2017-12-05 10:01:30 +01:00
if ( $isErasable == - 4 ) {
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'DisabledBecausePayments' );
2020-05-21 15:05:19 +02:00
} elseif ( $isErasable == - 3 ) {
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'DisabledBecauseNotLastSituationInvoice' );
2020-05-21 15:05:19 +02:00
} elseif ( $isErasable == - 2 ) {
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'DisabledBecauseNotLastInvoice' );
2020-05-21 15:05:19 +02:00
} elseif ( $isErasable == - 1 ) {
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'DisabledBecauseDispatchedInBookkeeping' );
2021-02-23 21:09:01 +01:00
} elseif ( $isErasable <= 0 ) { // Any other cases
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'DisabledBecauseNotErasable' );
2021-02-23 21:09:01 +01:00
} elseif ( $objectidnext ) {
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'DisabledBecauseReplacedInvoice' );
2020-05-21 15:05:19 +02:00
} else {
2022-03-04 17:03:40 +01:00
$deleteHref = $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=delete&token=' . newToken ();
$enableDelete = true ;
2013-11-17 23:25:25 +01:00
}
2022-03-04 17:03:40 +01:00
print dolGetButtonAction ( $langs -> trans ( 'Delete' ), '' , 'delete' , $deleteHref , '' , $enableDelete , $params );
2014-02-23 20:10:05 +01:00
} else {
2022-03-04 17:03:40 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( 'NotAllowed' );
print dolGetButtonAction ( $langs -> trans ( 'Delete' ), '' , 'delete' , '#' , '' , false , $params );
2013-11-17 23:25:25 +01:00
}
}
2017-12-10 15:24:47 +01:00
print '</div>' ;
2013-11-17 23:25:25 +01:00
}
2014-03-01 19:45:13 +01:00
2015-05-27 07:41:25 +02:00
// Select mail models is same action as presend
2019-01-27 11:55:16 +01:00
if ( GETPOST ( 'modelselected' , 'alpha' )) {
2015-04-18 17:15:36 +02:00
$action = 'presend' ;
}
2021-02-23 15:35:16 +01:00
if ( $action != 'prerelance' && $action != 'presend' ) {
2013-11-17 23:25:25 +01:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
print '<a name="builddoc"></a>' ; // ancre
2014-03-01 19:45:13 +01:00
2021-03-16 04:04:18 +01:00
// Generated documents
2014-02-23 20:10:05 +01:00
$filename = dol_sanitizeFileName ( $object -> ref );
2019-11-12 00:15:34 +01:00
$filedir = $conf -> facture -> multidir_output [ $object -> entity ] . '/' . dol_sanitizeFileName ( $object -> ref );
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id ;
2018-11-14 14:59:36 +01:00
$genallowed = $usercanread ;
$delallowed = $usercancreate ;
2014-03-01 19:45:13 +01:00
2020-04-08 10:30:51 +02:00
print $formfile -> showdocuments (
2021-02-23 21:09:01 +01:00
'facture' ,
$filename ,
$filedir ,
$urlsource ,
$genallowed ,
$delallowed ,
$object -> model_pdf ,
1 ,
0 ,
0 ,
28 ,
0 ,
'' ,
'' ,
'' ,
$soc -> default_lang ,
'' ,
$object ,
0 ,
'remove_file_comfirm'
);
2020-04-08 10:50:16 +02:00
2014-02-23 20:10:05 +01:00
$somethingshown = $formfile -> numoffiles ;
2014-03-01 19:45:13 +01:00
2015-06-06 15:57:59 +02:00
// Show links to link elements
2016-08-04 11:57:37 +02:00
$linktoelem = $form -> showLinkToObjectBlock ( $object , null , array ( 'invoice' ));
2018-04-10 12:03:01 +02:00
2018-02-22 15:19:20 +01:00
$compatibleImportElementsList = false ;
2019-11-12 00:15:34 +01:00
if ( $usercancreate
2020-10-31 14:32:18 +01:00
&& $object -> statut == Facture :: STATUS_DRAFT
2021-02-23 21:09:01 +01:00
&& ( $object -> type == Facture :: TYPE_STANDARD || $object -> type == Facture :: TYPE_REPLACEMENT || $object -> type == Facture :: TYPE_DEPOSIT || $object -> type == Facture :: TYPE_PROFORMA || $object -> type == Facture :: TYPE_SITUATION )) {
2020-10-31 14:32:18 +01:00
$compatibleImportElementsList = array ( 'commande' , 'propal' ); // import from linked elements
2018-02-22 15:19:20 +01:00
}
2019-01-27 11:55:16 +01:00
$somethingshown = $form -> showLinkedObjectBlock ( $object , $linktoelem , $compatibleImportElementsList );
2018-04-10 12:03:01 +02:00
2017-02-22 06:33:52 +01:00
2017-09-12 12:18:26 +02:00
// Show online payment link
2019-11-12 00:15:34 +01:00
$useonlinepayment = ( ! empty ( $conf -> paypal -> enabled ) || ! empty ( $conf -> stripe -> enabled ) || ! empty ( $conf -> paybox -> enabled ));
2017-09-12 12:18:26 +02:00
2021-02-23 15:35:16 +01:00
if ( $object -> statut != Facture :: STATUS_DRAFT && $useonlinepayment ) {
2017-11-04 17:11:58 +01:00
print '<br><!-- Link to pay -->' . " \n " ;
2017-09-12 12:18:26 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php' ;
2017-11-04 17:11:58 +01:00
print showOnlinePaymentUrl ( 'invoice' , $object -> ref ) . '<br>' ;
}
2021-10-23 17:18:35 +02:00
print '</div><div class="fichehalfright">' ;
2014-03-01 19:45:13 +01:00
2013-11-17 23:25:25 +01:00
// List of actions on element
2019-11-12 00:15:34 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
2014-02-23 20:10:05 +01:00
$formactions = new FormActions ( $db );
2017-09-13 14:18:36 +02:00
$somethingshown = $formactions -> showactions ( $object , 'invoice' , $socid , 1 );
2014-03-01 19:45:13 +01:00
2021-10-23 17:18:35 +02:00
print '</div></div>' ;
2014-08-06 00:46:00 +02:00
}
2014-07-28 02:45:58 +02:00
2014-03-01 19:45:13 +01:00
2017-09-17 15:38:50 +02:00
// Presend form
2019-11-12 00:15:34 +01:00
$modelmail = 'facture_send' ;
$defaulttopic = 'SendBillRef' ;
2019-05-12 14:41:30 +02:00
$diroutput = $conf -> facture -> multidir_output [ $object -> entity ];
2017-09-17 15:38:50 +02:00
$trackid = 'inv' . $object -> id ;
2014-03-01 19:45:13 +01:00
2017-09-17 15:38:50 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php' ;
2013-04-20 17:10:03 +02:00
}
2008-08-12 20:20:18 +02:00
2018-07-30 17:28:44 +02:00
// End of page
2013-04-20 17:10:03 +02:00
llxFooter ();
$db -> close ();