Mutualize some code
This commit is contained in:
parent
5d1572a146
commit
aec5e4ab52
@ -294,14 +294,43 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio
|
|||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate invoice
|
||||||
$result=$invoice->validate($user);
|
$result=$invoice->validate($user);
|
||||||
|
|
||||||
if ($option == 'bankviainvoice')
|
if ($option == 'bankviainvoice')
|
||||||
{
|
{
|
||||||
// Now we add payment
|
// Now we add payment
|
||||||
// TODO
|
require_once(DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php');
|
||||||
|
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
|
||||||
|
|
||||||
|
// Creation de la ligne paiement
|
||||||
|
$amounts[$invoice->id] = price2num($cotisation);
|
||||||
|
$paiement = new Paiement($db);
|
||||||
|
$paiement->datepaye = $datecotisation;
|
||||||
|
$paiement->amounts = $amounts;
|
||||||
|
$paiement->paiementid = $operation;
|
||||||
|
$paiement->num_paiement = $num_chq;
|
||||||
|
$paiement->note = $label;
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$paiement_id = $paiement->create($user);
|
||||||
|
if (! $paiement_id > 0)
|
||||||
|
{
|
||||||
|
$errmsg=$paiement->error;
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$result=$paiement->addLinkInvoiceBank($user,'(SubscriptionPayment)',$accountid,$emetteur_nom,$emetteur_banque);
|
||||||
|
if (! $result > 0)
|
||||||
|
{
|
||||||
|
$errmsg=$paiement->error;
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,7 +342,6 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
$errmsg=$adh->error;
|
|
||||||
$action = 'addsubscription';
|
$action = 'addsubscription';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -168,7 +168,7 @@ class Account extends CommonObject
|
|||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object($result);
|
$obj = $this->db->fetch_object($result);
|
||||||
// Anciens liens (pour compatibilit<EFBFBD>)
|
// Anciens liens (pour compatibilite)
|
||||||
$lines[$i][0] = $obj->url;
|
$lines[$i][0] = $obj->url;
|
||||||
$lines[$i][1] = $obj->url_id;
|
$lines[$i][1] = $obj->url_id;
|
||||||
$lines[$i][2] = $obj->label;
|
$lines[$i][2] = $obj->label;
|
||||||
@ -525,9 +525,9 @@ class Account extends CommonObject
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Charge un compte en memoire depuis la base
|
* Load a bank account into memory from database
|
||||||
* \param id Id du compte a recuperer
|
* @param id Id du compte a recuperer
|
||||||
* \param ref Ref du compte a recuperer
|
* @param ref Ref du compte a recuperer
|
||||||
*/
|
*/
|
||||||
function fetch($id,$ref='')
|
function fetch($id,$ref='')
|
||||||
{
|
{
|
||||||
|
|||||||
@ -29,8 +29,8 @@
|
|||||||
|
|
||||||
require('../main.inc.php');
|
require('../main.inc.php');
|
||||||
require_once(DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php');
|
require_once(DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php');
|
||||||
include_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
|
require_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
|
||||||
include_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
|
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
|
||||||
|
|
||||||
$langs->load('companies');
|
$langs->load('companies');
|
||||||
$langs->load('bills');
|
$langs->load('bills');
|
||||||
@ -47,6 +47,14 @@ $amounts=array();
|
|||||||
$amountsresttopay=array();
|
$amountsresttopay=array();
|
||||||
$addwarning=0;
|
$addwarning=0;
|
||||||
|
|
||||||
|
// Security check
|
||||||
|
if ($user->societe_id > 0)
|
||||||
|
{
|
||||||
|
$socid = $user->societe_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Action add_paiement et confirm_paiement
|
* Action add_paiement et confirm_paiement
|
||||||
*/
|
*/
|
||||||
@ -130,10 +138,9 @@ if ($_POST['action'] == 'add_paiement')
|
|||||||
*/
|
*/
|
||||||
if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
|
if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
|
||||||
{
|
{
|
||||||
$datepaye = dol_mktime(12, 0 , 0,
|
$error=0;
|
||||||
$_POST['remonth'],
|
|
||||||
$_POST['reday'],
|
$datepaye = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
|
||||||
$_POST['reyear']);
|
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
@ -147,70 +154,27 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
|
|||||||
$paiement->num_paiement = $_POST['num_paiement'];
|
$paiement->num_paiement = $_POST['num_paiement'];
|
||||||
$paiement->note = $_POST['comment'];
|
$paiement->note = $_POST['comment'];
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
$paiement_id = $paiement->create($user);
|
$paiement_id = $paiement->create($user);
|
||||||
|
if (! $paiement_id > 0)
|
||||||
if ($paiement_id > 0)
|
|
||||||
{
|
|
||||||
if ($conf->banque->enabled)
|
|
||||||
{
|
|
||||||
// Insert payment into llx_bank
|
|
||||||
$label = "(CustomerInvoicePayment)";
|
|
||||||
$acc = new Account($db, $_POST['accountid']);
|
|
||||||
|
|
||||||
$bank_line_id = $acc->addline($paiement->datepaye,
|
|
||||||
$paiement->paiementid, // Payment mode id or code ("CHQ or VIR for example")
|
|
||||||
$label,
|
|
||||||
$totalpaiement,
|
|
||||||
$paiement->num_paiement,
|
|
||||||
'',
|
|
||||||
$user,
|
|
||||||
$_POST['chqemetteur'],
|
|
||||||
$_POST['chqbank']);
|
|
||||||
|
|
||||||
// Mise a jour fk_bank dans llx_paiement.
|
|
||||||
// On connait ainsi le paiement qui a genere l'ecriture bancaire
|
|
||||||
if ($bank_line_id > 0)
|
|
||||||
{
|
|
||||||
$result=$paiement->update_fk_bank($bank_line_id);
|
|
||||||
if ($result <= 0) dol_print_error($db);
|
|
||||||
// Add link in bank_url between payment and bank transaction
|
|
||||||
$result=$acc->add_url_line($bank_line_id,
|
|
||||||
$paiement_id,
|
|
||||||
DOL_URL_ROOT.'/compta/paiement/fiche.php?id=',
|
|
||||||
'(paiement)',
|
|
||||||
'payment');
|
|
||||||
if ($result <= 0) dol_print_error($db);
|
|
||||||
// Add link in bank_url between invoice and bank transaction (for each invoice concerned by payment)
|
|
||||||
$linkaddedforthirdparty=array();
|
|
||||||
foreach ($paiement->amounts as $key => $value)
|
|
||||||
{
|
|
||||||
$fac = new Facture($db);
|
|
||||||
$fac->fetch($key);
|
|
||||||
$fac->fetch_thirdparty();
|
|
||||||
if (! in_array($fac->client->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty
|
|
||||||
{
|
|
||||||
$result=$acc->add_url_line($bank_line_id,
|
|
||||||
$fac->client->id,
|
|
||||||
DOL_URL_ROOT.'/compta/fiche.php?socid=',
|
|
||||||
$fac->client->nom,
|
|
||||||
'company');
|
|
||||||
if ($result <= 0) dol_print_error($db);
|
|
||||||
$linkaddedforthirdparty[$fac->client->id]=$fac->client->id; // Mark as done for this thirdparty
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
$errmsg=$paiement->error;
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
$result=$paiement->addLinkInvoiceBank($user,'(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']);
|
||||||
|
if (! $result > 0)
|
||||||
|
{
|
||||||
|
$errmsg=$paiement->error;
|
||||||
$error++;
|
$error++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($error == 0)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
$loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id;
|
$loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id;
|
||||||
@ -224,13 +188,6 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Security check
|
|
||||||
if ($user->societe_id > 0)
|
|
||||||
{
|
|
||||||
$action = '';
|
|
||||||
$socid = $user->societe_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* View
|
* View
|
||||||
|
|||||||
@ -116,9 +116,10 @@ class Paiement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Create payment in database
|
* Create payment of invoices into database.
|
||||||
* \param user object user
|
* Use this->amounts to have list of invoices for the payment
|
||||||
* \return int id of created payment, < 0 if error
|
* @param user object user
|
||||||
|
* @return int id of created payment, < 0 if error
|
||||||
*/
|
*/
|
||||||
function create($user)
|
function create($user)
|
||||||
{
|
{
|
||||||
@ -138,11 +139,12 @@ class Paiement
|
|||||||
}
|
}
|
||||||
$this->total = price2num($this->total);
|
$this->total = price2num($this->total);
|
||||||
|
|
||||||
|
// Check parameters
|
||||||
|
if ($this->total == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement
|
||||||
|
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
if ($this->total <> 0) // On accepte les montants negatifs pour les rejets de prelevement
|
|
||||||
{
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)";
|
||||||
$sql.= " VALUES ('".$this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$this->total."', ".$this->paiementid.", '".$this->num_paiement."', '".addslashes($this->note)."', ".$user->id.")";
|
$sql.= " VALUES ('".$this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$this->total."', ".$this->paiementid.", '".$this->num_paiement."', '".addslashes($this->note)."', ".$user->id.")";
|
||||||
|
|
||||||
@ -193,9 +195,13 @@ class Paiement
|
|||||||
dol_syslog('Paiement::Create insert paiement error='.$this->error, LOG_ERR);
|
dol_syslog('Paiement::Create insert paiement error='.$this->error, LOG_ERR);
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->total <> 0 && ! $error) // On accepte les montants negatifs
|
// If option to add link to bank account is on
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (! $error) // On accepte les montants negatifs
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@ -293,6 +299,99 @@ class Paiement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A record into bank for payment with links between this bank record and invoices of payment.
|
||||||
|
* All payment properties must have been set first like after a call to create().
|
||||||
|
* @param user Object of user making payment
|
||||||
|
* @param label Label to use in bank record
|
||||||
|
* @param accountid Id of bank account to do link with
|
||||||
|
* @param emetteur_nom Name of transmitter
|
||||||
|
* @param emetteur_banque Name of bank
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
|
*/
|
||||||
|
function addLinkInvoiceBank($user,$label,$accountid,$emetteur_nom,$emetteur_banque)
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
if ($conf->banque->enabled)
|
||||||
|
{
|
||||||
|
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
|
||||||
|
|
||||||
|
$acc = new Account($this->db);
|
||||||
|
$acc->fetch($accountid);
|
||||||
|
|
||||||
|
// Insert payment into llx_bank
|
||||||
|
$bank_line_id = $acc->addline($this->datepaye,
|
||||||
|
$this->paiementid, // Payment mode id or code ("CHQ or VIR for example")
|
||||||
|
$label,
|
||||||
|
$this->total,
|
||||||
|
$this->num_paiement,
|
||||||
|
'',
|
||||||
|
$user,
|
||||||
|
$emetteur_nom,
|
||||||
|
$emetteur_banque);
|
||||||
|
|
||||||
|
// Mise a jour fk_bank dans llx_paiement.
|
||||||
|
// On connait ainsi le paiement qui a genere l'ecriture bancaire
|
||||||
|
if ($bank_line_id > 0)
|
||||||
|
{
|
||||||
|
$result=$this->update_fk_bank($bank_line_id);
|
||||||
|
if ($result <= 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
dol_print_error($this->db);
|
||||||
|
}
|
||||||
|
// Add link 'payment' in bank_url between payment and bank transaction
|
||||||
|
$result=$acc->add_url_line($bank_line_id,
|
||||||
|
$this->id,
|
||||||
|
DOL_URL_ROOT.'/compta/paiement/fiche.php?id=',
|
||||||
|
'(paiement)',
|
||||||
|
'payment');
|
||||||
|
if ($result <= 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
dol_print_error($this->db);
|
||||||
|
}
|
||||||
|
// Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
|
||||||
|
$linkaddedforthirdparty=array();
|
||||||
|
foreach ($this->amounts as $key => $value)
|
||||||
|
{
|
||||||
|
$fac = new Facture($this->db);
|
||||||
|
$fac->fetch($key);
|
||||||
|
$fac->fetch_thirdparty(); // This should be always same third party but we loop in case of.
|
||||||
|
if (! in_array($fac->client->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty
|
||||||
|
{
|
||||||
|
$result=$acc->add_url_line($bank_line_id,
|
||||||
|
$fac->client->id,
|
||||||
|
DOL_URL_ROOT.'/compta/fiche.php?socid=',
|
||||||
|
$fac->client->nom,
|
||||||
|
'company');
|
||||||
|
if ($result <= 0) dol_print_error($this->db);
|
||||||
|
$linkaddedforthirdparty[$fac->client->id]=$fac->client->id; // Mark as done for this thirdparty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$acc->error;
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Mise a jour du lien entre le paiement et la ligne generee dans llx_bank
|
* \brief Mise a jour du lien entre le paiement et la ligne generee dans llx_bank
|
||||||
* \param id_bank Id compte bancaire
|
* \param id_bank Id compte bancaire
|
||||||
@ -301,6 +400,8 @@ class Paiement
|
|||||||
{
|
{
|
||||||
$sql = 'UPDATE llx_paiement set fk_bank = '.$id_bank;
|
$sql = 'UPDATE llx_paiement set fk_bank = '.$id_bank;
|
||||||
$sql.= ' WHERE rowid = '.$this->id;
|
$sql.= ' WHERE rowid = '.$this->id;
|
||||||
|
|
||||||
|
dol_syslog('Paiement::update_fk_bank sql='.$sql);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -542,7 +542,7 @@ class CommonObject
|
|||||||
if (!$this->isnolinkedbythird && !$user->rights->societe->client->voir) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc";
|
if (!$this->isnolinkedbythird && !$user->rights->societe->client->voir) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc";
|
||||||
$sql.= " WHERE te.".$fieldid." < '".addslashes($this->ref)."'";
|
$sql.= " WHERE te.".$fieldid." < '".addslashes($this->ref)."'";
|
||||||
if (!$this->isnolinkedbythird && !$user->rights->societe->client->voir) $sql.= " AND sc.fk_user = " .$user->id;
|
if (!$this->isnolinkedbythird && !$user->rights->societe->client->voir) $sql.= " AND sc.fk_user = " .$user->id;
|
||||||
if (isset($filter)) $sql.=" AND ".$filter;
|
if (! empty($filter)) $sql.=" AND ".$filter;
|
||||||
if ($this->ismultientitymanaged == 2 || ($this->element != 'societe' && !$this->isnolinkedbythird && !$user->rights->societe->client->voir)) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity
|
if ($this->ismultientitymanaged == 2 || ($this->element != 'societe' && !$this->isnolinkedbythird && !$user->rights->societe->client->voir)) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity
|
||||||
if ($this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN (0,'.$conf->entity.')';
|
if ($this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN (0,'.$conf->entity.')';
|
||||||
|
|
||||||
|
|||||||
@ -159,4 +159,4 @@ LinkToGeneratedPagesDesc=This screen allows you to generate PDF files with busin
|
|||||||
DocForAllMembersCards=Generate business cards for all members (Format for output actually setup : <b>%s</b>)
|
DocForAllMembersCards=Generate business cards for all members (Format for output actually setup : <b>%s</b>)
|
||||||
DocForOneMemberCards=Generate business cards for a particular member (Format for output actually setup: <b>%s</b>)
|
DocForOneMemberCards=Generate business cards for a particular member (Format for output actually setup: <b>%s</b>)
|
||||||
DocForLabels=Generate address sheets (Format for output actually setup: <b>%s</b>)
|
DocForLabels=Generate address sheets (Format for output actually setup: <b>%s</b>)
|
||||||
|
SubscriptionPayment=Subscription payment
|
||||||
@ -159,3 +159,4 @@ LinkToGeneratedPagesDesc=Cet écran vous permet de générer des planches de car
|
|||||||
DocForAllMembersCards=Génération de cartes pour tous les adhérents (Format de planche actuellement configuré: <b>%s</b>)
|
DocForAllMembersCards=Génération de cartes pour tous les adhérents (Format de planche actuellement configuré: <b>%s</b>)
|
||||||
DocForOneMemberCards=Génération de cartes pour un adhérent particulier (Format de planche actuellement configuré: <b>%s</b>)
|
DocForOneMemberCards=Génération de cartes pour un adhérent particulier (Format de planche actuellement configuré: <b>%s</b>)
|
||||||
DocForLabels=Génération d'étiquette d'adresses (Format de planche actuellement configuré: <b>%s</b>)
|
DocForLabels=Génération d'étiquette d'adresses (Format de planche actuellement configuré: <b>%s</b>)
|
||||||
|
SubscriptionPayment=Paiement cotisation
|
||||||
Loading…
Reference in New Issue
Block a user