diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 0a78f5d9297..1f30e15e70f 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -18,14 +18,13 @@ * * $Id$ * $Source$ - * */ /** - \file htdocs/compta/paiement.php - \ingroup compta - \brief Page de création d'un paiement - \version $Revision$ + \file htdocs/compta/paiement.php + \ingroup compta + \brief Page de création d'un paiement + \version $Revision$ */ include_once("./pre.inc.php"); @@ -33,6 +32,9 @@ require_once(DOL_DOCUMENT_ROOT."/paiement.class.php"); include_once(DOL_DOCUMENT_ROOT."/facture.class.php"); include_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); +$langs->load("bills"); +$langs->load("banks"); + $facid=isset($_GET["facid"])?$_GET["facid"]:$_POST["facid"]; $socname=isset($_GET["socname"])?$_GET["socname"]:$_POST["socname"]; @@ -46,146 +48,153 @@ $page=isset($_GET["page"])?$_GET["page"]:$_POST["page"]; */ if ($_POST["action"] == 'add_paiement') { - $error = 0; + $error = 0; - if ($_POST["paiementid"] > 0) + if ($_POST["paiementid"] > 0) { - $datepaye = $db->idate(mktime(12, 0 , 0, - $_POST["remonth"], - $_POST["reday"], - $_POST["reyear"])); - - $paiement_id = 0; - $total = 0; - $amounts = array(); - foreach ($_POST as $key => $value) + $datepaye = $db->idate(mktime(12, 0 , 0, + $_POST["remonth"], + $_POST["reday"], + $_POST["reyear"])); + + $paiement_id = 0; + $total = 0; + $amounts = array(); + foreach ($_POST as $key => $value) { - if (substr($key,0,7) == 'amount_') + if (substr($key,0,7) == 'amount_') { - $other_facid = substr($key,7); - - $amounts[$other_facid] = $_POST[$key]; - $total = $total + $amounts[$other_facid]; + $other_facid = substr($key,7); + + $amounts[$other_facid] = $_POST[$key]; + $total = $total + $amounts[$other_facid]; } } - - if ($total > 0) - { - $db->begin(); - - // Creation de la ligne paiement - $paiement = new Paiement($db); - $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Tableau de montant - $paiement->paiementid = $_POST["paiementid"]; - $paiement->num_paiement = $_POST["num_paiement"]; - $paiement->note = $_POST["comment"]; - - $paiement_id = $paiement->create($user); + if ($total > 0) + { - if ($paiement_id > 0) - { - // On determine le montant total du paiement - $total=0; - foreach ($paiement->amounts as $key => $value) - { - $facid = $key; - $value = trim($value); - $amount = round(ereg_replace(",",".",$value), 2); - if (is_numeric($amount)) - { - $total += $amount; - } - } - - if ($conf->banque->enabled && $_POST["accountid"]) - { - // Insertion dans llx_bank - $label = "Règlement facture"; - $acc = new Account($db, $_POST["accountid"]); - //paiementid contient "CHQ ou VIR par exemple" - $bank_line_id = $acc->addline($paiement->datepaye, - $paiement->paiementid, - $label, - $total, - $paiement->num_paiement, - '', - $user); - + $db->begin(); - // Mise a jour fk_bank dans llx_paiement. - // On connait ainsi le paiement qui a généré l'écriture bancaire - if ($bank_line_id > 0) - { - $paiement->update_fk_bank($bank_line_id); - - // Mise a jour liens (pour chaque facture concernées par le paiement) - foreach ($paiement->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++; - } - } - - } - else - { - $error++; - } + // Creation de la ligne paiement + $paiement = new Paiement($db); + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; // Tableau de montant + $paiement->paiementid = $_POST["paiementid"]; + $paiement->num_paiement = $_POST["num_paiement"]; + $paiement->note = $_POST["comment"]; - - if ($error == 0) - { - $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id; - $db->commit(); - Header("Location: $loc"); - } - else - { - // Il y a eu erreur - $db->rollback(); - $fiche_erreur_message = $langs->trans("ErrorUnknown"); - } - } - else - { - $fiche_erreur_message = '
Aucun montants indiqués
'; - } + $paiement_id = $paiement->create($user); + + if ($paiement_id > 0) + { + // On determine le montant total du paiement + $total=0; + foreach ($paiement->amounts as $key => $value) + { + $facid = $key; + $value = trim($value); + $amount = round(ereg_replace(",",".",$value), 2); + if (is_numeric($amount)) + { + $total += $amount; + } + } + + if ($conf->banque->enabled) + { + // Si module bank actif, un compte est obligatoire lors de la saisie + // d'un paiement + if (! $_POST["accountid"]) + { + $fiche_erreur_message = '
'.$langs->trans("ErrorFieldRequired",$langs->trans("AccountToCredit")).'
'; + $error++; + } + else + { + // Insertion dans llx_bank + $label = "Règlement facture"; + $acc = new Account($db, $_POST["accountid"]); + //paiementid contient "CHQ ou VIR par exemple" + $bank_line_id = $acc->addline($paiement->datepaye, + $paiement->paiementid, + $label, + $total, + $paiement->num_paiement, + '', + $user); + + + // Mise a jour fk_bank dans llx_paiement. + // On connait ainsi le paiement qui a généré l'écriture bancaire + if ($bank_line_id > 0) + { + $paiement->update_fk_bank($bank_line_id); + + // Mise a jour liens (pour chaque facture concernées par le paiement) + foreach ($paiement->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++; + } + } + } + + } + else + { + $error++; + } + + + if ($error == 0) + { + $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id; + $db->commit(); + Header("Location: $loc"); + } + else + { + $db->rollback(); + } + } + else + { + $fiche_erreur_message = '
'.$langs->trans("ErrorFieldRequired",$langs->trans("Amount")).'
'; + } } - else + else { - $fiche_erreur_message = '
Vous devez sélectionner un mode de paiement
'; + $fiche_erreur_message = '
'.$langs->trans("ErrorFieldRequired",$langs->trans("PaymentMode")).'
'; } } -/* - * Sécurité accés client - */ +// Sécurité accés client if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } + /* * Affichage */ @@ -196,204 +205,164 @@ $html=new Form($db); if ($fiche_erreur_message) { - print ''.$fiche_erreur_message.''; + print ''.$fiche_erreur_message.''; } - -if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement') +if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement') { - $facture = new Facture($db); - $facture->fetch($facid); + $facture = new Facture($db); + $facture->fetch($facid); - $sql = "SELECT s.nom,s.idp, f.amount, f.total_ttc as total, f.facnumber"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp"; - $sql .= " AND f.rowid = $facid"; + $sql = "SELECT s.nom,s.idp, f.amount, f.total_ttc as total, f.facnumber"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp"; + $sql .= " AND f.rowid = $facid"; - $resql = $db->query($sql); - if ($resql) + $resql = $db->query($sql); + if ($resql) { - $num = $db->num_rows($resql); - if ($num) - { - $obj = $db->fetch_object($resql); + $num = $db->num_rows($resql); + if ($num) + { + $obj = $db->fetch_object($resql); - $total = $obj->total; + $total = $obj->total; - print_titre($langs->trans("DoPayment")); + print_titre($langs->trans("DoPayment")); - print '
'; - print ''; - print ""; - print "facnumber\">"; - print "idp\">"; - print "nom\">"; + print ''; + print ''; + print ""; + print "facnumber\">"; + print "idp\">"; + print "nom\">"; - print ''; - - print "\n"; - - print "'; - print ''; - - print '\n"; + print '
".$langs->trans("Company")." :$obj->nom
".$langs->trans("Date")." :"; - $html->select_date(); - print ''.$langs->trans("Comments").'
'.$langs->trans("Type").' :"; - print "
'; - print ''; + print "\n"; - print "\n"; + print "'; + print ''; + + print '\n"; + + print ''; + + print "\n"; - if ($conf->banque->enabled) - { - - print "\n"; - - } - else - { - print ''; - } - - /* - * Autres factures impayées - */ + if ($conf->banque->enabled) + { + print "\n"; + } + else + { + print ''; + } - $sql = "SELECT f.rowid as facid,f.facnumber,f.total_ttc,".$db->pdate("f.datef")." as df"; - $sql .= ", sum(pf.amount) as am"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_facture = f.rowid"; - $sql .= " WHERE f.fk_soc = ".$facture->socidp; - $sql .= " AND f.paye = 0"; - $sql .= " AND f.fk_statut = 1"; // Statut=0 => non validée, Statut=2 => annulée - $sql .= " GROUP BY f.facnumber"; + /* + * Autres factures impayées + */ + $sql = "SELECT f.rowid as facid,f.facnumber,f.total_ttc,".$db->pdate("f.datef")." as df"; + $sql .= ", sum(pf.amount) as am"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_facture = f.rowid"; + $sql .= " WHERE f.fk_soc = ".$facture->socidp; + $sql .= " AND f.paye = 0"; + $sql .= " AND f.fk_statut = 1"; // Statut=0 => non validée, Statut=2 => annulée + $sql .= " GROUP BY f.facnumber"; - $resql = $db->query($sql); + $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - - if ($num > 0) - { - $i = 0; - print '"; + + print '\n"; + + if ($objp->df > 0 ) + { + print "\n"; + } + else + { + print "\n"; + } + + print '"; + print '"; + print '"; + + print '\n"; + $total+=$objp->total; + $total_ttc+=$objp->total_ttc; + $totalrecu+=$objp->am; + $i++; + } + if ($i > 1) + { + // Print total + print ''; + print ''; + print ""; + print ""; + print ""; + print ''; + print "\n"; + } + print "
'; - print '
".$langs->trans("Company")."$obj->nom
Numéro :
Numéro du chèque / virement
".$langs->trans("Date").""; + $html->select_date(); + print ''.$langs->trans("Comments").'
'.$langs->trans("PaymentMode").''; + $html->select_types_paiements('','paiementid'); + print "'; + print '
".$langs->trans("Numero")."
Numéro du chèque / virement
Compte à créditer :"; - print "
 
".$langs->trans("AccountToCredit").""; + $html->select_comptes('','accountid',0,'',1); + print "
 
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - $var=True; - $total=0; - $totalrecu=0; - - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $var=!$var; - - print ""; - - print '\n"; - - if ($objp->df > 0 ) - { - print "\n"; - } - else - { - print "\n"; - } - - print '"; - print '"; - print '"; - - print '\n"; - } - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } - /* - * - */ + $var=True; + $total=0; + $totalrecu=0; - print ''; - print "
'.$langs->trans("Bill").''.$langs->trans("Date").''.$langs->trans("AmountTTC").''.$langs->trans("Received").''.$langs->trans("RemainderToPay").''.$langs->trans("Amount").'
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->facnumber; - print ""; - print strftime("%d %b %Y",$objp->df)."!!!'.price($objp->total_ttc)."'.price($objp->am)."'.price($objp->total_ttc - $objp->am)."'; + if ($resql) + { + $num = $db->num_rows($resql); - $namef = "amount_".$objp->facid; - print ''; + if ($num > 0) + { + $i = 0; + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; - print "\n"; - $total+=$objp->total; - $total_ttc+=$objp->total_ttc; - $totalrecu+=$objp->am; - $i++; - } - if ($i > 1) - { - // Print total - print ""; - print ''; - print ""; - print ""; - print ""; - print ''; - print "\n"; - } - print "
'.$langs->trans("Bill").''.$langs->trans("Date").''.$langs->trans("AmountTTC").''.$langs->trans("Received").''.$langs->trans("RemainderToPay").''.$langs->trans("Amount").'
'.$langs->trans("TotalTTC").':".price($total_ttc)."".price($totalrecu)."".price($total_ttc - $totalrecu)." 
"; - print "\n"; - } + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + + print "
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->facnumber; + print ""; + print strftime("%d %b %Y",$objp->df)."!!!'.price($objp->total_ttc)."'.price($objp->am)."'.price($objp->total_ttc - $objp->am)."'; + + $namef = "amount_".$objp->facid; + print ''; + + print "
'.$langs->trans("TotalTTC").':".price($total_ttc)."".price($totalrecu)."".price($total_ttc - $totalrecu)." 
\n"; + } + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } + + /* + * + */ + print ''; + print ""; + print "\n"; + } } } diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 32bb494314b..2b90b5c97a3 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -636,26 +636,32 @@ class Form } - /** - * \brief Retourne la liste des comptes - * \param selected Id compte présélectionné - * \param htmlname Nom de la zone select - * \param statut Statut des comptes recherchés - * \param filtre Pour filtre sur la liste - */ - function select_comptes($selected='',$htmlname='accountid',$statut=0,$filtre='') + /** + * \brief Retourne la liste des comptes + * \param selected Id compte présélectionné + * \param htmlname Nom de la zone select + * \param statut Statut des comptes recherchés + * \param filtre Pour filtre sur la liste + * \param useempty Affiche valeur vide dans liste + */ + function select_comptes($selected='',$htmlname='accountid',$statut=0,$filtre='',$useempty=0) { global $langs; $sql = "SELECT rowid, label, bank"; $sql.= " FROM ".MAIN_DB_PREFIX."bank_account"; - $sql.= " WHERE clos = '".$satut."'"; + $sql.= " WHERE clos = '".$statut."'"; if ($filtre) $sql.=" AND ".$filtre; $sql.= " ORDER BY rowid"; $result = $this->db->query($sql); if ($result) { print '