2012-10-28 13:57:21 +01:00
< ? php
2019-10-27 09:51:15 +01:00
/* Copyright ( C ) 2002 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2020-07-25 02:59:49 +02:00
* Copyright ( C ) 2004 - 2020 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-10-28 13:57:21 +01:00
* Copyright ( C ) 2004 Christophe Combelles < ccomb @ free . fr >
* Copyright ( C ) 2005 Marc Barilley < marc @ ocebo . fr >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2013 Regis Houssin < regis . houssin @ inodbox . com >
2019-06-14 18:28:01 +02:00
* Copyright ( C ) 2010 - 2019 Juanjo Menent < jmenent @ 2 byte . es >
2015-12-10 16:14:37 +01:00
* Copyright ( C ) 2013 - 2015 Philippe Grand < philippe . grand @ atoo - net . com >
2016-10-02 21:39:24 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2016-11-06 15:01:40 +01:00
* Copyright ( C ) 2014 - 2016 Marcos García < marcosgdf @ gmail . com >
2019-01-28 21:39:22 +01:00
* Copyright ( C ) 2016 - 2017 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2019-10-27 09:51:15 +01:00
* Copyright ( C ) 2018 - 2019 Frédéric France < frederic . france @ netlogic . fr >
2019-09-17 09:43:15 +02:00
* Copyright ( C ) 2019 Ferran Marcet < fmarcet @ 2 byte . es >
2012-10-28 13:57:21 +01: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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2012-10-28 13:57:21 +01:00
* ( 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 />.
2012-10-28 13:57:21 +01:00
*/
/**
2014-09-18 21:18:25 +02:00
* \file htdocs / fourn / facture / card . php
2012-10-28 13:57:21 +01:00
* \ingroup facture , fournisseur
* \brief Page for supplier invoice card ( view , edit , validate )
*/
require '../../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/paiementfourn.class.php' ;
2018-02-14 10:47:10 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php' ;
2012-10-28 13:57:21 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php' ;
2013-01-23 11:28:11 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2013-04-09 17:18:07 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-06-24 21:18:49 +02:00
if ( ! empty ( $conf -> product -> enabled )) {
2013-01-23 11:28:11 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2020-06-11 16:52:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
2018-10-27 18:07:05 +02:00
}
2013-06-14 22:33:01 +02:00
if ( ! empty ( $conf -> projet -> enabled )) {
2013-01-23 11:28:11 +01:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2013-06-14 22:33:01 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
}
2012-10-28 13:57:21 +01:00
2017-02-08 12:37:38 +01:00
if ( ! empty ( $conf -> variants -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductCombination.class.php' ;
2016-07-23 16:37:21 +02:00
}
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php' ;
2016-07-23 16:37:21 +02:00
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
$langs -> loadLangs ( array ( 'bills' , 'compta' , 'suppliers' , 'companies' , 'products' , 'banks' ));
2015-02-23 09:16:14 +01:00
if ( ! empty ( $conf -> incoterm -> enabled )) $langs -> load ( 'incoterm' );
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
$id = ( GETPOST ( 'facid' , 'int' ) ? GETPOST ( 'facid' , 'int' ) : GETPOST ( 'id' , 'int' ));
$socid = GETPOST ( 'socid' , 'int' );
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'aZ09' );
2012-10-28 13:57:21 +01:00
$confirm = GETPOST ( " confirm " );
2019-11-08 10:53:31 +01:00
$ref = GETPOST ( 'ref' , 'alpha' );
2019-01-27 11:55:16 +01:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2016-10-02 21:39:24 +02:00
$lineid = GETPOST ( 'lineid' , 'int' );
2019-11-08 10:53:31 +01:00
$projectid = GETPOST ( 'projectid' , 'int' );
2016-10-02 21:39:24 +02:00
$origin = GETPOST ( 'origin' , 'alpha' );
2019-11-08 10:53:31 +01:00
$originid = GETPOST ( 'originid' , 'int' );
2012-10-28 13:57:21 +01:00
2017-05-05 12:33:49 +02:00
// PDF
2019-11-08 10:53:31 +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-10-28 13:57:21 +01: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-08 10:53:31 +01:00
$hookmanager -> initHooks ( array ( 'invoicesuppliercard' , 'globalcard' ));
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
$object = new FactureFournisseur ( $db );
2014-10-14 17:00:06 +02:00
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2012-10-28 13:57:21 +01:00
2013-03-29 15:36:54 +01:00
// Load object
2019-11-08 10:53:31 +01:00
if ( $id > 0 || ! empty ( $ref ))
2013-03-29 15:36:54 +01:00
{
2019-11-08 10:53:31 +01:00
$ret = $object -> fetch ( $id , $ref );
2019-01-27 11:55:16 +01:00
if ( $ret < 0 ) dol_print_error ( $db , $object -> error );
2019-11-08 10:53:31 +01:00
$ret = $object -> fetch_thirdparty ();
2019-01-27 11:55:16 +01:00
if ( $ret < 0 ) dol_print_error ( $db , $object -> error );
2013-03-29 15:36:54 +01:00
}
2018-10-29 18:19:40 +01:00
// Security check
2019-11-08 10:53:31 +01:00
$socid = '' ;
if ( ! empty ( $user -> socid )) $socid = $user -> socid ;
2018-10-29 18:28:19 +01:00
$isdraft = (( $object -> statut == FactureFournisseur :: STATUS_DRAFT ) ? 1 : 0 );
2018-10-30 14:47:39 +01:00
$result = restrictedArea ( $user , 'fournisseur' , $id , 'facture_fourn' , 'facture' , 'fk_soc' , 'rowid' , $isdraft );
2018-10-29 18:19:40 +01:00
2020-04-21 12:25:44 +02:00
// Common permissions
$usercanread = $user -> rights -> fournisseur -> facture -> lire ;
$usercancreate = $user -> rights -> fournisseur -> facture -> creer ;
$usercandelete = $user -> rights -> fournisseur -> facture -> supprimer ;
// Advanced permissions
$usercanvalidate = (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $usercancreate )) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> fournisseur -> supplier_invoice_advance -> validate )));
$usercansend = ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || $user -> rights -> fournisseur -> supplier_invoice_advance -> send );
// Permissions for includes
$permissionnote = $usercancreate ; // Used by the include of actions_setnotes.inc.php
$permissiondellink = $usercancreate ; // Used by the include of actions_dellink.inc.php
$permissiontoedit = $usercancreate ; // Used by the include of actions_lineupdown.inc.php
$permissiontoadd = $usercancreate ; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
2012-10-28 13:57:21 +01:00
/*
* Actions
2013-09-06 13:25:45 +02:00
*/
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +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
2014-09-28 03:41:32 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2014-07-22 04:24:08 +02:00
2015-02-28 03:11:15 +01:00
if ( empty ( $reshook ))
2012-10-28 13:57:21 +01:00
{
2017-09-17 15:38:50 +02:00
if ( $cancel )
{
2019-11-08 10:53:31 +01:00
if ( ! empty ( $backtopage ))
2017-09-17 15:38:50 +02:00
{
header ( " Location: " . $backtopage );
exit ;
}
2019-11-08 10:53:31 +01:00
$action = '' ;
2017-09-17 15:38:50 +02:00
}
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php' ; // Must be include, not include_once
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +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-08 10:53:31 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_lineupdown.inc.php' ; // Must be include, not include_once
2012-10-28 13:57:21 +01:00
2016-02-16 22:26:23 +01:00
// Link invoice to order
if ( GETPOST ( 'linkedOrder' ) && empty ( $cancel ) && $id > 0 )
{
2017-10-16 08:47:05 +02:00
$object -> fetch ( $id );
$object -> fetch_thirdparty ();
$result = $object -> add_object_linked ( 'order_supplier' , GETPOST ( 'linkedOrder' ));
2016-02-16 22:26:23 +01:00
}
2016-08-10 09:47:25 +02:00
2015-02-28 03:11:15 +01:00
// Action clone object
2019-04-12 12:12:08 +02:00
if ( $action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd )
2012-10-28 13:57:21 +01:00
{
2019-11-08 10:53:31 +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.
2019-04-12 12:12:08 +02:00
if ( GETPOST ( 'newsupplierref' , 'alphanohtml' )) $objectutil -> ref_supplier = GETPOST ( 'newsupplierref' , 'alphanohtml' );
$objectutil -> date = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'newdatemonth' , 'int' ), GETPOST ( 'newdateday' , 'int' ), GETPOST ( 'newdateyear' , 'int' ));
2019-11-08 10:53:31 +01:00
$result = $objectutil -> createFromClone ( $user , $id );
2019-04-12 12:12:08 +02:00
if ( $result > 0 )
{
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?id=' . $result );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2019-04-12 12:12:08 +02:00
$langs -> load ( " errors " );
setEventMessages ( $objectutil -> error , $objectutil -> errors , 'errors' );
2019-11-08 10:53:31 +01:00
$action = '' ;
2019-04-12 12:12:08 +02:00
}
2020-05-26 00:25:38 +02:00
} elseif ( $action == 'confirm_valid' && $confirm == 'yes' && $usercanvalidate ) {
2019-11-08 10:53:31 +01:00
$idwarehouse = GETPOST ( 'idwarehouse' );
2015-02-28 03:11:15 +01:00
2017-10-16 08:47:05 +02:00
$object -> fetch ( $id );
$object -> fetch_thirdparty ();
2015-02-28 03:11:15 +01:00
2019-11-08 10:53:31 +01:00
$qualified_for_stock_change = 0 ;
2017-10-16 08:47:05 +02:00
if ( empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
{
2019-11-08 10:53:31 +01:00
$qualified_for_stock_change = $object -> hasProductsOrServices ( 2 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 10:53:31 +01:00
$qualified_for_stock_change = $object -> hasProductsOrServices ( 1 );
2017-10-16 08:47:05 +02:00
}
2015-02-28 03:11:15 +01:00
2017-10-16 08:47:05 +02:00
// Check parameters
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> stock -> enabled ) && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_BILL ) && $qualified_for_stock_change )
2017-10-16 08:47:05 +02:00
{
$langs -> load ( " stocks " );
2019-11-08 10:53:31 +01:00
if ( ! $idwarehouse || $idwarehouse == - 1 )
2017-10-16 08:47:05 +02:00
{
$error ++ ;
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( " Warehouse " )), null , 'errors' );
2019-11-08 10:53:31 +01:00
$action = '' ;
2017-10-16 08:47:05 +02:00
}
}
2015-02-28 03:11:15 +01:00
2019-11-08 10:53:31 +01:00
if ( ! $error )
2017-10-16 08:47:05 +02:00
{
2019-01-27 11:55:16 +01:00
$result = $object -> validate ( $user , '' , $idwarehouse );
2017-10-16 08:47:05 +02:00
if ( $result < 0 )
{
2019-01-27 11:55:16 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2019-11-08 10:53:31 +01:00
} else {
2017-10-16 08:47:05 +02:00
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2019-01-27 11:55:16 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2017-10-16 08:47:05 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
2019-11-08 10:53:31 +01:00
if ( ! empty ( $newlang )) {
2017-10-16 08:47:05 +02:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2019-11-08 10:53:31 +01:00
$model = $object -> modelpdf ;
2017-10-16 08:47:05 +02:00
$ret = $object -> fetch ( $id ); // Reload to get new records
2017-06-07 16:44:04 +02:00
2019-11-08 10:53:31 +01:00
$result = $object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
2019-01-27 11:55:16 +01:00
if ( $result < 0 ) dol_print_error ( $db , $result );
2017-10-16 08:47:05 +02:00
}
}
}
2020-05-21 15:05:19 +02:00
} elseif ( $action == 'confirm_delete' && $confirm == 'yes' )
2015-02-28 03:11:15 +01:00
{
2017-10-16 08:47:05 +02:00
$object -> fetch ( $id );
$object -> fetch_thirdparty ();
2018-10-29 14:56:00 +01:00
2019-11-08 10:53:31 +01:00
$isErasable = $object -> is_erasable ();
2018-10-29 14:56:00 +01:00
2020-04-21 10:02:18 +02:00
if (( $usercandelete && $isErasable > 0 ) || ( $usercancreate && $isErasable == 1 ))
2017-10-16 08:47:05 +02:00
{
2019-11-08 10:53:31 +01:00
$result = $object -> delete ( $user );
2018-10-29 14:56:00 +01:00
if ( $result > 0 )
{
header ( 'Location: list.php?restore_lastsearch_values=1' );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2018-10-29 14:56:00 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2017-10-16 08:47:05 +02:00
}
2015-02-28 03:11:15 +01:00
}
2015-02-27 18:05:12 +01:00
2015-02-28 04:59:27 +01:00
// Remove a product line
2020-04-21 10:02:18 +02:00
elseif ( $action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate )
2015-02-28 03:11:15 +01:00
{
2015-02-28 04:59:27 +01:00
$result = $object -> deleteline ( $lineid );
if ( $result > 0 )
2015-02-28 03:11:15 +01:00
{
2015-02-28 04:59:27 +01:00
// Define output language
2016-10-16 21:29:12 +02:00
/* $outputlangs = $langs ;
2015-02-28 04:59:27 +01:00
$newlang = '' ;
2017-06-27 17:27:01 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' ))
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
2015-02-28 04:59:27 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ))
$newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
$ret = $object -> fetch ( $object -> id ); // Reload to get new records
$object -> generateDocument ( $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2016-10-16 21:29:12 +02:00
} */
2015-02-28 04:59:27 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
2015-02-28 03:11:15 +01:00
exit ;
2020-05-21 15:05:19 +02:00
} else {
2015-12-10 16:14:37 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-02-28 03:11:15 +01:00
/* Fix bug 1485 : Reset action to avoid asking again confirmation on failure */
2019-11-08 10:53:31 +01:00
$action = '' ;
2015-02-28 03:11:15 +01:00
}
}
2012-10-28 13:57:21 +01:00
2018-02-14 10:47:10 +01:00
// Delete link of credit note to invoice
2020-04-21 10:02:18 +02:00
elseif ( $action == 'unlinkdiscount' && $usercancreate )
2018-02-14 10:47:10 +01:00
{
$discount = new DiscountAbsolute ( $db );
$result = $discount -> fetch ( GETPOST ( " discountid " ));
2018-02-14 18:02:40 +01:00
$discount -> unlink_invoice ();
2020-05-26 00:25:38 +02:00
} elseif ( $action == 'confirm_paid' && $confirm == 'yes' && $usercancreate ) {
2017-10-16 08:47:05 +02:00
$object -> fetch ( $id );
2019-11-08 10:53:31 +01:00
$result = $object -> set_paid ( $user );
if ( $result < 0 )
2017-10-16 08:47:05 +02:00
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2015-02-28 03:11:15 +01:00
}
2012-10-28 13:57:21 +01:00
2015-02-28 03:11:15 +01:00
// Set supplier ref
2020-04-21 10:02:18 +02:00
if ( $action == 'setref_supplier' && $usercancreate )
2015-02-28 03:11:15 +01:00
{
2016-04-16 18:44:31 +02:00
$object -> ref_supplier = GETPOST ( 'ref_supplier' , 'alpha' );
2016-08-10 09:47:25 +02:00
2016-04-30 13:58:35 +02:00
if ( $object -> update ( $user ) < 0 ) {
2016-04-23 13:44:43 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
2019-10-27 09:51:15 +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' );
2019-10-27 09:51:15 +01:00
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
2019-11-08 10:53:31 +01:00
if ( ! empty ( $newlang )) {
2019-10-27 09:51:15 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
$ret = $object -> fetch ( $object -> id ); // Reload to get new records
$object -> generateDocument ( $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
2016-09-28 18:59:44 +02:00
}
2015-02-28 03:11:15 +01:00
}
2012-10-28 13:57:21 +01:00
2015-12-10 16:14:37 +01:00
// payments conditions
2020-04-21 10:02:18 +02:00
if ( $action == 'setconditions' && $usercancreate )
2015-02-28 03:11:15 +01:00
{
2019-11-08 10:53:31 +01:00
$result = $object -> setPaymentTerms ( GETPOST ( 'cond_reglement_id' , 'int' ));
2015-02-28 03:11:15 +01:00
}
2014-05-29 18:58:55 +02:00
2018-04-12 21:39:12 +02:00
// Set incoterm
elseif ( $action == 'set_incoterms' && ! empty ( $conf -> incoterm -> enabled ))
{
$result = $object -> setIncoterms ( GETPOST ( 'incoterm_id' , 'int' ), GETPOST ( 'location_incoterms' , 'alpha' ));
2015-02-28 03:11:15 +01:00
}
2014-05-29 18:58:55 +02:00
2015-12-10 16:14:37 +01:00
// payment mode
2020-04-21 10:02:18 +02:00
elseif ( $action == 'setmode' && $usercancreate )
2015-02-28 03:11:15 +01:00
{
2019-01-27 11:55:16 +01:00
$result = $object -> setPaymentMethods ( GETPOST ( 'mode_reglement_id' , 'int' ));
2015-02-28 03:11:15 +01:00
}
2016-08-10 09:47:25 +02:00
2016-02-19 22:25:59 +01:00
// Multicurrency Code
2020-04-21 10:02:18 +02:00
elseif ( $action == 'setmulticurrencycode' && $usercancreate ) {
2016-02-19 22:25:59 +01:00
$result = $object -> setMulticurrencyCode ( GETPOST ( 'multicurrency_code' , 'alpha' ));
}
// Multicurrency rate
2020-04-21 10:02:18 +02:00
elseif ( $action == 'setmulticurrencyrate' && $usercancreate ) {
2017-09-25 19:45:01 +02:00
$result = $object -> setMulticurrencyRate ( price2num ( GETPOST ( 'multicurrency_tx' , 'alpha' )));
2016-02-19 22:25:59 +01:00
}
2014-05-06 18:31:39 +02:00
2015-02-28 03:11:15 +01:00
// bank account
2020-04-21 10:02:18 +02:00
elseif ( $action == 'setbankaccount' && $usercancreate ) {
2019-11-08 10:53:31 +01:00
$result = $object -> setBankAccount ( GETPOST ( 'fk_account' , 'int' ));
2015-02-28 03:11:15 +01:00
}
2013-11-17 23:25:25 +01:00
2015-02-28 03:11:15 +01:00
// Set label
2020-04-21 10:02:18 +02:00
elseif ( $action == 'setlabel' && $usercancreate )
2013-11-17 23:25:25 +01:00
{
2017-10-16 08:47:05 +02:00
$object -> fetch ( $id );
2019-11-08 10:53:31 +01:00
$object -> label = GETPOST ( 'label' );
$result = $object -> update ( $user );
2017-10-16 08:47:05 +02:00
if ( $result < 0 ) dol_print_error ( $db );
2020-05-26 00:25:38 +02:00
} elseif ( $action == 'setdatef' && $usercancreate ) {
2019-11-08 10:53:31 +01:00
$newdate = dol_mktime ( 0 , 0 , 0 , $_POST [ 'datefmonth' ], $_POST [ 'datefday' ], $_POST [ 'datefyear' ]);
if ( $newdate > ( dol_now () + ( empty ( $conf -> global -> INVOICE_MAX_OFFSET_IN_FUTURE ) ? 0 : $conf -> global -> INVOICE_MAX_OFFSET_IN_FUTURE )))
2017-10-16 08:47:05 +02:00
{
if ( empty ( $conf -> global -> INVOICE_MAX_OFFSET_IN_FUTURE )) setEventMessages ( $langs -> trans ( " WarningInvoiceDateInFuture " ), null , 'warnings' );
else setEventMessages ( $langs -> trans ( " WarningInvoiceDateTooFarInFuture " ), null , 'warnings' );
}
2017-02-02 20:07:41 +01:00
2017-10-16 08:47:05 +02:00
$object -> fetch ( $id );
2017-01-27 01:46:21 +01:00
2019-11-08 10:53:31 +01:00
$object -> date = $newdate ;
$date_echence_calc = $object -> calculate_date_lim_reglement ();
if ( ! empty ( $object -> date_echeance ) && $object -> date_echeance < $date_echence_calc )
2017-10-16 08:47:05 +02:00
{
$object -> date_echeance = $date_echence_calc ;
}
if ( $object -> date_echeance && $object -> date_echeance < $object -> date )
{
2019-11-08 10:53:31 +01:00
$object -> date_echeance = $object -> date ;
2017-10-16 08:47:05 +02:00
}
2017-01-27 01:46:21 +01:00
2019-11-08 10:53:31 +01:00
$result = $object -> update ( $user );
2019-01-27 11:55:16 +01:00
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
2020-05-26 00:25:38 +02:00
} elseif ( $action == 'setdate_lim_reglement' && $usercancreate ) {
2017-10-16 08:47:05 +02:00
$object -> fetch ( $id );
2019-11-08 10:53:31 +01:00
$object -> date_echeance = dol_mktime ( 12 , 0 , 0 , $_POST [ 'date_lim_reglementmonth' ], $_POST [ 'date_lim_reglementday' ], $_POST [ 'date_lim_reglementyear' ]);
if ( ! empty ( $object -> date_echeance ) && $object -> date_echeance < $object -> date )
2017-10-16 08:47:05 +02:00
{
2019-11-08 10:53:31 +01:00
$object -> date_echeance = $object -> date ;
2017-10-16 08:47:05 +02:00
setEventMessages ( $langs -> trans ( " DatePaymentTermCantBeLowerThanObjectDate " ), null , 'warnings' );
}
2019-11-08 10:53:31 +01:00
$result = $object -> update ( $user );
2019-01-27 11:55:16 +01:00
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
2020-05-21 15:05:19 +02:00
} elseif ( $action == " setabsolutediscount " && $usercancreate )
2018-02-14 10:47:10 +01:00
{
// POST[remise_id] or POST[remise_id_for_payment]
2018-03-08 20:49:37 +01:00
2018-02-14 10:47:10 +01:00
// We use the credit to reduce amount of invoice
2019-11-08 10:53:31 +01:00
if ( ! empty ( $_POST [ " remise_id " ])) {
2018-02-14 10:47:10 +01:00
$ret = $object -> fetch ( $id );
if ( $ret > 0 ) {
$result = $object -> insert_discount ( $_POST [ " remise_id " ]);
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
} else {
dol_print_error ( $db , $object -> error );
}
}
// We use the credit to reduce remain to pay
2019-11-08 10:53:31 +01:00
if ( ! empty ( $_POST [ " remise_id_for_payment " ]))
2018-02-14 10:47:10 +01:00
{
2019-11-08 10:53:31 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php' ;
2018-02-14 10:47:10 +01:00
$discount = new DiscountAbsolute ( $db );
$discount -> fetch ( $_POST [ " remise_id_for_payment " ]);
2018-03-08 20:49:37 +01:00
2018-02-14 10:47:10 +01:00
//var_dump($object->getRemainToPay(0));
//var_dump($discount->amount_ttc);exit;
2019-02-28 19:30:44 +01:00
if ( price2num ( $discount -> amount_ttc ) > price2num ( $object -> getRemainToPay ( 0 )))
2018-02-14 10:47:10 +01:00
{
// TODO Split the discount in 2 automatically
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorDiscountLargerThanRemainToPaySplitItBefore " ), null , 'errors' );
}
2019-11-08 10:53:31 +01:00
if ( ! $error )
2018-02-14 10:47:10 +01:00
{
2018-02-14 18:02:40 +01:00
$result = $discount -> link_to_invoice ( 0 , $id );
2018-02-14 10:47:10 +01:00
if ( $result < 0 ) {
setEventMessages ( $discount -> error , $discount -> errors , 'errors' );
}
}
}
2018-03-08 20:49:37 +01:00
2018-02-14 10:47:10 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2019-01-27 11:55:16 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2018-02-14 10:47:10 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
2019-11-08 10:53:31 +01:00
if ( ! empty ( $newlang )) {
2018-02-14 10:47:10 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$ret = $object -> fetch ( $id ); // Reload to get new records
2018-03-08 20:49:37 +01:00
2018-02-14 10:47:10 +01:00
$result = $object -> generateDocument ( $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
if ( $result < 0 ) setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
// Convertir en reduc
2020-01-01 19:04:14 +01:00
elseif ( $action == 'confirm_converttoreduc' && $confirm == 'yes' && $usercancreate )
2018-02-14 10:47:10 +01:00
{
$object -> fetch ( $id );
$object -> fetch_thirdparty ();
//$object->fetch_lines(); // Already done into fetch
2018-03-08 20:49:37 +01:00
2018-02-14 10:47:10 +01:00
// Check if there is already a discount (protection to avoid duplicate creation when resubmit post)
2019-11-08 10:53:31 +01:00
$discountcheck = new DiscountAbsolute ( $db );
$result = $discountcheck -> fetch ( 0 , 0 , $object -> id );
2018-02-14 10:47:10 +01:00
2019-11-08 10:53:31 +01:00
$canconvert = 0 ;
if ( $object -> type == FactureFournisseur :: 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)
2020-01-01 19:04:14 +01:00
if (( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE || $object -> type == FactureFournisseur :: TYPE_STANDARD ) && $object -> paye == 0 && empty ( $discountcheck -> id )) $canconvert = 1 ; // we can convert credit note into discount if credit note is not refunded completely and not already converted and amount of payment is 0 (see also the real condition used as the condition to show button converttoreduc)
2018-02-14 10:47:10 +01:00
if ( $canconvert )
{
$db -> begin ();
2018-03-08 20:49:37 +01:00
2018-02-14 10:47:10 +01:00
$amount_ht = $amount_tva = $amount_ttc = array ();
2020-01-01 19:04:14 +01:00
$multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array ();
2020-01-01 22:58:26 +01:00
2018-02-14 10:47:10 +01:00
// Loop on each vat rate
$i = 0 ;
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
{ // no need to create discount if amount is null
$amount_ht [ $line -> tva_tx ] += $line -> total_ht ;
$amount_tva [ $line -> tva_tx ] += $line -> total_tva ;
$amount_ttc [ $line -> tva_tx ] += $line -> total_ttc ;
2019-11-08 10:53:31 +01:00
$i ++ ;
2018-02-14 10:47:10 +01:00
}
}
2018-03-08 20:49:37 +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
2020-04-10 10:59:32 +02:00
if ( ! empty ( $conf -> global -> SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED )) {
$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-04-10 10:59:32 +02: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' );
}
}
}
//var_dump($amount_ht);var_dump($amount_tva);var_dump($amount_ttc);exit;
2018-02-14 10:47:10 +01:00
// Insert one discount by VAT rate category
$discount = new DiscountAbsolute ( $db );
if ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE )
$discount -> description = '(CREDIT_NOTE)' ;
elseif ( $object -> type == FactureFournisseur :: TYPE_DEPOSIT )
$discount -> description = '(DEPOSIT)' ;
elseif ( $object -> type == FactureFournisseur :: TYPE_STANDARD || $object -> type == FactureFournisseur :: TYPE_REPLACEMENT || $object -> type == FactureFournisseur :: TYPE_SITUATION )
$discount -> description = '(EXCESS PAID)' ;
else {
setEventMessages ( $langs -> trans ( 'CantConvertToReducAnInvoiceOfThisType' ), null , 'errors' );
}
2018-02-14 18:02:40 +01:00
$discount -> discount_type = 1 ; // Supplier discount
2018-02-14 10:47:10 +01:00
$discount -> fk_soc = $object -> socid ;
$discount -> fk_invoice_supplier_source = $object -> id ;
2018-03-08 20:49:37 +01:00
2018-02-14 10:47:10 +01:00
$error = 0 ;
2018-03-08 20:49:37 +01:00
2018-02-14 10:47:10 +01:00
if ( $object -> type == FactureFournisseur :: TYPE_STANDARD || $object -> type == FactureFournisseur :: TYPE_REPLACEMENT || $object -> type == FactureFournisseur :: TYPE_SITUATION )
{
// If we're on a standard invoice, we have to get excess paid to create a discount in TTC without VAT
2018-03-08 20:49:37 +01:00
2020-01-01 19:04:14 +01:00
// Total payments
2018-02-14 10:47:10 +01:00
$sql = 'SELECT SUM(pf.amount) as total_paiements' ;
2019-11-08 10:53:31 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiementfourn_facturefourn as pf, ' . MAIN_DB_PREFIX . 'paiementfourn as p' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN (' . getEntity ( 'c_paiement' ) . ')' ;
$sql .= ' WHERE pf.fk_facturefourn = ' . $object -> id ;
$sql .= ' AND pf.fk_paiementfourn = p.rowid' ;
$sql .= ' AND p.entity IN (' . getEntity ( 'invoice' ) . ')' ;
2018-02-14 10:47:10 +01:00
$resql = $db -> query ( $sql );
2019-11-08 10:53:31 +01:00
if ( ! $resql ) dol_print_error ( $db );
2018-02-14 10:47:10 +01:00
$res = $db -> fetch_object ( $resql );
$total_paiements = $res -> total_paiements ;
2018-03-08 20:49:37 +01:00
2020-01-01 19:04:14 +01:00
// Total credit note and deposit
$total_creditnote_and_deposit = 0 ;
$sql = " SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, " ;
$sql .= " re.description, re.fk_invoice_supplier_source " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_remise_except as re " ;
$sql .= " WHERE fk_invoice_supplier = " . $object -> id ;
$resql = $db -> query ( $sql );
if ( ! empty ( $resql )) {
while ( $obj = $db -> fetch_object ( $resql )) {
$total_creditnote_and_deposit += $obj -> amount_ttc ;
}
} else dol_print_error ( $db );
2020-01-01 22:58:26 +01:00
2020-01-01 19:04:14 +01:00
$discount -> amount_ht = $discount -> amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object -> total_ttc ;
2018-02-14 10:47:10 +01:00
$discount -> amount_tva = 0 ;
$discount -> tva_tx = 0 ;
$result = $discount -> create ( $user );
if ( $result < 0 )
{
$error ++ ;
}
}
if ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE || $object -> type == FactureFournisseur :: TYPE_DEPOSIT )
{
foreach ( $amount_ht as $tva_tx => $xxx )
{
$discount -> amount_ht = abs ( $amount_ht [ $tva_tx ]);
$discount -> amount_tva = abs ( $amount_tva [ $tva_tx ]);
$discount -> amount_ttc = abs ( $amount_ttc [ $tva_tx ]);
$discount -> tva_tx = abs ( $tva_tx );
2018-03-08 20:49:37 +01:00
2018-02-14 10:47:10 +01:00
$result = $discount -> create ( $user );
if ( $result < 0 )
{
$error ++ ;
break ;
}
}
}
2018-03-08 20:49:37 +01:00
2018-02-14 10:47:10 +01:00
if ( empty ( $error ))
{
2019-11-08 10:53:31 +01:00
if ( $object -> type != FactureFournisseur :: TYPE_DEPOSIT ) {
2018-02-14 10:47:10 +01:00
// Classe facture
$result = $object -> set_paid ( $user );
if ( $result >= 0 )
{
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2018-02-14 10:47:10 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$db -> rollback ();
}
} else {
$db -> commit ();
}
2020-05-21 15:05:19 +02:00
} else {
2018-02-14 10:47:10 +01:00
setEventMessages ( $discount -> error , $discount -> errors , 'errors' );
$db -> rollback ();
}
}
}
2018-03-08 20:49:37 +01:00
2012-10-28 13:57:21 +01:00
2015-02-28 03:11:15 +01:00
// Delete payment
2020-04-21 10:02:18 +02:00
elseif ( $action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercancreate )
2014-05-29 18:58:55 +02:00
{
2016-07-01 16:59:03 +02:00
$object -> fetch ( $id );
2017-10-16 08:47:05 +02:00
if ( $object -> statut == FactureFournisseur :: STATUS_VALIDATED && $object -> paye == 0 )
{
$paiementfourn = new PaiementFourn ( $db );
2019-11-08 10:53:31 +01:00
$result = $paiementfourn -> fetch ( GETPOST ( 'paiement_id' ));
2017-10-16 08:47:05 +02:00
if ( $result > 0 ) {
2019-11-08 10:53:31 +01:00
$result = $paiementfourn -> delete (); // If fetch ok and found
2017-10-16 08:47:05 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
}
if ( $result < 0 ) {
setEventMessages ( $paiementfourn -> error , $paiementfourn -> errors , 'errors' );
}
}
2015-02-28 03:11:15 +01:00
}
2012-10-28 13:57:21 +01:00
2015-02-28 03:11:15 +01:00
// Create
2020-01-01 19:04:14 +01:00
elseif ( $action == 'add' && $usercancreate )
2015-02-28 03:11:15 +01:00
{
2016-10-03 20:41:39 +02:00
if ( $socid > 0 ) $object -> socid = GETPOST ( 'socid' , 'int' );
2015-02-28 03:11:15 +01:00
2016-10-03 20:41:39 +02:00
$db -> begin ();
2015-02-28 03:11:15 +01:00
2016-10-03 20:41:39 +02:00
$error = 0 ;
2015-02-28 03:11:15 +01:00
2016-10-03 20:41:39 +02:00
// Fill array 'array_options' with data from add form
2019-10-06 14:41:52 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
2016-10-03 20:41:39 +02:00
if ( $ret < 0 ) $error ++ ;
2015-02-28 03:11:15 +01:00
2020-05-21 09:34:20 +02:00
$datefacture = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'remonth' , 'int' ), GETPOST ( 'reday' , 'int' ), GETPOST ( 'reyear' , 'int' ));
2019-11-08 10:53:31 +01:00
$datedue = dol_mktime ( 12 , 0 , 0 , $_POST [ 'echmonth' ], $_POST [ 'echday' ], $_POST [ 'echyear' ]);
2015-02-28 03:11:15 +01:00
2016-10-03 20:41:39 +02:00
// Replacement invoice
if ( $_POST [ 'type' ] == FactureFournisseur :: TYPE_REPLACEMENT )
{
if ( $datefacture == '' )
{
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentities ( 'DateInvoice' )), null , 'errors' );
2019-11-08 10:53:31 +01:00
$action = 'create' ;
$_GET [ 'socid' ] = $_POST [ 'socid' ];
2016-10-03 20:41:39 +02:00
$error ++ ;
}
2020-04-10 10:59:32 +02:00
if ( ! ( GETPOST ( 'fac_replacement' , 'int' ) > 0 )) {
2019-11-08 10:53:31 +01:00
$error ++ ;
2016-10-03 20:41:39 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ReplaceInvoice " )), null , 'errors' );
}
2015-02-28 03:11:15 +01:00
2019-11-08 10:53:31 +01:00
if ( ! $error ) {
2016-10-03 20:41:39 +02:00
// This is a replacement invoice
2020-01-01 19:04:14 +01:00
$result = $object -> fetch ( GETPOST ( 'fac_replacement' , 'int' ));
2016-10-03 20:41:39 +02:00
$object -> fetch_thirdparty ();
2019-11-08 10:53:31 +01:00
$object -> ref = GETPOST ( 'ref' , 'nohtml' );
$object -> ref_supplier = GETPOST ( 'ref_supplier' , 'alpha' );
$object -> socid = GETPOST ( 'socid' , 'int' );
$object -> libelle = GETPOST ( 'label' , 'nohtml' );
$object -> date = $datefacture ;
$object -> date_echeance = $datedue ;
$object -> note_public = GETPOST ( 'note_public' , 'none' );
$object -> note_private = GETPOST ( 'note_private' , 'none' );
2016-10-03 20:41:39 +02:00
$object -> cond_reglement_id = GETPOST ( 'cond_reglement_id' );
$object -> mode_reglement_id = GETPOST ( 'mode_reglement_id' );
$object -> fk_account = GETPOST ( 'fk_account' , 'int' );
$object -> fk_project = ( $tmpproject > 0 ) ? $tmpproject : null ;
2019-11-08 10:53:31 +01:00
$object -> fk_incoterms = GETPOST ( 'incoterm_id' , 'int' );
2016-10-03 20:41:39 +02:00
$object -> location_incoterms = GETPOST ( 'location_incoterms' , 'alpha' );
$object -> multicurrency_code = GETPOST ( 'multicurrency_code' , 'alpha' );
2019-11-08 10:53:31 +01:00
$object -> multicurrency_tx = GETPOST ( 'originmulticurrency_tx' , 'int' );
2016-10-03 20:41:39 +02:00
// Proprietes particulieres a facture de remplacement
2016-12-18 01:44:26 +01:00
$object -> fk_facture_source = GETPOST ( 'fac_replacement' );
2016-10-03 20:41:39 +02:00
$object -> type = FactureFournisseur :: TYPE_REPLACEMENT ;
$id = $object -> createFromCurrent ( $user );
if ( $id <= 0 ) {
2017-10-16 08:47:05 +02:00
$error ++ ;
2016-10-03 20:41:39 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
}
2015-02-28 03:11:15 +01:00
2016-10-03 20:41:39 +02:00
// Credit note invoice
if ( $_POST [ 'type' ] == FactureFournisseur :: TYPE_CREDIT_NOTE )
{
2019-01-27 11:55:16 +01:00
$sourceinvoice = GETPOST ( 'fac_avoir' , 'int' );
2019-11-08 10:53:31 +01:00
if ( ! ( $sourceinvoice > 0 ) && empty ( $conf -> global -> INVOICE_CREDIT_NOTE_STANDALONE ))
2016-10-03 20:41:39 +02:00
{
2019-11-08 10:53:31 +01:00
$error ++ ;
2016-10-03 20:41:39 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CorrectInvoice " )), null , 'errors' );
}
2019-11-08 10:53:31 +01:00
if ( GETPOST ( 'socid' , 'int' ) < 1 )
2016-10-03 20:41:39 +02:00
{
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentities ( 'Supplier' )), null , 'errors' );
2019-11-08 10:53:31 +01:00
$action = 'create' ;
2016-10-03 20:41:39 +02:00
$error ++ ;
}
if ( $datefacture == '' )
{
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentities ( 'DateInvoice' )), null , 'errors' );
2019-11-08 10:53:31 +01:00
$action = 'create' ;
$_GET [ 'socid' ] = $_POST [ 'socid' ];
2016-10-03 20:41:39 +02:00
$error ++ ;
}
2019-11-08 10:53:31 +01:00
if ( ! GETPOST ( 'ref_supplier' ))
2016-10-03 20:41:39 +02:00
{
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentities ( 'RefSupplier' )), null , 'errors' );
2019-11-08 10:53:31 +01:00
$action = 'create' ;
$_GET [ 'socid' ] = $_POST [ 'socid' ];
2016-10-03 20:41:39 +02:00
$error ++ ;
}
2015-02-28 03:11:15 +01:00
2019-11-08 10:53:31 +01:00
if ( ! $error )
2016-10-03 20:41:39 +02:00
{
$tmpproject = GETPOST ( 'projectid' , 'int' );
// Creation facture
2019-11-08 10:53:31 +01:00
$object -> ref = GETPOST ( 'ref' , 'nohtml' );
$object -> ref_supplier = GETPOST ( 'ref_supplier' , 'nohtml' );
2019-11-02 12:59:38 +01:00
$object -> socid = GETPOST ( 'socid' , 'int' );
2019-11-08 10:53:31 +01:00
$object -> libelle = GETPOST ( 'label' , 'nohtml' );
2019-11-02 12:59:38 +01:00
$object -> label = GETPOST ( 'label' , 'nohtml' );
2019-11-08 10:53:31 +01:00
$object -> date = $datefacture ;
$object -> date_echeance = $datedue ;
$object -> note_public = GETPOST ( 'note_public' , 'none' );
$object -> note_private = GETPOST ( 'note_private' , 'none' );
2016-10-03 20:41:39 +02:00
$object -> cond_reglement_id = GETPOST ( 'cond_reglement_id' );
$object -> mode_reglement_id = GETPOST ( 'mode_reglement_id' );
$object -> fk_account = GETPOST ( 'fk_account' , 'int' );
$object -> fk_project = ( $tmpproject > 0 ) ? $tmpproject : null ;
2019-11-08 10:53:31 +01:00
$object -> fk_incoterms = GETPOST ( 'incoterm_id' , 'int' );
2016-10-03 20:41:39 +02:00
$object -> location_incoterms = GETPOST ( 'location_incoterms' , 'alpha' );
$object -> multicurrency_code = GETPOST ( 'multicurrency_code' , 'alpha' );
2019-11-08 10:53:31 +01:00
$object -> multicurrency_tx = GETPOST ( 'originmulticurrency_tx' , 'int' );
2016-10-03 20:41:39 +02:00
// Proprietes particulieres a facture avoir
2019-11-08 10:53:31 +01:00
$object -> fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice : '' ;
2016-10-03 20:41:39 +02:00
$object -> type = FactureFournisseur :: TYPE_CREDIT_NOTE ;
$id = $object -> create ( $user );
2019-11-08 10:53:31 +01:00
if ( $id <= 0 ) {
2018-02-14 10:47:10 +01:00
$error ++ ;
}
2019-11-08 10:53:31 +01:00
if ( GETPOST ( 'invoiceAvoirWithLines' , 'int' ) == 1 && $id > 0 )
2016-10-03 20:41:39 +02:00
{
$facture_source = new FactureFournisseur ( $db ); // fetch origin object
2019-11-08 10:53:31 +01:00
if ( $facture_source -> fetch ( $object -> fk_facture_source ) > 0 )
2016-10-03 20:41:39 +02:00
{
$fk_parent_line = 0 ;
2015-02-28 03:11:15 +01:00
2019-11-08 10:53:31 +01:00
foreach ( $facture_source -> lines as $line )
2016-10-03 20:41:39 +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 ) {
2016-11-02 07:13:17 +01:00
$fk_parent_line = 0 ;
2016-10-03 20:41:39 +02:00
}
2016-08-10 09:47:25 +02:00
2016-11-02 07:13:17 +01:00
$line -> fk_facture_fourn = $object -> id ;
2016-10-03 20:41:39 +02:00
$line -> fk_parent_line = $fk_parent_line ;
2016-08-10 09:47:25 +02:00
2019-11-08 10:53:31 +01:00
$line -> subprice = - $line -> subprice ; // invert price for object
2016-10-03 20:41:39 +02:00
$line -> pa_ht = - $line -> pa_ht ;
2019-11-08 10:53:31 +01: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 ;
2015-02-28 03:11:15 +01:00
2016-10-03 20:41:39 +02:00
$result = $line -> insert ();
2016-08-10 09:47:25 +02:00
2016-10-03 20:41:39 +02:00
$object -> lines [] = $line ; // insert new line in current object
2015-02-28 03:11:15 +01:00
2016-10-03 20:41:39 +02:00
// Defined the new fk_parent_line
if ( $result > 0 && $line -> product_type == 9 ) {
2017-10-16 08:47:05 +02:00
$fk_parent_line = $result ;
2016-10-03 20:41:39 +02:00
}
}
2015-02-28 03:11:15 +01:00
2016-10-03 20:41:39 +02:00
$object -> update_price ( 1 );
}
}
2019-11-08 10:53:31 +01:00
if ( GETPOST ( 'invoiceAvoirWithPaymentRestAmount' , 'int' ) == 1 && $id > 0 )
2016-10-03 20:41:39 +02:00
{
$facture_source = new FactureFournisseur ( $db ); // fetch origin object if not previously defined
2019-11-08 10:53:31 +01:00
if ( $facture_source -> fetch ( $object -> fk_facture_source ) > 0 )
2016-10-03 20:41:39 +02:00
{
$totalpaye = $facture_source -> getSommePaiement ();
$totalcreditnotes = $facture_source -> getSumCreditNotesUsed ();
$totaldeposits = $facture_source -> getSumDepositsUsed ();
$remain_to_pay = abs ( $facture_source -> total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits );
2019-02-28 19:06:51 +01:00
$object -> addline ( $langs -> trans ( 'invoiceAvoirLineWithPaymentRestAmount' ), $remain_to_pay , 0 , 0 , 0 , 1 , 0 , 0 , '' , '' , 'TTC' );
2016-10-03 20:41:39 +02:00
}
}
}
}
// Standard or deposit
if ( $_POST [ 'type' ] == FactureFournisseur :: TYPE_STANDARD || $_POST [ 'type' ] == FactureFournisseur :: TYPE_DEPOSIT )
{
2019-11-08 10:53:31 +01:00
if ( GETPOST ( 'socid' , 'int' ) < 1 )
2016-10-03 20:41:39 +02:00
{
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentities ( 'Supplier' )), null , 'errors' );
2019-11-08 10:53:31 +01:00
$action = 'create' ;
2016-10-03 20:41:39 +02:00
$error ++ ;
}
if ( $datefacture == '' )
{
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentities ( 'DateInvoice' )), null , 'errors' );
2019-11-08 10:53:31 +01:00
$action = 'create' ;
$_GET [ 'socid' ] = $_POST [ 'socid' ];
2016-10-03 20:41:39 +02:00
$error ++ ;
}
2019-11-08 10:53:31 +01:00
if ( ! GETPOST ( 'ref_supplier' ))
2016-10-03 20:41:39 +02:00
{
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentities ( 'RefSupplier' )), null , 'errors' );
2019-11-08 10:53:31 +01:00
$action = 'create' ;
$_GET [ 'socid' ] = $_POST [ 'socid' ];
2016-10-03 20:41:39 +02:00
$error ++ ;
}
2019-11-08 10:53:31 +01:00
if ( ! $error )
2016-10-03 20:41:39 +02:00
{
$tmpproject = GETPOST ( 'projectid' , 'int' );
// Creation facture
$object -> ref = $_POST [ 'ref' ];
$object -> ref_supplier = $_POST [ 'ref_supplier' ];
$object -> socid = $_POST [ 'socid' ];
$object -> libelle = $_POST [ 'label' ];
$object -> date = $datefacture ;
$object -> date_echeance = $datedue ;
2019-01-27 11:55:16 +01:00
$object -> note_public = GETPOST ( 'note_public' , 'none' );
$object -> note_private = GETPOST ( 'note_private' , 'none' );
2016-10-03 20:41:39 +02:00
$object -> cond_reglement_id = GETPOST ( 'cond_reglement_id' );
$object -> mode_reglement_id = GETPOST ( 'mode_reglement_id' );
$object -> fk_account = GETPOST ( 'fk_account' , 'int' );
2019-11-08 10:53:31 +01:00
$object -> fk_project = ( $tmpproject > 0 ) ? $tmpproject : null ;
2016-10-03 20:41:39 +02:00
$object -> fk_incoterms = GETPOST ( 'incoterm_id' , 'int' );
$object -> location_incoterms = GETPOST ( 'location_incoterms' , 'alpha' );
$object -> multicurrency_code = GETPOST ( 'multicurrency_code' , 'alpha' );
$object -> multicurrency_tx = GETPOST ( 'originmulticurrency_tx' , 'int' );
// Auto calculation of date due if not filled by user
2019-11-08 10:53:31 +01:00
if ( empty ( $object -> date_echeance )) $object -> date_echeance = $object -> calculate_date_lim_reglement ();
2016-10-03 20:41:39 +02:00
2019-06-14 18:28:01 +02:00
$object -> fetch_thirdparty ();
2016-10-03 20:41:39 +02:00
// If creation from another object of another module
2019-11-08 10:53:31 +01:00
if ( ! $error && $_POST [ 'origin' ] && $_POST [ 'originid' ])
2016-10-03 20:41:39 +02:00
{
// Parse element/subelement (ex: project_task)
2020-02-25 15:14:37 +01:00
$element = $subelement = GETPOST ( 'origin' , 'alpha' );
2016-10-03 20:41:39 +02:00
/* if ( preg_match ( '/^([^_]+)_([^_]+)/i' , $_POST [ 'origin' ], $regs ))
{
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
} */
// For compatibility
2019-11-08 10:53:31 +01:00
if ( $element == 'order' ) {
2016-10-03 20:41:39 +02:00
$element = $subelement = 'commande' ;
}
2019-11-08 10:53:31 +01:00
if ( $element == 'propal' ) {
2016-10-03 20:41:39 +02:00
$element = 'comm/propal' ; $subelement = 'propal' ;
}
if ( $element == 'contract' ) {
$element = $subelement = 'contrat' ;
}
if ( $element == 'order_supplier' ) {
$element = 'fourn' ; $subelement = 'fournisseur.commande' ;
}
if ( $element == 'project' )
{
$element = 'projet' ;
}
2020-02-25 15:14:37 +01:00
$object -> origin = GETPOST ( 'origin' , 'alpha' );
$object -> origin_id = GETPOST ( 'originid' , 'int' );
2016-10-03 20:41:39 +02:00
2019-01-17 19:27:26 +01:00
2018-10-18 10:26:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/' . $element . '/class/' . $subelement . '.class.php' ;
$classname = ucfirst ( $subelement );
2019-11-08 10:53:31 +01:00
if ( $classname == 'Fournisseur.commande' ) $classname = 'CommandeFournisseur' ;
2018-10-18 10:26:32 +02:00
$objectsrc = new $classname ( $db );
$objectsrc -> fetch ( $originid );
$objectsrc -> fetch_thirdparty ();
2020-03-27 16:02:58 +01:00
if ( ! empty ( $object -> origin ) && ! empty ( $object -> origin_id ))
{
$object -> linkedObjectsIds [ $object -> origin ] = $object -> origin_id ;
}
// Add also link with order if object is reception
2018-10-18 10:26:32 +02:00
if ( $object -> origin == 'reception' )
{
$objectsrc -> fetchObjectLinked ();
if ( count ( $objectsrc -> linkedObjectsIds [ 'order_supplier' ]) > 0 )
{
foreach ( $objectsrc -> linkedObjectsIds [ 'order_supplier' ] as $key => $value )
{
2020-03-27 16:02:58 +01:00
$object -> linkedObjectsIds [ 'order_supplier' ] = $value ;
2018-10-18 10:26:32 +02:00
}
}
}
2016-10-03 20:41:39 +02:00
$id = $object -> create ( $user );
// Add lines
if ( $id > 0 )
{
require_once DOL_DOCUMENT_ROOT . '/' . $element . '/class/' . $subelement . '.class.php' ;
$classname = ucfirst ( $subelement );
2019-11-08 10:53:31 +01:00
if ( $classname == 'Fournisseur.commande' ) $classname = 'CommandeFournisseur' ;
2016-10-03 20:41:39 +02:00
$srcobject = new $classname ( $db );
2019-11-08 10:53:31 +01:00
$result = $srcobject -> fetch ( GETPOST ( 'originid' , 'int' ));
2016-10-03 20:41:39 +02:00
if ( $result > 0 )
{
$lines = $srcobject -> lines ;
2019-01-27 11:55:16 +01:00
if ( empty ( $lines ) && method_exists ( $srcobject , 'fetch_lines' ))
2016-10-03 20:41:39 +02:00
{
$srcobject -> fetch_lines ();
$lines = $srcobject -> lines ;
}
2019-11-08 10:53:31 +01:00
$num = count ( $lines );
2018-02-14 10:47:10 +01:00
for ( $i = 0 ; $i < $num ; $i ++ ) // TODO handle subprice < 0
2016-10-03 20:41:39 +02:00
{
2019-11-08 10:53:31 +01:00
$desc = ( $lines [ $i ] -> desc ? $lines [ $i ] -> desc : $lines [ $i ] -> libelle );
$product_type = ( $lines [ $i ] -> product_type ? $lines [ $i ] -> product_type : 0 );
2016-10-03 20:41:39 +02:00
2018-01-02 12:06:11 +01:00
// 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 ();
2018-01-02 12:06:11 +01:00
}
2018-01-12 00:16:55 +01:00
2016-10-03 20:41:39 +02:00
// Dates
// TODO mutualiser
2019-11-08 10:53:31 +01:00
$date_start = $lines [ $i ] -> date_debut_prevue ;
if ( $lines [ $i ] -> date_debut_reel ) $date_start = $lines [ $i ] -> date_debut_reel ;
if ( $lines [ $i ] -> date_start ) $date_start = $lines [ $i ] -> date_start ;
$date_end = $lines [ $i ] -> date_fin_prevue ;
if ( $lines [ $i ] -> date_fin_reel ) $date_end = $lines [ $i ] -> date_fin_reel ;
if ( $lines [ $i ] -> date_end ) $date_end = $lines [ $i ] -> date_end ;
2016-10-03 20:41:39 +02:00
2018-10-30 10:46:33 +01:00
// FIXME Missing special_code into addline and updateline methods
$object -> special_code = $lines [ $i ] -> special_code ;
2020-04-02 17:06:57 +02:00
2020-03-31 18:58:59 +02:00
// FIXME If currency different from main currency, take multicurrency price
if ( $object -> multicurrency_code != $conf -> currency || $object -> multicurrency_tx != 1 )
{
$pu = 0 ;
$pu_currency = $lines [ $i ] -> multicurrency_subprice ;
2020-05-21 15:05:19 +02:00
} else {
2020-03-31 18:58:59 +02:00
$pu = $lines [ $i ] -> subprice ;
$pu_currency = 0 ;
}
2018-11-26 14:33:45 +01:00
2016-10-03 20:41:39 +02:00
// FIXME Missing $lines[$i]->ref_supplier and $lines[$i]->label into addline and updateline methods. They are filled when coming from order for example.
$result = $object -> addline (
$desc ,
2020-03-31 18:58:59 +02:00
$pu ,
2016-10-03 20:41:39 +02:00
$lines [ $i ] -> tva_tx ,
$lines [ $i ] -> localtax1_tx ,
$lines [ $i ] -> localtax2_tx ,
$lines [ $i ] -> qty ,
$lines [ $i ] -> fk_product ,
$lines [ $i ] -> remise_percent ,
$date_start ,
$date_end ,
0 ,
$lines [ $i ] -> info_bits ,
'HT' ,
$product_type ,
$lines [ $i ] -> rang ,
0 ,
$lines [ $i ] -> array_options ,
$lines [ $i ] -> fk_unit ,
2018-10-22 14:32:50 +02:00
$lines [ $i ] -> id ,
2020-03-31 18:58:59 +02:00
$pu_currency ,
2019-03-07 14:13:38 +01:00
$lines [ $i ] -> ref_supplier ,
2019-03-06 12:10:24 +01:00
$lines [ $i ] -> special_code
2016-10-03 20:41:39 +02:00
);
if ( $result < 0 )
{
$error ++ ;
break ;
}
}
// Now reload line
$object -> fetch_lines ();
2020-05-21 15:05:19 +02:00
} else {
2016-10-03 20:41:39 +02:00
$error ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2016-10-03 20:41:39 +02:00
$error ++ ;
}
2020-05-21 15:05:19 +02:00
} elseif ( ! $error )
2016-10-03 20:41:39 +02:00
{
$id = $object -> create ( $user );
if ( $id < 0 )
{
$error ++ ;
}
}
2016-11-08 11:23:40 +01:00
}
}
2016-10-03 20:41:39 +02:00
2016-11-08 11:23:40 +01:00
if ( $error )
{
$langs -> load ( " errors " );
$db -> rollback ();
2016-10-03 20:41:39 +02:00
2016-11-08 11:23:40 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2019-11-08 10:53:31 +01:00
$action = 'create' ;
$_GET [ 'socid' ] = $_POST [ 'socid' ];
2020-05-21 15:05:19 +02:00
} else {
2016-11-08 11:23:40 +01:00
$db -> commit ();
2016-10-03 20:41:39 +02:00
2016-11-08 11:23:40 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
$outputlangs = $langs ;
$result = $object -> generateDocument ( $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2019-11-08 10:53:31 +01:00
if ( $result < 0 )
2016-11-08 11:23:40 +01:00
{
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , $object -> error , $object -> errors );
2016-10-03 20:41:39 +02:00
exit ;
}
}
2016-11-08 11:23:40 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
exit ;
2016-10-03 20:41:39 +02:00
}
2015-02-28 03:11:15 +01:00
}
2012-10-28 13:57:21 +01:00
2015-02-28 03:11:15 +01:00
// Edit line
2020-04-21 10:02:18 +02:00
elseif ( $action == 'updateline' && $usercancreate )
2015-02-28 03:11:15 +01:00
{
$db -> begin ();
2019-10-27 09:51:15 +01:00
$object -> fetch ( $id );
$object -> fetch_thirdparty ();
2015-02-28 03:11:15 +01:00
2019-10-27 09:51:15 +01:00
$tva_tx = ( GETPOST ( 'tva_tx' ) ? GETPOST ( 'tva_tx' ) : 0 );
2015-02-28 18:10:31 +01:00
2019-10-27 09:51:15 +01:00
if ( GETPOST ( 'price_ht' ) != '' )
{
$up = price2num ( GETPOST ( 'price_ht' ));
$price_base_type = 'HT' ;
2020-05-21 15:05:19 +02:00
} else {
2019-10-27 09:51:15 +01:00
$up = price2num ( GETPOST ( 'price_ttc' ));
$price_base_type = 'TTC' ;
}
2017-10-16 08:47:05 +02:00
2019-10-27 09:51:15 +01:00
if ( GETPOST ( 'productid' ) > 0 )
{
$productsupplier = new ProductFournisseur ( $db );
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> global -> SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY ))
2017-10-16 08:47:05 +02:00
{
2019-11-08 10:53:31 +01:00
if ( GETPOST ( 'productid' ) > 0 && $productsupplier -> get_buyprice ( 0 , price2num ( $_POST [ 'qty' ]), GETPOST ( 'productid' ), 'none' , GETPOST ( 'socid' , 'int' )) < 0 )
2018-04-24 13:22:34 +02:00
{
2019-10-27 09:51:15 +01:00
setEventMessages ( $langs -> trans ( " ErrorQtyTooLowForThisSupplier " ), null , 'warnings' );
2018-04-24 13:22:34 +02:00
}
2019-10-27 09:51:15 +01:00
}
2018-04-24 13:22:34 +02:00
2019-10-27 09:51:15 +01:00
$prod = new Product ( $db );
$prod -> fetch ( GETPOST ( 'productid' ));
$label = $prod -> description ;
2019-11-08 10:53:31 +01:00
if ( trim ( $_POST [ 'product_desc' ]) != trim ( $label )) $label = $_POST [ 'product_desc' ];
2017-10-16 08:47:05 +02:00
2019-10-27 09:51:15 +01:00
$type = $prod -> type ;
2020-05-21 15:05:19 +02:00
} else {
2019-10-27 09:51:15 +01:00
$label = $_POST [ 'product_desc' ];
2019-11-08 10:53:31 +01:00
$type = $_POST [ " type " ] ? $_POST [ " type " ] : 0 ;
2019-10-27 09:51:15 +01:00
}
2015-02-28 03:11:15 +01:00
2019-11-08 10:53:31 +01:00
$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' ));
2015-02-28 03:11:15 +01:00
2019-10-27 09:51:15 +01:00
// Define info_bits
$info_bits = 0 ;
if ( preg_match ( '/\*/' , $tva_tx ))
$info_bits |= 0x01 ;
2017-10-22 14:02:24 +02:00
2019-10-27 09:51:15 +01:00
// Define vat_rate
$tva_tx = str_replace ( '*' , '' , $tva_tx );
2019-11-08 10:53:31 +01:00
$localtax1_tx = get_localtax ( $tva_tx , 1 , $mysoc , $object -> thirdparty );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $mysoc , $object -> thirdparty );
2017-10-22 14:02:24 +02:00
2019-11-08 10:53:31 +01:00
$remise_percent = GETPOST ( 'remise_percent' );
2019-10-27 09:51:15 +01:00
$pu_ht_devise = GETPOST ( 'multicurrency_subprice' );
2015-02-28 03:11:15 +01:00
2019-10-27 09:51:15 +01:00
// Extrafields Lines
$extralabelsline = $extrafields -> fetch_name_optionals_label ( $object -> table_element_line );
$array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element_line );
// Unset extrafield POST Data
if ( is_array ( $extralabelsline )) {
foreach ( $extralabelsline as $key => $value ) {
2019-11-08 10:53:31 +01:00
unset ( $_POST [ " options_ " . $key ]);
2015-02-28 03:11:15 +01:00
}
2019-10-27 09:51:15 +01:00
}
2014-08-07 15:12:27 +02:00
2019-11-08 10:53:31 +01:00
$result = $object -> updateline ( GETPOST ( 'lineid' ), $label , $up , $tva_tx , $localtax1_tx , $localtax2_tx , GETPOST ( 'qty' ), GETPOST ( 'productid' ), $price_base_type , $info_bits , $type , $remise_percent , 0 , $date_start , $date_end , $array_options , $_POST [ 'units' ], $pu_ht_devise , GETPOST ( 'fourn_ref' , 'alpha' ));
2019-10-27 09:51:15 +01:00
if ( $result >= 0 )
{
unset ( $_POST [ 'label' ]);
unset ( $_POST [ 'fourn_ref' ]);
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' ]);
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2019-10-27 09:51:15 +01:00
$db -> rollback ();
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2020-05-26 00:25:38 +02:00
} elseif ( $action == 'addline' && $usercancreate ) {
2015-02-28 03:11:15 +01:00
$db -> begin ();
2019-11-08 10:53:31 +01:00
$ret = $object -> fetch ( $id );
2017-10-16 08:47:05 +02:00
if ( $ret < 0 )
{
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , $object -> error );
2017-10-16 08:47:05 +02:00
exit ;
}
2019-11-08 10:53:31 +01:00
$ret = $object -> fetch_thirdparty ();
2015-02-28 03:11:15 +01:00
2017-10-16 08:47:05 +02:00
$langs -> load ( 'errors' );
2019-11-08 10:53:31 +01:00
$error = 0 ;
2015-02-28 03:11:15 +01:00
// Set if we used free entry or predefined product
2019-11-08 10:53:31 +01:00
$predef = '' ;
$product_desc = ( GETPOST ( 'dp_desc' ) ? GETPOST ( 'dp_desc' ) : '' );
$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' ));
2018-08-29 17:03:18 +02:00
2016-07-23 16:37:21 +02:00
$prod_entry_mode = GETPOST ( 'prod_entry_mode' );
if ( $prod_entry_mode == 'free' )
2015-02-28 03:11:15 +01:00
{
2019-11-08 10:53:31 +01:00
$idprod = 0 ;
2015-02-28 03:11:15 +01:00
$price_ht = GETPOST ( 'price_ht' );
$tva_tx = ( GETPOST ( 'tva_tx' ) ? GETPOST ( 'tva_tx' ) : 0 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 10:53:31 +01:00
$idprod = GETPOST ( 'idprod' , 'int' );
2020-01-01 17:15:26 +01:00
$price_ht = GETPOST ( 'price_ht' );
2015-02-28 03:11:15 +01:00
$tva_tx = '' ;
}
2012-10-28 13:57:21 +01:00
2015-02-28 03:11:15 +01:00
$qty = GETPOST ( 'qty' . $predef );
2019-11-08 10:53:31 +01:00
$remise_percent = GETPOST ( 'remise_percent' . $predef );
2016-12-11 02:09:57 +01:00
$price_ht_devise = GETPOST ( 'multicurrency_price_ht' );
2015-02-28 03:11:15 +01:00
2017-10-16 08:47:05 +02: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 );
2017-10-16 08:47:05 +02:00
// Unset extrafield
if ( is_array ( $extralabelsline )) {
// Get extra fields
foreach ( $extralabelsline as $key => $value ) {
2019-11-08 10:53:31 +01:00
unset ( $_POST [ " options_ " . $key ]);
2017-10-16 08:47:05 +02:00
}
}
2015-12-07 03:59:03 +01:00
2019-11-08 10:53:31 +01:00
if ( $prod_entry_mode == 'free' && GETPOST ( 'price_ht' ) < 0 && $qty < 0 )
2017-10-16 08:47:05 +02:00
{
setEventMessages ( $langs -> trans ( 'ErrorBothFieldCantBeNegative' , $langs -> transnoentitiesnoconv ( 'UnitPrice' ), $langs -> transnoentitiesnoconv ( 'Qty' )), null , 'errors' );
$error ++ ;
}
2019-11-08 10:53:31 +01:00
if ( $prod_entry_mode == 'free' && ! GETPOST ( 'idprodfournprice' ) && GETPOST ( 'type' ) < 0 )
2017-10-16 08:47:05 +02:00
{
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( 'Type' )), null , 'errors' );
$error ++ ;
}
2019-11-08 10:53:31 +01:00
if ( $prod_entry_mode == 'free' && GETPOST ( 'price_ht' ) === '' && GETPOST ( 'price_ttc' ) === '' && $price_ht_devise === '' ) // Unit price can be 0 but not ''
2017-10-16 08:47:05 +02:00
{
2019-07-05 20:24:22 +02:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( 'UnitPrice' )), null , 'errors' );
2017-10-16 08:47:05 +02:00
$error ++ ;
}
2019-11-08 10:53:31 +01:00
if ( $prod_entry_mode == 'free' && ! GETPOST ( 'dp_desc' ))
2017-10-16 08:47:05 +02:00
{
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( 'Description' )), null , 'errors' );
$error ++ ;
}
2019-11-08 10:53:31 +01:00
if ( ! GETPOST ( 'qty' ))
2017-10-16 08:47:05 +02:00
{
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( 'Qty' )), null , 'errors' );
$error ++ ;
}
2015-02-28 03:11:15 +01:00
2017-02-08 12:37:38 +01:00
if ( ! $error && ! empty ( $conf -> variants -> enabled ) && $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 ;
} else {
2018-07-25 15:36:50 +02:00
setEventMessages ( $langs -> trans ( 'ErrorProductCombinationNotFound' ), null , 'errors' );
2019-11-08 10:53:31 +01:00
$error ++ ;
2016-07-23 16:37:21 +02:00
}
}
}
2016-12-24 21:39:40 +01:00
if ( $prod_entry_mode != 'free' && empty ( $error )) // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
2017-10-16 08:47:05 +02:00
{
2019-11-08 10:53:31 +01:00
$productsupplier = new ProductFournisseur ( $db );
2015-02-28 03:11:15 +01:00
2019-11-08 10:53:31 +01:00
$idprod = 0 ;
if ( GETPOST ( 'idprodfournprice' , 'alpha' ) == - 1 || GETPOST ( 'idprodfournprice' , 'alpha' ) == '' ) $idprod = - 99 ; // Same behaviour than with combolist. When not select idprodfournprice is now -99 (to avoid conflict with next action that may return -1, -2, ...)
2015-02-28 03:11:15 +01:00
2020-01-01 17:15:26 +01:00
$reg = array ();
2019-01-27 11:55:16 +01:00
if ( preg_match ( '/^idprod_([0-9]+)$/' , GETPOST ( 'idprodfournprice' , 'alpha' ), $reg ))
2017-08-23 15:02:38 +02:00
{
2019-11-08 10:53:31 +01:00
$idprod = $reg [ 1 ];
$res = $productsupplier -> fetch ( $idprod ); // Load product from its id
2018-06-16 14:47:33 +02:00
// Call to init some price properties of $productsupplier
2017-08-23 15:02:38 +02:00
// So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> global -> SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER ))
2018-06-16 14:47:33 +02:00
{
$fksoctosearch = 0 ;
2019-11-08 10:53:31 +01:00
$productsupplier -> get_buyprice ( 0 , - 1 , $idprod , 'none' , $fksoctosearch ); // We force qty to -1 to be sure to find if a supplier price exist
2018-06-16 14:47:33 +02:00
if ( $productsupplier -> fourn_socid != $socid ) // The price we found is for another supplier, so we clear supplier price
{
$productsupplier -> ref_supplier = '' ;
}
2020-05-21 15:05:19 +02:00
} else {
2018-06-16 14:47:33 +02:00
$fksoctosearch = $object -> thirdparty -> id ;
2019-11-08 10:53:31 +01:00
$productsupplier -> get_buyprice ( 0 , - 1 , $idprod , 'none' , $fksoctosearch ); // We force qty to -1 to be sure to find if a supplier price exist
2018-06-16 14:47:33 +02:00
}
2020-05-21 15:05:19 +02:00
} elseif ( GETPOST ( 'idprodfournprice' , 'alpha' ) > 0 )
2017-10-16 08:47:05 +02:00
{
2019-11-08 10:53:31 +01:00
$qtytosearch = $qty ; // Just to see if a price exists for the quantity. Not used to found vat.
2017-10-16 08:47:05 +02:00
//$qtytosearch=-1; // We force qty to -1 to be sure to find if a supplier price exist
2019-11-08 10:53:31 +01:00
$idprod = $productsupplier -> get_buyprice ( GETPOST ( 'idprodfournprice' , 'alpha' ), $qtytosearch );
$res = $productsupplier -> fetch ( $idprod );
2017-10-16 08:47:05 +02:00
}
2015-02-28 03:11:15 +01:00
2017-10-16 08:47:05 +02:00
if ( $idprod > 0 )
{
$label = $productsupplier -> label ;
2015-02-28 03:11:15 +01:00
2018-08-06 16:26:25 +02:00
// if we use supplier description of the products
2019-11-08 10:53:31 +01:00
if ( ! empty ( $productsupplier -> desc_supplier ) && ! empty ( $conf -> global -> PRODUIT_FOURN_TEXTS )) {
2018-08-06 16:26:25 +02:00
$desc = $productsupplier -> desc_supplier ;
} else $desc = $productsupplier -> description ;
2018-08-29 17:03:18 +02:00
2019-03-22 13:00:48 +01:00
if ( trim ( $product_desc ) != trim ( $desc )) $desc = dol_concatdesc ( $desc , $product_desc , '' , ! empty ( $conf -> global -> MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION ));
2015-02-28 03:11:15 +01:00
2018-04-24 12:57:31 +02:00
$type = $productsupplier -> type ;
2020-01-01 17:15:26 +01:00
if ( $price_ht != '' || $price_ht_devise != '' ) {
$price_base_type = 'HT' ;
$pu = price2num ( $price_ht , 'MU' );
$pu_ht_devise = price2num ( $price_ht_devise , 'MU' );
} else {
$price_base_type = ( $productsupplier -> fourn_price_base_type ? $productsupplier -> fourn_price_base_type : 'HT' );
if ( empty ( $object -> multicurrency_code ) || ( $productsupplier -> fourn_multicurrency_code != $object -> multicurrency_code )) { // If object is in a different currency and price not in this currency
$pu = $productsupplier -> fourn_pu ;
$pu_ht_devise = 0 ;
} else {
$pu = $productsupplier -> fourn_pu ;
$pu_ht_devise = $productsupplier -> fourn_multicurrency_unitprice ;
}
}
2015-02-28 03:11:15 +01:00
2018-04-24 12:57:31 +02:00
$ref_supplier = $productsupplier -> ref_supplier ;
2019-11-08 10:53:31 +01:00
$tva_tx = get_default_tva ( $object -> thirdparty , $mysoc , $productsupplier -> id , GETPOST ( 'idprodfournprice' , 'alpha' ));
2019-01-27 11:55:16 +01:00
$tva_npr = get_default_npr ( $object -> thirdparty , $mysoc , $productsupplier -> id , GETPOST ( 'idprodfournprice' , 'alpha' ));
2019-11-08 10:53:31 +01:00
if ( empty ( $tva_tx )) $tva_npr = 0 ;
$localtax1_tx = get_localtax ( $tva_tx , 1 , $mysoc , $object -> thirdparty , $tva_npr );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $mysoc , $object -> thirdparty , $tva_npr );
2017-10-16 08:47:05 +02:00
2019-11-08 10:53:31 +01:00
if ( empty ( $pu )) $pu = 0 ; // If pu is '' or null, we force to have a numeric value
2018-06-16 14:47:33 +02:00
2019-11-08 10:53:31 +01:00
$result = $object -> addline (
2017-10-16 08:47:05 +02:00
$desc ,
2018-06-16 14:47:33 +02:00
$pu ,
2017-10-16 08:47:05 +02:00
$tva_tx ,
$localtax1_tx ,
$localtax2_tx ,
$qty ,
$idprod ,
$remise_percent ,
$date_start ,
$date_end ,
0 ,
$tva_npr ,
$price_base_type ,
$type ,
2018-04-24 12:57:31 +02:00
- 1 ,
2017-10-16 08:47:05 +02:00
0 ,
$array_options ,
2017-11-12 16:06:08 +01:00
$productsupplier -> fk_unit ,
2018-02-23 11:06:07 +01:00
0 ,
2020-01-01 17:15:26 +01:00
$pu_ht_devise ,
$ref_supplier ,
''
2017-10-16 08:47:05 +02:00
);
}
if ( $idprod == - 99 || $idprod == 0 )
{
// Product not selected
$error ++ ;
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ProductOrService " )), null , 'errors' );
}
if ( $idprod == - 1 )
{
// Quantity too low
$error ++ ;
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " ErrorQtyTooLowForThisSupplier " ), null , 'errors' );
}
2020-05-21 15:05:19 +02:00
} elseif ( empty ( $error )) // $price_ht is already set
2015-02-28 03:11:15 +01:00
{
$tva_npr = ( preg_match ( '/\*/' , $tva_tx ) ? 1 : 0 );
$tva_tx = str_replace ( '*' , '' , $tva_tx );
$label = ( GETPOST ( 'product_label' ) ? GETPOST ( 'product_label' ) : '' );
$desc = $product_desc ;
$type = GETPOST ( 'type' );
2019-01-27 11:55:16 +01:00
$ref_supplier = GETPOST ( 'fourn_ref' , 'alpha' );
2015-02-28 03:11:15 +01:00
2019-11-08 10:53:31 +01:00
$fk_unit = GETPOST ( 'units' , 'alpha' );
2015-04-19 15:59:49 +02:00
2019-11-08 10:53:31 +01:00
$tva_tx = price2num ( $tva_tx ); // When vat is text input field
2015-02-28 03:11:15 +01:00
2017-10-16 08:47:05 +02:00
// Local Taxes
2019-11-08 10:53:31 +01:00
$localtax1_tx = get_localtax ( $tva_tx , 1 , $mysoc , $object -> thirdparty );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $mysoc , $object -> thirdparty );
2015-02-28 03:11:15 +01:00
FIX: excl. tax price not properly rounded
When adding a 'free line' product or service in a supplier invoice, the amount excluding tax (HT) is not properly rounded, in particular when calculated from full tax price. This leads to inconsistencies in results when using large quantities or small precision in settings. Test case :
with default settings
MAIN_MAX_DECIMALS_UNIT = 5
MAIN_MAX_DECIMALS_TOT = 2
MAIN_MAX_DECIMALS_SHOWN = 8
Add in a new invoice a free product with 13.33 TTC (full tax), quantity 1, save, then edit the line with quantity 10111
Now in another invoice, add a free product with 13.33 TTC (full tax), quantity 10111, save.
Exact same data in the two invoices, but Tax and grand total are different, and false in second case because computed before rounding.
Also removed some direct access to $_POST array.
2016-10-26 08:55:43 +02:00
if ( $price_ht !== '' )
2015-02-28 03:11:15 +01:00
{
FIX: excl. tax price not properly rounded
When adding a 'free line' product or service in a supplier invoice, the amount excluding tax (HT) is not properly rounded, in particular when calculated from full tax price. This leads to inconsistencies in results when using large quantities or small precision in settings. Test case :
with default settings
MAIN_MAX_DECIMALS_UNIT = 5
MAIN_MAX_DECIMALS_TOT = 2
MAIN_MAX_DECIMALS_SHOWN = 8
Add in a new invoice a free product with 13.33 TTC (full tax), quantity 1, save, then edit the line with quantity 10111
Now in another invoice, add a free product with 13.33 TTC (full tax), quantity 10111, save.
Exact same data in the two invoices, but Tax and grand total are different, and false in second case because computed before rounding.
Also removed some direct access to $_POST array.
2016-10-26 08:55:43 +02:00
$pu_ht = price2num ( $price_ht , 'MU' ); // $pu_ht must be rounded according to settings
2020-05-21 15:05:19 +02:00
} else {
FIX: excl. tax price not properly rounded
When adding a 'free line' product or service in a supplier invoice, the amount excluding tax (HT) is not properly rounded, in particular when calculated from full tax price. This leads to inconsistencies in results when using large quantities or small precision in settings. Test case :
with default settings
MAIN_MAX_DECIMALS_UNIT = 5
MAIN_MAX_DECIMALS_TOT = 2
MAIN_MAX_DECIMALS_SHOWN = 8
Add in a new invoice a free product with 13.33 TTC (full tax), quantity 1, save, then edit the line with quantity 10111
Now in another invoice, add a free product with 13.33 TTC (full tax), quantity 10111, save.
Exact same data in the two invoices, but Tax and grand total are different, and false in second case because computed before rounding.
Also removed some direct access to $_POST array.
2016-10-26 08:55:43 +02:00
$pu_ttc = price2num ( GETPOST ( 'price_ttc' ), 'MU' );
$pu_ht = price2num ( $pu_ttc / ( 1 + ( $tva_tx / 100 )), 'MU' ); // $pu_ht must be rounded according to settings
}
$price_base_type = 'HT' ;
2016-12-11 02:09:57 +01:00
$pu_ht_devise = price2num ( $price_ht_devise , 'MU' );
2015-04-19 15:59:49 +02:00
2019-07-05 20:24:22 +02:00
$result = $object -> addline ( $product_desc , $pu_ht , $tva_tx , $localtax1_tx , $localtax2_tx , $qty , 0 , $remise_percent , $date_start , $date_end , 0 , $tva_npr , $price_base_type , $type , - 1 , 0 , $array_options , $fk_unit , 0 , $pu_ht_devise , $ref_supplier );
2017-10-16 08:47:05 +02:00
}
2015-02-28 03:11:15 +01:00
2017-10-16 08:47:05 +02:00
//print "xx".$tva_tx; exit;
2019-11-08 10:53:31 +01:00
if ( ! $error && $result > 0 )
2017-10-16 08:47:05 +02:00
{
$db -> commit ();
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2019-01-27 11:55:16 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2017-10-16 08:47:05 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
2019-11-08 10:53:31 +01:00
if ( ! empty ( $newlang )) {
2017-10-16 08:47:05 +02:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2019-11-08 10:53:31 +01:00
$model = $object -> modelpdf ;
2017-10-16 08:47:05 +02:00
$ret = $object -> fetch ( $id ); // Reload to get new records
2019-11-08 10:53:31 +01:00
$result = $object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
2019-01-27 11:55:16 +01:00
if ( $result < 0 ) dol_print_error ( $db , $result );
2017-10-16 08:47:05 +02:00
}
2015-02-28 03:11:15 +01:00
unset ( $_POST [ 'prod_entry_mode' ]);
2017-10-16 08:47:05 +02:00
unset ( $_POST [ 'qty' ]);
unset ( $_POST [ 'type' ]);
unset ( $_POST [ 'remise_percent' ]);
unset ( $_POST [ 'pu' ]);
unset ( $_POST [ 'price_ht' ]);
2016-04-12 14:10:27 +02:00
unset ( $_POST [ 'multicurrency_price_ht' ]);
2017-10-16 08:47:05 +02:00
unset ( $_POST [ 'price_ttc' ]);
2017-11-12 16:06:08 +01:00
unset ( $_POST [ 'fourn_ref' ]);
2017-10-16 08:47:05 +02:00
unset ( $_POST [ 'tva_tx' ]);
unset ( $_POST [ 'label' ]);
unset ( $localtax1_tx );
unset ( $localtax2_tx );
2015-02-28 03:11:15 +01:00
unset ( $_POST [ 'np_marginRate' ]);
unset ( $_POST [ 'np_markRate' ]);
2017-10-16 08:47:05 +02:00
unset ( $_POST [ 'dp_desc' ]);
2015-02-28 03:11:15 +01:00
unset ( $_POST [ 'idprodfournprice' ]);
2017-10-16 08:47:05 +02:00
unset ( $_POST [ 'units' ]);
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' ]);
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
$db -> rollback ();
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
$action = '' ;
2020-05-26 00:25:38 +02:00
} elseif ( $action == 'classin' && $usercancreate ) {
2017-10-16 08:47:05 +02:00
$object -> fetch ( $id );
2019-11-08 10:53:31 +01:00
$result = $object -> setProject ( $projectid );
2015-02-28 03:11:15 +01:00
}
2012-10-28 13:57:21 +01:00
2015-02-28 03:11:15 +01:00
// Set invoice to draft status
2020-04-21 10:02:18 +02:00
elseif ( $action == 'confirm_edit' && $confirm == 'yes' && $usercancreate )
2015-02-28 03:11:15 +01:00
{
2017-10-16 08:47:05 +02:00
$object -> fetch ( $id );
2015-02-28 03:11:15 +01:00
2017-10-16 08:47:05 +02:00
$totalpaye = $object -> getSommePaiement ();
$resteapayer = $object -> total_ttc - $totalpaye ;
2015-02-28 03:11:15 +01:00
2019-06-29 16:29:32 +02:00
// We check that lines of invoices are exported in accountancy
2019-10-04 10:31:57 +02:00
$ventilExportCompta = $object -> getVentilExportCompta ();
2019-11-08 10:53:31 +01:00
if ( ! $ventilExportCompta )
2019-10-04 10:31:57 +02:00
{
// On verifie si aucun paiement n'a ete effectue
if ( $resteapayer == price2num ( $object -> total_ttc , 'MT' , 1 ) && $object -> statut == FactureFournisseur :: STATUS_VALIDATED )
{
$idwarehouse = GETPOST ( 'idwarehouse' );
$object -> fetch_thirdparty ();
2019-11-08 10:53:31 +01:00
$qualified_for_stock_change = 0 ;
2019-10-04 10:31:57 +02:00
if ( empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
{
2019-11-08 10:53:31 +01:00
$qualified_for_stock_change = $object -> hasProductsOrServices ( 2 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 10:53:31 +01:00
$qualified_for_stock_change = $object -> hasProductsOrServices ( 1 );
2019-10-04 10:31:57 +02:00
}
// Check parameters
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> stock -> enabled ) && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_BILL ) && $qualified_for_stock_change )
2019-10-04 10:31:57 +02:00
{
$langs -> load ( " stocks " );
2019-11-08 10:53:31 +01:00
if ( ! $idwarehouse || $idwarehouse == - 1 )
2019-10-04 10:31:57 +02:00
{
$error ++ ;
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( " Warehouse " )), null , 'errors' );
2019-11-08 10:53:31 +01:00
$action = '' ;
2019-10-04 10:31:57 +02:00
}
}
$object -> setDraft ( $user , $idwarehouse );
2015-02-28 03:11:15 +01:00
2019-10-04 10:31:57 +02:00
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
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-08 10:53:31 +01:00
if ( ! empty ( $newlang )) {
2019-10-04 10:31:57 +02:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2019-11-08 10:53:31 +01:00
$model = $object -> modelpdf ;
2019-10-04 10:31:57 +02:00
$ret = $object -> fetch ( $id ); // Reload to get new records
2015-02-28 03:11:15 +01:00
2019-11-08 10:53:31 +01:00
$result = $object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
2019-10-04 10:31:57 +02:00
if ( $result < 0 ) dol_print_error ( $db , $result );
2017-10-16 08:47:05 +02:00
}
2019-11-08 10:53:31 +01:00
$action = '' ;
2017-10-16 08:47:05 +02:00
}
}
2015-02-28 03:11:15 +01:00
}
2012-10-28 13:57:21 +01:00
2015-02-28 03:11:15 +01:00
// Set invoice to validated/unpaid status
2020-04-21 10:02:18 +02:00
elseif ( $action == 'reopen' && $usercancreate )
2015-02-28 03:11:15 +01:00
{
2017-10-16 08:47:05 +02:00
$result = $object -> fetch ( $id );
if ( $object -> statut == FactureFournisseur :: STATUS_CLOSED
|| ( $object -> statut == FactureFournisseur :: STATUS_ABANDONED && $object -> close_code != 'replaced' ))
{
$result = $object -> set_unpaid ( $user );
if ( $result > 0 )
{
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
2015-02-28 03:11:15 +01:00
}
2012-10-28 13:57:21 +01: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' ;
2016-08-10 09:47:25 +02:00
2016-06-24 16:10:52 +02:00
// Actions to send emails
2019-12-02 09:38:16 +01:00
$triggersendname = 'BILL_SUPPLIER_SENTBYMAIL' ;
2019-11-08 10:53:31 +01:00
$paramname = 'id' ;
$autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO' ;
$trackid = 'sin' . $object -> id ;
2016-06-24 16:10:52 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php' ;
2016-08-10 09:47:25 +02:00
2017-05-05 12:33:49 +02:00
// Actions to build doc
$upload_dir = $conf -> fournisseur -> facture -> dir_output ;
2020-04-21 10:02:18 +02:00
$permissiontoadd = $usercancreate ;
2017-05-05 12:33:49 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php' ;
2017-06-07 16:44:04 +02:00
2015-02-28 03:11:15 +01:00
// Make calculation according to calculationrule
if ( $action == 'calculate' )
{
2019-11-08 10:53:31 +01:00
$calculationrule = GETPOST ( 'calculationrule' );
2015-02-28 03:11:15 +01:00
2017-10-16 08:47:05 +02:00
$object -> fetch ( $id );
$object -> fetch_thirdparty ();
2019-11-08 10:53:31 +01:00
$result = $object -> update_price ( 0 , (( $calculationrule == 'totalofround' ) ? '0' : '1' ), 0 , $object -> thirdparty );
if ( $result <= 0 )
2017-10-16 08:47:05 +02:00
{
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , $result );
2017-10-16 08:47:05 +02:00
exit ;
}
2015-02-28 03:11:15 +01:00
}
if ( $action == 'update_extras' )
{
2018-02-23 16:11:00 +01:00
$object -> oldcopy = dol_clone ( $object );
2015-02-28 03:11:15 +01:00
// Fill array 'array_options' with data from add form
2019-10-06 14:41:52 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object , GETPOST ( 'attribute' , 'none' ));
2015-02-28 03:11:15 +01:00
if ( $ret < 0 ) $error ++ ;
2013-09-06 13:25:45 +02:00
2019-11-08 10:53:31 +01:00
if ( ! $error )
2015-02-28 03:11:15 +01:00
{
2018-04-10 12:03:01 +02:00
// Actions on extra fields
2020-04-23 13:21:39 +02:00
if ( ! $error )
2015-02-28 03:11:15 +01:00
{
2019-11-08 10:53:31 +01:00
$result = $object -> insertExtraFields ( 'BILL_SUPPLIER_MODIFY' );
2018-04-10 12:03:01 +02:00
if ( $result < 0 )
2015-02-28 03:11:15 +01:00
{
2018-04-10 12:03:01 +02:00
$error ++ ;
2015-02-28 03:11:15 +01:00
}
}
}
2018-04-10 12:03:01 +02:00
if ( $error )
2015-02-28 03:11:15 +01:00
$action = 'edit_extras' ;
}
2014-10-14 17:00:06 +02:00
2020-04-21 10:02:18 +02:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ) && $usercancreate )
2014-10-14 17:00:06 +02:00
{
2015-02-28 03:11:15 +01:00
if ( $action == 'addcontact' )
2014-10-14 17:00:06 +02:00
{
2015-02-28 03:11:15 +01:00
$result = $object -> fetch ( $id );
2014-10-14 17:00:06 +02:00
2015-02-28 03:11:15 +01:00
if ( $result > 0 && $id > 0 )
{
$contactid = ( GETPOST ( 'userid' ) ? GETPOST ( 'userid' ) : GETPOST ( 'contactid' ));
$result = $object -> add_contact ( $contactid , $_POST [ " type " ], $_POST [ " source " ]);
}
2014-10-14 17:00:06 +02:00
2015-02-28 03:11:15 +01:00
if ( $result >= 0 )
{
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2015-02-28 03:11:15 +01:00
if ( $object -> error == 'DB_ERROR_RECORD_ALREADY_EXISTS' )
2014-10-14 17:00:06 +02:00
{
2015-02-28 03:11:15 +01:00
$langs -> load ( " errors " );
2015-12-10 16:14:37 +01:00
setEventMessages ( $langs -> trans ( " ErrorThisContactIsAlreadyDefinedAsThisType " ), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2015-12-10 16:14:37 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2014-10-14 17:00:06 +02:00
}
}
}
2012-10-28 13:57:21 +01:00
2015-02-28 03:11:15 +01:00
// bascule du statut d'un contact
2019-01-27 10:49:34 +01:00
elseif ( $action == 'swapstatut' )
2012-10-28 13:57:21 +01:00
{
2015-02-28 03:11:15 +01:00
if ( $object -> fetch ( $id ))
2012-10-28 13:57:21 +01:00
{
2019-11-08 10:53:31 +01:00
$result = $object -> swapContactStatus ( GETPOST ( 'ligne' ));
2020-05-21 15:05:19 +02:00
} else {
2015-02-28 03:11:15 +01:00
dol_print_error ( $db );
2012-10-28 13:57:21 +01:00
}
}
2015-02-28 03:11:15 +01:00
// Efface un contact
2019-01-27 10:49:34 +01:00
elseif ( $action == 'deletecontact' )
2012-10-28 13:57:21 +01:00
{
2015-02-28 03:11:15 +01:00
$object -> fetch ( $id );
$result = $object -> delete_contact ( $_GET [ " lineid " ]);
2012-10-28 13:57:21 +01:00
2015-02-28 03:11:15 +01:00
if ( $result >= 0 )
{
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2015-02-28 03:11:15 +01:00
dol_print_error ( $db );
}
2012-10-28 13:57:21 +01:00
}
}
}
/*
* View
*/
$form = new Form ( $db );
$formfile = new FormFile ( $db );
2019-11-08 10:53:31 +01:00
$bankaccountstatic = new Account ( $db );
$paymentstatic = new PaiementFourn ( $db );
if ( ! empty ( $conf -> projet -> enabled )) { $formproject = new FormProjets ( $db ); }
2016-09-26 00:10:29 +02:00
$now = dol_now ();
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
$title = $langs -> trans ( 'SupplierInvoice' ) . " - " . $langs -> trans ( 'Card' );
2016-08-31 07:05:23 +02:00
$helpurl = " EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores " ;
llxHeader ( '' , $title , $helpurl );
2012-10-28 13:57:21 +01:00
// Mode creation
if ( $action == 'create' )
{
2014-11-06 22:16:27 +01:00
$facturestatic = new FactureFournisseur ( $db );
2015-01-25 21:32:40 +01:00
2020-04-25 13:49:44 +02:00
print load_fiche_titre ( $langs -> trans ( 'NewBill' ), '' , 'supplier_invoice' );
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
dol_htmloutput_events ();
2012-10-28 13:57:21 +01:00
2016-02-21 22:47:52 +01:00
$currency_code = $conf -> currency ;
2016-08-10 09:47:25 +02:00
2019-11-08 10:53:31 +01:00
$societe = '' ;
2016-10-02 21:39:24 +02:00
if ( GETPOST ( 'socid' ) > 0 )
{
2019-11-08 10:53:31 +01:00
$societe = new Societe ( $db );
2019-01-27 11:55:16 +01:00
$societe -> fetch ( GETPOST ( 'socid' , 'int' ));
2016-02-21 22:47:52 +01:00
if ( ! empty ( $conf -> multicurrency -> enabled ) && ! empty ( $societe -> multicurrency_code )) $currency_code = $societe -> multicurrency_code ;
2016-10-02 21:39:24 +02:00
}
2016-08-10 09:47:25 +02:00
2019-11-08 10:53:31 +01:00
if ( ! empty ( $origin ) && ! empty ( $originid ))
2017-10-16 08:47:05 +02:00
{
// Parse element/subelement (ex: project_task)
$element = $subelement = $origin ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
if ( $element == 'project' )
{
$projectid = $originid ;
$element = 'projet' ;
}
2019-01-17 19:27:26 +01:00
2019-10-27 09:51:15 +01:00
// For compatibility
2019-11-08 10:53:31 +01:00
if ( $element == 'order' ) {
2019-10-27 09:51:15 +01:00
$element = $subelement = 'commande' ;
}
2019-11-08 10:53:31 +01:00
if ( $element == 'propal' ) {
2019-10-27 09:51:15 +01:00
$element = 'comm/propal' ; $subelement = 'propal' ;
}
if ( $element == 'contract' ) {
$element = $subelement = 'contrat' ;
}
if ( $element == 'order_supplier' ) {
$element = 'fourn' ; $subelement = 'fournisseur.commande' ;
}
2018-10-18 10:26:32 +02:00
2019-10-27 09:51:15 +01:00
require_once DOL_DOCUMENT_ROOT . '/' . $element . '/class/' . $subelement . '.class.php' ;
$classname = ucfirst ( $subelement );
2019-11-08 10:53:31 +01:00
if ( $classname == 'Fournisseur.commande' ) $classname = 'CommandeFournisseur' ;
2019-10-27 09:51:15 +01:00
$objectsrc = new $classname ( $db );
$objectsrc -> fetch ( $originid );
$objectsrc -> fetch_thirdparty ();
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
$projectid = ( ! empty ( $objectsrc -> fk_project ) ? $objectsrc -> fk_project : '' );
2019-10-27 09:51:15 +01:00
//$ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:'');
2012-10-28 13:57:21 +01:00
2019-10-27 09:51:15 +01:00
$soc = $objectsrc -> thirdparty ;
2019-11-08 10:53:31 +01:00
$cond_reglement_id = ( ! empty ( $objectsrc -> cond_reglement_id ) ? $objectsrc -> cond_reglement_id : ( ! empty ( $soc -> cond_reglement_supplier_id ) ? $soc -> cond_reglement_supplier_id : 0 )); // TODO maybe add default value option
$mode_reglement_id = ( ! empty ( $objectsrc -> mode_reglement_id ) ? $objectsrc -> mode_reglement_id : ( ! empty ( $soc -> mode_reglement_supplier_id ) ? $soc -> mode_reglement_supplier_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_supplier_percent ) ? $soc -> remise_supplier_percent : 0 ));
$remise_absolue = ( ! empty ( $objectsrc -> remise_absolue ) ? $objectsrc -> remise_absolue : ( ! empty ( $soc -> remise_absolue ) ? $soc -> remise_absolue : 0 ));
$dateinvoice = empty ( $conf -> global -> MAIN_AUTOFILL_DATE ) ? - 1 : '' ;
2012-10-28 13:57:21 +01:00
2019-10-27 09:51:15 +01:00
if ( ! empty ( $conf -> multicurrency -> enabled ))
{
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 ;
}
2016-08-10 09:47:25 +02:00
2020-05-21 09:34:20 +02:00
$datetmp = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'remonth' , 'int' ), GETPOST ( 'reday' , 'int' ), GETPOST ( 'reyear' , 'int' ));
2019-11-08 10:53:31 +01:00
$dateinvoice = ( $datetmp == '' ? ( empty ( $conf -> global -> MAIN_AUTOFILL_DATE ) ? - 1 : '' ) : $datetmp );
$datetmp = dol_mktime ( 12 , 0 , 0 , $_POST [ 'echmonth' ], $_POST [ 'echday' ], $_POST [ 'echyear' ]);
$datedue = ( $datetmp == '' ? - 1 : $datetmp );
2017-10-18 17:21:30 +02:00
2019-10-27 09:51:15 +01:00
// Replicate extrafields
2020-03-27 16:02:58 +01:00
$objectsrc -> fetch_optionals ();
2019-10-27 09:51:15 +01:00
$object -> array_options = $objectsrc -> array_options ;
2020-05-21 15:05:19 +02:00
} else {
2013-07-30 16:21:39 +02:00
$cond_reglement_id = $societe -> cond_reglement_supplier_id ;
$mode_reglement_id = $societe -> mode_reglement_supplier_id ;
2017-10-16 08:47:05 +02:00
$fk_account = $societe -> fk_account ;
2020-05-21 09:34:20 +02:00
$datetmp = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'remonth' , 'int' ), GETPOST ( 'reday' , 'int' ), GETPOST ( 'reyear' , 'int' ));
2019-11-08 10:53:31 +01:00
$dateinvoice = ( $datetmp == '' ? ( empty ( $conf -> global -> MAIN_AUTOFILL_DATE ) ? - 1 : '' ) : $datetmp );
$datetmp = dol_mktime ( 12 , 0 , 0 , $_POST [ 'echmonth' ], $_POST [ 'echday' ], $_POST [ 'echyear' ]);
$datedue = ( $datetmp == '' ? - 1 : $datetmp );
2016-08-10 09:47:25 +02:00
2016-02-19 22:25:59 +01:00
if ( ! empty ( $conf -> multicurrency -> enabled ) && ! empty ( $soc -> multicurrency_code )) $currency_code = $soc -> multicurrency_code ;
2017-10-16 08:47:05 +02:00
}
2020-05-22 08:00:26 +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 )) {
2020-05-22 08:00:26 +02:00
$cond_reglement_id = GETPOST ( " cond_reglement_id " );
}
// when payment mode 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 ( $mode_reglement_id )) {
2020-05-22 08:00:26 +02:00
$mode_reglement_id = GETPOST ( " mode_reglement_id " );
}
2020-05-22 08:08:12 +02:00
2020-07-30 21:10:06 +02:00
$note_public = $object -> getDefaultCreateValueFor ( 'note_public' , (( ! empty ( $origin ) && ! empty ( $originid ) && is_object ( $objectsrc ) && ! empty ( $conf -> global -> FACTUREFOURN_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 -> FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM )) ? $objectsrc -> note_private : null ));
2017-10-16 08:47:05 +02:00
print '<form name="add" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2019-12-18 23:12:31 +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="add">' ;
2019-11-08 10:53:31 +01:00
if ( $societe -> id > 0 ) print '<input type="hidden" name="socid" value="' . $societe -> id . '">' . " \n " ;
2017-10-16 08:47:05 +02:00
print '<input type="hidden" name="origin" value="' . $origin . '">' ;
print '<input type="hidden" name="originid" value="' . $originid . '">' ;
2019-11-08 10:53:31 +01:00
if ( ! empty ( $currency_tx )) print '<input type="hidden" name="originmulticurrency_tx" value="' . $currency_tx . '">' ;
2016-08-10 09:47:25 +02:00
2017-10-16 08:47:05 +02:00
dol_fiche_head ();
2016-08-10 09:47:25 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Ref
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( 'Ref' ) . '</td><td>' . $langs -> trans ( 'Draft' ) . '</td></tr>' ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Third party
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Supplier' ) . '</td>' ;
print '<td>' ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
if ( $societe -> id > 0 )
{
2018-02-14 18:02:40 +01:00
$absolute_discount = $societe -> getAvailableDiscounts ( '' , '' , 0 , 1 );
2017-10-16 08:47:05 +02:00
print $societe -> getNomUrl ( 1 );
print '<input type="hidden" name="socid" value="' . $societe -> id . '">' ;
2020-05-21 15:05:19 +02:00
} else {
2019-05-21 17:22:38 +02:00
print $form -> select_company ( $societe -> id , 'socid' , 's.fournisseur=1' , 'SelectThirdParty' , 0 , 0 , null , 0 , 'minwidth300' );
2017-10-16 08:47:05 +02:00
// reload page to retrieve supplier informations
if ( ! empty ( $conf -> global -> RELOAD_PAGE_ON_SUPPLIER_CHANGE ))
{
print ' < script type = " text/javascript " >
2017-01-31 10:15:04 +01:00
$ ( document ) . ready ( function () {
$ ( " #socid " ) . change ( function () {
var socid = $ ( this ) . val ();
// reload page
window . location . href = " '. $_SERVER["PHP_SELF"] .'?action=create&socid= " + socid ;
});
});
</ script > ' ;
2017-10-16 08:47:05 +02:00
}
2020-03-13 16:52:00 +01:00
print ' <a href="' . DOL_URL_ROOT . '/societe/card.php?action=create&client=0&fournisseur=1&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?action=create' ) . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs -> trans ( " AddThirdParty " ) . '"></span></a>' ;
2017-10-16 08:47:05 +02:00
}
print '</td></tr>' ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Ref supplier
2020-08-26 17:09:45 +02:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'RefSupplier' ) . '</td><td><input name="ref_supplier" value="' . ( isset ( $_POST [ 'ref_supplier' ]) ? $_POST [ 'ref_supplier' ] : $objectsrc -> ref_supplier ) . '" type="text"' ;
if ( $societe -> id > 0 ) print ' autofocus' ;
print '></td>' ;
2017-10-16 08:47:05 +02:00
print '</tr>' ;
2012-10-28 13:57:21 +01:00
2016-11-25 17:47:47 +01:00
print '<tr><td class="tdtop fieldrequired">' . $langs -> trans ( 'Type' ) . '</td><td>' ;
2016-10-02 21:39:24 +02:00
2019-11-08 10:53:31 +01:00
print '<div class="tagtable">' . " \n " ;
2016-10-02 21:39:24 +02:00
// Standard invoice
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2019-11-08 10:53:31 +01:00
$tmp = '<input type="radio" id="radio_standard" name="type" value="0"' . ( GETPOST ( 'type' ) == 0 ? ' checked' : '' ) . '> ' ;
2016-10-02 21:39:24 +02:00
$desc = $form -> textwithpicto ( $tmp . $langs -> trans ( " InvoiceStandardAsk " ), $langs -> transnoentities ( " InvoiceStandardDesc " ), 1 , 'help' , '' , 0 , 3 );
print $desc ;
print '</div></div>' ;
2016-10-04 11:14:00 +02:00
/* Not yet supported
2016-10-02 21:39:24 +02:00
if (( empty ( $origin )) || ((( $origin == 'propal' ) || ( $origin == 'commande' )) && ( ! empty ( $originid ))))
{
// Deposit
2016-11-06 15:01:40 +01:00
if ( empty ( $conf -> global -> INVOICE_DISABLE_DEPOSIT ))
2016-10-02 21:39:24 +02:00
{
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
$tmp = '<input type="radio" id="radio_deposit" name="type" value="3"' . ( GETPOST ( 'type' ) == 3 ? ' checked' : '' ) . '> ' ;
print ' < script type = " text/javascript " language = " javascript " >
jQuery ( document ) . ready ( function () {
jQuery ( " #typedeposit, #valuedeposit " ) . click ( function () {
jQuery ( " #radio_deposit " ) . prop ( " checked " , true );
});
});
</ script > ' ;
$desc = $form -> textwithpicto ( $tmp . $langs -> trans ( " InvoiceDeposit " ), $langs -> transnoentities ( " InvoiceDepositDesc " ), 1 , 'help' , '' , 0 , 3 );
print '<table class="nobordernopadding"><tr><td>' ;
print $desc ;
print '</td>' ;
if (( $origin == 'propal' ) || ( $origin == 'commande' ))
{
print '<td class="nowrap" style="padding-left: 5px">' ;
2020-01-16 02:48:24 +01:00
$arraylist = array ( 'amount' => $langs -> transnoentitiesnoconv ( 'FixAmount' , $langs -> transnoentitiesnoconv ( 'Deposit' )), 'variable' => $langs -> transnoentitiesnoconv ( 'VarAmountOneLine' , $langs -> transnoentitiesnoconv ( 'Deposit' )));
2016-10-02 21:39:24 +02:00
print $form -> selectarray ( 'typedeposit' , $arraylist , GETPOST ( 'typedeposit' ), 0 , 0 , 0 , '' , 1 );
print '</td>' ;
print '<td class="nowrap" style="padding-left: 5px">' . $langs -> trans ( 'Value' ) . ':<input type="text" id="valuedeposit" name="valuedeposit" size="3" value="' . GETPOST ( 'valuedeposit' , 'int' ) . '"/>' ;
}
print '</td></tr></table>' ;
print '</div></div>' ;
}
}
2012-10-28 13:57:21 +01:00
*/
2016-11-06 15:01:40 +01:00
2017-11-23 15:22:32 +01:00
/* Not yet supported for supplier
2016-10-02 21:39:24 +02:00
if ( $societe -> id > 0 )
{
// Replacement
2016-11-06 15:01:40 +01:00
if ( empty ( $conf -> global -> INVOICE_DISABLE_REPLACEMENT ))
2016-10-02 21:39:24 +02:00
{
2019-09-17 09:43:15 +02:00
// Type invoice
$facids = $facturestatic -> list_replacable_supplier_invoices ( $societe -> id );
if ( $facids < 0 ) {
dol_print_error ( $db , $facturestatic );
exit ();
}
$options = " " ;
foreach ( $facids as $facparam )
{
$options .= '<option value="' . $facparam [ 'id' ] . '"' ;
if ( $facparam [ 'id' ] == $_POST [ 'fac_replacement' ])
$options .= ' selected' ;
$options .= '>' . $facparam [ 'ref' ];
$options .= ' (' . $facturestatic -> LibStatut ( 0 , $facparam [ 'status' ]) . ')' ;
$options .= '</option>' ;
}
2016-10-02 21:39:24 +02:00
print '<!-- replacement line -->' ;
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
$tmp = '<input type="radio" name="type" id="radio_replacement" value="1"' . ( GETPOST ( 'type' ) == 1 ? ' checked' : '' );
if ( ! $options ) $tmp .= ' disabled' ;
$tmp .= '> ' ;
print ' < script type = " text/javascript " language = " javascript " >
jQuery ( document ) . ready ( function () {
jQuery ( " #fac_replacement " ) . change ( function () {
jQuery ( " #radio_replacement " ) . prop ( " checked " , true );
});
});
</ script > ' ;
$text = $tmp . $langs -> trans ( " InvoiceReplacementAsk " ) . ' ' ;
$text .= '<select class="flat" name="fac_replacement" id="fac_replacement"' ;
if ( ! $options )
$text .= ' disabled' ;
$text .= '>' ;
if ( $options ) {
$text .= '<option value="-1"> </option>' ;
$text .= $options ;
} else {
$text .= '<option value="-1">' . $langs -> trans ( " NoReplacableInvoice " ) . '</option>' ;
}
$text .= '</select>' ;
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceReplacementDesc " ), 1 , 'help' , '' , 0 , 3 );
print $desc ;
print '</div></div>' ;
}
}
else
{
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
$tmp = '<input type="radio" name="type" id="radio_replacement" value="0" disabled> ' ;
$text = $tmp . $langs -> trans ( " InvoiceReplacement " ) . ' ' ;
$text .= '(' . $langs -> trans ( " YouMustCreateInvoiceFromSupplierThird " ) . ') ' ;
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceReplacementDesc " ), 1 , 'help' , '' , 0 , 3 );
print $desc ;
print '</div></div>' ;
}
2016-10-04 11:14:00 +02:00
*/
2016-10-02 21:39:24 +02:00
if ( empty ( $origin ))
{
2018-03-05 10:58:19 +01:00
if ( $societe -> id > 0 )
2017-10-16 08:47:05 +02:00
{
2018-03-05 10:58:19 +01:00
// Credit note
if ( empty ( $conf -> global -> INVOICE_DISABLE_CREDIT_NOTE ))
2017-10-16 08:47:05 +02:00
{
2019-09-17 09:43:15 +02:00
// Show link for credit note
2019-11-08 10:53:31 +01:00
$facids = $facturestatic -> list_qualified_avoir_supplier_invoices ( $societe -> id );
2019-09-17 09:43:15 +02:00
if ( $facids < 0 )
{
dol_print_error ( $db , $facturestatic );
exit ;
}
$optionsav = " " ;
$newinvoice_static = new FactureFournisseur ( $db );
foreach ( $facids as $key => $valarray )
{
$newinvoice_static -> id = $key ;
$newinvoice_static -> ref = $valarray [ 'ref' ];
$newinvoice_static -> statut = $valarray [ 'status' ];
$newinvoice_static -> type = $valarray [ 'type' ];
$newinvoice_static -> paye = $valarray [ 'paye' ];
2019-11-08 10:53:31 +01:00
$optionsav .= '<option value="' . $key . '"' ;
2019-09-17 09:43:15 +02:00
if ( $key == GETPOST ( 'fac_avoir' , 'int' ))
$optionsav .= ' selected' ;
$optionsav .= '>' ;
$optionsav .= $newinvoice_static -> ref ;
2019-11-08 10:53:31 +01:00
$optionsav .= ' (' . $newinvoice_static -> getLibStatut ( 1 , $valarray [ 'paymentornot' ]) . ')' ;
2019-09-17 09:43:15 +02:00
$optionsav .= '</option>' ;
}
2017-10-16 08:47:05 +02:00
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2019-11-08 10:53:31 +01:00
$tmp = '<input type="radio" id="radio_creditnote" name="type" value="2"' . ( GETPOST ( 'type' ) == 2 ? ' checked' : '' );
if ( ! $optionsav ) $tmp .= ' disabled' ;
$tmp .= '> ' ;
2018-03-05 10:58:19 +01:00
// Show credit note options only if we checked credit note
print ' < script type = " text/javascript " language = " javascript " >
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-08 10:53:31 +01:00
$text = $tmp . $langs -> transnoentities ( " InvoiceAvoirAsk " ) . ' ' ;
2018-03-05 10:58:19 +01:00
// $text.='<input type="text" value="">';
$text .= '<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"' ;
2019-11-08 10:53:31 +01:00
if ( ! $optionsav )
2018-03-05 10:58:19 +01:00
$text .= ' disabled' ;
$text .= '>' ;
if ( $optionsav ) {
$text .= '<option value="-1"></option>' ;
$text .= $optionsav ;
} else {
2019-11-08 10:53:31 +01:00
$text .= '<option value="-1">' . $langs -> trans ( " NoInvoiceToCorrect " ) . '</option>' ;
2018-03-05 10:58:19 +01:00
}
$text .= '</select>' ;
2017-10-16 08:47:05 +02:00
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceAvoirDesc " ), 1 , 'help' , '' , 0 , 3 );
print $desc ;
2018-03-05 10:58:19 +01:00
print '<div id="credit_note_options" class="clearboth">' ;
2019-11-08 10:53:31 +01:00
print ' <input type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithPaymentRestAmount\').removeAttr(\'checked\'); }" ' . ( GETPOST ( 'invoiceAvoirWithLines' , 'int' ) > 0 ? 'checked' : '' ) . ' /> ' ;
2018-05-27 15:04:12 +02:00
print '<label for="invoiceAvoirWithLines">' . $langs -> trans ( 'invoiceAvoirWithLines' ) . " </label> " ;
2019-11-08 10:53:31 +01:00
print '<br> <input type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithLines\').removeAttr(\'checked\'); }" ' . ( GETPOST ( 'invoiceAvoirWithPaymentRestAmount' , 'int' ) > 0 ? 'checked' : '' ) . ' /> ' ;
2018-05-27 15:04:12 +02:00
print '<label for="invoiceAvoirWithPaymentRestAmount">' . $langs -> trans ( 'invoiceAvoirWithPaymentRestAmount' ) . " </label> " ;
2018-03-05 10:58:19 +01:00
print '</div>' ;
print '</div></div>' ;
2017-10-16 08:47:05 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2018-03-05 10:58:19 +01:00
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">' ;
2019-11-08 10:53:31 +01:00
$tmp = '<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ' ;
$text = $tmp . $langs -> trans ( " InvoiceAvoir " ) . ' ' ;
$text .= '(' . $langs -> trans ( " YouMustCreateInvoiceFromSupplierThird " ) . ') ' ;
2018-03-05 10:58:19 +01:00
$desc = $form -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceAvoirDesc " ), 1 , 'help' , '' , 0 , 3 );
print $desc ;
2019-11-08 10:53:31 +01:00
print '</div></div>' . " \n " ;
2018-03-05 10:58:19 +01:00
}
2016-10-02 21:39:24 +02:00
}
print '</div>' ;
print '</td></tr>' ;
2018-03-05 10:58:19 +01:00
if ( $societe -> id > 0 )
2016-10-02 21:39:24 +02:00
{
// Discounts for third party
2019-11-08 10:53:31 +01:00
print '<tr><td>' . $langs -> trans ( 'Discounts' ) . '</td><td>' ;
2018-02-27 16:30:39 +01:00
2018-03-02 16:48:25 +01:00
$thirdparty = $societe ;
$discount_type = 1 ;
2019-11-08 10:53:31 +01:00
$backtopage = urlencode ( $_SERVER [ " PHP_SELF " ] . '?socid=' . $societe -> id . '&action=' . $action . '&origin=' . GETPOST ( 'origin' ) . '&originid=' . GETPOST ( 'originid' ));
2018-03-02 16:48:25 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/object_discounts.tpl.php' ;
2018-02-27 16:30:39 +01:00
2016-10-02 21:39:24 +02:00
print '</td></tr>' ;
}
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Label
print '<tr><td>' . $langs -> trans ( 'Label' ) . '</td><td><input class="minwidth200" name="label" value="' . dol_escape_htmltag ( GETPOST ( 'label' )) . '" type="text"></td></tr>' ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Date invoice
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'DateInvoice' ) . '</td><td>' ;
2018-09-09 09:56:33 +02:00
print $form -> selectDate ( $dateinvoice , '' , '' , '' , '' , " add " , 1 , 1 );
2017-10-16 08:47:05 +02:00
print '</td></tr>' ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Due date
print '<tr><td>' . $langs -> trans ( 'DateMaxPayment' ) . '</td><td>' ;
2018-09-09 09:56:33 +02:00
print $form -> selectDate ( $datedue , 'ech' , '' , '' , '' , " add " , 1 , 1 );
2017-10-16 08:47:05 +02:00
print '</td></tr>' ;
2013-09-06 09:26:23 +02:00
2013-07-30 16:21:39 +02:00
// Payment term
2017-06-07 16:44:04 +02:00
print '<tr><td class="nowrap">' . $langs -> trans ( 'PaymentConditionsShort' ) . '</td><td>' ;
2019-11-08 10:53:31 +01:00
$form -> select_conditions_paiements ( GETPOSTISSET ( 'cond_reglement_id' ) ? GETPOST ( 'cond_reglement_id' , 'int' ) : $cond_reglement_id , 'cond_reglement_id' );
2013-07-30 16:21:39 +02:00
print '</td></tr>' ;
// Payment mode
2017-06-07 16:44:04 +02:00
print '<tr><td>' . $langs -> trans ( 'PaymentMode' ) . '</td><td>' ;
2019-11-08 10:53:31 +01:00
$form -> select_types_paiements ( GETPOSTISSET ( 'mode_reglement_id' ) ? GETPOST ( 'mode_reglement_id' , 'int' ) : $mode_reglement_id , 'mode_reglement_id' , 'DBIT' );
2013-07-30 16:21:39 +02:00
print '</td></tr>' ;
2013-05-22 17:29:25 +02:00
2017-10-16 08:47:05 +02:00
// Bank Account
2020-08-28 13:08:04 +02:00
if ( ! empty ( $conf -> banque -> enabled ))
{
print '<tr><td>' . $langs -> trans ( 'BankAccount' ) . '</td><td>' ;
$form -> select_comptes (( GETPOSTISSET ( 'fk_account' ) ? GETPOST ( 'fk_account' , 'alpha' ) : $fk_account ), 'fk_account' , 0 , '' , 1 );
print '</td></tr>' ;
}
2016-04-01 16:29:47 +02:00
// Multicurrency
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> multicurrency -> enabled ))
2016-04-01 16:29:47 +02:00
{
print '<tr>' ;
2018-10-27 18:07:05 +02:00
print '<td>' . $form -> editfieldkey ( 'Currency' , 'multicurrency_code' , '' , $object , 0 ) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '<td class="maxwidthonsmartphone">' ;
2019-11-08 10:53:31 +01:00
print $form -> selectMultiCurrency (( GETPOSTISSET ( 'multicurrency_code' ) ? GETPOST ( 'multicurrency_code' , 'alpha' ) : $currency_code ), 'multicurrency_code' );
2016-04-01 16:29:47 +02:00
print '</td></tr>' ;
}
2014-09-07 12:22:04 +02:00
// Project
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> projet -> enabled ))
2015-01-30 16:33:39 +01:00
{
2014-09-07 12:22:04 +02:00
$formproject = new FormProjets ( $db );
$langs -> load ( 'projects' );
2019-11-08 10:53:31 +01:00
print '<tr><td>' . $langs -> trans ( 'Project' ) . '</td><td>' ;
2020-03-27 19:08:39 +01:00
$formproject -> select_projects (( empty ( $conf -> global -> PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS ) ? $societe -> id : - 1 ), $projectid , 'projectid' , 0 , 0 , 1 , 1 , 0 , 0 , 0 , '' , 0 , 0 , 'maxwidth500' );
2014-09-07 12:22:04 +02:00
print '</td></tr>' ;
}
2015-02-23 09:16:14 +01:00
// Incoterms
if ( ! empty ( $conf -> incoterm -> enabled ))
{
print '<tr>' ;
2019-06-25 13:00:02 +02:00
print '<td><label for="incoterm_id">' . $form -> textwithpicto ( $langs -> trans ( " IncotermLabel " ), $objectsrc -> label_incoterms , 1 ) . '</label></td>' ;
2017-10-16 08:47:05 +02:00
print '<td colspan="3" class="maxwidthonsmartphone">' ;
2019-11-08 10:53:31 +01:00
print $form -> select_incoterms ( GETPOSTISSET ( 'incoterm_id' ) ? GETPOST ( 'incoterm_id' , 'alphanohtml' ) : ( ! empty ( $objectsrc -> fk_incoterms ) ? $objectsrc -> fk_incoterms : '' ), GETPOSTISSET ( 'location_incoterms' ) ? GETPOST ( 'location_incoterms' , 'alphanohtml' ) : ( ! empty ( $objectsrc -> location_incoterms ) ? $objectsrc -> location_incoterms : '' ));
2015-02-23 09:16:14 +01:00
print '</td></tr>' ;
}
2014-09-07 12:22:04 +02:00
2014-08-06 16:46:04 +02:00
// Public note
print '<tr><td>' . $langs -> trans ( 'NotePublic' ) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '<td>' ;
2019-11-08 10:53:31 +01:00
$doleditor = new DolEditor ( 'note_public' , ( GETPOSTISSET ( 'note_public' ) ? GETPOST ( 'note_public' , 'none' ) : $note_public ), '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , '90%' );
2017-10-16 08:47:05 +02:00
print $doleditor -> Create ( 1 );
print '</td>' ;
2019-10-27 09:51:15 +01:00
// print '<td><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
2017-10-16 08:47:05 +02:00
print '</tr>' ;
2013-04-12 00:00:31 +02:00
2017-10-16 08:47:05 +02:00
// Private note
print '<tr><td>' . $langs -> trans ( 'NotePrivate' ) . '</td>' ;
print '<td>' ;
2019-11-08 10:53:31 +01:00
$doleditor = new DolEditor ( 'note_private' , ( GETPOSTISSET ( 'note_private' ) ? GETPOST ( 'note_private' , 'none' ) : $note_private ), '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , '90%' );
2017-10-16 08:47:05 +02:00
print $doleditor -> Create ( 1 );
print '</td>' ;
// print '<td><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
print '</tr>' ;
2015-01-25 21:32:40 +01:00
2018-04-13 13:28:48 +02:00
if ( empty ( $reshook ))
2014-11-06 22:16:27 +01:00
{
print $object -> showOptionals ( $extrafields , 'edit' );
}
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
if ( is_object ( $objectsrc ))
{
print " \n <!-- " . $classname . " info --> " ;
print " \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 " ;
print '<input type="hidden" name="origin" value="' . $objectsrc -> element . '">' ;
print '<input type="hidden" name="originid" value="' . $objectsrc -> id . '">' ;
2019-11-08 10:53:31 +01:00
$txt = $langs -> trans ( $classname );
if ( $classname == 'CommandeFournisseur' ) {
2017-10-16 08:47:05 +02:00
$langs -> load ( 'orders' );
2019-11-08 10:53:31 +01:00
$txt = $langs -> trans ( " SupplierOrder " );
2017-10-16 08:47:05 +02:00
}
print '<tr><td>' . $txt . '</td><td>' . $objectsrc -> getNomUrl ( 1 );
// 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 , '' , 'invoice_supplier' );
2019-10-28 10:40:07 +01:00
$invoice_supplier = $objectsrc -> linkedObjects [ 'invoice_supplier' ];
// count function need a array as argument (Note: the array must implement Countable too)
2019-11-08 10:53:31 +01:00
if ( is_array ( $invoice_supplier ))
2017-10-16 08:47:05 +02:00
{
2019-10-28 10:40:07 +01:00
$cntinvoice = count ( $invoice_supplier );
if ( $cntinvoice >= 1 )
{
setEventMessages ( 'WarningBillExist' , null , 'warnings' );
echo ' (' . $langs -> trans ( 'LatestRelatedBill' ) . end ( $invoice_supplier ) -> getNomUrl ( 1 ) . ')' ;
}
2017-10-16 08:47:05 +02:00
}
2019-10-28 10:40:07 +01:00
2017-10-16 08:47:05 +02:00
echo '</td></tr>' ;
2019-03-13 14:10:36 +01:00
print '<tr><td>' . $langs -> trans ( 'AmountHT' ) . '</td><td>' . price ( $objectsrc -> total_ht ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'AmountVAT' ) . '</td><td>' . price ( $objectsrc -> total_tva ) . " </td></tr> " ;
2019-11-08 10:53:31 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $object -> total_localtax1 != 0 ) //Localtax1
2017-10-16 08:47:05 +02:00
{
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT1 " , $mysoc -> country_code ) . '</td><td>' . price ( $objectsrc -> total_localtax1 ) . " </td></tr> " ;
2017-10-16 08:47:05 +02:00
}
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
if ( $mysoc -> localtax2_assuj == " 1 " || $object -> total_localtax2 != 0 ) //Localtax2
2017-10-16 08:47:05 +02:00
{
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT2 " , $mysoc -> country_code ) . '</td><td>' . price ( $objectsrc -> total_localtax2 ) . " </td></tr> " ;
2017-10-16 08:47:05 +02:00
}
2019-03-13 14:10:36 +01:00
print '<tr><td>' . $langs -> trans ( 'AmountTTC' ) . '</td><td>' . price ( $objectsrc -> total_ttc ) . " </td></tr> " ;
2016-08-10 09:47:25 +02:00
2016-02-19 22:25:59 +01:00
if ( ! empty ( $conf -> multicurrency -> enabled ))
{
2019-11-08 10:53:31 +01:00
print '<tr><td>' . $langs -> trans ( 'MulticurrencyAmountHT' ) . '</td><td>' . price ( $objectsrc -> multicurrency_total_ht ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'MulticurrencyAmountVAT' ) . '</td><td>' . price ( $objectsrc -> multicurrency_total_tva ) . " </td></tr> " ;
print '<tr><td>' . $langs -> trans ( 'MulticurrencyAmountTTC' ) . '</td><td>' . price ( $objectsrc -> multicurrency_total_ttc ) . " </td></tr> " ;
2016-02-19 22:25:59 +01:00
}
2017-10-16 08:47:05 +02:00
}
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Other options
2019-11-08 10:53:31 +01:00
$parameters = array ();
$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 ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Bouton "Create Draft"
print " </table> \n " ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
dol_fiche_end ();
2015-05-18 22:25:51 +02:00
2017-10-16 08:47:05 +02:00
print '<div class="center">' ;
print '<input type="submit" class="button" name="bouton" value="' . $langs -> trans ( 'CreateDraft' ) . '">' ;
2016-04-01 16:15:07 +02:00
print ' ' ;
2019-11-08 10:53:31 +01:00
print '<input type="button" class="button" value="' . $langs -> trans ( " Cancel " ) . '" onClick="javascript:history.go(-1)">' ;
2017-10-16 08:47:05 +02:00
print '</div>' ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
print " </form> \n " ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Show origin lines
if ( is_object ( $objectsrc ))
{
print '<br>' ;
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
$title = $langs -> trans ( 'ProductsAndServices' );
2017-10-16 08:47:05 +02:00
print load_fiche_titre ( $title );
2012-10-28 13:57:21 +01:00
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
$objectsrc -> printOriginLinesList ();
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
print '</table>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 10:53:31 +01:00
if ( $id > 0 || ! empty ( $ref ))
2017-10-16 08:47:05 +02:00
{
/* *************************************************************************** */
/* */
/* Fiche en mode visu ou edition */
/* */
/* *************************************************************************** */
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
$now = dol_now ();
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
$productstatic = new Product ( $db );
2012-10-28 13:57:21 +01:00
2019-01-27 11:55:16 +01:00
$object -> fetch ( $id , $ref );
2019-11-08 10:53:31 +01:00
$result = $object -> fetch_thirdparty ();
2017-10-16 08:47:05 +02:00
if ( $result < 0 ) dol_print_error ( $db );
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
$societe = new Fournisseur ( $db );
2019-11-08 10:53:31 +01:00
$result = $societe -> fetch ( $object -> socid );
2017-10-16 08:47:05 +02:00
if ( $result < 0 ) dol_print_error ( $db );
2015-01-25 21:32:40 +01:00
2017-12-05 12:31:57 +01:00
$totalpaye = $object -> getSommePaiement ();
$totalcreditnotes = $object -> getSumCreditNotesUsed ();
$totaldeposits = $object -> getSumDepositsUsed ();
// print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits."
// selleruserrevenuestamp=".$selleruserevenustamp;
// We can also use bcadd to avoid pb with floating points
// For example print 239.2 - 229.3 - 9.9; does not return 0.
// $resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
// $resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
$resteapayer = price2num ( $object -> total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits , 'MT' );
if ( $object -> paye )
{
$resteapayer = 0 ;
}
$resteapayeraffiche = $resteapayer ;
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS )) { // Never use this
2018-02-19 17:32:59 +01:00
$filterabsolutediscount = " fk_invoice_supplier_source IS NULL " ; // If we want deposit to be substracted to payments only and not to total of final invoice
$filtercreditnote = " fk_invoice_supplier_source IS NOT NULL " ; // If we want deposit to be substracted to payments only and not to total of final invoice
2018-02-14 10:47:10 +01:00
} else {
2018-02-19 17:32:59 +01:00
$filterabsolutediscount = " fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%') " ;
2018-02-20 10:08:55 +01:00
$filtercreditnote = " fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%') " ;
2018-02-14 10:47:10 +01:00
}
2018-03-08 20:49:37 +01:00
2018-02-14 18:02:40 +01:00
$absolute_discount = $societe -> getAvailableDiscounts ( '' , $filterabsolutediscount , 0 , 1 );
$absolute_creditnote = $societe -> getAvailableDiscounts ( '' , $filtercreditnote , 0 , 1 );
2018-02-14 10:47:10 +01:00
$absolute_discount = price2num ( $absolute_discount , 'MT' );
$absolute_creditnote = price2num ( $absolute_creditnote , 'MT' );
2016-10-02 21:39:24 +02:00
2017-10-16 08:47:05 +02:00
/*
2012-10-28 13:57:21 +01:00
* View card
2013-04-01 22:35:54 +02:00
*/
2017-10-16 08:47:05 +02:00
$head = facturefourn_prepare_head ( $object );
2019-11-08 10:53:31 +01:00
$titre = $langs -> trans ( 'SupplierInvoice' );
2013-11-17 23:25:25 +01:00
2017-10-16 08:47:05 +02:00
dol_fiche_head ( $head , 'card' , $titre , - 1 , 'bill' );
2012-10-28 13:57:21 +01:00
2018-02-14 10:47:10 +01:00
$formconfirm = '' ;
// Confirmation de la conversion de l'avoir en reduc
if ( $action == 'converttoreduc' ) {
2019-11-08 10:53:31 +01:00
if ( $object -> type == FactureFournisseur :: TYPE_STANDARD ) $type_fac = 'ExcessPaid' ;
elseif ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE ) $type_fac = 'CreditNote' ;
elseif ( $object -> type == FactureFournisseur :: TYPE_DEPOSIT ) $type_fac = 'Deposit' ;
2018-02-19 15:52:07 +01:00
$text = $langs -> trans ( 'ConfirmConvertToReducSupplier' , strtolower ( $langs -> transnoentities ( $type_fac )));
2019-06-19 14:24:48 +02:00
$text .= '<br>' . $langs -> trans ( 'ConfirmConvertToReducSupplier2' );
2019-11-08 10:53:31 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $langs -> trans ( 'ConvertToReduc' ), $text , 'confirm_converttoreduc' , '' , " yes " , 2 );
2018-02-14 10:47:10 +01:00
}
2017-10-16 08:47:05 +02:00
// Clone confirmation
if ( $action == 'clone' )
{
// Create an array for form
2019-11-08 10:53:31 +01:00
$formquestion = array (
2019-04-12 12:12:08 +02:00
array ( 'type' => 'text' , 'name' => 'newsupplierref' , 'label' => $langs -> trans ( " RefSupplier " ), 'value' => $langs -> trans ( " CopyOf " ) . ' ' . $object -> ref_supplier ),
array ( 'type' => 'date' , 'name' => 'newdate' , 'label' => $langs -> trans ( " Date " ), 'value' => dol_now ())
2017-10-16 08:47:05 +02:00
);
2019-04-12 12:12:08 +02:00
// Ask confirmation to clone
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'ToClone' ), $langs -> trans ( 'ConfirmCloneInvoice' , $object -> ref ), 'confirm_clone' , $formquestion , 'yes' , 1 , 250 );
2017-10-16 08:47:05 +02:00
}
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Confirmation de la validation
if ( $action == 'valid' )
{
2013-03-29 15:36:54 +01:00
// on verifie si l'objet est en numerotation provisoire
2017-10-16 08:47:05 +02:00
$objectref = substr ( $object -> ref , 1 , 4 );
if ( $objectref == 'PROV' )
{
2019-11-08 10:53:31 +01:00
$savdate = $object -> date ;
2017-10-16 08:47:05 +02:00
$numref = $object -> getNextNumRef ( $societe );
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
$numref = $object -> ref ;
}
2013-04-12 00:00:31 +02:00
2019-11-08 10:53:31 +01:00
$text = $langs -> trans ( 'ConfirmValidateBill' , $numref );
2017-10-16 08:47:05 +02:00
/* if ( ! empty ( $conf -> notification -> enabled ))
2013-04-21 14:24:19 +02:00
{
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php' ;
$notify = new Notify ( $db );
$text .= '<br>' ;
2015-03-18 21:44:57 +01:00
$text .= $notify -> confirmMessage ( 'BILL_SUPPLIER_VALIDATE' , $object -> socid , $object );
2013-04-12 00:00:31 +02:00
} */
2019-11-08 10:53:31 +01:00
$formquestion = array ();
2013-04-12 00:00:31 +02:00
2019-11-08 10:53:31 +01:00
$qualified_for_stock_change = 0 ;
2017-10-16 08:47:05 +02:00
if ( empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
{
2019-11-08 10:53:31 +01:00
$qualified_for_stock_change = $object -> hasProductsOrServices ( 2 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 10:53:31 +01:00
$qualified_for_stock_change = $object -> hasProductsOrServices ( 1 );
2017-10-16 08:47:05 +02:00
}
2014-06-23 11:47:07 +02:00
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> stock -> enabled ) && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_BILL ) && $qualified_for_stock_change )
2012-10-28 13:57:21 +01:00
{
$langs -> load ( " stocks " );
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
2019-11-08 10:53:31 +01:00
$formproduct = new FormProduct ( $db );
2017-10-21 20:26:32 +02:00
$warehouse = new Entrepot ( $db );
$warehouse_array = $warehouse -> list_array ();
if ( count ( $warehouse_array ) == 1 ) {
$label = $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE ? $langs -> trans ( " WarehouseForStockDecrease " , current ( $warehouse_array )) : $langs -> trans ( " WarehouseForStockIncrease " , current ( $warehouse_array ));
2019-11-08 10:53:31 +01:00
$value = '<input type="hidden" id="idwarehouse" name="idwarehouse" value="' . key ( $warehouse_array ) . '">' ;
2017-10-21 20:26:32 +02:00
} else {
$label = $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE ? $langs -> trans ( " SelectWarehouseForStockDecrease " ) : $langs -> trans ( " SelectWarehouseForStockIncrease " );
2019-11-08 10:53:31 +01:00
$value = $formproduct -> selectWarehouses ( GETPOST ( 'idwarehouse' ) ? GETPOST ( 'idwarehouse' ) : 'ifone' , 'idwarehouse' , '' , 1 );
2017-10-21 20:26:32 +02:00
}
$formquestion = array (
2019-11-08 10:53:31 +01:00
array ( 'type' => 'other' , 'name' => 'idwarehouse' , 'label' => $label , 'value' => $value )
2017-10-21 20:26:32 +02:00
);
2012-10-28 13:57:21 +01:00
}
2017-10-21 20:26:32 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'ValidateBill' ), $text , 'confirm_valid' , $formquestion , 1 , 1 );
}
// Confirmation edit (back to draft)
if ( $action == 'edit' )
{
$formquestion = array ();
$qualified_for_stock_change = 0 ;
if ( empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
{
$qualified_for_stock_change = $object -> hasProductsOrServices ( 2 );
2020-05-21 15:05:19 +02:00
} else {
2017-10-21 20:26:32 +02:00
$qualified_for_stock_change = $object -> hasProductsOrServices ( 1 );
}
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> stock -> enabled ) && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_BILL ) && $qualified_for_stock_change )
2017-10-21 20:26:32 +02:00
{
$langs -> load ( " stocks " );
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
$formproduct = new FormProduct ( $db );
$warehouse = new Entrepot ( $db );
$warehouse_array = $warehouse -> list_array ();
if ( count ( $warehouse_array ) == 1 ) {
$label = $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE ? $langs -> trans ( " WarehouseForStockIncrease " , current ( $warehouse_array )) : $langs -> trans ( " WarehouseForStockDecrease " , current ( $warehouse_array ));
2019-11-08 10:53:31 +01:00
$value = '<input type="hidden" id="idwarehouse" name="idwarehouse" value="' . key ( $warehouse_array ) . '">' ;
2017-10-21 20:26:32 +02:00
} else {
$label = $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE ? $langs -> trans ( " SelectWarehouseForStockIncrease " ) : $langs -> trans ( " SelectWarehouseForStockDecrease " );
2019-11-08 10:53:31 +01:00
$value = $formproduct -> selectWarehouses ( GETPOST ( 'idwarehouse' ) ? GETPOST ( 'idwarehouse' ) : 'ifone' , 'idwarehouse' , '' , 1 );
2017-10-21 20:26:32 +02:00
}
$formquestion = array (
2019-11-08 10:53:31 +01:00
array ( 'type' => 'other' , 'name' => 'idwarehouse' , 'label' => $label , 'value' => $value )
2017-10-21 20:26:32 +02:00
);
}
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'UnvalidateBill' ), $langs -> trans ( 'ConfirmUnvalidateBill' , $object -> ref ), 'confirm_edit' , $formquestion , 1 , 1 );
2017-10-16 08:47:05 +02:00
}
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Confirmation set paid
if ( $action == 'paid' )
{
2016-03-25 15:53:44 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'ClassifyPaid' ), $langs -> trans ( 'ConfirmClassifyPaidBill' , $object -> ref ), 'confirm_paid' , '' , 0 , 1 );
2017-10-16 08:47:05 +02:00
}
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Confirmation de la suppression de la facture fournisseur
if ( $action == 'delete' )
{
2016-03-25 15:53:44 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'DeleteBill' ), $langs -> trans ( 'ConfirmDeleteBill' ), 'confirm_delete' , '' , 0 , 1 );
2017-10-16 08:47:05 +02:00
}
if ( $action == 'deletepaiement' )
{
$payment_id = GETPOST ( 'paiement_id' );
2016-07-01 16:59:03 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&paiement_id=' . $payment_id , $langs -> trans ( 'DeletePayment' ), $langs -> trans ( 'ConfirmDeletePayment' ), 'confirm_delete_paiement' , '' , 0 , 1 );
2017-10-16 08:47:05 +02:00
}
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Confirmation to delete line
2015-02-28 04:59:27 +01:00
if ( $action == 'ask_deleteline' )
{
2019-11-08 10:53:31 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&lineid=' . $lineid , $langs -> trans ( 'DeleteProductLine' ), $langs -> trans ( 'ConfirmDeleteProductLine' ), 'confirm_deleteline' , '' , 0 , 1 );
2015-02-28 04:59:27 +01:00
}
2017-10-16 08:47:05 +02:00
if ( ! $formconfirm )
{
2020-01-28 12:00:27 +01:00
$parameters = array ( 'formConfirm' => $formconfirm , 'lineid' => $lineid );
2015-03-18 14:31:37 +01:00
$reshook = $hookmanager -> executeHooks ( 'formConfirm' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2019-11-08 10:53:31 +01:00
if ( empty ( $reshook )) $formconfirm .= $hookmanager -> resPrint ;
elseif ( $reshook > 0 ) $formconfirm = $hookmanager -> resPrint ;
2014-07-22 04:25:44 +02:00
}
2014-07-22 04:24:08 +02:00
// Print form confirm
2014-07-22 04:27:41 +02:00
print $formconfirm ;
2014-07-22 04:24:08 +02:00
2012-10-28 13:57:21 +01:00
2016-09-26 00:10:29 +02:00
// Supplier invoice card
2019-11-08 10:53:31 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/fourn/facture/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
$morehtmlref = '<div class="refidno">' ;
2016-09-26 00:10:29 +02:00
// Ref supplier
2020-04-21 10:02:18 +02:00
$morehtmlref .= $form -> editfieldkey ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , $usercancreate , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , $usercancreate , 'string' , '' , null , null , '' , 1 );
2016-09-26 00:10:29 +02:00
// Thirdparty
2019-11-08 10:53:31 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 );
if ( empty ( $conf -> global -> MAIN_DISABLE_OTHER_LINK ) && $object -> thirdparty -> id > 0 ) $morehtmlref .= ' (<a href="' . DOL_URL_ROOT . '/fourn/facture/list.php?socid=' . $object -> thirdparty -> id . '&search_company=' . urlencode ( $object -> thirdparty -> name ) . '">' . $langs -> trans ( " OtherBills " ) . '</a>)' ;
2016-09-26 00:10:29 +02:00
// Project
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> projet -> enabled ))
2016-09-26 00:10:29 +02:00
{
$langs -> load ( " projects " );
2019-11-08 10:53:31 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2020-04-21 10:02:18 +02:00
if ( $usercancreate )
2016-09-26 00:10:29 +02:00
{
2019-10-27 09:51:15 +01:00
if ( $action != 'classify' ) {
2019-11-08 10:53:31 +01:00
$morehtmlref .= '<a class="editfielda" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=classify&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetProject' )) . '</a> : ' ;
2019-10-27 09:51:15 +01: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-08 10:53:31 +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-08 10:53:31 +01:00
$morehtmlref .= $formproject -> select_projects (( empty ( $conf -> global -> PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS ) ? $object -> socid : - 1 ), $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-27 09:51:15 +01:00
} else {
2019-11-08 10:53:31 +01:00
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
2019-10-27 09:51:15 +01:00
}
2016-09-26 00:10:29 +02:00
} else {
2019-11-08 10:53:31 +01:00
if ( ! empty ( $object -> fk_project )) {
2016-09-26 00:10:29 +02:00
$proj = new Project ( $db );
$proj -> fetch ( $object -> fk_project );
2019-11-08 10:53:31 +01:00
$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $object -> fk_project . '" title="' . $langs -> trans ( 'ShowProject' ) . '">' ;
$morehtmlref .= $proj -> ref ;
$morehtmlref .= '</a>' ;
2016-09-26 00:10:29 +02:00
} else {
2019-11-08 10:53:31 +01:00
$morehtmlref .= '' ;
2016-09-26 00:10:29 +02:00
}
}
}
2019-11-08 10:53:31 +01:00
$morehtmlref .= '</div>' ;
2016-10-02 21:39:24 +02:00
2019-11-08 10:53:31 +01:00
$object -> totalpaye = $totalpaye ; // To give a chance to dol_banner_tab to use already paid amount to show correct status
2016-10-02 21:39:24 +02:00
2016-11-06 15:01:40 +01:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
2016-10-02 21:39:24 +02:00
2016-09-26 00:10:29 +02:00
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2016-10-02 21:39:24 +02:00
2019-01-17 19:27:26 +01:00
print '<table class="border tableforfield" width="100%">' ;
2012-10-28 13:57:21 +01:00
// Type
2016-09-26 00:10:29 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( 'Type' ) . '</td><td>' ;
2012-10-28 13:57:21 +01:00
print $object -> getLibType ();
2014-02-26 01:09:34 +01:00
if ( $object -> type == FactureFournisseur :: TYPE_REPLACEMENT )
2012-10-28 13:57:21 +01:00
{
2019-11-08 10:53:31 +01:00
$facreplaced = new FactureFournisseur ( $db );
2012-10-28 13:57:21 +01:00
$facreplaced -> fetch ( $object -> fk_facture_source );
2019-01-27 11:55:16 +01:00
print ' (' . $langs -> transnoentities ( " ReplaceInvoice " , $facreplaced -> getNomUrl ( 1 )) . ')' ;
2012-10-28 13:57:21 +01:00
}
2014-02-26 01:09:34 +01:00
if ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE )
2012-10-28 13:57:21 +01:00
{
2019-11-08 10:53:31 +01:00
$facusing = new FactureFournisseur ( $db );
2012-10-28 13:57:21 +01:00
$facusing -> fetch ( $object -> fk_facture_source );
2019-01-27 11:55:16 +01:00
print ' (' . $langs -> transnoentities ( " CorrectInvoice " , $facusing -> getNomUrl ( 1 )) . ')' ;
2012-10-28 13:57:21 +01:00
}
2019-11-08 10:53:31 +01:00
$facidavoir = $object -> getListIdAvoirFromInvoice ();
2012-10-28 13:57:21 +01:00
if ( count ( $facidavoir ) > 0 )
{
print ' (' . $langs -> transnoentities ( " InvoiceHasAvoir " );
2019-11-08 10:53:31 +01:00
$i = 0 ;
foreach ( $facidavoir as $id )
2012-10-28 13:57:21 +01:00
{
2019-11-08 10:53:31 +01:00
if ( $i == 0 ) print ' ' ;
2012-10-28 13:57:21 +01:00
else print ',' ;
2019-11-08 10:53:31 +01:00
$facavoir = new FactureFournisseur ( $db );
2012-10-28 13:57:21 +01:00
$facavoir -> fetch ( $id );
print $facavoir -> getNomUrl ( 1 );
}
print ')' ;
}
if ( isset ( $facidnext ) && $facidnext > 0 )
{
2019-11-08 10:53:31 +01:00
$facthatreplace = new FactureFournisseur ( $db );
2012-10-28 13:57:21 +01:00
$facthatreplace -> fetch ( $facidnext );
2019-01-27 11:55:16 +01:00
print ' (' . $langs -> transnoentities ( " ReplacedByInvoice " , $facthatreplace -> getNomUrl ( 1 )) . ')' ;
2012-10-28 13:57:21 +01:00
}
2018-02-21 17:15:16 +01:00
if ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE || $object -> type == FactureFournisseur :: TYPE_DEPOSIT ) {
$discount = new DiscountAbsolute ( $db );
$result = $discount -> fetch ( 0 , 0 , $object -> id );
2019-11-08 10:53:31 +01:00
if ( $result > 0 ) {
2018-08-28 18:34:53 +02:00
print '. ' . $langs -> trans ( " CreditNoteConvertedIntoDiscount " , $object -> getLibType ( 1 ), $discount -> getNomUrl ( 1 , 'discount' )) . '<br>' ;
2018-02-21 17:15:16 +01:00
}
}
2012-10-28 13:57:21 +01:00
print '</td></tr>' ;
2018-02-27 16:30:39 +01:00
2018-03-05 10:58:19 +01:00
// Relative and absolute discounts
2019-11-08 10:53:31 +01:00
print '<!-- Discounts --><tr><td>' . $langs -> trans ( 'Discounts' );
2018-03-05 10:58:19 +01:00
print '</td><td>' ;
2018-02-27 16:30:39 +01:00
2018-03-05 10:58:19 +01:00
$thirdparty = $societe ;
$discount_type = 1 ;
2019-11-08 10:53:31 +01:00
$backtopage = urlencode ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id );
2018-03-05 10:58:19 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/object_discounts.tpl.php' ;
print '</td></tr>' ;
2018-02-27 16:30:39 +01:00
2012-10-28 13:57:21 +01:00
// Label
2016-11-22 20:55:57 +01:00
print '<tr>' ;
2020-04-21 10:02:18 +02:00
print '<td>' . $form -> editfieldkey ( " Label " , 'label' , $object -> label , $object , ( $usercancreate )) . '</td>' ;
print '<td>' . $form -> editfieldval ( " Label " , 'label' , $object -> label , $object , ( $usercancreate )) . '</td>' ;
2012-10-28 13:57:21 +01:00
print '</tr>' ;
2020-04-21 10:02:18 +02:00
$form_permission = ( $object -> statut < FactureFournisseur :: STATUS_CLOSED ) && $usercancreate && ( $object -> getSommePaiement () <= 0 );
2015-04-03 05:18:47 +02:00
2012-10-28 13:57:21 +01:00
// Date
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $form -> editfieldkey ( " DateInvoice " , 'datef' , $object -> datep , $object , $form_permission , 'datepicker' ) . '</td><td colspan="3">' ;
print $form -> editfieldval ( " Date " , 'datef' , $object -> datep , $object , $form_permission , 'datepicker' );
2012-10-28 13:57:21 +01:00
print '</td>' ;
2019-03-22 09:44:30 +01:00
// Default terms of the settlement
2013-07-30 16:21:39 +02:00
$langs -> load ( 'bills' );
print '<tr><td class="nowrap">' ;
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">' ;
print $langs -> trans ( 'PaymentConditions' );
print '<td>' ;
2020-04-21 10:02:18 +02:00
if ( $action != 'editconditions' && $usercancreate ) {
2019-10-06 15:34:22 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editconditions&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetConditions' ), 1 ) . '</a></td>' ;
2017-04-09 18:09:08 +02:00
}
2013-07-30 16:21:39 +02:00
print '</tr></table>' ;
print '</td><td colspan="2">' ;
if ( $action == 'editconditions' )
{
2019-02-09 12:00:49 +01:00
$form -> form_conditions_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> cond_reglement_id , 'cond_reglement_id' );
2020-05-21 15:05:19 +02:00
} else {
2019-02-09 12:00:49 +01:00
$form -> form_conditions_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> cond_reglement_id , 'none' );
2013-07-30 16:21:39 +02:00
}
print " </td> " ;
print '</tr>' ;
2013-09-06 09:26:23 +02:00
2020-06-22 22:54:33 +02:00
// Due date
print '<tr><td>' . $form -> editfieldkey ( " DateMaxPayment " , 'date_lim_reglement' , $object -> date_echeance , $object , $form_permission , 'datepicker' ) . '</td><td colspan="3">' ;
print $form -> editfieldval ( " DateMaxPayment " , 'date_lim_reglement' , $object -> date_echeance , $object , $form_permission , 'datepicker' );
if ( $action != 'editdate_lim_reglement' && $object -> hasDelay ()) {
print img_warning ( $langs -> trans ( 'Late' ));
}
print '</td>' ;
2013-07-30 16:21:39 +02:00
// Mode of payment
$langs -> load ( 'bills' );
print '<tr><td class="nowrap">' ;
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">' ;
print $langs -> trans ( 'PaymentMode' );
print '</td>' ;
2020-04-21 10:02:18 +02:00
if ( $action != 'editmode' && $usercancreate ) {
2019-10-06 15:34:22 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editmode&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetMode' ), 1 ) . '</a></td>' ;
2017-04-09 18:09:08 +02:00
}
2013-07-30 16:21:39 +02:00
print '</tr></table>' ;
print '</td><td colspan="2">' ;
if ( $action == 'editmode' )
{
2018-12-29 07:54:30 +01:00
$form -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> mode_reglement_id , 'mode_reglement_id' , 'DBIT' , 1 , 1 );
2020-05-21 15:05:19 +02:00
} else {
2018-12-29 07:54:30 +01:00
$form -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> mode_reglement_id , 'none' );
2013-07-30 16:21:39 +02:00
}
print '</td></tr>' ;
2016-02-19 22:25:59 +01:00
// Multicurrency
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> multicurrency -> enabled ))
2016-02-19 22:25:59 +01:00
{
// Multicurrency code
print '<tr>' ;
print '<td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
2018-10-27 18:07:05 +02:00
print $form -> editfieldkey ( 'Currency' , 'multicurrency_code' , '' , $object , 0 );
2016-02-19 22:25:59 +01:00
print '</td>' ;
2019-11-03 17:48:16 +01:00
if ( $action != 'editmulticurrencycode' && $object -> statut == $object :: STATUS_DRAFT )
2019-11-08 10:53:31 +01:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editmulticurrencycode&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetMultiCurrencyCode' ), 1 ) . '</a></td>' ;
2016-02-19 22:25:59 +01:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
if ( $action == 'editmulticurrencycode' ) {
2019-11-08 10:53:31 +01:00
$form -> form_multicurrency_code ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> multicurrency_code , 'multicurrency_code' );
2016-02-19 22:25:59 +01:00
} else {
2019-11-08 10:53:31 +01:00
$form -> form_multicurrency_code ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> multicurrency_code , 'none' );
2016-02-19 22:25:59 +01:00
}
print '</td></tr>' ;
2016-08-10 09:47:25 +02:00
2016-02-19 22:25:59 +01:00
// Multicurrency rate
2019-11-03 17:48:16 +01:00
if ( $object -> multicurrency_code != $conf -> currency || $object -> multicurrency_tx != 1 )
{
print '<tr>' ;
print '<td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $form -> editfieldkey ( 'CurrencyRate' , 'multicurrency_tx' , '' , $object , 0 );
print '</td>' ;
if ( $action != 'editmulticurrencyrate' && $object -> statut == $object :: STATUS_DRAFT && $object -> multicurrency_code && $object -> multicurrency_code != $conf -> currency )
2019-11-08 10:53:31 +01:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editmulticurrencyrate&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetMultiCurrencyCode' ), 1 ) . '</a></td>' ;
2019-11-03 17:48:16 +01:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
if ( $action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate' ) {
if ( $action == 'actualizemulticurrencyrate' ) {
list ( $object -> fk_multicurrency , $object -> multicurrency_tx ) = MultiCurrency :: getIdAndTxFromCode ( $object -> db , $object -> multicurrency_code );
}
2019-11-08 10:53:31 +01:00
$form -> form_multicurrency_rate ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> multicurrency_tx , 'multicurrency_tx' , $object -> multicurrency_code );
2019-11-03 17:48:16 +01:00
} else {
2019-11-08 10:53:31 +01:00
$form -> form_multicurrency_rate ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> multicurrency_tx , 'none' , $object -> multicurrency_code );
2019-11-03 17:48:16 +01:00
if ( $object -> statut == $object :: STATUS_DRAFT && $object -> multicurrency_code && $object -> multicurrency_code != $conf -> currency ) {
print '<div class="inline-block"> ' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=actualizemulticurrencyrate">' . $langs -> trans ( " ActualizeCurrency " ) . '</a>' ;
print '</div>' ;
}
2016-12-11 02:50:21 +01:00
}
2019-11-03 17:48:16 +01:00
print '</td></tr>' ;
2016-02-19 22:25:59 +01:00
}
}
2017-10-16 08:47:05 +02:00
// Bank Account
2020-08-28 12:53:30 +02:00
if ( ! empty ( $conf -> banque -> enabled ))
{
print '<tr><td class="nowrap">' ;
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">' ;
print $langs -> trans ( 'BankAccount' );
print '<td>' ;
if ( $action != 'editbankaccount' && $usercancreate )
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editbankaccount&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetBankAccount' ), 1 ) . '</a></td>' ;
print '</tr></table>' ;
print '</td><td colspan="3">' ;
if ( $action == 'editbankaccount' ) {
$form -> formSelectAccount ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> fk_account , 'fk_account' , 1 );
} else {
$form -> formSelectAccount ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> fk_account , 'none' );
}
print " </td> " ;
print '</tr>' ;
2017-10-16 08:47:05 +02:00
}
2014-07-09 18:44:20 +02:00
2015-02-23 09:16:14 +01:00
// Incoterms
if ( ! empty ( $conf -> incoterm -> enabled ))
2015-03-04 23:03:29 +01:00
{
2015-02-23 09:16:14 +01:00
print '<tr><td>' ;
2017-10-16 08:47:05 +02:00
print '<table width="100%" class="nobordernopadding"><tr><td>' ;
print $langs -> trans ( 'IncotermLabel' );
2019-03-07 20:46:38 +01:00
print '<td><td class="right">' ;
2020-04-21 10:02:18 +02:00
if ( $usercancreate ) print '<a class="editfielda" href="' . DOL_URL_ROOT . '/fourn/facture/card.php?facid=' . $object -> id . '&action=editincoterm">' . img_edit () . '</a>' ;
2017-10-16 08:47:05 +02:00
else print ' ' ;
print '</td></tr></table>' ;
print '</td>' ;
print '<td colspan="3">' ;
2015-02-23 09:16:14 +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-08 10:53:31 +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
}
2015-03-04 23:03:29 +01:00
2017-10-16 08:47:05 +02:00
// Other attributes
$cols = 2 ;
2019-11-08 10:53:31 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2016-11-06 15:01:40 +01:00
2017-10-16 08:47:05 +02:00
print '</table>' ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
print '</div>' ;
print '<div class="fichehalfright">' ;
print '<div class="ficheaddleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2016-10-29 07:45:24 +02:00
2019-01-17 19:31:01 +01:00
print '<table class="border tableforfield centpercent">' ;
2016-10-29 07:45:24 +02:00
2017-10-16 08:47:05 +02:00
if ( ! empty ( $conf -> multicurrency -> enabled ) && ( $object -> multicurrency_code != $conf -> currency ))
2016-11-03 20:55:55 +01:00
{
2017-10-16 08:47:05 +02:00
// Multicurrency Amount HT
2019-11-08 10:53:31 +01:00
print '<tr><td class="titlefieldmiddle">' . $form -> editfieldkey ( 'MulticurrencyAmountHT' , 'multicurrency_total_ht' , '' , $object , 0 ) . '</td>' ;
print '<td class="nowrap">' . price ( $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-08 10:53:31 +01:00
print '<tr><td>' . $form -> editfieldkey ( 'MulticurrencyAmountVAT' , 'multicurrency_total_tva' , '' , $object , 0 ) . '</td>' ;
print '<td>' . price ( $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-08 10:53:31 +01:00
print '<tr><td height="10">' . $form -> editfieldkey ( 'MulticurrencyAmountTTC' , 'multicurrency_total_ttc' , '' , $object , 0 ) . '</td>' ;
print '<td>' . price ( $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-11-03 20:55:55 +01:00
2017-10-16 08:47:05 +02:00
// Amount
2019-01-27 11:55:16 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( 'AmountHT' ) . '</td><td>' . price ( $object -> total_ht , 1 , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'AmountVAT' ) . '</td><td>' . price ( $object -> total_tva , 1 , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '<div class="inline-block"> ' ;
2019-11-08 10:53:31 +01:00
if ( GETPOST ( 'calculationrule' )) $calculationrule = GETPOST ( 'calculationrule' , 'alpha' );
else $calculationrule = ( empty ( $conf -> global -> MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND ) ? 'totalofround' : 'roundoftotal' );
if ( $calculationrule == 'totalofround' ) $calculationrulenum = 1 ;
2020-05-21 01:52:25 +02:00
else $calculationrulenum = 2 ;
2019-11-22 14:51:13 +01:00
// Show link for "recalculate"
2019-11-24 18:12:40 +01:00
if ( $object -> getVentilExportCompta () == 0 ) {
2019-11-22 15:04:40 +01:00
$s = $langs -> trans ( " ReCalculate " ) . ' ' ;
$s .= '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=calculate&calculationrule=totalofround">' . $langs -> trans ( " Mode1 " ) . '</a>' ;
$s .= ' / ' ;
$s .= '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=calculate&calculationrule=roundoftotal">' . $langs -> trans ( " Mode2 " ) . '</a>' ;
2019-11-22 14:51:13 +01:00
print $form -> textwithtooltip ( $s , $langs -> trans ( " CalculationRuleDesc " , $calculationrulenum ) . '<br>' . $langs -> trans ( " CalculationRuleDescSupplier " ), 2 , 1 , img_picto ( '' , 'help' ));
2019-11-21 14:58:20 +01:00
}
2017-10-16 08:47:05 +02:00
print '</div></td></tr>' ;
// Amount Local Taxes
//TODO: Place into a function to control showing by country or study better option
2019-11-08 10:53:31 +01:00
if ( $societe -> localtax1_assuj == " 1 " ) //Localtax1
2017-10-16 08:47:05 +02:00
{
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT1 " , $societe -> country_code ) . '</td>' ;
print '<td>' . price ( $object -> total_localtax1 , 1 , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '</tr>' ;
}
2019-11-08 10:53:31 +01:00
if ( $societe -> localtax2_assuj == " 1 " ) //Localtax2
2017-10-16 08:47:05 +02:00
{
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT2 " , $societe -> country_code ) . '</td>' ;
print '<td>' . price ( $object -> total_localtax2 , 1 , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '</tr>' ;
}
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> trans ( 'AmountTTC' ) . '</td><td colspan="3">' . price ( $object -> total_ttc , 1 , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2016-10-29 07:45:24 +02:00
2017-10-16 08:47:05 +02:00
print '</table>' ;
2016-11-06 15:01:40 +01:00
2017-10-16 08:47:05 +02:00
/*
2016-09-26 00:10:29 +02:00
* List of payments
*/
2017-02-02 20:07:41 +01:00
2017-10-16 08:47:05 +02:00
$totalpaye = 0 ;
2017-02-02 20:07:41 +01:00
2016-10-29 07:45:24 +02:00
$sign = 1 ;
if ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE ) $sign = - 1 ;
2019-11-08 10:53:31 +01:00
$nbrows = 9 ; $nbcols = 3 ;
if ( ! empty ( $conf -> projet -> enabled )) $nbrows ++ ;
if ( ! empty ( $conf -> banque -> enabled )) { $nbrows ++ ; $nbcols ++ ; }
if ( ! empty ( $conf -> incoterm -> enabled )) $nbrows ++ ;
if ( ! empty ( $conf -> multicurrency -> enabled )) $nbrows += 5 ;
2016-10-29 07:45:24 +02:00
2017-10-16 08:47:05 +02:00
// Local taxes
2019-11-08 10:53:31 +01:00
if ( $societe -> localtax1_assuj == " 1 " ) $nbrows ++ ;
if ( $societe -> localtax2_assuj == " 1 " ) $nbrows ++ ;
2017-10-16 08:47:05 +02:00
$sql = 'SELECT p.datep as dp, p.ref, p.num_paiement, p.rowid, p.fk_bank,' ;
2019-11-08 10:53:31 +01:00
$sql .= ' c.id as paiement_type,' ;
$sql .= ' pf.amount,' ;
$sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiementfourn as p' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_paiement as c ON p.fk_paiement = c.id' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid' ;
$sql .= ' WHERE pf.fk_facturefourn = ' . $object -> id ;
$sql .= ' ORDER BY p.datep, p.tms' ;
2017-10-16 08:47:05 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ( $result );
$i = 0 ;
2018-01-12 00:16:55 +01:00
print '<div class="div-table-responsive-no-min">' ;
2017-10-16 08:47:05 +02:00
print '<table class="noborder paymenttable" width="100%">' ;
print '<tr class="liste_titre">' ;
2019-11-08 10:53:31 +01:00
print '<td class="liste_titre">' . ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE ? $langs -> trans ( " PaymentsBack " ) : $langs -> trans ( 'Payments' )) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '<td>' . $langs -> trans ( 'Date' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Type' ) . '</td>' ;
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> banque -> enabled )) print '<td class="right">' . $langs -> trans ( 'BankAccount' ) . '</td>' ;
2019-03-07 20:46:38 +01:00
print '<td class="right">' . $langs -> trans ( 'Amount' ) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '<td width="18"> </td>' ;
print '</tr>' ;
if ( $num > 0 )
{
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
2019-11-08 10:53:31 +01:00
$paymentstatic -> id = $objp -> rowid ;
$paymentstatic -> datepaye = $db -> jdate ( $objp -> dp );
$paymentstatic -> ref = ( $objp -> ref ? $objp -> ref : $objp -> rowid );
$paymentstatic -> num_paiement = $objp -> num_paiement ;
$paymentstatic -> payment_code = $objp -> payment_code ;
2017-11-23 15:22:32 +01:00
print '<tr class="oddeven">' ;
print '<td>' ;
2017-10-16 08:47:05 +02:00
print $paymentstatic -> getNomUrl ( 1 );
print '</td>' ;
2019-11-08 10:53:31 +01:00
print '<td>' . dol_print_date ( $db -> jdate ( $objp -> dp ), 'day' ) . '</td>' ;
2017-10-16 08:47:05 +02:00
print '<td>' ;
2019-01-27 11:55:16 +01:00
print $form -> form_modes_reglement ( null , $objp -> paiement_type , 'none' ) . ' ' . $objp -> num_paiement ;
2017-10-16 08:47:05 +02:00
print '</td>' ;
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> banque -> enabled ))
2017-10-16 08:47:05 +02:00
{
2019-11-08 10:53:31 +01:00
$bankaccountstatic -> id = $objp -> baid ;
$bankaccountstatic -> ref = $objp -> baref ;
$bankaccountstatic -> label = $objp -> baref ;
2017-05-15 05:11:00 +02:00
$bankaccountstatic -> number = $objp -> banumber ;
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) {
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
}
2019-03-07 20:46:38 +01:00
print '<td class="right">' ;
2019-01-27 11:55:16 +01:00
if ( $objp -> baid > 0 ) print $bankaccountstatic -> getNomUrl ( 1 , 'transactions' );
2017-10-16 08:47:05 +02:00
print '</td>' ;
}
2019-11-08 10:53:31 +01:00
print '<td class="right">' . price ( $sign * $objp -> amount ) . '</td>' ;
2019-03-07 20:46:38 +01:00
print '<td class="center">' ;
2019-10-31 20:46:31 +01:00
if ( $object -> statut == FactureFournisseur :: STATUS_VALIDATED && $object -> paye == 0 && $user -> socid == 0 )
2017-10-16 08:47:05 +02:00
{
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=deletepaiement&paiement_id=' . $objp -> rowid . '">' ;
print img_delete ();
print '</a>' ;
}
print '</td>' ;
print '</tr>' ;
$totalpaye += $objp -> amount ;
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-05-03 11:25:53 +02:00
print '<tr class="oddeven"><td colspan="' . $nbcols . '"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td><td></td><td></td></tr>' ;
2017-10-16 08:47:05 +02:00
}
2016-11-02 07:13:17 +01:00
/*
2016-09-26 00:10:29 +02:00
if ( $object -> paye == 0 )
{
2019-03-07 20:46:38 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' . $langs -> trans ( 'AlreadyPaid' ) . ' :</td><td class="right">' . price ( $totalpaye ) . '</td><td></td></tr>' ;
print '<tr><td colspan="' . $nbcols . '" class="right">' . $langs -> trans ( " Billed " ) . ' :</td><td class="right">' . price ( $object -> total_ttc ) . '</td><td></td></tr>' ;
2016-11-06 15:01:40 +01:00
2016-09-26 00:10:29 +02:00
$resteapayer = $object -> total_ttc - $totalpaye ;
2016-11-06 15:01:40 +01:00
2019-03-07 20:46:38 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' . $langs -> trans ( 'RemainderToPay' ) . ' :</td>' ;
2019-03-31 11:25:29 +02:00
print '<td class="right' . ( $resteapayer ? ' amountremaintopay' : '' ) . '">' . price ( $resteapayer ) . '</td><td></td></tr>' ;
2016-09-26 00:10:29 +02:00
}
2016-11-02 07:13:17 +01:00
*/
2017-10-16 08:47:05 +02:00
$db -> free ( $result );
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
dol_print_error ( $db );
}
2016-09-26 00:10:29 +02:00
2017-02-02 20:07:41 +01:00
if ( $object -> type != FactureFournisseur :: TYPE_CREDIT_NOTE )
2017-01-22 23:19:14 +01:00
{
2016-11-02 07:13:17 +01:00
// Total already paid
2019-11-08 10:53:31 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
2016-11-02 07:13:17 +01:00
if ( $object -> type != FactureFournisseur :: TYPE_DEPOSIT )
print $langs -> trans ( 'AlreadyPaidNoCreditNotesNoDeposits' );
2020-05-21 01:52:25 +02:00
else print $langs -> trans ( 'AlreadyPaid' );
2019-11-08 10:53:31 +01:00
print ' :</td><td class="right"' . (( $totalpaye > 0 ) ? ' class="amountalreadypaid"' : '' ) . '>' . price ( $totalpaye ) . '</td><td> </td></tr>' ;
2016-11-02 07:13:17 +01:00
2018-02-14 10:47:10 +01:00
//$resteapayer = $object->total_ttc - $totalpaye;
2016-11-02 07:13:17 +01:00
$resteapayeraffiche = $resteapayer ;
2018-02-14 10:47:10 +01:00
2016-11-02 07:13:17 +01:00
$cssforamountpaymentcomplete = 'amountpaymentcomplete' ;
// Loop on each credit note or deposit amount applied
$creditnoteamount = 0 ;
$depositamount = 0 ;
2018-02-14 10:47:10 +01:00
2018-03-05 10:58:19 +01:00
2016-11-02 07:13:17 +01:00
$sql = " SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, " ;
2018-03-05 10:58:19 +01:00
$sql .= " re.description, re.fk_invoice_supplier_source " ;
2019-11-08 10:53:31 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_remise_except as re " ;
$sql .= " WHERE fk_invoice_supplier = " . $object -> id ;
2016-11-02 07:13:17 +01:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$i = 0 ;
$invoice = new FactureFournisseur ( $db );
while ( $i < $num ) {
$obj = $db -> fetch_object ( $resql );
2018-03-05 10:58:19 +01:00
$invoice -> fetch ( $obj -> fk_invoice_supplier_source );
2019-11-08 10:53:31 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
2016-11-02 07:13:17 +01:00
if ( $invoice -> type == FactureFournisseur :: TYPE_CREDIT_NOTE )
2019-11-08 10:53:31 +01:00
print $langs -> trans ( " CreditNote " ) . ' ' ;
2016-11-02 07:13:17 +01:00
if ( $invoice -> type == FactureFournisseur :: TYPE_DEPOSIT )
2019-11-08 10:53:31 +01:00
print $langs -> trans ( " Deposit " ) . ' ' ;
2016-11-02 07:13:17 +01:00
print $invoice -> getNomUrl ( 0 );
print ' :</td>' ;
2019-11-08 10:53:31 +01:00
print '<td class="right">' . price ( $obj -> amount_ttc ) . '</td>' ;
2019-03-07 20:46:38 +01:00
print '<td class="right">' ;
2019-11-08 10:53:31 +01:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=unlinkdiscount&discountid=' . $obj -> rowid . '">' . img_delete () . '</a>' ;
2016-11-02 07:13:17 +01:00
print '</td></tr>' ;
2019-11-08 10:53:31 +01:00
$i ++ ;
2016-11-02 07:13:17 +01:00
if ( $invoice -> type == FactureFournisseur :: TYPE_CREDIT_NOTE )
$creditnoteamount += $obj -> amount_ttc ;
if ( $invoice -> type == FactureFournisseur :: TYPE_DEPOSIT )
$depositamount += $obj -> amount_ttc ;
}
} else {
dol_print_error ( $db );
}
// Paye partiellement 'escompte'
if (( $object -> statut == FactureFournisseur :: STATUS_CLOSED || $object -> statut == FactureFournisseur :: STATUS_ABANDONED ) && $object -> close_code == 'discount_vat' ) {
2019-11-08 10:53:31 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right nowrap">' ;
print $form -> textwithpicto ( $langs -> trans ( " Discount " ) . ':' , $langs -> trans ( " HelpEscompte " ), - 1 );
print '</td><td class="right">' . price ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaye ) . '</td><td> </td></tr>' ;
2016-11-02 07:13:17 +01:00
$resteapayeraffiche = 0 ;
2018-06-23 14:39:24 +02:00
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
2016-11-02 07:13:17 +01:00
}
// Paye partiellement ou Abandon 'badsupplier'
if (( $object -> statut == FactureFournisseur :: STATUS_CLOSED || $object -> statut == FactureFournisseur :: STATUS_ABANDONED ) && $object -> close_code == 'badsupplier' ) {
2019-11-08 10:53:31 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right nowrap">' ;
print $form -> textwithpicto ( $langs -> trans ( " Abandoned " ) . ':' , $langs -> trans ( " HelpAbandonBadCustomer " ), - 1 );
print '</td><td class="right">' . price ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaye ) . '</td><td> </td></tr>' ;
2016-11-02 07:13:17 +01:00
// $resteapayeraffiche=0;
2018-06-23 14:39:24 +02:00
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
2016-11-02 07:13:17 +01:00
}
// Paye partiellement ou Abandon 'product_returned'
if (( $object -> statut == FactureFournisseur :: STATUS_CLOSED || $object -> statut == FactureFournisseur :: STATUS_ABANDONED ) && $object -> close_code == 'product_returned' ) {
2019-11-08 10:53:31 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right nowrap">' ;
print $form -> textwithpicto ( $langs -> trans ( " ProductReturned " ) . ':' , $langs -> trans ( " HelpAbandonProductReturned " ), - 1 );
print '</td><td class="right">' . price ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaye ) . '</td><td> </td></tr>' ;
2016-11-02 07:13:17 +01:00
$resteapayeraffiche = 0 ;
2018-06-23 14:39:24 +02:00
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
2016-11-02 07:13:17 +01:00
}
// Paye partiellement ou Abandon 'abandon'
if (( $object -> statut == FactureFournisseur :: STATUS_CLOSED || $object -> statut == FactureFournisseur :: STATUS_ABANDONED ) && $object -> close_code == 'abandon' ) {
2019-11-08 10:53:31 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right nowrap">' ;
2016-11-02 07:13:17 +01:00
$text = $langs -> trans ( " HelpAbandonOther " );
if ( $object -> close_note )
2019-11-08 10:53:31 +01:00
$text .= '<br><br><b>' . $langs -> trans ( " Reason " ) . '</b>:' . $object -> close_note ;
print $form -> textwithpicto ( $langs -> trans ( " Abandoned " ) . ':' , $text , - 1 );
print '</td><td class="right">' . price ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaye ) . '</td><td> </td></tr>' ;
2016-11-02 07:13:17 +01:00
$resteapayeraffiche = 0 ;
2018-06-23 14:39:24 +02:00
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
2016-11-02 07:13:17 +01:00
}
// Billed
2019-11-08 10:53:31 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' . $langs -> trans ( " Billed " ) . ' :</td><td class="right">' . price ( $object -> total_ttc ) . '</td><td> </td></tr>' ;
2016-11-02 07:13:17 +01:00
// Remainder to pay
2019-11-08 10:53:31 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
2016-11-02 07:13:17 +01:00
if ( $resteapayeraffiche >= 0 )
print $langs -> trans ( 'RemainderToPay' );
2020-05-21 01:52:25 +02:00
else print $langs -> trans ( 'ExcessPaid' );
2016-11-02 07:13:17 +01:00
print ' :</td>' ;
2019-11-08 10:53:31 +01:00
print '<td class="right' . ( $resteapayeraffiche ? ' amountremaintopay' : ( ' ' . $cssforamountpaymentcomplete )) . '">' . price ( $resteapayeraffiche ) . '</td>' ;
2016-11-02 07:13:17 +01:00
print '<td class="nowrap"> </td></tr>' ;
2020-05-21 15:05:19 +02:00
} else // Credit note
2016-11-02 07:13:17 +01:00
{
2019-11-08 10:53:31 +01:00
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
2017-12-05 12:31:57 +01:00
2016-11-02 07:13:17 +01:00
// Total already paid back
2019-11-08 10:53:31 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
2016-11-02 07:13:17 +01:00
print $langs -> trans ( 'AlreadyPaidBack' );
2019-11-08 10:53:31 +01:00
print ' :</td><td class="right">' . price ( $sign * $totalpaye ) . '</td><td> </td></tr>' ;
2016-11-02 07:13:17 +01:00
// Billed
2019-11-08 10:53:31 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' . $langs -> trans ( " Billed " ) . ' :</td><td class="right">' . price ( $sign * $object -> total_ttc ) . '</td><td> </td></tr>' ;
2016-11-02 07:13:17 +01:00
// Remainder to pay back
2019-11-08 10:53:31 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' ;
2016-11-02 07:13:17 +01:00
if ( $resteapayeraffiche <= 0 )
print $langs -> trans ( 'RemainderToPayBack' );
2020-05-21 01:52:25 +02:00
else print $langs -> trans ( 'ExcessPaid' );
2016-11-02 07:13:17 +01:00
print ' :</td>' ;
2019-11-08 10:53:31 +01:00
print '<td class="right' . ( $resteapayeraffiche ? ' amountremaintopay' : ( ' ' . $cssforamountpaymentcomplete )) . '">' . price ( $sign * $resteapayeraffiche ) . '</td>' ;
2016-11-02 07:13:17 +01:00
print '<td class="nowrap"> </td></tr>' ;
// Sold credit note
2019-03-07 20:46: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 *
2016-11-02 07:13:17 +01:00
// $object->total_ttc).'</b></td><td> </td></tr>';
}
print '</table>' ;
2018-01-12 00:16:55 +01:00
print '</div>' ;
2016-11-02 07:13:17 +01:00
2017-10-16 08:47:05 +02:00
print '</div>' ;
print '</div>' ;
print '</div>' ;
2016-11-06 15:01:40 +01:00
2017-10-16 08:47:05 +02:00
print '<div class="clearboth"></div><br>' ;
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ))
2017-10-16 08:47:05 +02:00
{
$blocname = 'contacts' ;
$title = $langs -> trans ( 'ContactsAddresses' );
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
}
2012-10-28 13:57:21 +01:00
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_NOTES_TAB ))
2017-10-16 08:47:05 +02:00
{
2019-11-08 10:53:31 +01:00
$colwidth = 20 ;
2017-10-16 08:47:05 +02:00
$blocname = 'notes' ;
$title = $langs -> trans ( 'Notes' );
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
}
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
/*
2012-10-28 13:57:21 +01:00
* Lines
2013-09-06 11:51:24 +02:00
*/
2019-11-08 10:53:31 +01:00
print '<form name="addproduct" id="addproduct" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . (( $action != 'editline' ) ? '#addline' : '#line_' . GETPOST ( 'lineid' )) . '" method="POST">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-08 10:53:31 +01:00
print '<input type="hidden" name="action" value="' . (( $action != 'editline' ) ? 'addline' : 'updateline' ) . '">' ;
2016-10-29 07:45:24 +02:00
print '<input type="hidden" name="mode" value="">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
print '<input type="hidden" name="socid" value="' . $societe -> id . '">' ;
2013-11-17 23:25:25 +01:00
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && $object -> statut == FactureFournisseur :: STATUS_DRAFT ) {
include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php' ;
2015-02-27 18:05:12 +01:00
}
2017-10-16 08:47:05 +02:00
print '<div class="div-table-responsive-no-min">' ;
2015-02-27 18:05:12 +01:00
print '<table id="tablelines" class="noborder noshadow" width="100%">' ;
2013-11-17 23:25:25 +01:00
2016-10-29 07:45:24 +02:00
global $forceall , $senderissupplier , $dateSelector , $inputalsopricewithtax ;
2019-11-08 10:53:31 +01:00
$forceall = 1 ; $dateSelector = 0 ; $inputalsopricewithtax = 1 ;
$senderissupplier = 2 ; // $senderissupplier=2 is same than 1 but disable test on minimum qty and disable autofill qty with minimum.
2018-04-24 12:57:31 +02:00
//if (! empty($conf->global->SUPPLIER_INVOICE_WITH_NOPRICEDEFINED)) $senderissupplier=2;
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> global -> SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY )) $senderissupplier = 1 ;
2016-08-10 09:47:25 +02:00
2015-02-27 18:05:12 +01:00
// Show object lines
2019-11-08 10:53:31 +01:00
if ( ! empty ( $object -> lines ))
2015-11-04 18:21:59 +01:00
$ret = $object -> printObjectLines ( $action , $societe , $mysoc , $lineid , 1 );
2015-02-27 18:05:12 +01:00
2019-11-08 10:53:31 +01:00
$num = count ( $object -> lines );
2015-02-27 18:05:12 +01:00
2014-05-06 18:31:39 +02:00
// Form to add new line
2020-04-21 10:02:18 +02:00
if ( $object -> statut == FactureFournisseur :: STATUS_DRAFT && $usercancreate )
2015-02-28 04:59:27 +01:00
{
if ( $action != 'editline' )
2014-05-06 18:31:39 +02:00
{
2015-02-28 04:59:27 +01:00
// Add free products/services
$object -> formAddObjectLine ( 1 , $societe , $mysoc );
2014-05-06 18:31:39 +02:00
2015-02-28 04:59:27 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formAddObjectLine' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2014-05-06 18:31:39 +02:00
}
2017-10-16 08:47:05 +02:00
}
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
print '</table>' ;
print '</div>' ;
print '</form>' ;
2013-11-17 23:25:25 +01:00
2017-10-16 08:47:05 +02:00
dol_fiche_end ();
2013-11-17 23:25:25 +01:00
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
if ( $action != 'presend' )
{
/*
2019-06-17 17:53:43 +02:00
* Buttons actions
2013-01-06 13:33:09 +01:00
*/
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
print '<div class="tabsAction">' ;
2012-10-28 13:57:21 +01:00
2015-07-31 11:06:25 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been
2017-10-16 08:47:05 +02:00
// modified by hook
2016-08-10 09:47:25 +02:00
if ( empty ( $reshook ))
2013-01-06 13:33:09 +01:00
{
2015-07-31 11:06:25 +02:00
// Modify a validated invoice with no payments
2020-04-21 10:02:18 +02:00
if ( $object -> statut == FactureFournisseur :: STATUS_VALIDATED && $action != 'confirm_edit' && $object -> getSommePaiement () == 0 && $usercancreate )
2015-07-31 11:06:25 +02:00
{
2019-10-04 10:31:57 +02:00
// We check if lines of invoice are not already transfered into accountancy
2019-11-08 10:53:31 +01:00
$ventilExportCompta = $object -> getVentilExportCompta (); // Should be 0 since the sum of payments are zero. But we keep the protection.
2019-10-04 10:31:57 +02:00
if ( $ventilExportCompta == 0 )
{
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=edit">' . $langs -> trans ( 'Modify' ) . '</a></div>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 10:53:31 +01:00
print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="' . $langs -> trans ( " DisabledBecauseDispatchedInBookkeeping " ) . '">' . $langs -> trans ( 'Modify' ) . '</span></div>' ;
2019-10-04 10:31:57 +02:00
}
2015-07-31 11:06:25 +02:00
}
2016-08-10 09:47:25 +02:00
2019-02-15 11:26:29 +01:00
$discount = new DiscountAbsolute ( $db );
$result = $discount -> fetch ( 0 , 0 , $object -> id );
2015-07-31 11:06:25 +02:00
// Reopen a standard paid invoice
2019-02-15 11:26:29 +01:00
if (( $object -> type == FactureFournisseur :: TYPE_STANDARD || $object -> type == FactureFournisseur :: TYPE_REPLACEMENT
|| ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE && empty ( $discount -> id )))
2019-10-04 10:31:57 +02:00
&& ( $object -> statut == FactureFournisseur :: STATUS_CLOSED || $object -> statut == FactureFournisseur :: STATUS_ABANDONED )) // A paid invoice (partially or completely)
2017-10-16 08:47:05 +02:00
{
2020-04-21 10:02:18 +02:00
if ( ! $facidnext && $object -> close_code != 'replaced' && $usercancreate ) // Not replaced by another invoice
2017-10-16 08:47:05 +02:00
{
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=reopen">' . $langs -> trans ( 'ReOpen' ) . '</a></div>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-21 10:02:18 +02:00
if ( $usercancreate ) {
2018-11-13 21:40:17 +01:00
print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'ReOpen' ) . '</span></div>' ;
2017-10-16 08:47:05 +02:00
} elseif ( empty ( $conf -> global -> MAIN_BUTTON_HIDE_UNAUTHORIZED )) {
2018-11-13 21:40:17 +01:00
print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip">' . $langs -> trans ( 'ReOpen' ) . '</span></div>' ;
2017-10-16 08:47:05 +02:00
}
}
}
2016-08-10 09:47:25 +02:00
2017-10-16 08:47:05 +02:00
// Send by mail
2020-04-10 01:37:04 +02:00
if ( empty ( $user -> socid )) {
if (( $object -> statut == FactureFournisseur :: STATUS_VALIDATED || $object -> statut == FactureFournisseur :: STATUS_CLOSED ))
2017-10-16 08:47:05 +02:00
{
2020-04-21 10:02:18 +02:00
if ( $usercansend )
2020-04-10 01:37:04 +02:00
{
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=presend&mode=init#formmailbeforetitle">' . $langs -> trans ( 'SendMail' ) . '</a></div>' ;
2020-05-21 15:05:19 +02:00
} else print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip">' . $langs -> trans ( 'SendMail' ) . '</a></div>' ;
2017-10-16 08:47:05 +02:00
}
}
2016-08-10 09:47:25 +02:00
2015-07-31 11:06:25 +02:00
// Make payments
2019-11-08 10:53:31 +01:00
if ( $object -> type != FactureFournisseur :: TYPE_CREDIT_NOTE && $action != 'confirm_edit' && $object -> statut == FactureFournisseur :: STATUS_VALIDATED && $object -> paye == 0 && $user -> socid == 0 )
2015-07-31 11:06:25 +02:00
{
2019-11-08 10:53:31 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="paiement.php?facid=' . $object -> id . '&action=create' . ( $object -> fk_account > 0 ? '&accountid=' . $object -> fk_account : '' ) . '">' . $langs -> trans ( 'DoPayment' ) . '</a></div>' ; // must use facid because id is for payment id not invoice
2015-07-31 11:06:25 +02:00
}
2016-08-10 09:47:25 +02:00
2015-07-31 11:06:25 +02:00
// Classify paid
2019-11-08 10:53:31 +01:00
if ( $action != 'confirm_edit' && $object -> statut == FactureFournisseur :: STATUS_VALIDATED && $object -> paye == 0 && $user -> socid == 0 )
2015-07-31 11:06:25 +02:00
{
2016-11-10 06:29:11 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=paid"' ;
print '>' . $langs -> trans ( 'ClassifyPaid' ) . '</a></div>' ;
2016-08-10 09:47:25 +02:00
2017-10-16 08:47:05 +02:00
//print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=paid">'.$langs->trans('ClassifyPaid').'</a>';
}
2016-08-10 09:47:25 +02:00
2016-11-10 06:51:15 +01:00
// Reverse back money or convert to reduction
2018-03-05 10:58:19 +01:00
if ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE || $object -> type == FactureFournisseur :: TYPE_DEPOSIT || $object -> type == FactureFournisseur :: TYPE_STANDARD ) {
2016-11-10 06:51:15 +01:00
// For credit note only
if ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE && $object -> statut == 1 && $object -> paye == 0 )
{
if ( $resteapayer == 0 )
{
2018-11-13 21:40:17 +01:00
print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="' . $langs -> trans ( " DisabledBecauseRemainderToPayIsZero " ) . '">' . $langs -> trans ( 'DoPaymentBack' ) . '</span></div>' ;
2020-05-21 15:05:19 +02:00
} else {
2016-11-10 06:51:15 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="paiement.php?facid=' . $object -> id . '&action=create&accountid=' . $object -> fk_account . '">' . $langs -> trans ( 'DoPaymentBack' ) . '</a></div>' ;
}
}
2018-02-14 10:47:10 +01:00
// For standard invoice with excess paid
2020-04-21 10:02:18 +02:00
if ( $object -> type == FactureFournisseur :: TYPE_STANDARD && empty ( $object -> paye ) && ( $object -> total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits ) < 0 && $usercancreate && empty ( $discount -> id ))
2018-02-14 10:47:10 +01:00
{
2018-02-19 15:52:07 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=converttoreduc">' . $langs -> trans ( 'ConvertExcessPaidToReduc' ) . '</a></div>' ;
2018-02-14 10:47:10 +01:00
}
2016-11-10 06:51:15 +01:00
// For credit note
2020-04-21 10:02:18 +02:00
if ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE && $object -> statut == 1 && $object -> paye == 0 && $usercancreate
2020-04-10 10:59:32 +02:00
&& ( ! empty ( $conf -> global -> SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED ) || $object -> getSommePaiement () == 0 )
2020-01-01 19:04:14 +01:00
) {
2019-11-08 10:53:31 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=converttoreduc" title="' . dol_escape_htmltag ( $langs -> trans ( " ConfirmConvertToReducSupplier2 " )) . '">' . $langs -> trans ( 'ConvertToReduc' ) . '</a></div>' ;
2016-11-10 06:51:15 +01:00
}
// For deposit invoice
2020-04-21 10:02:18 +02:00
if ( $object -> type == FactureFournisseur :: TYPE_DEPOSIT && $object -> paye == 1 && $resteapayer == 0 && $usercancreate && empty ( $discount -> id ))
2016-11-10 06:51:15 +01:00
{
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=converttoreduc">' . $langs -> trans ( 'ConvertToReduc' ) . '</a></div>' ;
}
}
2015-07-31 11:06:25 +02:00
// Validate
2017-10-21 20:26:32 +02:00
if ( $action != 'confirm_edit' && $object -> statut == FactureFournisseur :: STATUS_DRAFT )
2015-07-31 11:06:25 +02:00
{
if ( count ( $object -> lines ))
{
2020-04-21 10:02:18 +02:00
if ( $usercanvalidate )
2015-07-31 11:06:25 +02:00
{
2016-11-10 06:29:11 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=valid"' ;
print '>' . $langs -> trans ( 'Validate' ) . '</a></div>' ;
2020-05-21 15:05:19 +02:00
} else {
2018-11-13 21:40:17 +01:00
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " NotAllowed " )) . '"' ;
2016-11-10 06:29:11 +01:00
print '>' . $langs -> trans ( 'Validate' ) . '</a></div>' ;
2015-07-31 11:06:25 +02:00
}
}
}
2016-08-10 09:47:25 +02:00
2016-03-04 10:38:33 +01:00
// Create event
2017-12-07 00:28:43 +01:00
/* if ( $conf -> agenda -> enabled && ! empty ( $conf -> global -> MAIN_ADD_EVENT_ON_ELEMENT_CARD )) // Add hidden condition because this is not a "workflow" action so should appears somewhere else on page.
2016-03-04 10:38:33 +01:00
{
print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&origin=' . $object -> element . '&originid=' . $object -> id . '&socid=' . $object -> socid . '">' . $langs -> trans ( " AddAction " ) . '</a></div>' ;
2017-12-07 00:28:43 +01:00
} */
2016-08-10 09:47:25 +02:00
2017-10-16 08:47:05 +02:00
// Clone
2020-04-21 10:02:18 +02:00
if ( $action != 'edit' && $usercancreate )
2017-10-16 08:47:05 +02:00
{
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=clone&socid=' . $object -> socid . '">' . $langs -> trans ( 'ToClone' ) . '</a></div>' ;
}
2016-08-10 09:47:25 +02:00
2016-10-02 21:39:24 +02:00
// Create a credit note
2020-04-21 10:02:18 +02:00
if (( $object -> type == FactureFournisseur :: TYPE_STANDARD || $object -> type == FactureFournisseur :: TYPE_DEPOSIT ) && $object -> statut > 0 && $usercancreate )
2016-10-02 21:39:24 +02:00
{
2019-11-08 10:53:31 +01:00
if ( ! $objectidnext )
2016-10-02 21:39:24 +02:00
{
2019-11-08 10:53:31 +01:00
print '<div class="inline-block divButAction"><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 : '' ) . '">' . $langs -> trans ( " CreateCreditNote " ) . '</a></div>' ;
2016-10-02 21:39:24 +02:00
}
}
2015-07-31 11:06:25 +02:00
// Delete
2019-11-08 10:53:31 +01:00
$isErasable = $object -> is_erasable ();
2020-04-21 10:02:18 +02:00
if ( $action != 'confirm_edit' && ( $user -> rights -> fournisseur -> facture -> supprimer || ( $usercancreate && $isErasable == 1 ))) // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions)
2015-07-31 11:06:25 +02:00
{
2017-12-05 10:01:30 +01:00
//var_dump($isErasable);
if ( $isErasable == - 4 ) {
2019-11-08 10:53:31 +01:00
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " DisabledBecausePayments " ) . '">' . $langs -> trans ( 'Delete' ) . '</a></div>' ;
2020-05-21 15:05:19 +02:00
} elseif ( $isErasable == - 3 ) { // Should never happen with supplier invoice
2019-11-08 10:53:31 +01:00
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " DisabledBecauseNotLastSituationInvoice " ) . '">' . $langs -> trans ( 'Delete' ) . '</a></div>' ;
2020-05-21 15:05:19 +02:00
} elseif ( $isErasable == - 2 ) { // Should never happen with supplier invoice
2019-11-08 10:53:31 +01:00
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " DisabledBecauseNotLastInvoice " ) . '">' . $langs -> trans ( 'Delete' ) . '</a></div>' ;
2020-05-21 15:05:19 +02:00
} elseif ( $isErasable == - 1 ) {
2019-11-08 10:53:31 +01:00
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " DisabledBecauseDispatchedInBookkeeping " ) . '">' . $langs -> trans ( 'Delete' ) . '</a></div>' ;
2020-05-21 15:05:19 +02:00
} elseif ( $isErasable <= 0 ) // Any other cases
2017-12-05 10:01:30 +01:00
{
2019-11-08 10:53:31 +01:00
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " DisabledBecauseNotErasable " ) . '">' . $langs -> trans ( 'Delete' ) . '</a></div>' ;
2020-05-21 15:05:19 +02:00
} else {
2016-11-10 06:29:11 +01:00
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete">' . $langs -> trans ( 'Delete' ) . '</a></div>' ;
2012-10-28 13:57:21 +01:00
}
2015-07-31 11:06:25 +02:00
}
print '</div>' ;
2016-08-10 09:47:25 +02:00
2017-10-21 20:26:32 +02:00
if ( $action != 'confirm_edit' )
2015-07-31 11:06:25 +02:00
{
print '<div class="fichecenter"><div class="fichehalfleft">' ;
2016-08-10 09:47:25 +02:00
2016-08-28 02:40:20 +02:00
/*
2015-07-31 11:06:25 +02:00
* Documents generes
2016-08-28 02:40:20 +02:00
*/
2019-11-08 10:53:31 +01:00
$ref = dol_sanitizeFileName ( $object -> ref );
2017-10-16 08:47:05 +02:00
$subdir = get_exdir ( $object -> id , 2 , 0 , 0 , $object , 'invoice_supplier' ) . $ref ;
$filedir = $conf -> fournisseur -> facture -> dir_output . '/' . $subdir ;
2019-11-08 10:53:31 +01:00
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id ;
2020-04-21 10:02:18 +02:00
$genallowed = $usercanread ;
$delallowed = $usercancreate ;
2019-11-08 10:53:31 +01:00
$modelpdf = ( ! empty ( $object -> modelpdf ) ? $object -> modelpdf : ( empty ( $conf -> global -> INVOICE_SUPPLIER_ADDON_PDF ) ? '' : $conf -> global -> INVOICE_SUPPLIER_ADDON_PDF ));
2017-10-16 08:47:05 +02:00
2019-01-27 11:55:16 +01:00
print $formfile -> showdocuments ( 'facture_fournisseur' , $subdir , $filedir , $urlsource , $genallowed , $delallowed , $modelpdf , 1 , 0 , 0 , 40 , 0 , '' , '' , '' , $societe -> default_lang );
2019-11-08 10:53:31 +01:00
$somethingshown = $formfile -> numoffiles ;
2017-10-16 08:47:05 +02:00
// Show links to link elements
$linktoelem = $form -> showLinkToObjectBlock ( $object , null , array ( 'invoice_supplier' ));
$somethingshown = $form -> showLinkedObjectBlock ( $object , $linktoelem );
print '</div><div class="fichehalfright"><div class="ficheaddleft">' ;
//print '</td><td valign="top" width="50%">';
//print '<br>';
// List of actions on element
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
2019-11-08 10:53:31 +01:00
$formactions = new FormActions ( $db );
$somethingshown = $formactions -> showactions ( $object , 'invoice_supplier' , $socid , 1 , 'listaction' . ( $genallowed ? 'largetitle' : '' ));
2016-08-10 09:47:25 +02:00
2015-07-31 11:06:25 +02:00
print '</div></div></div>' ;
2017-10-16 08:47:05 +02:00
//print '</td></tr></table>';
}
2013-01-06 13:33:09 +01:00
}
2017-10-16 08:47:05 +02:00
}
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Select mail models is same action as presend
if ( GETPOST ( 'modelselected' )) {
$action = 'presend' ;
}
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
// Presend form
2019-11-08 10:53:31 +01:00
$modelmail = 'invoice_supplier_send' ;
$defaulttopic = 'SendBillRef' ;
2017-10-16 08:47:05 +02:00
$diroutput = $conf -> fournisseur -> facture -> dir_output ;
2019-11-08 10:53:31 +01:00
$autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO' ;
2017-10-16 08:47:05 +02:00
$trackid = 'sin' . $object -> id ;
2012-10-28 13:57:21 +01:00
2017-10-16 08:47:05 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php' ;
}
2012-10-28 13:57:21 +01:00
}
2019-02-21 09:34:05 +01:00
2012-10-28 13:57:21 +01:00
// End of page
llxFooter ();
$db -> close ();