From dcfc4fc78771c4899445bfbdbeb81715439867a2 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Tue, 10 Feb 2004 15:24:22 +0000 Subject: [PATCH] Fin gestion des paiements sur multiple factures --- htdocs/compta/paiement.php | 223 +++++++++++++++++++++++++++++++------ 1 file changed, 192 insertions(+), 31 deletions(-) diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 528b4ec0a47..1174f981f57 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -19,10 +19,84 @@ * $Source$ * */ -require("./pre.inc.php"); -require("../paiement.class.php"); -require("./bank/account.class.php"); +include_once("./pre.inc.php"); +include_once("../paiement.class.php"); +include_once(DOL_DOCUMENT_ROOT."/facture.class.php"); +include_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); +/* + * + */ +if ($HTTP_POST_VARS["action"] == 'add_paiement') +{ + + if ($HTTP_POST_VARS["paiementid"] > 0) + { + + $datepaye = $db->idate(mktime(12, 0 , 0, + $HTTP_POST_VARS["remonth"], + $HTTP_POST_VARS["reday"], + $HTTP_POST_VARS["reyear"])); + + $paiement_id = 0; + $amounts = array(); + foreach ($HTTP_POST_VARS as $key => $value) + { + if (substr($key,0,7) == 'amount_') + { + $other_facid = substr($key,7); + + $amounts[$other_facid] = $HTTP_POST_VARS[$key]; + } + } + + $paiement = new Paiement($db); + + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; + $paiement->author = $HTTP_POST_VARS["author"]; + $paiement->paiementid = $HTTP_POST_VARS["paiementid"]; + $paiement->num_paiement = $HTTP_POST_VARS["num_paiement"]; + $paiement->note = $HTTP_POST_VARS["note"]; + $paiement_id = $paiement->create($user); + + if ($paiement_id > 0) + { + $paiement = new Paiement($db); + if ( $paiement->fetch($paiement_id) ) + { + $fac = new Facture($db); + $fac->fetch($HTTP_POST_VARS["facid"]); + $fac->fetch_client(); + + $label = "Règlement facture"; + + //On ajoute une ligne dans la table llx_bank pour qu'ensuite on puisse rapprocher le compte ! + $acc = new Account($db, $HTTP_POST_VARS["accountid"]); + //paiementid est correct, il contient "CHQ ou VIR par exemple" + $bank_line_id = $acc->addline($datepaye, $HTTP_POST_VARS["paiementid"], $label, $paiement->montant, $num_paiement); + + // TODO + // Mise a jour fk_bank dans llx_paiement + // $acc->update_fk_bank($paiement_id,$bank_line_id); + + $acc->add_url_line($bank_line_id, $paiement_id, DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', "(paiement)"); + $acc->add_url_line($bank_line_id, $fac->client->id, DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom); + + $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id; + Header("Location: $loc"); + } + } + else + { + // print "Pas d'entrée dans la banque"; + } + } + else + { + $fiche_erreur_message = "Vous devez sélectionner un mode de paiement"; + } +} /* * Sécurité accés client @@ -39,9 +113,10 @@ if ($user->societe_id > 0) llxHeader(); - -if ($action == 'create') +if ($_GET["action"] == 'create') { + $facture = new Facture($db); + $facture->fetch($_GET["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"; @@ -58,26 +133,13 @@ if ($action == 'create') $total = $obj->total; print_titre("Emettre un paiement"); - print '
'; + + print ''; print ''; print ''; - print "\n"; - - print "\n"; print "\n"; - print ''; - - $sql = "SELECT sum(p.amount) FROM ".MAIN_DB_PREFIX."paiement as p WHERE p.fk_facture = $facid;"; - $result = $db->query($sql); - if ($result) - { - $sumpayed = $db->result(0,0); - $db->free(); - } - print ''; - print ''; print ""; print "facnumber\">"; print "idp\">"; @@ -106,9 +168,8 @@ if ($action == 'create') } print ""; print "\n"; - print "'; - + print ''; print "\n"; - - - print "\n"; - print "\n"; - print "\n"; + + print "\n"; + + /* + * 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 > 0";// AND f.rowid <>".$_GET["facid"]; + $sql .= " GROUP BY f.facnumber"; + + if ($db->query($sql)) + { + $num = $db->num_rows(); + + if ($num > 0) + { + $i = 0; + print '\n"; + } + $db->free(); + } + else + { + print $sql ."
".$db->error(); + } + /* + * + */ + + if ($fiche_erreur_message) + { + print ''; + } + print ''; - print "\n"; - print "
Facture
Numéro :$obj->facnumber
Société :$obj->nom
Montant :'.price($obj->total).' euros TTC
Déjà payé'.price($sumpayed).' euros TTC
Paiement"; - print '
'; + print '
Compte à créditer :"; print "
Numéro :
Num du cheque ou virement
 Reste à payer : ".price($total - $sumpayed)." euros TTC
Montant :
Numéro :
Numéro du chèque / virement
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $var=True; + $total=0; + $totalrecu=0; + + while ($i < $num) + { + $objp = $db->fetch_object($i); + $var=!$var; + + 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 "
FactureDateMontant TTCReçuReste à payerMontant
' . $objp->facnumber; + print ""; + print strftime("%d %b %Y",$objp->df)."!!!'.price($objp->total_ttc)."'.price($objp->am)."'.price($objp->total_ttc - $objp->am)."'; + + if ($objp->total_ttc <> $objp->am) + { + $namef = "amount_".$objp->facid; + print ''; + } + else + { + print '-'; + } + print "
Total :".price($total_ttc)."".price($totalrecu)."".price($total_ttc - $totalrecu)." 
'.$fiche_erreur_message.'
\n"; - + print ""; + print "\n"; } } }