mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Mutualize some code
This commit is contained in:
parent
aec5e4ab52
commit
1918fb582e
|
|
@ -235,8 +235,8 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio
|
|||
{
|
||||
$db->begin();
|
||||
|
||||
// Create subscription (and bank record if option is 'bankdirect')
|
||||
$crowid=$adh->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $option);
|
||||
|
||||
if ($crowid <= 0)
|
||||
{
|
||||
$error++;
|
||||
|
|
@ -297,9 +297,9 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio
|
|||
// Validate invoice
|
||||
$result=$invoice->validate($user);
|
||||
|
||||
// Add payment
|
||||
if ($option == 'bankviainvoice')
|
||||
{
|
||||
// Now we add payment
|
||||
require_once(DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php');
|
||||
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
|
||||
|
||||
|
|
@ -324,7 +324,7 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio
|
|||
|
||||
if (! $error)
|
||||
{
|
||||
$result=$paiement->addLinkInvoiceBank($user,'(SubscriptionPayment)',$accountid,$emetteur_nom,$emetteur_banque);
|
||||
$result=$paiement->addPaymentToBank($user,'payment','(SubscriptionPayment)',$accountid,$emetteur_nom,$emetteur_banque);
|
||||
if (! $result > 0)
|
||||
{
|
||||
$errmsg=$paiement->error;
|
||||
|
|
|
|||
|
|
@ -1229,12 +1229,6 @@ class Adherent extends CommonObject
|
|||
}
|
||||
}
|
||||
|
||||
// Create invoice and payment
|
||||
if ($option == 'bankviainvoice' && $accountid)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Change properties of object (used by triggers)
|
||||
$this->last_subscription_date=$dateop;
|
||||
$this->last_subscription_amount=$montant;
|
||||
|
|
|
|||
|
|
@ -244,69 +244,29 @@ switch ( $_GET['action'] )
|
|||
$paiement_id = $payment->create($user);
|
||||
if ($paiement_id > 0)
|
||||
{
|
||||
// Ajout d'une ecriture sur le compte bancaire
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
$bankaccountid=0;
|
||||
if ( $obj_facturation->mode_reglement() == 'ESP' )
|
||||
{
|
||||
$bankaccountid=$conf_fkaccount_cash;
|
||||
}
|
||||
if ( $obj_facturation->mode_reglement() == 'CHQ' )
|
||||
{
|
||||
$bankaccountid=$conf_fkaccount_cheque;
|
||||
}
|
||||
if ( $obj_facturation->mode_reglement() == 'CB' )
|
||||
{
|
||||
$bankaccountid=$conf_fkaccount_cb;
|
||||
}
|
||||
$bankaccountid=0;
|
||||
if ( $obj_facturation->mode_reglement() == 'ESP' )
|
||||
{
|
||||
$bankaccountid=$conf_fkaccount_cash;
|
||||
}
|
||||
if ( $obj_facturation->mode_reglement() == 'CHQ' )
|
||||
{
|
||||
$bankaccountid=$conf_fkaccount_cheque;
|
||||
}
|
||||
if ( $obj_facturation->mode_reglement() == 'CB' )
|
||||
{
|
||||
$bankaccountid=$conf_fkaccount_cb;
|
||||
}
|
||||
|
||||
if ($bankaccountid > 0)
|
||||
{
|
||||
// Insertion dans llx_bank
|
||||
$label = "(CustomerInvoicePayment)";
|
||||
$acc = new Account($db, $bankaccountid);
|
||||
|
||||
$bank_line_id = $acc->addline($payment->datepaye,
|
||||
$payment->paiementid, // Payment mode id or code ("CHQ or VIR for example")
|
||||
$label,
|
||||
$obj_facturation->prix_total_ttc(),
|
||||
$payment->num_paiement,
|
||||
'',
|
||||
$user,
|
||||
'',
|
||||
'');
|
||||
|
||||
// Mise a jour fk_bank dans llx_paiement.
|
||||
// On connait ainsi le paiement qui a genere l'ecriture bancaire
|
||||
if ($bank_line_id > 0)
|
||||
{
|
||||
$payment->update_fk_bank($bank_line_id);
|
||||
// Mise a jour liens (pour chaque facture concernees par le paiement)
|
||||
foreach ($payment->amounts as $key => $value)
|
||||
{
|
||||
$facid = $key;
|
||||
$fac = new Facture($db);
|
||||
$fac->fetch($facid);
|
||||
$fac->fetch_client();
|
||||
$acc->add_url_line($bank_line_id,
|
||||
$paiement_id,
|
||||
DOL_URL_ROOT.'/compta/paiement/fiche.php?id=',
|
||||
'(paiement)',
|
||||
'payment');
|
||||
$acc->add_url_line($bank_line_id,
|
||||
$fac->client->id,
|
||||
DOL_URL_ROOT.'/compta/fiche.php?socid=',
|
||||
$fac->client->nom,
|
||||
'company');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! $error)
|
||||
{
|
||||
$result=$payment->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$bankaccountid,'','');
|
||||
if (! $result > 0)
|
||||
{
|
||||
$errmsg=$paiement->error;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -202,6 +202,7 @@ class Account extends CommonObject
|
|||
// Clean parameters
|
||||
$emetteur=trim($emetteur);
|
||||
$banque=trim($banque);
|
||||
|
||||
if (is_numeric($oper)) // Clean oper to have a code instead of a rowid
|
||||
{
|
||||
$sql ="SELECT code FROM ".MAIN_DB_PREFIX."c_paiement";
|
||||
|
|
@ -236,7 +237,6 @@ class Account extends CommonObject
|
|||
return -3;
|
||||
}
|
||||
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$datev = $date;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ $amountsresttopay=array();
|
|||
$addwarning=0;
|
||||
|
||||
// Security check
|
||||
$socid=0;
|
||||
if ($user->societe_id > 0)
|
||||
{
|
||||
$socid = $user->societe_id;
|
||||
|
|
@ -166,7 +167,7 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
|
|||
|
||||
if (! $error)
|
||||
{
|
||||
$result=$paiement->addLinkInvoiceBank($user,'(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']);
|
||||
$result=$paiement->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']);
|
||||
if (! $result > 0)
|
||||
{
|
||||
$errmsg=$paiement->error;
|
||||
|
|
|
|||
|
|
@ -304,13 +304,14 @@ 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 mode 'payment', 'payment_supplier'
|
||||
* @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)
|
||||
function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
|
|
@ -323,11 +324,15 @@ class Paiement
|
|||
$acc = new Account($this->db);
|
||||
$acc->fetch($accountid);
|
||||
|
||||
$total=$this->total;
|
||||
if ($mode == 'payment_supplier') $total=-$total;
|
||||
if ($mode == 'payment_sc') $total=-$total;
|
||||
|
||||
// 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,
|
||||
$total,
|
||||
$this->num_paiement,
|
||||
'',
|
||||
$user,
|
||||
|
|
@ -344,33 +349,50 @@ class Paiement
|
|||
$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)
|
||||
|
||||
// Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction
|
||||
$url='';
|
||||
if ($mode == 'payment') $url=DOL_URL_ROOT.'/compta/paiement/fiche.php?id=';
|
||||
if ($mode == 'payment_supplier') $url=DOL_URL_ROOT.'/fourn/paiement/fiche.php?id=';
|
||||
if ($url)
|
||||
{
|
||||
$error++;
|
||||
dol_print_error($this->db);
|
||||
$result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
|
||||
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
|
||||
if ($mode == 'payment')
|
||||
{
|
||||
$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
|
||||
$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
|
||||
}
|
||||
}
|
||||
if ($mode == 'payment_supplier')
|
||||
{
|
||||
$fac = new FactureFournisseur($this->db);
|
||||
$fac->fetch($key);
|
||||
$fac->fetch_fournisseur(); // 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->fournisseur->id,
|
||||
DOL_URL_ROOT.'/fourn/fiche.php?socid=', $fac->fournisseur->nom, 'company');
|
||||
if ($result <= 0) dol_print_error($this->db);
|
||||
$linkaddedforthirdparty[$fac->fournisseur->id]=$fac->fournisseur->id; // Mark as done for this thirdparty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,11 +30,12 @@ include_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php");
|
|||
$langs->load("bills");
|
||||
|
||||
$chid=isset($_GET["id"])?$_GET["id"]:$_POST["id"];
|
||||
$amounts = array();
|
||||
|
||||
// Securite acces client
|
||||
// Security check
|
||||
$socid=0;
|
||||
if ($user->societe_id > 0)
|
||||
{
|
||||
$action = '';
|
||||
$socid = $user->societe_id;
|
||||
}
|
||||
|
||||
|
|
@ -74,14 +75,12 @@ if ($_POST["action"] == 'add_paiement')
|
|||
$paymentid = 0;
|
||||
|
||||
// Read possible payments
|
||||
$amounts = array();
|
||||
foreach ($_POST as $key => $value)
|
||||
{
|
||||
if (substr($key,0,7) == 'amount_')
|
||||
{
|
||||
$other_chid = substr($key,7);
|
||||
|
||||
$amounts[$other_chid] = $_POST[$key];
|
||||
$amounts[$other_chid] = price2num($_POST[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,57 +94,38 @@ if ($_POST["action"] == 'add_paiement')
|
|||
$paiement->paiementtype = $_POST["paiementtype"];
|
||||
$paiement->num_paiement = $_POST["num_paiement"];
|
||||
$paiement->note = $_POST["note"];
|
||||
$paymentid = $paiement->create($user);
|
||||
|
||||
$socialcontrib = new ChargeSociales($db);
|
||||
$socialcontrib->fetch($paiement->chid);
|
||||
|
||||
if ($paymentid > 0)
|
||||
if (! $error)
|
||||
{
|
||||
// On determine le montant total du paiement
|
||||
$total=0;
|
||||
foreach ($paiement->amounts as $key => $value)
|
||||
{
|
||||
$chid = $key;
|
||||
$value = trim($value);
|
||||
$amount = price2num(trim($value), 'MT'); // Un round est ok si nb avec '.'
|
||||
$total += $amount;
|
||||
}
|
||||
|
||||
// Insertion dans llx_bank
|
||||
$langs->load("banks");
|
||||
$label = $langs->transnoentities("SocialContributionPayment");
|
||||
$acc = new Account($db, $_POST["accountid"]);
|
||||
$bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -$total, $paiement->num_paiement, '', $user);
|
||||
|
||||
// Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a genere l'ecriture bancaire
|
||||
if ($bank_line_id > 0)
|
||||
{
|
||||
$paiement->update_fk_bank($bank_line_id);
|
||||
|
||||
// Mise a jour liens (pour chaque charge concernee par le paiement)
|
||||
foreach ($paiement->amounts as $key => $value)
|
||||
{
|
||||
$acc->add_url_line($bank_line_id, $chid, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc');
|
||||
$acc->add_url_line($bank_line_id, $paymentid, DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id=', '(paiement)','payment_sc');
|
||||
}
|
||||
|
||||
$db->commit();
|
||||
|
||||
$loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid;
|
||||
Header("Location: ".$loc);
|
||||
exit;
|
||||
}
|
||||
else {
|
||||
$db->rollback();
|
||||
$mesg = "Echec de la creation entree compte: ".$db->error();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
$mesg = "Failed to create payment: paiement_id=".$paymentid." ".$db->error();
|
||||
$paymentid = $paiement->create($user);
|
||||
if (! $paymentid > 0)
|
||||
{
|
||||
$errmsg=$paiement->error;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$result=$paiement->addPaymentToBank($user,'payment_sc','(SocialContributionPayment)',$_POST['accountid'],'','');
|
||||
if (! $result > 0)
|
||||
{
|
||||
$errmsg=$paiement->error;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$db->commit();
|
||||
$loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid;
|
||||
Header('Location: '.$loc);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
$_GET["action"]='create';
|
||||
|
|
|
|||
|
|
@ -374,7 +374,7 @@ class PaiementCharge extends CommonObject
|
|||
* \brief Constructor
|
||||
* \param DB Database handler
|
||||
*/
|
||||
function Paiementcharge($DB)
|
||||
function PaiementCharge($DB)
|
||||
{
|
||||
$this->db = $DB;
|
||||
return 1;
|
||||
|
|
@ -414,7 +414,6 @@ class PaiementCharge extends CommonObject
|
|||
$total=0;
|
||||
foreach ($this->amounts as $key => $value)
|
||||
{
|
||||
$facid = $key;
|
||||
$amount = price2num(trim($value), 'MT');
|
||||
$total += $amount;
|
||||
}
|
||||
|
|
@ -758,6 +757,100 @@ class PaiementCharge extends CommonObject
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 mode 'payment_sc'
|
||||
* @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 addPaymentToBank($user,$mode,$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);
|
||||
|
||||
$total=$this->total;
|
||||
if ($mode == 'payment_sc') $total=-$total;
|
||||
|
||||
// Insert payment into llx_bank
|
||||
$bank_line_id = $acc->addline($this->datepaye,
|
||||
$this->paiementtype, // Payment mode id or code ("CHQ or VIR for example")
|
||||
$label,
|
||||
$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', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction
|
||||
$url='';
|
||||
if ($mode == 'payment_sc') $url=DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id=';
|
||||
if ($url)
|
||||
{
|
||||
$result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
|
||||
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)
|
||||
{
|
||||
if ($mode == 'payment_sc')
|
||||
{
|
||||
$socialcontrib = new ChargeSociales($this->db);
|
||||
$socialcontrib->fetch($key);
|
||||
$result=$acc->add_url_line($bank_line_id, $socialcontrib->id,
|
||||
DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc');
|
||||
if ($result <= 0) dol_print_error($this->db);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$acc->error;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee
|
||||
* \param id_bank Id de la banque
|
||||
|
|
|
|||
|
|
@ -48,12 +48,13 @@ $offset = $limit * $page ;
|
|||
if (! $sortorder) $sortorder="DESC";
|
||||
if (! $sortfield) $sortfield="p.rowid";
|
||||
|
||||
$amounts = array();
|
||||
|
||||
// Security check
|
||||
$socid=0;
|
||||
if ($user->societe_id > 0)
|
||||
{
|
||||
$action = '';
|
||||
$socid = $user->societe_id;
|
||||
$socid = $user->societe_id;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -64,130 +65,96 @@ if ($user->societe_id > 0)
|
|||
*/
|
||||
if ($action == 'add_paiement')
|
||||
{
|
||||
$error = 0;
|
||||
$error = 0;
|
||||
|
||||
$datepaye = dol_mktime(12, 0 , 0,
|
||||
$_POST['remonth'],
|
||||
$_POST['reday'],
|
||||
$_POST['reyear']);
|
||||
$paiement_id = 0;
|
||||
$total = 0;
|
||||
// Genere tableau des montants amounts
|
||||
$amounts = array();
|
||||
foreach ($_POST as $key => $value)
|
||||
{
|
||||
if (substr($key,0,7) == 'amount_')
|
||||
{
|
||||
$other_facid = substr($key,7);
|
||||
$amounts[$other_facid] = $_POST[$key];
|
||||
$total = $total + $amounts[$other_facid];
|
||||
}
|
||||
}
|
||||
$datepaye = dol_mktime(12, 0 , 0,
|
||||
$_POST['remonth'],
|
||||
$_POST['reday'],
|
||||
$_POST['reyear']);
|
||||
$paiement_id = 0;
|
||||
$total = 0;
|
||||
// Genere tableau des montants amounts
|
||||
foreach ($_POST as $key => $value)
|
||||
{
|
||||
if (substr($key,0,7) == 'amount_')
|
||||
{
|
||||
$other_facid = substr($key,7);
|
||||
$amounts[$other_facid] = $_POST[$key];
|
||||
$total = $total + $amounts[$other_facid];
|
||||
}
|
||||
}
|
||||
|
||||
// Effectue les verifications des parametres
|
||||
if ($_POST['paiementid'] <= 0)
|
||||
{
|
||||
$mesg = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'</div>';
|
||||
$error++;
|
||||
}
|
||||
// Effectue les verifications des parametres
|
||||
if ($_POST['paiementid'] <= 0)
|
||||
{
|
||||
$mesg = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'</div>';
|
||||
$error++;
|
||||
}
|
||||
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
// Si module bank actif, un compte est obligatoire lors de la saisie
|
||||
// d'un paiement
|
||||
if (! $_POST['accountid'])
|
||||
{
|
||||
$mesg = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
// Si module bank actif, un compte est obligatoire lors de la saisie
|
||||
// d'un paiement
|
||||
if (! $_POST['accountid'])
|
||||
{
|
||||
$mesg = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
\TODO A activer qd gestion avoir active et que creation facture fournisseur negative interdit
|
||||
if ($total <= 0)
|
||||
{
|
||||
$mesg = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Amount')).'</div>';
|
||||
$error++;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
\TODO A activer qd gestion avoir active et que creation facture fournisseur negative interdit
|
||||
if ($total <= 0)
|
||||
{
|
||||
$mesg = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Amount')).'</div>';
|
||||
$error++;
|
||||
}
|
||||
*/
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$db->begin();
|
||||
if (! $error)
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
// Creation de la ligne paiement
|
||||
$paiement = new PaiementFourn($db);
|
||||
$paiement->datepaye = $datepaye;
|
||||
$paiement->amounts = $amounts; // Array of amounts
|
||||
$paiement->paiementid = $_POST['paiementid'];
|
||||
$paiement->num_paiement = $_POST['num_paiement'];
|
||||
$paiement->note = $_POST['comment'];
|
||||
// Creation de la ligne paiement
|
||||
$paiement = new PaiementFourn($db);
|
||||
$paiement->datepaye = $datepaye;
|
||||
$paiement->amounts = $amounts; // Array of amounts
|
||||
$paiement->paiementid = $_POST['paiementid'];
|
||||
$paiement->num_paiement = $_POST['num_paiement'];
|
||||
$paiement->note = $_POST['comment'];
|
||||
|
||||
$paiement_id = $paiement->create($user);
|
||||
if ($paiement_id > 0)
|
||||
{
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
// Insertion dans llx_bank
|
||||
$label = "(SupplierInvoicePayment)";
|
||||
$acc = new Account($db, $_POST['accountid']);
|
||||
//paiementid contient "CHQ ou VIR par exemple"
|
||||
$bank_line_id = $acc->addline($paiement->datepaye,
|
||||
$paiement->paiementid,
|
||||
$label,
|
||||
0.0 - $paiement->total,
|
||||
$paiement->num_paiement,
|
||||
'',
|
||||
$user);
|
||||
if (! $error)
|
||||
{
|
||||
$paiement_id = $paiement->create($user);
|
||||
if (! $paiement_id > 0)
|
||||
{
|
||||
$errmsg='<div class="error">'.$paiement->error.'</div>';
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
// Mise a jour fk_bank dans llx_paiement.
|
||||
// On connait ainsi le paiement qui a genere l'ecriture bancaire
|
||||
if ($bank_line_id > 0)
|
||||
{
|
||||
$paiement->update_fk_bank($bank_line_id);
|
||||
// Mise a jour liens (pour chaque facture concernees par le paiement)
|
||||
foreach ($paiement->amounts as $key => $value)
|
||||
{
|
||||
$facid = $key;
|
||||
$fac = new FactureFournisseur($db);
|
||||
$fac->fetch($facid);
|
||||
$fac->fetch_fournisseur();
|
||||
$acc->add_url_line($bank_line_id,
|
||||
$paiement_id,
|
||||
DOL_URL_ROOT.'/fourn/paiement/fiche.php?id=',
|
||||
'(paiement)',
|
||||
'payment_supplier');
|
||||
$acc->add_url_line($bank_line_id,
|
||||
$fac->fournisseur->id,
|
||||
DOL_URL_ROOT.'/fourn/fiche.php?socid=',
|
||||
$fac->fournisseur->nom,
|
||||
'company');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg = '<div class="error">'.$langs->trans($paiement->error).'</div>';
|
||||
$error++;
|
||||
}
|
||||
if (! $error)
|
||||
{
|
||||
$result=$paiement->addPaymentToBank($user,'payment_supplier','(SupplierInvoicePayment)',$_POST['accountid'],'','');
|
||||
if (! $result > 0)
|
||||
{
|
||||
$errmsg='<div class="error">'.$paiement->error.'</div>';
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($error == 0)
|
||||
{
|
||||
$loc = DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$paiement_id;
|
||||
$db->commit();
|
||||
Header('Location: '.$loc);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
if (! $error)
|
||||
{
|
||||
$db->commit();
|
||||
$loc = DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$paiement_id;
|
||||
Header('Location: '.$loc);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -204,159 +171,159 @@ if ($mesg) print $mesg;
|
|||
|
||||
if ($action == 'create' || $action == 'add_paiement')
|
||||
{
|
||||
$facture = new FactureFournisseur($db);
|
||||
$facture->fetch($facid);
|
||||
$facture = new FactureFournisseur($db);
|
||||
$facture->fetch($facid);
|
||||
|
||||
$datefacture=dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
|
||||
$dateinvoice=($datefacture==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datefacture);
|
||||
$datefacture=dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
|
||||
$dateinvoice=($datefacture==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datefacture);
|
||||
|
||||
$sql = 'SELECT s.nom, s.rowid as socid,';
|
||||
$sql.= ' f.rowid as ref, f.facnumber, f.amount, f.total_ttc as total';
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn as f';
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql .= ' WHERE f.fk_soc = s.rowid';
|
||||
$sql .= ' AND f.rowid = '.$facid;
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
$total = $obj->total;
|
||||
$sql = 'SELECT s.nom, s.rowid as socid,';
|
||||
$sql.= ' f.rowid as ref, f.facnumber, f.amount, f.total_ttc as total';
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn as f';
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql .= ' WHERE f.fk_soc = s.rowid';
|
||||
$sql .= ' AND f.rowid = '.$facid;
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
$total = $obj->total;
|
||||
|
||||
print_fiche_titre($langs->trans('DoPayment'));
|
||||
print_fiche_titre($langs->trans('DoPayment'));
|
||||
|
||||
print '<form name="addpaiement" action="paiement.php" method="post">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="add_paiement">';
|
||||
print '<input type="hidden" name="facid" value="'.$facid.'">';
|
||||
print '<input type="hidden" name="facnumber" value="'.$obj->facnumber.'">';
|
||||
print '<input type="hidden" name="socid" value="'.$obj->socid.'">';
|
||||
print '<input type="hidden" name="societe" value="'.$obj->nom.'">';
|
||||
print '<form name="addpaiement" action="paiement.php" method="post">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="add_paiement">';
|
||||
print '<input type="hidden" name="facid" value="'.$facid.'">';
|
||||
print '<input type="hidden" name="facnumber" value="'.$obj->facnumber.'">';
|
||||
print '<input type="hidden" name="socid" value="'.$obj->socid.'">';
|
||||
print '<input type="hidden" name="societe" value="'.$obj->nom.'">';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans('Payment').'</td>';
|
||||
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2">'.$obj->nom.'</td></tr>';
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td>';
|
||||
$html->select_date($dateinvoice,'','','','',"addpaiement",1,1);
|
||||
print '</td>';
|
||||
print '<td>'.$langs->trans('Comments').'</td></tr>';
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans('PaymentMode').'</td><td>';
|
||||
$html->select_types_paiements(empty($_POST['paiementid'])?'':$_POST['paiementid'],'paiementid');
|
||||
print '</td>';
|
||||
print '<td rowspan="3" valign="top">';
|
||||
print '<textarea name="comment" wrap="soft" cols="60" rows="'._ROWS_3.'">'.(empty($_POST['comment'])?'':$_POST['comment']).'</textarea></td></tr>';
|
||||
print '<tr><td>'.$langs->trans('Numero').'</td><td><input name="num_paiement" type="text" value="'.(empty($_POST['num_paiement'])?'':$_POST['num_paiement']).'"></td></tr>';
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans('Account').'</td><td>';
|
||||
$html->select_comptes(empty($_POST['accountid'])?'':$_POST['accountid'],'accountid',0,'',1);
|
||||
print '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="2"> </td></tr>';
|
||||
}
|
||||
print '</table>';
|
||||
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans('Payment').'</td>';
|
||||
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2">'.$obj->nom.'</td></tr>';
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td>';
|
||||
$html->select_date($dateinvoice,'','','','',"addpaiement",1,1);
|
||||
print '</td>';
|
||||
print '<td>'.$langs->trans('Comments').'</td></tr>';
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans('PaymentMode').'</td><td>';
|
||||
$html->select_types_paiements(empty($_POST['paiementid'])?'':$_POST['paiementid'],'paiementid');
|
||||
print '</td>';
|
||||
print '<td rowspan="3" valign="top">';
|
||||
print '<textarea name="comment" wrap="soft" cols="60" rows="'._ROWS_3.'">'.(empty($_POST['comment'])?'':$_POST['comment']).'</textarea></td></tr>';
|
||||
print '<tr><td>'.$langs->trans('Numero').'</td><td><input name="num_paiement" type="text" value="'.(empty($_POST['num_paiement'])?'':$_POST['num_paiement']).'"></td></tr>';
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans('Account').'</td><td>';
|
||||
$html->select_comptes(empty($_POST['accountid'])?'':$_POST['accountid'],'accountid',0,'',1);
|
||||
print '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="2"> </td></tr>';
|
||||
}
|
||||
print '</table>';
|
||||
|
||||
/*
|
||||
* Autres factures impayees
|
||||
*/
|
||||
$sql = 'SELECT f.rowid as facid,f.rowid as ref,f.facnumber,f.total_ttc, f.datef as df';
|
||||
$sql .= ', sum(pf.amount) as am';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
|
||||
$sql .= ' WHERE f.fk_soc = '.$facture->socid;
|
||||
$sql .= ' AND f.paye = 0';
|
||||
$sql .= ' AND f.fk_statut = 1'; // Statut=0 => non validee, Statut=2 => annulee
|
||||
$sql .= ' GROUP BY f.rowid,f.facnumber,f.total_ttc,f.datef';
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num > 0)
|
||||
{
|
||||
$i = 0;
|
||||
print '<br>';
|
||||
/*
|
||||
* Autres factures impayees
|
||||
*/
|
||||
$sql = 'SELECT f.rowid as facid,f.rowid as ref,f.facnumber,f.total_ttc, f.datef as df';
|
||||
$sql .= ', sum(pf.amount) as am';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
|
||||
$sql .= ' WHERE f.fk_soc = '.$facture->socid;
|
||||
$sql .= ' AND f.paye = 0';
|
||||
$sql .= ' AND f.fk_statut = 1'; // Statut=0 => non validee, Statut=2 => annulee
|
||||
$sql .= ' GROUP BY f.rowid,f.facnumber,f.total_ttc,f.datef';
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num > 0)
|
||||
{
|
||||
$i = 0;
|
||||
print '<br>';
|
||||
|
||||
print $langs->trans('Invoices').'<br>';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans('Ref').'</td>';
|
||||
print '<td>'.$langs->trans('RefSupplier').'</td>';
|
||||
print '<td align="center">'.$langs->trans('Date').'</td>';
|
||||
print '<td align="right">'.$langs->trans('AmountTTC').'</td>';
|
||||
print '<td align="right">'.$langs->trans('AlreadyPaid').'</td>';
|
||||
print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
|
||||
print '<td align="center">'.$langs->trans('Amount').'</td>';
|
||||
print '</tr>';
|
||||
print $langs->trans('Invoices').'<br>';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans('Ref').'</td>';
|
||||
print '<td>'.$langs->trans('RefSupplier').'</td>';
|
||||
print '<td align="center">'.$langs->trans('Date').'</td>';
|
||||
print '<td align="right">'.$langs->trans('AmountTTC').'</td>';
|
||||
print '<td align="right">'.$langs->trans('AlreadyPaid').'</td>';
|
||||
print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
|
||||
print '<td align="center">'.$langs->trans('Amount').'</td>';
|
||||
print '</tr>';
|
||||
|
||||
$var=True;
|
||||
$total=0;
|
||||
$totalrecu=0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td><a href="fiche.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').' '.$objp->ref;
|
||||
print '</a></td>';
|
||||
print '<td>'.$objp->facnumber.'</td>';
|
||||
if ($objp->df > 0 )
|
||||
{
|
||||
print '<td align="center">';
|
||||
print dol_print_date($db->jdate($objp->df)).'</td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td align="center"><b>!!!</b></td>';
|
||||
}
|
||||
print '<td align="right">'.price($objp->total_ttc).'</td>';
|
||||
print '<td align="right">'.price($objp->am).'</td>';
|
||||
print '<td align="right">'.price($objp->total_ttc - $objp->am).'</td>';
|
||||
print '<td align="center">';
|
||||
$namef = 'amount_'.$objp->facid;
|
||||
print '<input type="text" size="8" name="'.$namef.'">';
|
||||
print "</td></tr>\n";
|
||||
$total+=$objp->total;
|
||||
$total_ttc+=$objp->total_ttc;
|
||||
$totalrecu+=$objp->am;
|
||||
$i++;
|
||||
}
|
||||
if ($i > 1)
|
||||
{
|
||||
// Print total
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="3" align="left">'.$langs->trans('TotalTTC').':</td>';
|
||||
print '<td align="right"><b>'.price($total_ttc).'</b></td>';
|
||||
print '<td align="right"><b>'.price($totalrecu).'</b></td>';
|
||||
print '<td align="right"><b>'.price($total_ttc - $totalrecu).'</b></td>';
|
||||
print '<td align="center"> </td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
print "</table>\n";
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
$var=True;
|
||||
$total=0;
|
||||
$totalrecu=0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td><a href="fiche.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').' '.$objp->ref;
|
||||
print '</a></td>';
|
||||
print '<td>'.$objp->facnumber.'</td>';
|
||||
if ($objp->df > 0 )
|
||||
{
|
||||
print '<td align="center">';
|
||||
print dol_print_date($db->jdate($objp->df)).'</td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td align="center"><b>!!!</b></td>';
|
||||
}
|
||||
print '<td align="right">'.price($objp->total_ttc).'</td>';
|
||||
print '<td align="right">'.price($objp->am).'</td>';
|
||||
print '<td align="right">'.price($objp->total_ttc - $objp->am).'</td>';
|
||||
print '<td align="center">';
|
||||
$namef = 'amount_'.$objp->facid;
|
||||
print '<input type="text" size="8" name="'.$namef.'">';
|
||||
print "</td></tr>\n";
|
||||
$total+=$objp->total;
|
||||
$total_ttc+=$objp->total_ttc;
|
||||
$totalrecu+=$objp->am;
|
||||
$i++;
|
||||
}
|
||||
if ($i > 1)
|
||||
{
|
||||
// Print total
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="3" align="left">'.$langs->trans('TotalTTC').':</td>';
|
||||
print '<td align="right"><b>'.price($total_ttc).'</b></td>';
|
||||
print '<td align="right"><b>'.price($totalrecu).'</b></td>';
|
||||
print '<td align="right"><b>'.price($total_ttc - $totalrecu).'</b></td>';
|
||||
print '<td align="center"> </td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
print "</table>\n";
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
print '<br>';
|
||||
print '<center><input type="submit" class="button" value="'.$langs->trans('Save').'"></center>';
|
||||
print '<br>';
|
||||
print '<center><input type="submit" class="button" value="'.$langs->trans('Save').'"></center>';
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
}
|
||||
print '</form>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -364,147 +331,147 @@ if ($action == 'create' || $action == 'add_paiement')
|
|||
*/
|
||||
if (! $_GET['action'] && ! $_POST['action'])
|
||||
{
|
||||
if ($page == -1) $page = 0 ;
|
||||
$limit = $conf->liste_limit;
|
||||
$offset = $limit * $page ;
|
||||
if ($page == -1) $page = 0 ;
|
||||
$limit = $conf->liste_limit;
|
||||
$offset = $limit * $page ;
|
||||
|
||||
if (! $sortorder) $sortorder='DESC';
|
||||
if (! $sortfield) $sortfield='p.datep';
|
||||
if (! $sortorder) $sortorder='DESC';
|
||||
if (! $sortfield) $sortfield='p.datep';
|
||||
|
||||
$sql = 'SELECT p.rowid, p.rowid as pid, p.datep as dp, p.amount as pamount,';
|
||||
$sql.= ' f.rowid as facid, f.rowid as ref, f.facnumber, f.amount,';
|
||||
$sql.= ' s.rowid as socid, s.nom,';
|
||||
$sql.= ' c.libelle as paiement_type, p.num_paiement,';
|
||||
$sql.= ' ba.rowid as bid, ba.label';
|
||||
if (!$user->rights->societe->client->voir) $sql .= ", sc.fk_soc, sc.fk_user ";
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p';
|
||||
if (!$user->rights->societe->client->voir) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn ';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.rowid = f.fk_soc';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
|
||||
$sql.= ' WHERE 1=1';
|
||||
if (!$user->rights->societe->client->voir) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
if ($socid)
|
||||
{
|
||||
$sql .= ' AND f.fk_soc = '.$socid;
|
||||
}
|
||||
// Search criteria
|
||||
if ($_REQUEST["search_ref"])
|
||||
{
|
||||
$sql .=" AND p.rowid=".$_REQUEST["search_ref"];
|
||||
}
|
||||
$sql = 'SELECT p.rowid, p.rowid as pid, p.datep as dp, p.amount as pamount,';
|
||||
$sql.= ' f.rowid as facid, f.rowid as ref, f.facnumber, f.amount,';
|
||||
$sql.= ' s.rowid as socid, s.nom,';
|
||||
$sql.= ' c.libelle as paiement_type, p.num_paiement,';
|
||||
$sql.= ' ba.rowid as bid, ba.label';
|
||||
if (!$user->rights->societe->client->voir) $sql .= ", sc.fk_soc, sc.fk_user ";
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p';
|
||||
if (!$user->rights->societe->client->voir) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn ';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.rowid = f.fk_soc';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
|
||||
$sql.= ' WHERE 1=1';
|
||||
if (!$user->rights->societe->client->voir) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
if ($socid)
|
||||
{
|
||||
$sql .= ' AND f.fk_soc = '.$socid;
|
||||
}
|
||||
// Search criteria
|
||||
if ($_REQUEST["search_ref"])
|
||||
{
|
||||
$sql .=" AND p.rowid=".$_REQUEST["search_ref"];
|
||||
}
|
||||
if ($_REQUEST["search_account"])
|
||||
{
|
||||
$sql .=" AND b.fk_account=".$_REQUEST["search_account"];
|
||||
}
|
||||
if ($_REQUEST["search_paymenttype"])
|
||||
if ($_REQUEST["search_paymenttype"])
|
||||
{
|
||||
$sql .=" AND c.code='".$_REQUEST["search_paymenttype"]."'";
|
||||
}
|
||||
if ($_REQUEST["search_amount"])
|
||||
{
|
||||
$sql .=" AND p.amount=".price2num($_REQUEST["search_amount"]);
|
||||
}
|
||||
if ($_REQUEST["search_company"])
|
||||
{
|
||||
$sql .=" AND s.nom LIKE '%".addslashes($_REQUEST["search_company"])."%'";
|
||||
}
|
||||
$sql.= $db->order($sortfield,$sortorder);
|
||||
$sql.= $db->plimit($limit + 1 ,$offset);
|
||||
if ($_REQUEST["search_amount"])
|
||||
{
|
||||
$sql .=" AND p.amount=".price2num($_REQUEST["search_amount"]);
|
||||
}
|
||||
if ($_REQUEST["search_company"])
|
||||
{
|
||||
$sql .=" AND s.nom LIKE '%".addslashes($_REQUEST["search_company"])."%'";
|
||||
}
|
||||
$sql.= $db->order($sortfield,$sortorder);
|
||||
$sql.= $db->plimit($limit + 1 ,$offset);
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$var=True;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$var=True;
|
||||
|
||||
$paramlist='';
|
||||
$paramlist.=($_REQUEST["search_ref"]?"&search_ref=".$_REQUEST["search_ref"]:"");
|
||||
$paramlist.=($_REQUEST["search_company"]?"&search_company=".$_REQUEST["search_company"]:"");
|
||||
$paramlist.=($_REQUEST["search_amount"]?"&search_amount=".$_REQUEST["search_amount"]:"");
|
||||
$paramlist='';
|
||||
$paramlist.=($_REQUEST["search_ref"]?"&search_ref=".$_REQUEST["search_ref"]:"");
|
||||
$paramlist.=($_REQUEST["search_company"]?"&search_company=".$_REQUEST["search_company"]:"");
|
||||
$paramlist.=($_REQUEST["search_amount"]?"&search_amount=".$_REQUEST["search_amount"]:"");
|
||||
|
||||
print_barre_liste($langs->trans('SupplierPayments'), $page, 'paiement.php',$paramlist,$sortfield,$sortorder,'',$num);
|
||||
print_barre_liste($langs->trans('SupplierPayments'), $page, 'paiement.php',$paramlist,$sortfield,$sortorder,'',$num);
|
||||
|
||||
print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print_liste_field_titre($langs->trans('RefPayment'),'paiement.php','p.rowid','',$paramlist,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('Date'),'paiement.php','dp','',$paramlist,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('ThirdParty'),'paiement.php','s.nom','',$paramlist,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('Type'),'paiement.php','c.libelle','',$paramlist,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('Account'),'paiement.php','ba.label','',$paramlist,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('Amount'),'paiement.php','f.amount','',$paramlist,'align="right"',$sortfield,$sortorder);
|
||||
//print_liste_field_titre($langs->trans('Invoice'),'paiement.php','facnumber','',$paramlist,'',$sortfield,$sortorder);
|
||||
print "</tr>\n";
|
||||
print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print_liste_field_titre($langs->trans('RefPayment'),'paiement.php','p.rowid','',$paramlist,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('Date'),'paiement.php','dp','',$paramlist,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('ThirdParty'),'paiement.php','s.nom','',$paramlist,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('Type'),'paiement.php','c.libelle','',$paramlist,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('Account'),'paiement.php','ba.label','',$paramlist,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('Amount'),'paiement.php','f.amount','',$paramlist,'align="right"',$sortfield,$sortorder);
|
||||
//print_liste_field_titre($langs->trans('Invoice'),'paiement.php','facnumber','',$paramlist,'',$sortfield,$sortorder);
|
||||
print "</tr>\n";
|
||||
|
||||
// Lines for filters fields
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">';
|
||||
print '<input class="fat" type="text" size="4" name="search_ref" value="'.$_REQUEST["search_ref"].'">';
|
||||
print '</td>';
|
||||
print '<td> </td>';
|
||||
print '<td align="left">';
|
||||
print '<input class="fat" type="text" size="6" name="search_company" value="'.$_REQUEST["search_company"].'">';
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
// Lines for filters fields
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">';
|
||||
print '<input class="fat" type="text" size="4" name="search_ref" value="'.$_REQUEST["search_ref"].'">';
|
||||
print '</td>';
|
||||
print '<td> </td>';
|
||||
print '<td align="left">';
|
||||
print '<input class="fat" type="text" size="6" name="search_company" value="'.$_REQUEST["search_company"].'">';
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
$html->select_types_paiements($_REQUEST["search_paymenttype"],'search_paymenttype','',2,1,1);
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
$html->select_comptes($_REQUEST["search_account"],'search_account',0,'',1);
|
||||
print '</td>';
|
||||
print '<td align="right">';
|
||||
print '<input class="fat" type="text" size="4" name="search_amount" value="'.$_REQUEST["search_amount"].'">';
|
||||
print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans("Search").'">';
|
||||
print '</td>';
|
||||
print "</tr>\n";
|
||||
print '</td>';
|
||||
print '<td align="right">';
|
||||
print '<input class="fat" type="text" size="4" name="search_amount" value="'.$_REQUEST["search_amount"].'">';
|
||||
print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans("Search").'">';
|
||||
print '</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
while ($i < min($num,$limit))
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
while ($i < min($num,$limit))
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
|
||||
// Ref payment
|
||||
print '<td nowrap="nowrap"><a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$objp->pid.'">'.img_object($langs->trans('ShowPayment'),'payment').' '.$objp->pid.'</a></td>';
|
||||
// Ref payment
|
||||
print '<td nowrap="nowrap"><a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$objp->pid.'">'.img_object($langs->trans('ShowPayment'),'payment').' '.$objp->pid.'</a></td>';
|
||||
|
||||
// Date
|
||||
print '<td nowrap="nowrap" align="center">'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
|
||||
// Date
|
||||
print '<td nowrap="nowrap" align="center">'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
|
||||
|
||||
print '<td>';
|
||||
if ($objp->socid) print '<a href="'.DOL_URL_ROOT.'/societe/soc.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.dol_trunc($objp->nom,32).'</a>';
|
||||
else print ' ';
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
if ($objp->socid) print '<a href="'.DOL_URL_ROOT.'/societe/soc.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.dol_trunc($objp->nom,32).'</a>';
|
||||
else print ' ';
|
||||
print '</td>';
|
||||
|
||||
print '<td>'.dol_trunc($objp->paiement_type.' '.$objp->num_paiement,32)."</td>\n";
|
||||
print '<td>'.dol_trunc($objp->paiement_type.' '.$objp->num_paiement,32)."</td>\n";
|
||||
|
||||
print '<td>';
|
||||
if ($objp->bid) print '<a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"),'account').' '.dol_trunc($objp->label,24).'</a>';
|
||||
else print ' ';
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
if ($objp->bid) print '<a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"),'account').' '.dol_trunc($objp->label,24).'</a>';
|
||||
else print ' ';
|
||||
print '</td>';
|
||||
|
||||
print '<td align="right">'.price($objp->pamount).'</td>';
|
||||
print '<td align="right">'.price($objp->pamount).'</td>';
|
||||
|
||||
// Ref invoice
|
||||
/*$invoicesupplierstatic->ref=$objp->facnumber;
|
||||
$invoicesupplierstatic->id=$objp->facid;
|
||||
print '<td nowrap="nowrap">';
|
||||
print $invoicesupplierstatic->getNomUrl(1);
|
||||
print '</td>';*/
|
||||
// Ref invoice
|
||||
/*$invoicesupplierstatic->ref=$objp->facnumber;
|
||||
$invoicesupplierstatic->id=$objp->facid;
|
||||
print '<td nowrap="nowrap">';
|
||||
print $invoicesupplierstatic->getNomUrl(1);
|
||||
print '</td>';*/
|
||||
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
print "</table>";
|
||||
print "</form>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
print "</table>";
|
||||
print "</form>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user