2004-10-20 23:06:45 +02:00
< ? php
2018-10-20 17:17:21 +02:00
/* Copyright ( C ) 2002 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 Marc Barilley / Ocebo < marc @ ocebo . com >
2014-11-14 16:43:49 +01:00
* Copyright ( C ) 2012 Cédric Salvador < csalvador @ gpcsolutions . fr >
* Copyright ( C ) 2014 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2015-09-26 10:37:36 +02:00
* Copyright ( C ) 2014 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2015 Juanjo Menent < jmenent @ 2 byte . es >
2018-06-15 11:19:04 +02:00
* Copyright ( C ) 2018 Ferran Marcet < fmarcet @ 2 byte . es >
2018-10-16 16:55:25 +02:00
* Copyright ( C ) 2018 Thibault FOUCART < support @ ptibogxiv . net >
2018-10-20 17:17:21 +02:00
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2020-08-22 18:28:15 +02:00
* Copyright ( C ) 2020 Andreu Bisquerra Gaya < jove @ bisquerra . com >
2002-12-19 15:41:37 +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
2002-12-19 15:41:37 +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 />.
2002-12-19 15:41:37 +01:00
*/
2005-04-15 23:57:04 +02:00
/**
2010-07-21 14:35:56 +02:00
* \file htdocs / compta / paiement / class / paiement . class . php
2010-02-03 03:38:18 +01:00
* \ingroup facture
2010-12-27 19:46:45 +01:00
* \brief File of class to manage payments of customers invoices
2009-10-22 02:36:21 +02:00
*/
2020-02-13 12:36:05 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/multicurrency/class/multicurrency.class.php' ;
2004-09-14 22:53:49 +02:00
2015-12-19 18:18:24 +01:00
/**
* Class to manage payments of customer invoices
2009-10-22 02:36:21 +02:00
*/
2011-03-06 18:03:27 +01:00
class Paiement extends CommonObject
2002-12-19 15:41:37 +01:00
{
2018-08-23 17:07:27 +02:00
/**
* @ var string ID to identify managed object
*/
2020-02-13 12:36:05 +01:00
public $element = 'payment' ;
2018-09-02 13:38:11 +02:00
2018-08-22 18:34:50 +02:00
/**
* @ var string Name of table without prefix where object is stored
*/
2020-02-13 12:36:05 +01:00
public $table_element = 'paiement' ;
2018-09-02 13:38:11 +02:00
2018-09-05 10:31:12 +02:00
/**
* @ var string String with name of icon for myobject . Must be the part after the 'object_' into object_myobject . png
*/
public $picto = 'payment' ;
public $facid ;
public $datepaye ;
2017-06-09 09:25:15 +02:00
2015-04-23 23:21:06 +02:00
/**
* @ deprecated
2019-04-08 16:04:15 +02:00
* @ see $amount , $amounts
2015-04-23 23:21:06 +02:00
*/
2018-09-05 10:31:12 +02:00
public $total ;
2015-04-23 23:21:06 +02:00
/**
* @ deprecated
2019-04-08 16:04:15 +02:00
* @ see $amount , $amounts
2015-04-23 23:21:06 +02:00
*/
2018-09-05 10:31:12 +02:00
public $montant ;
2020-06-17 11:06:31 +02:00
public $amount ; // Total amount of payment (in the main currency)
public $multicurrency_amount ; // Total amount of payment (in the currency of the bank account)
2020-06-17 14:53:24 +02:00
public $amounts = array (); // array: invoice ID => amount for that invoice (in the main currency)>
public $multicurrency_amounts = array (); // array: invoice ID => amount for that invoice (in the invoice's currency)>
2020-08-22 18:46:39 +02:00
2020-08-23 22:22:05 +02:00
public $pos_change = 0 ; // Excess received in TakePOS cash payment
2020-06-17 14:53:24 +02:00
2018-09-05 10:31:12 +02:00
public $author ;
2020-02-13 12:36:05 +01:00
public $paiementid ; // Type of payment. Id saved into fields fk_paiement on llx_paiement
public $paiementcode ; // Code of payment.
2018-10-20 17:17:21 +02:00
/**
* @ var string type libelle
*/
2019-11-02 11:12:57 +01:00
public $type_label ;
2018-10-20 17:17:21 +02:00
/**
* @ var string type code
*/
public $type_code ;
/**
* @ var string Numero du CHQ , VIR , etc ...
* @ deprecated
2019-08-31 02:08:26 +02:00
* @ see $num_payment
2018-10-20 17:17:21 +02:00
*/
public $numero ;
/**
* @ var string Numero du CHQ , VIR , etc ...
* @ deprecated
2019-08-31 02:08:26 +02:00
* @ see $num_payment
2018-10-20 17:17:21 +02:00
*/
public $num_paiement ;
/**
* @ var string Numero du CHQ , VIR , etc ...
*/
public $num_payment ;
/**
* @ var string Id of external payment mode
*/
public $ext_payment_id ;
/**
* @ var string Name of external payment mode
*/
public $ext_payment_site ;
/**
* @ var int bank account id of payment
* @ deprecated
2019-09-09 08:47:23 +02:00
* @ see $fk_account
2018-10-20 17:17:21 +02:00
*/
public $bank_account ;
/**
* @ var int bank account id of payment
*/
public $fk_account ;
/**
* @ var int id of payment line in bank account
*/
public $bank_line ;
2005-10-05 03:48:00 +02:00
// fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
2018-10-20 17:17:21 +02:00
// fk_paiement dans llx_paiement_facture est le rowid du paiement
/**
* @ var int payment id
*/
2020-02-13 12:36:05 +01:00
public $fk_paiement ; // Type of payment
2004-02-28 21:50:27 +01:00
2017-06-09 09:25:15 +02:00
2006-04-08 14:52:30 +02:00
/**
2011-10-01 23:24:39 +02:00
* Constructor
*
2012-02-01 18:29:06 +01:00
* @ param DoliDB $db Database handler
2006-04-08 14:52:30 +02:00
*/
2018-10-20 17:17:21 +02:00
public function __construct ( $db )
2005-10-05 03:48:00 +02:00
{
2012-07-30 17:17:33 +02:00
$this -> db = $db ;
2005-10-05 03:48:00 +02:00
}
2004-09-14 22:53:49 +02:00
2009-10-22 02:36:21 +02:00
/**
2011-03-06 18:03:27 +01:00
* Load payment from database
2011-10-01 23:24:39 +02:00
*
2015-06-26 17:29:54 +02:00
* @ param int $id Id of payment to get
2015-07-04 04:34:14 +02:00
* @ param string $ref Ref of payment to get ( currently ref = id but this may change in future )
2015-06-26 17:29:54 +02:00
* @ param int $fk_bank Id of bank line associated to payment
2015-12-19 18:18:24 +01:00
* @ return int < 0 if KO , 0 if not found , > 0 if OK
2009-10-22 02:36:21 +02:00
*/
2019-01-27 15:20:16 +01:00
public function fetch ( $id , $ref = '' , $fk_bank = '' )
2004-02-09 15:41:41 +01:00
{
2020-06-17 11:06:31 +02:00
$sql = 'SELECT p.rowid, p.ref, p.datep as dp, p.amount, p.statut, p.ext_payment_id, p.ext_payment_site, p.fk_bank, p.multicurrency_amount,' ;
2020-02-13 12:36:05 +01:00
$sql .= ' c.code as type_code, c.libelle as type_label,' ;
$sql .= ' p.num_paiement as num_payment, p.note,' ;
$sql .= ' b.fk_account' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement as p LEFT JOIN ' . MAIN_DB_PREFIX . 'c_paiement as c ON p.fk_paiement = c.id' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid' ;
$sql .= ' WHERE p.entity IN (' . getEntity ( 'invoice' ) . ')' ;
2015-07-04 04:34:14 +02:00
if ( $id > 0 )
2020-02-13 12:36:05 +01:00
$sql .= ' AND p.rowid = ' . $id ;
2019-01-27 10:49:34 +01:00
elseif ( $ref )
2020-02-13 12:36:05 +01:00
$sql .= " AND p.ref = ' " . $ref . " ' " ;
2019-01-27 10:49:34 +01:00
elseif ( $fk_bank )
2020-02-13 12:36:05 +01:00
$sql .= ' AND p.fk_bank = ' . $fk_bank ;
2004-02-09 15:41:41 +01:00
2015-12-19 18:18:24 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
2005-10-05 03:48:00 +02:00
{
2015-12-19 18:18:24 +01:00
if ( $this -> db -> num_rows ( $resql ))
2005-10-05 03:48:00 +02:00
{
2015-12-19 18:18:24 +01:00
$obj = $this -> db -> fetch_object ( $resql );
2020-06-17 14:53:24 +02:00
2005-10-05 03:48:00 +02:00
$this -> id = $obj -> rowid ;
2020-02-13 12:36:05 +01:00
$this -> ref = $obj -> ref ? $obj -> ref : $obj -> rowid ;
2010-01-13 19:51:19 +01:00
$this -> date = $this -> db -> jdate ( $obj -> dp );
$this -> datepaye = $this -> db -> jdate ( $obj -> dp );
2020-02-13 12:36:05 +01:00
$this -> num_paiement = $obj -> num_payment ; // deprecated
2018-03-31 22:44:32 +02:00
$this -> num_payment = $obj -> num_payment ;
2020-02-13 12:36:05 +01:00
$this -> montant = $obj -> amount ; // deprecated
2010-12-27 19:46:45 +01:00
$this -> amount = $obj -> amount ;
2020-06-17 11:06:31 +02:00
$this -> multicurrency_amount = $obj -> multicurrency_amount ;
2005-10-05 03:48:00 +02:00
$this -> note = $obj -> note ;
2020-02-13 12:36:05 +01:00
$this -> type_label = $obj -> type_label ;
2006-11-10 01:28:39 +01:00
$this -> type_code = $obj -> type_code ;
2005-10-05 03:48:00 +02:00
$this -> statut = $obj -> statut ;
2018-10-20 17:17:21 +02:00
$this -> ext_payment_id = $obj -> ext_payment_id ;
$this -> ext_payment_site = $obj -> ext_payment_site ;
2007-05-24 00:38:46 +02:00
2015-06-26 18:50:31 +02:00
$this -> bank_account = $obj -> fk_account ; // deprecated
$this -> fk_account = $obj -> fk_account ;
2010-02-10 18:07:25 +01:00
$this -> bank_line = $obj -> fk_bank ;
2015-12-19 18:18:24 +01:00
$this -> db -> free ( $resql );
2005-10-05 03:48:00 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2015-12-19 18:18:24 +01:00
$this -> db -> free ( $resql );
2007-05-24 00:38:46 +02:00
return 0 ;
2005-10-05 03:48:00 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2005-10-15 17:32:01 +02:00
return - 1 ;
2005-10-05 03:48:00 +02:00
}
2004-02-09 15:41:41 +01:00
}
2004-09-14 22:53:49 +02:00
2006-04-08 14:52:30 +02:00
/**
2019-02-03 20:36:20 +01:00
* Create payment of invoices into database .
* Use this -> amounts to have list of invoices for the payment .
* For payment of a customer invoice , amounts are positive , for payment of credit note , amounts are negative
2011-10-01 23:24:39 +02:00
*
2019-02-03 20:36:20 +01:00
* @ param User $user Object user
* @ param int $closepaidinvoices 1 = Also close payed invoices to paid , 0 = Do nothing more
* @ param Societe $thirdparty Thirdparty
* @ return int id of created payment , < 0 if error
2006-04-08 14:52:30 +02:00
*/
2019-03-02 00:14:22 +01:00
public function create ( $user , $closepaidinvoices = 0 , $thirdparty = null )
2005-10-05 03:48:00 +02:00
{
2012-02-01 18:29:06 +01:00
global $conf , $langs ;
2009-06-06 04:50:59 +02:00
2006-04-08 14:52:30 +02:00
$error = 0 ;
2016-02-21 22:47:52 +01:00
$way = $this -> getWay ();
2017-06-09 09:25:15 +02:00
2020-02-13 12:36:05 +01:00
$now = dol_now ();
2017-06-09 09:25:15 +02:00
2010-12-27 19:46:45 +01:00
// Clean parameters
$totalamount = 0 ;
2016-02-10 23:16:38 +01:00
$totalamount_converted = 0 ;
2012-10-13 17:00:38 +02:00
$atleastonepaymentnotnull = 0 ;
2017-06-09 09:25:15 +02:00
2016-02-10 23:16:38 +01:00
if ( $way == 'dolibarr' )
2005-10-05 03:48:00 +02:00
{
2016-02-10 23:16:38 +01:00
$amounts = & $this -> amounts ;
$amounts_to_update = & $this -> multicurrency_amounts ;
2020-05-21 15:05:19 +02:00
} else {
2016-02-10 23:16:38 +01:00
$amounts = & $this -> multicurrency_amounts ;
$amounts_to_update = & $this -> amounts ;
}
2017-06-09 09:25:15 +02:00
2016-02-10 23:16:38 +01:00
foreach ( $amounts as $key => $value ) // How payment is dispatch
{
$value_converted = Multicurrency :: getAmountConversionFromInvoiceRate ( $key , $value , $way );
$totalamount_converted += $value_converted ;
$amounts_to_update [ $key ] = price2num ( $value_converted , 'MT' );
2017-06-09 09:25:15 +02:00
2019-01-27 11:55:16 +01:00
$newvalue = price2num ( $value , 'MT' );
2016-02-10 23:16:38 +01:00
$amounts [ $key ] = $newvalue ;
2010-12-27 19:46:45 +01:00
$totalamount += $newvalue ;
2020-02-13 12:36:05 +01:00
if ( ! empty ( $newvalue )) $atleastonepaymentnotnull ++ ;
2005-10-05 03:48:00 +02:00
}
2017-06-09 09:25:15 +02:00
2010-12-27 19:46:45 +01:00
$totalamount = price2num ( $totalamount );
2016-02-10 23:16:38 +01:00
$totalamount_converted = price2num ( $totalamount_converted );
2017-06-09 09:25:15 +02:00
2010-09-09 01:50:52 +02:00
// Check parameters
2012-10-13 17:00:38 +02:00
if ( empty ( $totalamount ) && empty ( $atleastonepaymentnotnull )) // We accept negative amounts for withdraw reject but not empty arrays
{
2020-02-13 12:36:05 +01:00
$this -> errors [] = 'TotalAmountEmpty' ;
$this -> error = 'TotalAmountEmpty' ;
2012-10-13 17:00:38 +02:00
return - 1 ;
}
2006-04-08 14:52:30 +02:00
2020-02-10 00:22:53 +01:00
dol_syslog ( get_class ( $this ) . " ::create insert paiement " , LOG_DEBUG );
$this -> db -> begin ();
2006-04-08 14:52:30 +02:00
2020-02-13 12:36:05 +01:00
$this -> ref = $this -> getNextNumRef ( is_object ( $thirdparty ) ? $thirdparty : '' );
2015-10-03 15:53:36 +02:00
2016-02-10 23:16:38 +01:00
if ( $way == 'dolibarr' )
{
$total = $totalamount ;
$mtotal = $totalamount_converted ; // Maybe use price2num with MT for the converted value
2020-05-21 15:05:19 +02:00
} else {
2016-02-10 23:16:38 +01:00
$total = $totalamount_converted ; // Maybe use price2num with MT for the converted value
$mtotal = $totalamount ;
}
2019-09-09 08:47:23 +02:00
2020-02-13 12:36:05 +01:00
$num_payment = ( $this -> num_payment ? $this -> num_payment : $this -> num_paiement );
$note = ( $this -> note_public ? $this -> note_public : $this -> note );
2010-09-09 01:50:52 +02:00
2020-08-23 22:22:05 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " paiement (entity, ref, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, ext_payment_id, ext_payment_site, fk_user_creat, pos_change) " ;
2020-08-27 22:03:52 +02:00
$sql .= " VALUES ( " . $conf -> entity . " , ' " . $this -> db -> escape ( $this -> ref ) . " ', ' " . $this -> db -> idate ( $now ) . " ', ' " . $this -> db -> idate ( $this -> datepaye ) . " ', " . $total . " , " . $mtotal . " , " . $this -> paiementid . " , " ;
$sql .= " ' " . $this -> db -> escape ( $num_payment ) . " ', ' " . $this -> db -> escape ( $note ) . " ', " . ( $this -> ext_payment_id ? " ' " . $this -> db -> escape ( $this -> ext_payment_id ) . " ' " : " null " ) . " , " . ( $this -> ext_payment_site ? " ' " . $this -> db -> escape ( $this -> ext_payment_site ) . " ' " : " null " ) . " , " . $user -> id . " , " . (( int ) $this -> pos_change ) . " ) " ;
2017-06-09 09:25:15 +02:00
2010-09-09 01:50:52 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
2005-10-05 03:48:00 +02:00
{
2010-09-09 01:50:52 +02:00
$this -> id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . 'paiement' );
2007-02-20 16:22:41 +01:00
2011-03-19 14:59:04 +01:00
// Insert links amount / invoices
2010-09-09 01:50:52 +02:00
foreach ( $this -> amounts as $key => $amount )
2005-10-05 03:48:00 +02:00
{
2010-09-09 01:50:52 +02:00
$facid = $key ;
if ( is_numeric ( $amount ) && $amount <> 0 )
2005-10-05 03:48:00 +02:00
{
2010-09-09 01:50:52 +02:00
$amount = price2num ( $amount );
2016-02-10 23:16:38 +01:00
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount)' ;
2020-02-13 12:36:05 +01:00
$sql .= ' VALUES (' . $facid . ', ' . $this -> id . ', \'' . $amount . '\', \'' . $this -> multicurrency_amounts [ $key ] . '\')' ;
2017-06-09 09:25:15 +02:00
2020-02-10 00:22:53 +01:00
dol_syslog ( get_class ( $this ) . '::create Amount line ' . $key . ' insert paiement_facture' , LOG_DEBUG );
2020-02-13 12:36:05 +01:00
$resql = $this -> db -> query ( $sql );
2011-03-19 14:59:04 +01:00
if ( $resql )
{
2020-02-13 12:36:05 +01:00
$invoice = new Facture ( $this -> db );
2018-02-02 10:33:41 +01:00
$invoice -> fetch ( $facid );
2011-05-11 15:19:30 +02:00
// If we want to closed payed invoices
2011-03-19 14:59:04 +01:00
if ( $closepaidinvoices )
{
$paiement = $invoice -> getSommePaiement ();
2020-02-13 12:36:05 +01:00
$creditnotes = $invoice -> getSumCreditNotesUsed ();
$deposits = $invoice -> getSumDepositsUsed ();
$alreadypayed = price2num ( $paiement + $creditnotes + $deposits , 'MT' );
$remaintopay = price2num ( $invoice -> total_ttc - $paiement - $creditnotes - $deposits , 'MT' );
2012-12-09 18:39:42 +01:00
//var_dump($invoice->total_ttc.' - '.$paiement.' -'.$creditnotes.' - '.$deposits.' - '.$remaintopay);exit;
2014-02-25 01:17:38 +01:00
//Invoice types that are eligible for changing status to paid
$affected_types = array (
2014-11-14 16:43:49 +01:00
Facture :: TYPE_STANDARD ,
Facture :: TYPE_REPLACEMENT ,
Facture :: TYPE_CREDIT_NOTE ,
Facture :: TYPE_DEPOSIT ,
Facture :: TYPE_SITUATION
2014-02-25 01:17:38 +01:00
);
2014-11-14 16:43:49 +01:00
if ( ! in_array ( $invoice -> type , $affected_types )) dol_syslog ( " Invoice " . $facid . " is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more. " );
2019-01-27 10:49:34 +01:00
elseif ( $remaintopay ) dol_syslog ( " Remain to pay for invoice " . $facid . " not null. We do nothing more. " );
2017-06-11 16:18:21 +02:00
//else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
2020-05-21 01:52:25 +02:00
else {
2017-04-30 12:55:11 +02:00
// If invoice is a down payment, we also convert down payment to discount
if ( $invoice -> type == Facture :: TYPE_DEPOSIT )
2014-06-25 13:37:55 +02:00
{
2017-04-30 12:55:11 +02:00
$amount_ht = $amount_tva = $amount_ttc = array ();
2019-02-18 18:27:06 +01:00
$multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array ();
2017-06-09 09:25:15 +02:00
2018-06-15 11:19:04 +02:00
// Insert one discount by VAT rate category
$discount = new DiscountAbsolute ( $this -> db );
2019-01-27 11:55:16 +01:00
$discount -> fetch ( '' , $invoice -> id );
2018-06-22 14:34:59 +02:00
if ( empty ( $discount -> id )) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
2018-06-15 11:19:04 +02:00
$discount -> description = '(DEPOSIT)' ;
$discount -> fk_soc = $invoice -> socid ;
$discount -> fk_facture_source = $invoice -> id ;
// Loop on each vat rate
$i = 0 ;
foreach ( $invoice -> lines as $line ) {
if ( $line -> total_ht != 0 ) { // 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-02-18 18:27:06 +01:00
$multicurrency_amount_ht [ $line -> tva_tx ] += $line -> multicurrency_total_ht ;
$multicurrency_amount_tva [ $line -> tva_tx ] += $line -> multicurrency_total_tva ;
$multicurrency_amount_ttc [ $line -> tva_tx ] += $line -> multicurrency_total_ttc ;
2018-06-15 11:19:04 +02:00
$i ++ ;
}
}
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 ]);
2019-02-18 18:27:06 +01:00
$discount -> multicurrency_amount_ht = abs ( $multicurrency_amount_ht [ $tva_tx ]);
$discount -> multicurrency_amount_tva = abs ( $multicurrency_amount_tva [ $tva_tx ]);
$discount -> multicurrency_amount_ttc = abs ( $multicurrency_amount_ttc [ $tva_tx ]);
2018-06-15 11:19:04 +02:00
$discount -> tva_tx = abs ( $tva_tx );
$result = $discount -> create ( $user );
if ( $result < 0 ) {
$error ++ ;
break ;
}
}
}
2017-06-09 09:25:15 +02:00
2017-04-30 12:55:11 +02:00
if ( $error )
{
setEventMessages ( $discount -> error , $discount -> errors , 'errors' );
$error ++ ;
2017-06-09 09:25:15 +02:00
}
2017-04-30 12:55:11 +02:00
}
2017-06-09 09:25:15 +02:00
2017-04-30 12:55:11 +02:00
// Set invoice to paid
2020-02-13 12:36:05 +01:00
if ( ! $error )
2017-04-30 12:55:11 +02:00
{
2020-02-13 12:36:05 +01:00
$result = $invoice -> set_paid ( $user , '' , '' );
if ( $result < 0 )
2017-04-30 12:55:11 +02:00
{
2020-02-13 12:36:05 +01:00
$this -> error = $invoice -> error ;
2017-04-30 12:55:11 +02:00
$error ++ ;
}
2014-06-25 13:37:55 +02:00
}
2017-07-25 12:20:51 +02:00
}
2018-02-02 10:33:41 +01:00
}
2017-07-25 12:20:51 +02:00
2018-02-02 10:33:41 +01:00
// Regenerate documents of invoices
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
2020-02-10 00:22:53 +01:00
dol_syslog ( get_class ( $this ) . '::create Regenerate the document after inserting payment for thirdparty default_lang=' . ( is_object ( $invoice -> thirdparty ) ? $invoice -> thirdparty -> default_lang : 'null' ), LOG_DEBUG );
2020-02-13 12:36:05 +01:00
$newlang = '' ;
2018-02-02 10:33:41 +01:00
$outputlangs = $langs ;
2020-02-13 12:36:05 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
2020-02-10 00:22:53 +01:00
$invoice -> fetch_thirdparty ();
$newlang = $invoice -> thirdparty -> default_lang ;
}
2020-02-13 12:36:05 +01:00
if ( ! empty ( $newlang )) {
2018-02-02 10:33:41 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
2014-06-25 13:37:55 +02:00
}
2018-02-02 10:33:41 +01:00
$ret = $invoice -> fetch ( $facid ); // Reload to get new records
$result = $invoice -> generateDocument ( $invoice -> modelpdf , $outputlangs );
if ( $result < 0 ) {
setEventMessages ( $invoice -> error , $invoice -> errors , 'errors' );
$error ++ ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2020-02-13 12:36:05 +01:00
$this -> error = $this -> db -> lasterror ();
2010-09-09 01:50:52 +02:00
$error ++ ;
2005-10-05 03:48:00 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2010-09-12 13:49:02 +02:00
dol_syslog ( get_class ( $this ) . '::Create Amount line ' . $key . ' not a number. We discard it.' );
2006-04-08 14:52:30 +02:00
}
2005-10-05 03:48:00 +02:00
}
2010-09-09 01:50:52 +02:00
2020-02-13 12:36:05 +01:00
if ( ! $error ) // All payments into $this->amounts were recorded without errors
2005-10-05 03:48:00 +02:00
{
2010-09-09 01:50:52 +02:00
// Appel des triggers
2020-02-13 12:36:05 +01:00
$result = $this -> call_trigger ( 'PAYMENT_CUSTOMER_CREATE' , $user );
2014-06-27 13:39:01 +02:00
if ( $result < 0 ) { $error ++ ; }
2010-09-09 01:50:52 +02:00
// Fin appel triggers
2005-10-05 03:48:00 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-02-13 12:36:05 +01:00
$this -> error = $this -> db -> lasterror ();
2010-09-09 01:50:52 +02:00
$error ++ ;
}
2020-02-13 12:36:05 +01:00
if ( ! $error )
2005-10-05 03:48:00 +02:00
{
2020-02-13 12:36:05 +01:00
$this -> amount = $total ;
$this -> total = $total ; // deprecated
$this -> multicurrency_amount = $mtotal ;
2005-10-05 03:48:00 +02:00
$this -> db -> commit ();
return $this -> id ;
2020-05-21 15:05:19 +02:00
} else {
2005-10-05 03:48:00 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
2004-09-14 22:53:49 +02:00
2002-12-19 15:41:37 +01:00
2009-10-22 02:36:21 +02:00
/**
2016-02-06 12:37:48 +01:00
* Delete a payment and generated links into account
* - Si le paiement porte sur un ecriture compte qui est rapprochee , on refuse
* - Si le paiement porte sur au moins une facture a " payee " , on refuse
2011-10-01 23:24:39 +02:00
*
2016-02-06 12:37:48 +01:00
* @ param int $notrigger No trigger
* @ return int < 0 si ko , > 0 si ok
2009-10-22 02:36:21 +02:00
*/
2019-03-02 00:14:22 +01:00
public function delete ( $notrigger = 0 )
2005-10-05 03:48:00 +02:00
{
2011-06-16 12:32:41 +02:00
global $conf , $user , $langs ;
2011-08-05 23:05:19 +02:00
2020-02-13 12:36:05 +01:00
$error = 0 ;
2011-08-05 23:05:19 +02:00
2009-10-22 02:36:21 +02:00
$bank_line_id = $this -> bank_line ;
2005-10-15 20:28:21 +02:00
2005-10-05 03:48:00 +02:00
$this -> db -> begin ();
2005-10-15 20:28:21 +02:00
2009-10-22 02:36:21 +02:00
// Verifier si paiement porte pas sur une facture classee
// Si c'est le cas, on refuse la suppression
2020-02-13 12:36:05 +01:00
$billsarray = $this -> getBillsArray ( 'fk_statut > 1' );
2009-10-22 02:36:21 +02:00
if ( is_array ( $billsarray ))
{
2011-09-17 21:49:50 +02:00
if ( count ( $billsarray ))
2009-10-22 02:36:21 +02:00
{
2020-02-13 12:36:05 +01:00
$this -> error = " ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible " ;
2009-10-22 02:36:21 +02:00
$this -> db -> rollback ();
return - 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2009-10-22 02:36:21 +02:00
$this -> db -> rollback ();
return - 2 ;
}
2012-03-28 17:26:53 +02:00
// Delete bank urls. If payment is on a conciliated line, return error.
2016-02-06 12:37:48 +01:00
if ( $bank_line_id > 0 )
2005-10-15 20:28:21 +02:00
{
2016-02-06 12:37:48 +01:00
$accline = new AccountLine ( $this -> db );
2012-03-28 17:26:53 +02:00
$result = $accline -> fetch ( $bank_line_id );
2020-06-20 12:15:48 +02:00
if ( $result == 0 ) {
$accline -> id = $accline -> rowid = $bank_line_id ; // If not found, we set artificially rowid to allow delete of llx_bank_url
2020-06-18 20:56:46 +02:00
}
2012-03-28 17:26:53 +02:00
2016-02-06 12:37:48 +01:00
// Delete bank account url lines linked to payment
2020-02-13 12:36:05 +01:00
$result = $accline -> delete_urls ( $user );
2011-08-05 23:05:19 +02:00
if ( $result < 0 )
{
2020-02-13 12:36:05 +01:00
$this -> error = $accline -> error ;
2009-10-22 02:36:21 +02:00
$this -> db -> rollback ();
return - 3 ;
2011-08-05 23:05:19 +02:00
}
2016-02-06 12:37:48 +01:00
// Delete bank account lines linked to payment
2020-02-13 12:36:05 +01:00
$result = $accline -> delete ( $user );
2016-02-06 12:37:48 +01:00
if ( $result < 0 )
{
2020-02-13 12:36:05 +01:00
$this -> error = $accline -> error ;
2016-02-06 12:37:48 +01:00
$this -> db -> rollback ();
return - 4 ;
}
}
2020-02-13 12:36:05 +01:00
if ( ! $notrigger )
2016-02-06 12:37:48 +01:00
{
// Call triggers
2020-02-13 12:36:05 +01:00
$result = $this -> call_trigger ( 'PAYMENT_CUSTOMER_DELETE' , $user );
2016-02-06 12:37:48 +01:00
if ( $result < 0 )
{
$this -> db -> rollback ();
return - 1 ;
2019-02-03 14:29:45 +01:00
}
// End call triggers
2009-10-22 02:36:21 +02:00
}
2011-06-12 20:05:30 +02:00
// Delete payment (into paiement_facture and paiement)
2005-10-15 20:28:21 +02:00
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'paiement_facture' ;
2020-02-13 12:36:05 +01:00
$sql .= ' WHERE fk_paiement = ' . $this -> id ;
2012-03-28 17:34:58 +02:00
dol_syslog ( $sql );
2005-10-05 03:48:00 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
2005-10-15 20:28:21 +02:00
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'paiement' ;
2020-02-13 12:36:05 +01:00
$sql .= ' WHERE rowid = ' . $this -> id ;
2012-03-28 17:34:58 +02:00
dol_syslog ( $sql );
2005-10-05 03:48:00 +02:00
$result = $this -> db -> query ( $sql );
2020-02-13 12:36:05 +01:00
if ( ! $result )
2009-10-22 02:36:21 +02:00
{
2020-02-13 12:36:05 +01:00
$this -> error = $this -> db -> lasterror ();
2009-10-22 02:36:21 +02:00
$this -> db -> rollback ();
return - 3 ;
}
$this -> db -> commit ();
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-02-13 12:36:05 +01:00
$this -> error = $this -> db -> error ;
2005-10-05 03:48:00 +02:00
$this -> db -> rollback ();
2005-10-15 20:28:21 +02:00
return - 5 ;
2005-10-05 03:48:00 +02:00
}
}
2010-09-09 01:50:52 +02:00
/**
2017-09-15 18:39:10 +02:00
* Add a record into bank for payment + links between this bank record and sources of payment .
2012-12-09 18:39:42 +01:00
* All payment properties ( this -> amount , this -> amounts , ... ) must have been set first like after a call to create () .
2011-10-01 23:24:39 +02:00
*
* @ param User $user Object of user making payment
* @ param string $mode 'payment' , 'payment_supplier'
2017-09-15 16:40:52 +02:00
* @ param string $label Label to use in bank record . Note : If label is '(WithdrawalPayment)' , a third entry 'widthdraw' is added into bank_url .
2011-10-01 23:24:39 +02:00
* @ param int $accountid Id of bank account to do link with
* @ param string $emetteur_nom Name of transmitter
* @ param string $emetteur_banque Name of bank
* @ param int $notrigger No trigger
* @ return int < 0 if KO , bank_line_id if OK
2010-09-09 01:50:52 +02:00
*/
2019-03-02 00:14:22 +01:00
public function addPaymentToBank ( $user , $mode , $label , $accountid , $emetteur_nom , $emetteur_banque , $notrigger = 0 )
2010-09-09 01:50:52 +02:00
{
2020-02-13 11:39:08 +01:00
global $conf , $langs , $user ;
2010-09-09 01:50:52 +02:00
2020-02-21 17:53:37 +01:00
$error = 0 ;
$bank_line_id = 0 ;
2010-09-09 01:50:52 +02:00
2020-02-21 17:53:37 +01:00
if ( ! empty ( $conf -> banque -> enabled ))
2010-09-09 01:50:52 +02:00
{
2013-04-07 16:39:20 +02:00
if ( $accountid <= 0 )
{
2020-02-21 17:53:37 +01:00
$this -> error = 'Bad value for parameter accountid=' . $accountid ;
2013-04-07 16:39:20 +02:00
dol_syslog ( get_class ( $this ) . '::addPaymentToBank ' . $this -> error , LOG_ERR );
return - 1 ;
2013-06-05 16:24:32 +02:00
}
2013-04-07 16:39:20 +02:00
$this -> db -> begin ();
2020-02-21 17:53:37 +01:00
$this -> fk_account = $accountid ;
2013-04-07 16:39:20 +02:00
2018-07-26 11:57:25 +02:00
include_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2010-09-09 01:50:52 +02:00
2020-02-13 11:39:08 +01:00
dol_syslog ( " $user->id , $mode , $label , $this->fk_account , $emetteur_nom , $emetteur_banque " );
2010-12-21 01:44:57 +01:00
2010-09-09 01:50:52 +02:00
$acc = new Account ( $this -> db );
2020-02-21 17:53:37 +01:00
$result = $acc -> fetch ( $this -> fk_account );
2017-06-09 09:25:15 +02:00
2020-02-21 17:53:37 +01:00
$totalamount = $this -> amount ;
if ( empty ( $totalamount )) $totalamount = $this -> total ; // For backward compatibility
2017-06-09 09:25:15 +02:00
2016-02-10 23:16:38 +01:00
// if dolibarr currency != bank currency then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me)
2020-02-21 17:53:37 +01:00
if ( ! empty ( $conf -> multicurrency -> enabled ) && $conf -> currency != $acc -> currency_code ) $totalamount = $this -> multicurrency_amount ;
2017-06-09 09:25:15 +02:00
2020-02-21 17:53:37 +01:00
if ( $mode == 'payment_supplier' ) $totalamount = - $totalamount ;
2010-09-09 03:26:07 +02:00
2010-09-09 01:50:52 +02:00
// Insert payment into llx_bank
2011-10-01 23:24:39 +02:00
$bank_line_id = $acc -> addline (
$this -> datepaye ,
2020-02-21 17:53:37 +01:00
$this -> paiementid , // Payment mode id or code ("CHQ or VIR for example")
2011-10-01 23:24:39 +02:00
$label ,
2020-02-21 17:53:37 +01:00
$totalamount , // Sign must be positive when we receive money (customer payment), negative when you give money (supplier invoice or credit note)
2020-02-13 11:39:08 +01:00
$this -> num_payment ,
2011-10-01 23:24:39 +02:00
'' ,
$user ,
$emetteur_nom ,
$emetteur_banque
);
2010-09-09 01:50:52 +02:00
2010-09-10 00:45:05 +02:00
// Mise a jour fk_bank dans llx_paiement
2010-09-09 01:50:52 +02:00
// On connait ainsi le paiement qui a genere l'ecriture bancaire
if ( $bank_line_id > 0 )
{
2020-02-13 12:36:05 +01:00
$result = $this -> update_fk_bank ( $bank_line_id );
2010-09-09 01:50:52 +02:00
if ( $result <= 0 )
{
$error ++ ;
dol_print_error ( $this -> db );
}
2010-09-09 03:26:07 +02:00
2010-09-10 00:45:05 +02:00
// Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
2020-02-13 12:36:05 +01:00
if ( ! $error )
2010-09-09 01:50:52 +02:00
{
2020-02-13 12:36:05 +01:00
$url = '' ;
if ( $mode == 'payment' ) $url = DOL_URL_ROOT . '/compta/paiement/card.php?id=' ;
if ( $mode == 'payment_supplier' ) $url = DOL_URL_ROOT . '/fourn/paiement/card.php?id=' ;
2010-09-19 15:31:54 +02:00
if ( $url )
2010-09-09 03:26:07 +02:00
{
2020-02-13 12:36:05 +01:00
$result = $acc -> add_url_line ( $bank_line_id , $this -> id , $url , '(paiement)' , $mode );
2010-09-19 15:31:54 +02:00
if ( $result <= 0 )
{
$error ++ ;
dol_print_error ( $this -> db );
}
2010-09-09 03:26:07 +02:00
}
2010-09-09 01:50:52 +02:00
}
2010-09-09 03:26:07 +02:00
2010-09-09 01:50:52 +02:00
// Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
2017-09-15 18:39:10 +02:00
//if (! $error && $label != '(WithdrawalPayment)')
2020-02-13 12:36:05 +01:00
if ( ! $error )
2010-09-09 01:50:52 +02:00
{
2020-02-13 12:36:05 +01:00
$linkaddedforthirdparty = array ();
2017-09-15 18:39:10 +02:00
foreach ( $this -> amounts as $key => $value ) // We should have invoices always for same third party but we loop in case of.
2010-09-09 03:26:07 +02:00
{
2010-09-19 15:31:54 +02:00
if ( $mode == 'payment' )
2010-09-09 03:26:07 +02:00
{
2010-09-19 15:31:54 +02:00
$fac = new Facture ( $this -> db );
$fac -> fetch ( $key );
2011-01-15 15:01:59 +01:00
$fac -> fetch_thirdparty ();
2020-02-13 12:36:05 +01:00
if ( ! in_array ( $fac -> thirdparty -> id , $linkaddedforthirdparty )) // Not yet done for this thirdparty
2010-09-19 15:31:54 +02:00
{
2020-02-13 12:36:05 +01:00
$result = $acc -> add_url_line (
2011-10-01 23:24:39 +02:00
$bank_line_id ,
$fac -> thirdparty -> id ,
2014-09-18 21:18:25 +02:00
DOL_URL_ROOT . '/comm/card.php?socid=' ,
2014-10-04 17:20:17 +02:00
$fac -> thirdparty -> name ,
2011-10-01 23:24:39 +02:00
'company'
);
2015-02-04 02:17:37 +01:00
if ( $result <= 0 ) dol_syslog ( get_class ( $this ) . '::addPaymentToBank ' . $this -> db -> lasterror ());
2020-02-13 12:36:05 +01:00
$linkaddedforthirdparty [ $fac -> thirdparty -> id ] = $fac -> thirdparty -> id ; // Mark as done for this thirdparty
2010-09-19 15:31:54 +02:00
}
2010-09-09 03:26:07 +02:00
}
2010-09-19 15:31:54 +02:00
if ( $mode == 'payment_supplier' )
2010-09-09 03:26:07 +02:00
{
2010-09-19 15:31:54 +02:00
$fac = new FactureFournisseur ( $this -> db );
$fac -> fetch ( $key );
2011-01-15 15:01:59 +01:00
$fac -> fetch_thirdparty ();
2020-02-13 12:36:05 +01:00
if ( ! in_array ( $fac -> thirdparty -> id , $linkaddedforthirdparty )) // Not yet done for this thirdparty
2010-09-19 15:31:54 +02:00
{
2020-02-13 12:36:05 +01:00
$result = $acc -> add_url_line (
2011-10-01 23:24:39 +02:00
$bank_line_id ,
$fac -> thirdparty -> id ,
2014-09-18 21:18:25 +02:00
DOL_URL_ROOT . '/fourn/card.php?socid=' ,
2014-10-04 17:20:17 +02:00
$fac -> thirdparty -> name ,
2011-10-01 23:24:39 +02:00
'company'
);
2015-02-04 02:17:37 +01:00
if ( $result <= 0 ) dol_syslog ( get_class ( $this ) . '::addPaymentToBank ' . $this -> db -> lasterror ());
2020-02-13 12:36:05 +01:00
$linkaddedforthirdparty [ $fac -> thirdparty -> id ] = $fac -> thirdparty -> id ; // Mark as done for this thirdparty
2010-09-19 15:31:54 +02:00
}
2010-09-09 03:26:07 +02:00
}
2010-09-09 01:50:52 +02:00
}
}
2011-06-12 20:05:30 +02:00
2016-04-13 15:57:46 +02:00
// Add link 'WithdrawalPayment' in bank_url
2020-02-13 12:36:05 +01:00
if ( ! $error && $label == '(WithdrawalPayment)' ) {
$result = $acc -> add_url_line (
2016-04-13 15:57:46 +02:00
$bank_line_id ,
$this -> id_prelevement ,
DOL_URL_ROOT . '/compta/prelevement/card.php?id=' ,
$this -> num_paiement ,
'withdraw'
);
}
2020-02-13 12:36:05 +01:00
if ( ! $error && ! $notrigger )
2011-05-24 19:28:58 +02:00
{
// Appel des triggers
2020-02-13 12:36:05 +01:00
$result = $this -> call_trigger ( 'PAYMENT_ADD_TO_BANK' , $user );
2014-06-27 13:39:01 +02:00
if ( $result < 0 ) { $error ++ ; }
// Fin appel triggers
2011-05-24 19:28:58 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-02-13 12:36:05 +01:00
$this -> error = $acc -> error ;
2010-09-09 01:50:52 +02:00
$error ++ ;
}
2013-04-07 16:39:20 +02:00
2020-02-13 12:36:05 +01:00
if ( ! $error )
2013-04-07 16:39:20 +02:00
{
$this -> db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2013-04-07 16:39:20 +02:00
$this -> db -> rollback ();
}
2010-09-09 01:50:52 +02:00
}
2020-02-13 12:36:05 +01:00
if ( ! $error )
2010-09-09 01:50:52 +02:00
{
2010-09-10 00:45:05 +02:00
return $bank_line_id ;
2020-05-21 15:05:19 +02:00
} else {
2010-09-09 01:50:52 +02:00
return - 1 ;
}
}
2019-03-02 00:14:22 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2009-10-22 02:36:21 +02:00
/**
2010-09-19 15:31:54 +02:00
* Mise a jour du lien entre le paiement et la ligne generee dans llx_bank
2011-10-01 23:24:39 +02:00
*
* @ param int $id_bank Id compte bancaire
* @ return int < 0 if KO , > 0 if OK
2009-10-22 02:36:21 +02:00
*/
2019-03-02 00:14:22 +01:00
public function update_fk_bank ( $id_bank )
2005-10-05 03:48:00 +02:00
{
2018-09-02 13:38:11 +02:00
// phpcs:enable
2010-09-19 15:31:54 +02:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element . ' set fk_bank = ' . $id_bank ;
2020-02-13 12:36:05 +01:00
$sql .= ' WHERE rowid = ' . $this -> id ;
2010-09-09 01:50:52 +02:00
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::update_fk_bank' , LOG_DEBUG );
2005-10-05 03:48:00 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-02-13 12:36:05 +01:00
$this -> error = $this -> db -> lasterror ();
2010-09-19 15:31:54 +02:00
dol_syslog ( get_class ( $this ) . '::update_fk_bank ' . $this -> error );
return - 1 ;
2005-10-05 03:48:00 +02:00
}
2019-03-02 00:14:22 +01:00
}
2004-05-02 15:40:27 +02:00
2019-03-02 00:14:22 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2011-10-01 23:24:39 +02:00
/**
* Updates the payment date
*
2015-02-10 13:17:37 +01:00
* @ param int $date New date
2011-10-01 23:24:39 +02:00
* @ return int < 0 if KO , 0 if OK
*/
2019-03-02 00:14:22 +01:00
public function update_date ( $date )
2011-10-01 23:24:39 +02:00
{
2018-09-02 13:38:11 +02:00
// phpcs:enable
2020-02-13 12:36:05 +01:00
$error = 0 ;
2019-01-09 13:28:12 +01:00
if ( ! empty ( $date ) && $this -> statut != 1 )
2011-10-01 23:24:39 +02:00
{
2019-01-09 13:28:12 +01:00
$this -> db -> begin ();
dol_syslog ( get_class ( $this ) . " ::update_date with date = " . $date , LOG_DEBUG );
2011-10-01 23:24:39 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . $this -> table_element ;
2020-02-13 12:36:05 +01:00
$sql .= " SET datep = ' " . $this -> db -> idate ( $date ) . " ' " ;
$sql .= " WHERE rowid = " . $this -> id ;
2011-10-01 23:24:39 +02:00
$result = $this -> db -> query ( $sql );
2020-02-13 12:36:05 +01:00
if ( ! $result )
2011-10-01 23:24:39 +02:00
{
2019-01-09 13:28:12 +01:00
$error ++ ;
2020-02-13 12:36:05 +01:00
$this -> error = 'Error -1 ' . $this -> db -> error ();
2019-01-09 13:28:12 +01:00
}
$type = $this -> element ;
$sql = " UPDATE " . MAIN_DB_PREFIX . 'bank' ;
2020-02-13 12:36:05 +01:00
$sql .= " SET dateo = ' " . $this -> db -> idate ( $date ) . " ', datev = ' " . $this -> db -> idate ( $date ) . " ' " ;
$sql .= " WHERE rowid IN (SELECT fk_bank FROM " . MAIN_DB_PREFIX . " bank_url WHERE type = ' " . $type . " ' AND url_id = " . $this -> id . " ) " ;
$sql .= " AND rappro = 0 " ;
2019-01-09 13:28:12 +01:00
$result = $this -> db -> query ( $sql );
2020-02-13 12:36:05 +01:00
if ( ! $result )
2019-01-09 13:28:12 +01:00
{
$error ++ ;
2020-02-13 12:36:05 +01:00
$this -> error = 'Error -1 ' . $this -> db -> error ();
2019-01-09 13:28:12 +01:00
}
2020-02-13 12:36:05 +01:00
if ( ! $error )
2019-01-09 13:28:12 +01:00
{
}
2020-02-13 12:36:05 +01:00
if ( ! $error )
2019-01-09 13:28:12 +01:00
{
$this -> datepaye = $date ;
2011-10-01 23:24:39 +02:00
$this -> date = $date ;
2019-01-09 13:28:12 +01:00
$this -> db -> commit ();
2011-10-01 23:24:39 +02:00
return 0 ;
2020-05-21 15:05:19 +02:00
} else {
2019-01-09 13:28:12 +01:00
$this -> db -> rollback ();
2011-10-01 23:24:39 +02:00
return - 2 ;
}
}
return - 1 ; //no date given or already validated
}
2019-03-02 00:14:22 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2011-10-01 23:24:39 +02:00
/**
* Updates the payment number
*
* @ param string $num New num
* @ return int < 0 if KO , 0 if OK
*/
2019-03-02 00:14:22 +01:00
public function update_num ( $num )
2011-10-01 23:24:39 +02:00
{
2018-09-02 13:38:11 +02:00
// phpcs:enable
2020-02-13 12:36:05 +01:00
if ( ! empty ( $num ) && $this -> statut != 1 ) {
2011-10-01 23:24:39 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . $this -> table_element ;
2020-02-13 12:36:05 +01:00
$sql .= " SET num_paiement = ' " . $this -> db -> escape ( $num ) . " ' " ;
$sql .= " WHERE rowid = " . $this -> id ;
2011-10-01 23:24:39 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::update_num " , LOG_DEBUG );
2011-10-01 23:24:39 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
2019-09-09 08:47:23 +02:00
$this -> num_payment = $this -> db -> escape ( $num );
2011-10-01 23:24:39 +02:00
return 0 ;
2020-05-21 15:05:19 +02:00
} else {
2020-02-13 12:36:05 +01:00
$this -> error = 'Error -1 ' . $this -> db -> error ();
2011-10-01 23:24:39 +02:00
return - 2 ;
}
}
return - 1 ; //no num given or already validated
}
2009-10-22 02:36:21 +02:00
/**
2010-09-19 15:31:54 +02:00
* Validate payment
2011-10-01 23:24:39 +02:00
*
2018-11-20 10:03:38 +01:00
* @ param User $user User making validation
* @ return int < 0 if KO , > 0 if OK
2009-10-22 02:36:21 +02:00
*/
2019-03-02 00:14:22 +01:00
public function valide ( User $user = null )
{
2010-09-19 15:31:54 +02:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element . ' SET statut = 1 WHERE rowid = ' . $this -> id ;
2007-05-16 01:08:23 +02:00
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::valide' , LOG_DEBUG );
2005-10-05 03:48:00 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
2007-05-16 01:08:23 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-02-13 12:36:05 +01:00
$this -> error = $this -> db -> lasterror ();
2010-09-19 15:31:54 +02:00
dol_syslog ( get_class ( $this ) . '::valide ' . $this -> error );
2005-10-05 03:48:00 +02:00
return - 1 ;
}
2019-03-02 00:14:22 +01:00
}
2015-07-04 04:34:14 +02:00
2015-06-26 18:50:31 +02:00
/**
* Reject payment
*
2018-11-20 10:03:38 +01:00
* @ param User $user User making reject
* @ return int < 0 if KO , > 0 if OK
2015-06-26 18:50:31 +02:00
*/
2019-03-02 00:14:22 +01:00
public function reject ( User $user = null )
{
2015-06-26 18:50:31 +02:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element . ' SET statut = 2 WHERE rowid = ' . $this -> id ;
dol_syslog ( get_class ( $this ) . '::reject' , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
if ( $result )
{
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-02-13 12:36:05 +01:00
$this -> error = $this -> db -> lasterror ();
2015-06-26 18:50:31 +02:00
dol_syslog ( get_class ( $this ) . '::reject ' . $this -> error );
return - 1 ;
}
2019-03-02 00:14:22 +01:00
}
2004-12-16 14:26:13 +01:00
2015-09-12 18:00:19 +02:00
/**
* Information sur l ' objet
2017-06-09 09:25:15 +02:00
*
2015-09-12 18:00:19 +02:00
* @ param int $id id du paiement dont il faut afficher les infos
* @ return void
2009-10-22 02:36:21 +02:00
*/
2019-03-02 00:14:22 +01:00
public function info ( $id )
{
2012-02-01 18:29:06 +01:00
$sql = 'SELECT p.rowid, p.datec, p.fk_user_creat, p.fk_user_modif, p.tms' ;
2020-02-13 12:36:05 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement as p' ;
$sql .= ' WHERE p.rowid = ' . $id ;
2005-10-05 03:48:00 +02:00
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::info' , LOG_DEBUG );
2007-05-05 16:18:12 +02:00
$result = $this -> db -> query ( $sql );
2009-06-06 04:50:59 +02:00
2007-05-05 16:18:12 +02:00
if ( $result )
2005-10-05 03:48:00 +02:00
{
2007-05-05 16:18:12 +02:00
if ( $this -> db -> num_rows ( $result ))
2005-10-05 03:48:00 +02:00
{
2007-05-05 16:18:12 +02:00
$obj = $this -> db -> fetch_object ( $result );
2007-06-12 00:51:47 +02:00
$this -> id = $obj -> rowid ;
2005-10-05 03:48:00 +02:00
if ( $obj -> fk_user_creat )
{
2010-04-28 09:31:34 +02:00
$cuser = new User ( $this -> db );
$cuser -> fetch ( $obj -> fk_user_creat );
2020-02-13 12:36:05 +01:00
$this -> user_creation = $cuser ;
2005-10-05 03:48:00 +02:00
}
if ( $obj -> fk_user_modif )
{
2010-04-28 09:31:34 +02:00
$muser = new User ( $this -> db );
$muser -> fetch ( $obj -> fk_user_modif );
2005-10-05 03:48:00 +02:00
$this -> user_modification = $muser ;
}
2010-01-13 19:51:19 +01:00
$this -> date_creation = $this -> db -> jdate ( $obj -> datec );
$this -> date_modification = $this -> db -> jdate ( $obj -> tms );
2005-10-05 03:48:00 +02:00
}
2007-05-05 16:18:12 +02:00
$this -> db -> free ( $result );
2020-05-21 15:05:19 +02:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2005-10-05 03:48:00 +02:00
}
2019-03-02 00:14:22 +01:00
}
2009-06-06 04:50:59 +02:00
2009-10-22 02:36:21 +02:00
/**
2019-06-20 16:58:51 +02:00
* Return list of invoices the payment is related to .
2011-10-01 23:24:39 +02:00
*
2019-06-20 16:58:51 +02:00
* @ param string $filter Filter
* @ return int | array < 0 if KO or array of invoice id
2009-10-22 02:36:21 +02:00
*/
2019-03-02 00:14:22 +01:00
public function getBillsArray ( $filter = '' )
{
2019-06-20 16:58:51 +02:00
$sql = 'SELECT pf.fk_facture' ;
2020-02-13 12:36:05 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf, ' . MAIN_DB_PREFIX . 'facture as f' ; // We keep link on invoice to allow use of some filters on invoice
$sql .= ' WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = ' . $this -> id ;
if ( $filter ) $sql .= ' AND ' . $filter ;
2005-10-15 20:28:21 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2020-02-13 12:36:05 +01:00
$i = 0 ;
$num = $this -> db -> num_rows ( $resql );
$billsarray = array ();
2005-10-15 20:28:21 +02:00
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
2020-02-13 12:36:05 +01:00
$billsarray [ $i ] = $obj -> fk_facture ;
2009-10-22 02:36:21 +02:00
$i ++ ;
}
2005-10-15 20:28:21 +02:00
return $billsarray ;
2020-05-21 15:05:19 +02:00
} else {
2020-02-13 12:36:05 +01:00
$this -> error = $this -> db -> error ();
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::getBillsArray Error ' . $this -> error . ' -' , LOG_DEBUG );
2005-10-15 20:28:21 +02:00
return - 1 ;
}
2019-03-02 00:14:22 +01:00
}
2005-10-15 20:28:21 +02:00
2019-06-20 16:58:51 +02:00
/**
* Return list of amounts of payments .
*
* @ return int | array Array of amount of payments
*/
public function getAmountsArray ()
{
$sql = 'SELECT pf.fk_facture, pf.amount' ;
2020-02-13 12:36:05 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf' ;
$sql .= ' WHERE pf.fk_paiement = ' . $this -> id ;
2019-06-20 16:58:51 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2020-02-13 12:36:05 +01:00
$i = 0 ;
$num = $this -> db -> num_rows ( $resql );
2019-06-20 16:58:51 +02:00
$amounts = array ();
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
2020-02-13 12:36:05 +01:00
$amounts [ $obj -> fk_facture ] = $obj -> amount ;
2019-06-20 16:58:51 +02:00
$i ++ ;
}
return $amounts ;
2020-05-21 15:05:19 +02:00
} else {
2020-02-13 12:36:05 +01:00
$this -> error = $this -> db -> error ();
2019-06-20 16:58:51 +02:00
dol_syslog ( get_class ( $this ) . '::getAmountsArray Error ' . $this -> error . ' -' , LOG_DEBUG );
return - 1 ;
}
}
2015-10-03 15:53:36 +02:00
/**
* Return next reference of customer invoice not already used ( or last reference )
* according to numbering module defined into constant FACTURE_ADDON
*
* @ param Societe $soc object company
* @ param string $mode 'next' for next value or 'last' for last value
* @ return string free ref or last ref
*/
2019-03-02 00:14:22 +01:00
public function getNextNumRef ( $soc , $mode = 'next' )
2015-10-03 15:53:36 +02:00
{
global $conf , $db , $langs ;
$langs -> load ( " bills " );
// Clean parameters (if not defined or using deprecated value)
2020-02-13 12:36:05 +01:00
if ( empty ( $conf -> global -> PAYMENT_ADDON )) $conf -> global -> PAYMENT_ADDON = 'mod_payment_cicada' ;
elseif ( $conf -> global -> PAYMENT_ADDON == 'ant' ) $conf -> global -> PAYMENT_ADDON = 'mod_payment_ant' ;
elseif ( $conf -> global -> PAYMENT_ADDON == 'cicada' ) $conf -> global -> PAYMENT_ADDON = 'mod_payment_cicada' ;
2015-10-03 15:53:36 +02:00
2020-02-13 12:36:05 +01:00
if ( ! empty ( $conf -> global -> PAYMENT_ADDON ))
2015-10-03 15:53:36 +02:00
{
2020-02-13 12:36:05 +01:00
$mybool = false ;
2015-10-03 15:53:36 +02:00
$file = $conf -> global -> PAYMENT_ADDON . " .php " ;
$classname = $conf -> global -> PAYMENT_ADDON ;
// Include file with class
$dirmodels = array_merge ( array ( '/' ), ( array ) $conf -> modules_parts [ 'models' ]);
foreach ( $dirmodels as $reldir ) {
2015-10-03 16:58:46 +02:00
$dir = dol_buildpath ( $reldir . " core/modules/payment/ " );
2015-10-03 15:53:36 +02:00
// Load file with numbering class (if found)
if ( is_file ( $dir . $file ) && is_readable ( $dir . $file ))
{
2020-02-13 12:36:05 +01:00
$mybool |= include_once $dir . $file ;
2015-10-03 15:53:36 +02:00
}
}
// For compatibility
2020-02-13 12:36:05 +01:00
if ( ! $mybool )
2015-10-03 15:53:36 +02:00
{
2015-10-03 16:58:46 +02:00
$file = $conf -> global -> PAYMENT_ADDON . " .php " ;
$classname = " mod_payment_ " . $conf -> global -> PAYMENT_ADDON ;
2019-01-27 11:55:16 +01:00
$classname = preg_replace ( '/\-.*$/' , '' , $classname );
2015-10-03 15:53:36 +02:00
// Include file with class
foreach ( $conf -> file -> dol_document_root as $dirroot )
{
$dir = $dirroot . " /core/modules/payment/ " ;
// Load file with numbering class (if found)
if ( is_file ( $dir . $file ) && is_readable ( $dir . $file )) {
2020-02-13 12:36:05 +01:00
$mybool |= include_once $dir . $file ;
2015-10-03 15:53:36 +02:00
}
}
}
2020-02-13 12:36:05 +01:00
if ( ! $mybool )
2015-10-03 15:53:36 +02:00
{
2019-01-27 11:55:16 +01:00
dol_print_error ( '' , " Failed to include file " . $file );
2015-10-03 15:53:36 +02:00
return '' ;
}
$obj = new $classname ();
$numref = " " ;
2019-01-27 11:55:16 +01:00
$numref = $obj -> getNextValue ( $soc , $this );
2015-10-03 15:53:36 +02:00
/**
* $numref can be empty in case we ask for the last value because if there is no invoice created with the
* set up mask .
*/
if ( $mode != 'last' && ! $numref ) {
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , " Payment::getNextNumRef " . $obj -> error );
2015-10-03 15:53:36 +02:00
return " " ;
}
return $numref ;
2020-05-21 15:05:19 +02:00
} else {
2015-10-03 15:53:36 +02:00
$langs -> load ( " errors " );
2019-08-01 12:23:02 +02:00
print $langs -> trans ( " Error " ) . " " . $langs -> trans ( " ErrorModuleSetupNotComplete " , $langs -> transnoentitiesnoconv ( " Invoice " ));
2015-10-03 15:53:36 +02:00
return " " ;
}
}
2016-02-10 23:16:38 +01:00
/**
* get the right way of payment
2017-06-09 09:25:15 +02:00
*
2019-02-18 18:27:06 +01:00
* @ return string 'dolibarr' if standard comportment or paid in main currency , 'customer' if payment received from multicurrency inputs
2016-02-10 23:16:38 +01:00
*/
2019-03-02 00:14:22 +01:00
public function getWay ()
2016-02-10 23:16:38 +01:00
{
global $conf ;
2017-06-09 09:25:15 +02:00
2016-02-10 23:16:38 +01:00
$way = 'dolibarr' ;
if ( ! empty ( $conf -> multicurrency -> enabled ))
{
foreach ( $this -> multicurrency_amounts as $value )
{
if ( ! empty ( $value )) // one value found then payment is in invoice currency
{
$way = 'customer' ;
break ;
}
}
}
2017-06-09 09:25:15 +02:00
2016-02-10 23:16:38 +01:00
return $way ;
}
2017-06-09 09:25:15 +02:00
2015-09-26 10:37:36 +02:00
/**
* Initialise an instance with random values .
* Used to build previews or test instances .
* id must be 0 if object instance is a specimen .
*
* @ param string $option '' = Create a specimen invoice with lines , 'nolines' = No lines
* @ return void
*/
2019-03-02 00:14:22 +01:00
public function initAsSpecimen ( $option = '' )
2015-09-26 10:37:36 +02:00
{
2020-02-13 12:36:05 +01:00
global $user , $langs , $conf ;
2015-09-26 10:37:36 +02:00
2020-02-13 12:36:05 +01:00
$now = dol_now ();
$arraynow = dol_getdate ( $now );
$nownotime = dol_mktime ( 0 , 0 , 0 , $arraynow [ 'mon' ], $arraynow [ 'mday' ], $arraynow [ 'year' ]);
2015-09-26 10:37:36 +02:00
// Initialize parameters
2020-02-13 12:36:05 +01:00
$this -> id = 0 ;
2015-09-26 10:37:36 +02:00
$this -> ref = 'SPECIMEN' ;
2020-02-13 12:36:05 +01:00
$this -> specimen = 1 ;
2015-09-26 10:37:36 +02:00
$this -> facid = 1 ;
$this -> datepaye = $nownotime ;
}
2007-01-05 21:30:34 +01:00
/**
2015-03-15 14:04:07 +01:00
* Return clicable name ( with picto eventually )
2011-10-01 23:24:39 +02:00
*
2015-03-15 14:04:07 +01:00
* @ param int $withpicto 0 = No picto , 1 = Include picto into link , 2 = Only picto
2011-10-01 23:24:39 +02:00
* @ param string $option Sur quoi pointe le lien
2017-04-08 14:03:38 +02:00
* @ param string $mode 'withlistofinvoices' = Include list of invoices into tooltip
2018-02-05 17:07:38 +01:00
* @ param int $notooltip 1 = Disable tooltip
2011-10-01 23:24:39 +02:00
* @ return string Chaine avec URL
2007-01-05 21:30:34 +01:00
*/
2019-03-02 00:14:22 +01:00
public function getNomUrl ( $withpicto = 0 , $option = '' , $mode = 'withlistofinvoices' , $notooltip = 0 )
2007-01-05 21:30:34 +01:00
{
2018-02-08 17:22:07 +01:00
global $conf , $langs ;
2009-06-06 04:50:59 +02:00
2020-02-13 12:36:05 +01:00
if ( ! empty ( $conf -> dol_no_mouse_hover )) $notooltip = 1 ; // Force disable tooltips
2018-02-05 17:07:38 +01:00
2020-02-13 12:36:05 +01:00
$result = '' ;
2020-07-25 14:50:09 +02:00
$label = '<u>' . $langs -> trans ( " Payment " ) . '</u><br>' ;
2020-02-13 12:36:05 +01:00
$label .= '<strong>' . $langs -> trans ( " Ref " ) . ':</strong> ' . $this -> ref ;
if ( $this -> datepaye ? $this -> datepaye : $this -> date ) $label .= '<br><strong>' . $langs -> trans ( " Date " ) . ':</strong> ' . dol_print_date ( $this -> datepaye ? $this -> datepaye : $this -> date , 'dayhour' );
2017-04-08 14:03:38 +02:00
if ( $mode == 'withlistofinvoices' )
{
$arraybill = $this -> getBillsArray ();
2017-12-10 21:04:59 +01:00
if ( is_array ( $arraybill ) && count ( $arraybill ) > 0 )
2017-04-08 14:03:38 +02:00
{
2018-07-26 11:57:25 +02:00
include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
2020-02-13 12:36:05 +01:00
$facturestatic = new Facture ( $this -> db );
2017-04-08 14:03:38 +02:00
foreach ( $arraybill as $billid )
{
$facturestatic -> fetch ( $billid );
2020-02-13 12:36:05 +01:00
$label .= '<br> ' . $facturestatic -> getNomUrl ( 1 ) . ' ' . $facturestatic -> getLibStatut ( 2 , 1 );
2017-04-08 14:03:38 +02:00
}
}
}
2018-02-05 17:07:38 +01:00
2020-02-13 12:36:05 +01:00
$linkclose = '' ;
2018-02-05 17:07:38 +01:00
if ( empty ( $notooltip ))
{
2020-02-13 12:36:05 +01:00
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ))
2018-02-05 17:07:38 +01:00
{
2020-02-13 12:36:05 +01:00
$label = $langs -> trans ( " ShowMyObject " );
$linkclose .= ' alt="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
2018-02-05 17:07:38 +01:00
}
2020-02-13 12:36:05 +01:00
$linkclose .= ' title="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
$linkclose .= ' class="classfortooltip' . ( $morecss ? ' ' . $morecss : '' ) . '"' ;
2020-05-21 15:05:19 +02:00
} else $linkclose = ( $morecss ? ' class="' . $morecss . '"' : '' );
2018-02-05 17:07:38 +01:00
$url = DOL_URL_ROOT . '/compta/paiement/card.php?id=' . $this -> id ;
$linkstart = '<a href="' . $url . '"' ;
2020-02-13 12:36:05 +01:00
$linkstart .= $linkclose . '>' ;
$linkend = '</a>' ;
2007-01-05 21:30:34 +01:00
2018-02-05 17:07:38 +01:00
$result .= $linkstart ;
2020-02-13 12:36:05 +01:00
if ( $withpicto ) $result .= img_object (( $notooltip ? '' : $label ), ( $this -> picto ? $this -> picto : 'generic' ), ( $notooltip ? (( $withpicto != 2 ) ? 'class="paddingright"' : '' ) : 'class="' . (( $withpicto != 2 ) ? 'paddingright ' : '' ) . 'classfortooltip"' ), 0 , 0 , $notooltip ? 0 : 1 );
if ( $withpicto && $withpicto != 2 ) $result .= ( $this -> ref ? $this -> ref : $this -> id );
2018-02-05 17:07:38 +01:00
$result .= $linkend ;
2007-01-05 21:30:34 +01:00
return $result ;
}
2009-06-06 04:50:59 +02:00
2007-01-05 21:30:34 +01:00
/**
2011-10-01 23:24:39 +02:00
* Retourne le libelle du statut d ' une facture ( brouillon , validee , abandonnee , payee )
*
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ return string Libelle
2009-10-22 02:36:21 +02:00
*/
2019-03-02 00:14:22 +01:00
public function getLibStatut ( $mode = 0 )
2007-01-05 21:30:34 +01:00
{
2019-01-27 11:55:16 +01:00
return $this -> LibStatut ( $this -> statut , $mode );
2007-01-05 21:30:34 +01:00
}
2009-06-06 04:50:59 +02:00
2019-03-02 00:14:22 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2007-01-05 21:30:34 +01:00
/**
2011-10-01 23:24:39 +02:00
* Renvoi le libelle d ' un statut donne
*
* @ param int $status Statut
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ return string Libelle du statut
2009-10-22 02:36:21 +02:00
*/
2019-03-02 00:14:22 +01:00
public function LibStatut ( $status , $mode = 0 )
2007-01-05 21:30:34 +01:00
{
2018-09-02 13:38:11 +02:00
// phpcs:enable
2020-02-13 12:36:05 +01:00
global $langs ; // TODO Renvoyer le libelle anglais et faire traduction a affichage
2011-10-01 23:24:39 +02:00
2007-01-05 21:30:34 +01:00
$langs -> load ( 'compta' );
2017-04-06 23:28:06 +02:00
/* if ( $mode == 0 )
2007-01-05 21:30:34 +01:00
{
if ( $status == 0 ) return $langs -> trans ( 'ToValidate' );
if ( $status == 1 ) return $langs -> trans ( 'Validated' );
}
if ( $mode == 1 )
{
if ( $status == 0 ) return $langs -> trans ( 'ToValidate' );
if ( $status == 1 ) return $langs -> trans ( 'Validated' );
}
if ( $mode == 2 )
{
if ( $status == 0 ) return img_picto ( $langs -> trans ( 'ToValidate' ), 'statut1' ) . ' ' . $langs -> trans ( 'ToValidate' );
if ( $status == 1 ) return img_picto ( $langs -> trans ( 'Validated' ), 'statut4' ) . ' ' . $langs -> trans ( 'Validated' );
}
if ( $mode == 3 )
{
if ( $status == 0 ) return img_picto ( $langs -> trans ( 'ToValidate' ), 'statut1' );
if ( $status == 1 ) return img_picto ( $langs -> trans ( 'Validated' ), 'statut4' );
}
if ( $mode == 4 )
{
if ( $status == 0 ) return img_picto ( $langs -> trans ( 'ToValidate' ), 'statut1' ) . ' ' . $langs -> trans ( 'ToValidate' );
if ( $status == 1 ) return img_picto ( $langs -> trans ( 'Validated' ), 'statut4' ) . ' ' . $langs -> trans ( 'Validated' );
}
if ( $mode == 5 )
{
if ( $status == 0 ) return $langs -> trans ( 'ToValidate' ) . ' ' . img_picto ( $langs -> trans ( 'ToValidate' ), 'statut1' );
if ( $status == 1 ) return $langs -> trans ( 'Validated' ) . ' ' . img_picto ( $langs -> trans ( 'Validated' ), 'statut4' );
}
2017-04-06 23:28:06 +02:00
if ( $mode == 6 )
{
if ( $status == 0 ) return $langs -> trans ( 'ToValidate' ) . ' ' . img_picto ( $langs -> trans ( 'ToValidate' ), 'statut1' );
if ( $status == 1 ) return $langs -> trans ( 'Validated' ) . ' ' . img_picto ( $langs -> trans ( 'Validated' ), 'statut4' );
} */
return '' ;
2007-01-05 21:30:34 +01:00
}
2009-06-06 04:50:59 +02:00
2019-03-02 00:14:22 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2018-01-11 19:01:47 +01:00
/**
2018-08-13 17:26:32 +02:00
* Load the third party of object , from id into this -> thirdparty
2018-01-11 19:01:47 +01:00
*
2018-08-13 17:26:32 +02:00
* @ param int $force_thirdparty_id Force thirdparty id
* @ return int < 0 if KO , > 0 if OK
2018-01-11 19:01:47 +01:00
*/
2019-03-02 00:14:22 +01:00
public function fetch_thirdparty ( $force_thirdparty_id = 0 )
2018-01-11 19:01:47 +01:00
{
2018-09-02 13:38:11 +02:00
// phpcs:enable
2020-02-13 12:36:05 +01:00
include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
2018-01-11 19:01:47 +01:00
if ( empty ( $force_thirdparty_id ))
{
$billsarray = $this -> getBillsArray (); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
if ( ! empty ( $billsarray ))
{
2018-01-12 01:10:03 +01:00
$invoice = new Facture ( $this -> db );
if ( $invoice -> fetch ( $billsarray [ 0 ]) > 0 )
2018-01-11 19:01:47 +01:00
{
2018-01-12 01:10:03 +01:00
$force_thirdparty_id = $invoice -> fk_soc ;
2018-01-11 19:01:47 +01:00
}
}
}
return parent :: fetch_thirdparty ( $force_thirdparty_id );
}
2002-12-19 15:41:37 +01:00
}