From 496e780434408325bb73c1893ec887b3e536e29b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 10 Nov 2006 00:28:39 +0000 Subject: [PATCH] =?UTF-8?q?Am=E9lioration=20de=20la=20gestion=20des=20paie?= =?UTF-8?q?ments=20clients=20en=20ajoutant=20page=20de=20confirmation=20et?= =?UTF-8?q?=20warning=20si=20paiement=20saisi=20sup=E9rieur=20au=20reste?= =?UTF-8?q?=20=E0=20payer.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/compta/facture.php | 235 +++++++++--------- htdocs/compta/paiement.php | 401 ++++++++++++++++++------------- htdocs/compta/paiement/fiche.php | 24 +- htdocs/facture.class.php | 6 +- htdocs/html.form.class.php | 30 ++- htdocs/langs/en_US/bills.lang | 5 +- htdocs/langs/fr_FR/bills.lang | 5 +- htdocs/paiement.class.php | 15 +- mysql/migration/2.0.0-2.1.0.sql | 3 + 9 files changed, 424 insertions(+), 300 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index a7dd345985d..2a1f796f4e3 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -79,7 +79,7 @@ $NBLINES=4; * Actions */ -// Validation +// Validation if ($_GET['action'] == 'valid') { $facture = new Facture($db); @@ -92,7 +92,7 @@ if ($_GET['action'] == 'valid') if ($facture->total_ht >= 0) { $mesg='
'.$langs->trans("ErrorInvoiceAvoirMustBeNegative").'
'; - $_GET['action']=''; + $_GET['action']=''; } } else @@ -100,12 +100,12 @@ if ($_GET['action'] == 'valid') // Si non avoir, le signe doit etre positif if ($facture->total_ht < 0) { - $mesg='
'.$langs->trans("ErrorInvoiceOfThisTypeMustBePositive").'
'; - $_GET['action']=''; + $mesg='
'.$langs->trans("ErrorInvoiceOfThisTypeMustBePositive").'
'; + $_GET['action']=''; } } } - + if ($_POST['action'] == 'classin') { $facture = new Facture($db); @@ -201,19 +201,19 @@ if ($_GET['action'] == 'modif' && $user->rights->facture->modifier && $conf->glo { $fac = new Facture($db); $fac->fetch($_GET['facid']); - + // On vérifie si la facture a des paiements $sql = 'SELECT pf.amount'; $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf'; $sql.= ' WHERE pf.fk_facture = '.$fac->id; $result = $db->query($sql); - + if ($result) { $i = 0; $num = $db->num_rows($result); - + while ($i < $num) { $objp = $db->fetch_object($result); @@ -221,12 +221,12 @@ if ($_GET['action'] == 'modif' && $user->rights->facture->modifier && $conf->glo $i++; } } - + $resteapayer = $fac->total_ttc - $totalpaye; - + // On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées $ventilExportCompta = $fac->getVentilExportCompta(); - + // On vérifie si aucun paiement n'a été effectué if ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0) { @@ -311,7 +311,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $datefacture = mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); $result=$facture->fetch($_POST['fac_replacement']); - + $facture->date = $datefacture; $facture->note_public = trim($_POST['note_public']); $facture->note = trim($_POST['note']); @@ -371,7 +371,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("CorrectInvoice")).'
'; } } - + if ($_POST['type'] == 0 && $_POST['fac_rec'] > 0) { // Si facture récurrente @@ -575,7 +575,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) } } - + // Fin création facture, on l'affiche if ($facid > 0 && ! $error) { @@ -602,7 +602,7 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && $ret=$fac->fetch($_POST['facid']); $soc = new Societe($db); $ret=$soc->fetch($fac->socid); - + $date_start=''; $date_end=''; // Si ajout champ produit libre @@ -637,7 +637,7 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && { $prod = new Product($db, $_POST['idprod']); $prod->fetch($_POST['idprod']); - + // multiprix if ($conf->global->PRODUIT_MULTIPRICES == 1) { @@ -647,7 +647,7 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && { $pu=$prod->price; } - + // La description de la ligne est celle saisie ou // celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini) // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on @@ -656,7 +656,7 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && { $desc = $prod->description; } - + $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); } else @@ -739,7 +739,7 @@ if ($_GET['action'] == 'deleteline' && $user->rights->facture->creer && ! $conf- } else { - print $fac->error; + print $fac->error; } } @@ -758,7 +758,7 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') else { $mesg='
'.$fac->error.'
'; - } + } } } @@ -818,7 +818,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['c $file = $conf->facture->dir_output . '/' . $facref . '/' . $facref . '.pdf'; if (is_readable($file)) - { + { $soc = new Societe($db, $fac->socid); if ($_POST['sendto']) { @@ -839,7 +839,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['c $message = $_POST['message']; $sendtocc = $_POST['sendtocc']; $deliveryreceipt = $_POST['deliveryreceipt']; - + if ($_POST['action'] == 'send') { if(strlen($_POST['subject'])) @@ -850,16 +850,16 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['c { $subject = $langs->trans('Bill').' '.$fac->ref; } - + $actiontypeid=9; $actionmsg ='Mail envoyé par '.$from.' à '.$sendto.'.
'; - + if ($message) { $actionmsg.='Texte utilisé dans le corps du message:
'; $actionmsg.=$message; } - + $actionmsg2='Envoi facture par mail'; } if ($_POST['action'] == 'relance') @@ -892,7 +892,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['c if ($mailfile->sendfile()) { $mesg='
'.$langs->trans('MailSuccessfulySent',$from,$sendto).'.
'; - + // Insertion action require_once(DOL_DOCUMENT_ROOT.'/contact.class.php'); require_once(DOL_DOCUMENT_ROOT.'/actioncomm.class.php'); @@ -906,9 +906,9 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['c $actioncomm->societe = new Societe($db,$fac->socid); $actioncomm->user = $user; // User qui a fait l'action $actioncomm->facid = $fac->id; - + $ret=$actioncomm->add($user); // User qui saisit l'action - + if ($ret < 0) { dolibarr_print_error($db); @@ -960,18 +960,18 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post { $fac = new Facture($db, 0, $_GET['facid']); $fac->fetch($_GET['facid']); - + if ($_REQUEST['model']) { $fac->set_pdf_model($user, $_REQUEST['model']); } - + if ($_REQUEST['lang_id']) { $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs"); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } - + $result=facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); if ($result <= 0) { @@ -981,7 +981,7 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post else { Header ('Location: '.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'#builddoc'); - } + } } /********************************************************************* @@ -1022,11 +1022,11 @@ $html = new Form($db); if ($_GET['action'] == 'create') { $facturestatic=new Facture($db); - + print_titre($langs->trans('NewBill')); if ($mesg) print $mesg; - + $soc = new Societe($db); if ($_GET['propalid']) @@ -1092,7 +1092,7 @@ if ($_GET['action'] == 'create') // Ref print ''.$langs->trans('Ref').''.$langs->trans('Draft').''; - + /* \todo L'info "Reference commande client" est une carac de la commande et non de la facture. @@ -1107,7 +1107,7 @@ if ($_GET['action'] == 'create') print ''; } - // Societe + // Tiers print ''.$langs->trans('Company').''; print $soc->getNomUrl(1); print ''; @@ -1121,7 +1121,7 @@ if ($_GET['action'] == 'create') { $options.=''; } - $facids=$facturestatic->list_avoir_invoices($soc->id); + $facids=$facturestatic->list_qualified_avoir_invoices($soc->id); $optionsav=""; foreach ($facids as $key => $value) { @@ -1130,7 +1130,7 @@ if ($_GET['action'] == 'create') print ''.$langs->trans('Type').''; print ''."\n"; - + print ''."\n"; print ''."\n"; print '
'; print ''; print ''; @@ -1158,7 +1158,7 @@ if ($_GET['action'] == 'create') } $text.=''; $desc=$html->textwithhelp($text,$langs->transnoentities("InvoiceReplacementDesc"),1); - print $desc; + print $desc; print '
'; @@ -1183,12 +1183,12 @@ if ($_GET['action'] == 'create') $text.=''; $desc=$html->textwithhelp($text,$langs->transnoentities("InvoiceAvoirDesc"),1); //.' ('.$langs->trans("FeatureNotYetAvailable").')',$langs->transnoentities("InvoiceAvoirDesc"),1); - print $desc; + print $desc; print '
'; print ''; - + // Ligne info remises tiers print ''.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); @@ -1228,7 +1228,7 @@ if ($_GET['action'] == 'create') if ($relative_discount) { print $langs->trans("CompanyHasRelativeDiscount",$relative_discount); - } + } else { print $langs->trans("CompanyHasNoRelativeDiscount"); @@ -1248,14 +1248,14 @@ if ($_GET['action'] == 'create') if ($absolute_discount) { print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); - } + } else { print $langs->trans("CompanyHasNoAbsoluteDiscount"); } print ''; */ - + // Projet if ($conf->projet->enabled) { @@ -1264,7 +1264,7 @@ if ($_GET['action'] == 'create') $html->select_projects($societe_id, $projetid, 'projetid'); print ''; } - + // Modele PDF print ''.$langs->trans('Model').''; print ''; @@ -1273,7 +1273,7 @@ if ($_GET['action'] == 'create') $liste=$model->liste_modeles($db); $html->select_array('model',$liste,$conf->global->FACTURE_ADDON_PDF); print ""; - + // Note publique print ''; print ''.$langs->trans('NotePublic').''; @@ -1314,7 +1314,7 @@ if ($_GET['action'] == 'create') } print ''; } - + if ($_GET['propalid'] > 0) { print ''."\n"; @@ -1367,7 +1367,7 @@ if ($_GET['action'] == 'create') if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) { print ''; - + // Zone de choix des produits prédéfinis à la création print ''; print ''; @@ -1404,7 +1404,7 @@ if ($_GET['action'] == 'create') } print "\n"; } - + print '
'.$langs->trans('ProductsAndServices').'
'; print ''; } @@ -1423,7 +1423,7 @@ if ($_GET['action'] == 'create') { $num = $db->num_rows(); $i = 0; - + if ($num > 0) { print ''.$langs->trans('CreateFromRepeatableInvoice').' : '; print "\n"; @@ -1455,7 +1455,7 @@ if ($_GET['action'] == 'create') if ($_GET['propalid']) { $title=$langs->trans('ProductsAndServices'); - + $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.fk_remise_except,'; $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,'; $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,'; @@ -1479,7 +1479,7 @@ if ($_GET['action'] == 'create') if ($_GET['contratid']) { $title=$langs->trans('Services'); - + $sql = 'SELECT pt.rowid, pt.subprice, pt.tva_tx, pt.qty, pt.remise_percent, pt.description, pt.info_bits,'; $sql.= ' pt.date_ouverture_prevue as date_debut_prevue, pt.date_ouverture as date_debut_reel,'; $sql.= ' pt.date_fin_validite as date_fin_prevue, pt.date_cloture as date_fin_reel,'; @@ -1587,7 +1587,7 @@ else $totalpaye = $fac->getSommePaiement(); $resteapayer = $fac->total_ttc - $totalpaye; if ($fac->paye) $resteapayer=0; - + $author = new User($db); if ($fac->user_author) { @@ -1596,7 +1596,7 @@ else } $head = facture_prepare_head($fac); - + dolibarr_fiche_head($head, 'compta', $langs->trans('InvoiceCustomer')); /* @@ -1676,7 +1676,7 @@ else $html->form_confirm($_SERVER['PHP_SELF'].'?facid='.$fac->id,$langs->trans('CancelBill'),$langs->trans('ConfirmCancelBill',$fac->ref),'confirm_canceled'); print '
'; } - + /* * Confirmation de la suppression d'une ligne produit */ @@ -1690,10 +1690,10 @@ else * Facture */ print ''; - + // Reference print ''; - + // Ref client /* \todo @@ -1724,9 +1724,9 @@ else } print ''; print ''; - } - - // Société + } + + // Tiers Société print ''; print ''; print ''; @@ -1769,7 +1769,7 @@ else print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')'; } print ''; - + // Ligne info remises tiers print ''; - + // Dates print ''; print ''; - + $nbrows=8; if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++; if ($conf->projet->enabled) $nbrows++; @@ -1815,13 +1815,13 @@ else $num = $db->num_rows($result); $i = 0; print '
'.$langs->trans('Ref').''.$fac->ref.'
'.$langs->trans('Company').''.$soc->getNomUrl(1,'compta').'
'.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); @@ -1789,11 +1789,11 @@ else } else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; print '
'.$langs->trans('Date').''.dolibarr_print_date($fac->date,'%A %d %B %Y').'
'; - + if ($fac->type != 2) { // Liste des paiements print ''; print ''; - + $var=True; while ($i < $num) { @@ -1850,10 +1850,10 @@ else } else { - // Solde avoir + // Solde avoir print ''; print ''; - } + } print '
'.$langs->trans('Payments').''.$langs->trans('Type').''.$langs->trans('Amount').' 
'.$langs->trans('TotalTTCToYourCredit').' :'.price(abs($fac->total_ttc)).''.$langs->trans('Currency'.$conf->monnaie).'
'; $db->free($result); } @@ -1862,13 +1862,13 @@ else dolibarr_print_error($db); } - print ''; - + print ''; + // Date limite reglement print ''; print ''.$langs->trans('DateMaxPayment').''; print ''; - if ($fac->type != 2) + if ($fac->type != 2) { print dolibarr_print_date($fac->date_lim_reglement,'%A %d %B %Y'); if ($fac->date_lim_reglement < (time() - $conf->facture->client->warning_delay) && ! $fac->paye && $fac->statut == 1 && ! $fac->am) print img_warning($langs->trans('Late')); @@ -1900,10 +1900,10 @@ else } else { - print ' '; + print ' '; } print ''; - + // Mode de reglement print ''; print ''; print ''; @@ -1968,7 +1968,7 @@ else $langs->load('projects'); print ''; print ''; print ''; } - + print '
'; @@ -1945,10 +1945,10 @@ else $total_lignes_ht+=$ligne_ht; $total_lignes_vat+=$ligne_vat; $total_lignes_ttc+=$ligne_ttc; - $i++; + $i++; } } - + // Montants print '
'.$langs->trans('AmountHT').''.price($fac->total_ht).'
'; - + print ''; @@ -1979,7 +1979,7 @@ else print ''; } print '
'; print $langs->trans('Project'); print '
'; - + print '
'; if ($_GET['action'] == 'classer') { @@ -1992,7 +1992,7 @@ else print '

'; @@ -2055,13 +2055,13 @@ else print ' - '.nl2br(stripslashes($objp->product)); print_date_range($objp->date_start,$objp->date_end); print ($objp->description && $objp->description!=$objp->product)?'
'.stripslashes(nl2br($objp->description)):''; - + // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on if ($conf->global->PRODUIT_DESC_IN_FORM && !$conf->global->PRODUIT_CHANGE_PROD_DESC) { print '
'.nl2br($objp->product_desc); } - + print ''; } else @@ -2221,7 +2221,7 @@ else /* * Lignes de remise */ - + // Réductions relatives (Remises-Ristournes-Rabbais) /* Une réduction doit s'appliquer obligatoirement sur des lignes de factures $var=!$var; @@ -2390,7 +2390,7 @@ else print '
'; print ''; print ''; - + $var=! $var; print ''; print ''; @@ -2432,13 +2432,13 @@ else if ($user->societe_id == 0 && $_GET['action'] <> 'valid' && $_GET['action'] <> 'editline') { print '
'; - + // Editer une facture déjà validée, sans paiement effectué et pas exporté en compta if ($fac->statut == 1) { // On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées $ventilExportCompta = $fac->getVentilExportCompta(); - + if ($conf->global->FACTURE_ENABLE_EDITDELETE && $user->rights->facture->modifier && ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0)) { @@ -2449,15 +2449,15 @@ else // Récurrente if (! $conf->global->FACTURE_DISABLE_RECUR) { - print ' '.$langs->trans("ChangeIntoRepeatableInvoice").''; + print ''.$langs->trans("ChangeIntoRepeatableInvoice").''; } - + // Valider if ($fac->statut == 0 && $num_lignes > 0) { if ($user->rights->facture->valider) { - print ' '.$langs->trans('Validate').''; + print ''.$langs->trans('Validate').''; } } else @@ -2467,11 +2467,11 @@ else { if ($fac->paye == 0) { - print ' '.$langs->trans('BuildPDF').''; + print ''.$langs->trans('BuildPDF').''; } else { - print ' '.$langs->trans('RebuildPDF').''; + print ''.$langs->trans('RebuildPDF').''; } } } @@ -2479,42 +2479,63 @@ else // Envoyer if ($fac->statut == 1 && $user->rights->facture->envoyer) { - print ' '.$langs->trans('SendByMail').''; + if ($facidnext) + { + print ''.$langs->trans('SendByMail').''; + } + else + { + print ''.$langs->trans('SendByMail').''; + } } - + // Envoyer une relance if ($fac->statut == 1 && $resteapayer > 0 && $user->rights->facture->envoyer) { - print ' '.$langs->trans('SendRemindByMail').''; + if ($facidnext) + { + print ''.$langs->trans('SendRemindByMail').''; + } + else + { + print ''.$langs->trans('SendRemindByMail').''; + } } - + // Emettre paiement if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement) { - print ' '.$langs->trans('DoPaiement').''; + if ($facidnext) + { + print ''.$langs->trans('DoPaiement').''; + } + else + { + print ''.$langs->trans('DoPaiement').''; + } } - + // Classer 'payé' if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement && $resteapayer <= 0) { - print ' '.$langs->trans('ClassifyPayed').''; + print ''.$langs->trans('ClassifyPayed').''; } - + // Classer 'fermée' (possible si validée et pas encore classée payée) if ($fac->statut == 1 && $fac->paye == 0 && $resteapayer > 0 && $user->rights->facture->paiement) { if ($totalpaye > 0) { - print ' '.$langs->trans('ClassifyPayedPartially').''; + print ''.$langs->trans('ClassifyPayedPartially').''; } else { - print ' '.$langs->trans('ClassifyCanceled').''; + print ''.$langs->trans('ClassifyCanceled').''; // \todo - // Ajouter bouton "Annuler et Créer facture remplacement" + // Ajouter bouton "Annuler et Créer facture remplacement" } } @@ -2523,7 +2544,7 @@ else { print ''.$langs->trans('Delete').''; } - + print '
'; } @@ -2722,8 +2743,8 @@ else { dolibarr_print_error($db,$result); exit; - } - } + } + } print '
'; print_titre($langs->trans('SendBillByMail')); @@ -2778,9 +2799,9 @@ else { dolibarr_print_error($db,$result); exit; - } - } - + } + } + print '
'; print_titre($langs->trans('SendReminderBillByMail')); @@ -2987,7 +3008,7 @@ else print ''; print $facturestatic->LibStatut($objp->paye,$objp->fk_statut,5,$objp->am); print ''; - + print ''; $total+=$objp->total; $total_ttc+=$objp->total_ttc; diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 024b559c085..e7e0eade937 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -45,10 +45,15 @@ $sortorder = isset($_GET['sortorder'])?$_GET['sortorder']:$_POST['sortorder']; $page=isset($_GET['page'])?$_GET['page']:$_POST['page']; + +$amounts=array(); +$amountsresttopay=array(); +$addwarning=0; + /* - * Actions - */ -if ($_POST['action'] == 'add_paiement') +* Action add_paiement et confirm_paiement +*/ +if ($_POST['action'] == 'add_paiement' || $_POST['action'] == 'confirm_paiement') { $error = 0; @@ -57,16 +62,26 @@ if ($_POST['action'] == 'add_paiement') $_POST['reday'], $_POST['reyear'])); $paiement_id = 0; - $total = 0; - // Génère tableau des montants amounts - $amounts = array(); + + // Verifie si des paiements sont supérieurs au montant facture 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]; + $cursorfacid = substr($key,7); + $amounts[$cursorfacid] = $_POST[$key]; + $totalpaiement = $totalpaiement + price2num($amounts[$cursorfacid]); + $tmpfacture=new Facture($db); + $tmpfacture->fetch($cursorfacid); + $amountsresttopay[$cursorfacid]=($tmpfacture->total_ttc-$tmpfacture->getSommePaiement()); + if ($amounts[$cursorfacid] && $amounts[$cursorfacid] > $amountsresttopay[$cursorfacid]) + { + $addwarning=1; + $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' Attention, le montant de paiement pour une ou plusieurs facture est supérieur au reste à payer.'; + $formquestion['text'].='
Corriger votre saisie, sinon confirmer. Dolibarr pourra créer un avoir du trop perçu lors de la fermeture de chacune de facture.'; + } + + $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]); } } @@ -88,12 +103,31 @@ if ($_POST['action'] == 'add_paiement') } } - if ($total <= 0) + if ($totalpaiement <= 0) { $fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->trans('Amount')).'
'; $error++; } +} +/* +* Action add_paiement +*/ +if ($_POST['action'] == 'add_paiement') +{ + if ($error) + { + $_POST['action']=''; + $_GET['action'] = 'create'; + } + // Le reste propre a cette action s'affiche en bas de page. +} + +/* +* Action confirm_paiement +*/ +if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes') +{ if (! $error) { $db->begin(); @@ -110,13 +144,6 @@ if ($_POST['action'] == 'add_paiement') if ($paiement_id > 0) { - // On determine le montant total du paiement - $total=0; - foreach ($paiement->amounts as $value) - { - $total += $value; - } - if ($conf->banque->enabled) { // Insertion dans llx_bank @@ -126,7 +153,7 @@ if ($_POST['action'] == 'add_paiement') $bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementid, $label, - $total, + $totalpaiement, $paiement->num_paiement, '', $user); @@ -198,180 +225,220 @@ llxHeader(); $html=new Form($db); $facturestatic=new Facture($db); -if ($fiche_erreur_message) -{ - print ''.$fiche_erreur_message.''; -} -if ($_GET['action'] == 'create' || $_POST['action'] == 'add_paiement') +if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_POST['action'] == 'add_paiement') { $facture = new Facture($db); $result=$facture->fetch($facid); if ($result >= 0) { - $facture->fetch_client(); - - $total = $facture->total_ttc; + $facture->fetch_client(); + + $title=''; + if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer"); + if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer"); + print_fiche_titre($title); - $title=''; - if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer"); - if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer"); - print_fiche_titre($title); - print ''; - print ''; - print ''; - print ''; - print ''; + // Initialise donnees pour page de confirmation + if ($_POST["action"] == 'add_paiement') + { + $i=0; + + $formquestion[$i++]=array('type' => 'hidden','name' => 'facid', 'value' => $facture->id); + $formquestion[$i++]=array('type' => 'hidden','name' => 'socid', 'value' => $facture->socid); + $formquestion[$i++]=array('type' => 'hidden','name' => 'type', 'value' => $facture->type); - print ''; - print '\n"; + } - print '
'.$langs->trans('Company').''.$facture->client->getNomUrl(4)."
'.$langs->trans('Date').''; - if (!empty($_POST['remonth']) && !empty($_POST['reday']) && !empty($_POST['reyear'])) - $sel_date=mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); - else - $sel_date=''; - $html->select_date($sel_date,'','','','',"add_paiement"); + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + + print '\n"; + + print ''; + print ''; + + print '\n"; + + print ''; + + print ''; + print ''; + + print ''; + if ($conf->banque->enabled) + { + if ($facture->type != 2) print ''; + if ($facture->type == 2) print ''; + print ''; - print ''; + } + else + { + print ''; + } + print "\n"; - print '\n"; - print ''; + /* + * Liste factures impayées + */ + $sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.type, '; + $sql.= $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->socid; + $sql.= ' AND f.paye = 0'; + $sql.= ' AND f.fk_statut = 1'; // Statut=0 => non validée, Statut=2 => annulée + if ($facture->type != 2) + { + $sql .= ' AND type in (0,1)'; // Facture standard ou de remplacement + } + else + { + $sql .= ' AND type = 2'; + } + $sql .= ' GROUP BY f.facnumber'; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num > 0) + { - print ''; - print ''; + $i = 0; + print '\n"; } + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } - /* - * - */ + + // Bouton Enregistrer + if ($_POST["action"] != 'add_paiement') + { print ''; - print '
'.$langs->trans('Company').''.$facture->client->getNomUrl(4)."
'.$langs->trans('Date').''; + if (!empty($_POST['remonth']) && !empty($_POST['reday']) && !empty($_POST['reyear'])) + $sel_date=mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + else + $sel_date=''; + $html->select_date($sel_date,'','','','',"add_paiement"); + print ''.$langs->trans('Comments').'
'.$langs->trans('PaymentMode').''; + $html->select_types_paiements(empty($_POST['paiementid'])?'':$_POST['paiementid'],'paiementid'); + print "'; + print '
'.$langs->trans('Numero'); + print ' (Numéro chèque ou virement)'; // \todo a traduire + print '
'.$langs->trans('AccountToCredit').''.$langs->trans('AccountToDebit').''; + $html->select_comptes(empty($_POST['accountid'])?'':$_POST['accountid'],'accountid',0,'',1); print ''.$langs->trans('Comments').'
 
'.$langs->trans('PaymentMode').''; - $html->select_types_paiements(empty($_POST['paiementid'])?'':$_POST['paiementid'],'paiementid'); - print "'; - print '
'.$langs->trans('Numero'); - print ' (Numéro chèque ou virement)'; // \todo a traduire - print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; - print ''; - if ($conf->banque->enabled) - { - if ($facture->type != 2) print ''; - if ($facture->type == 2) print ''; - print ''; - } - else - { - print ''; - } - print "\n"; + $var=True; + $total=0; + $totalrecu=0; - /* - * Autres factures impayées - */ - $sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.type, '; - $sql.= $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->socid; - $sql.= ' AND f.paye = 0'; - $sql.= ' AND f.fk_statut = 1'; // Statut=0 => non validée, Statut=2 => annulée - if ($facture->type != 2) - { - $sql .= ' AND type in (0,1)'; // Facture standard ou de remplacement - } - else - { - $sql .= ' AND type = 2'; - } - $sql .= ' GROUP BY f.facnumber'; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - if ($num > 0) + while ($i < $num) { - $i = 0; - print '\n"; + $total+=$objp->total; + $total_ttc+=$objp->total_ttc; + $totalrecu+=$objp->am; + $i++; } - $db->free($resql); - } - else - { - dolibarr_print_error($db); + if ($i > 1) + { + // Print total + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + print "
'.$langs->trans('Invoice').''.$langs->trans('Date').''.$langs->trans('AmountTTC').''.$langs->trans('Received').''.$langs->trans('RemainderToPay').''.$langs->trans('PaymentAmount').' 
'.$langs->trans('AccountToCredit').''.$langs->trans('AccountToDebit').''; - $html->select_comptes(empty($_POST['accountid'])?'':$_POST['accountid'],'accountid',0,'',1); - print ' 
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + $objp = $db->fetch_object($resql); + $var=!$var; + + print ''; + + print '\n"; + + // Date + print '\n"; + + // Prix + print ''; + + // Recu + print ''; + + // Reste a payer + print ''; + + // Montant + print '"; + + // Warning + 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 ''; - } - - 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 "
'.$langs->trans('Invoice').''.$langs->trans('Date').''.$langs->trans('AmountTTC').''.$langs->trans('Received').''.$langs->trans('RemainderToPay').''.$langs->trans('Amount').'
'; + $facturestatic->ref=$objp->facnumber; + $facturestatic->id=$objp->facid; + $facturestatic->type=$objp->type; + print $facturestatic->getNomUrl(1,''); + print "'.dolibarr_print_date($objp->df)."'.price($objp->total_ttc).''.price($objp->am).''.price($objp->total_ttc - $objp->am).''; + $namef = 'amount_'.$objp->facid; + print ''; + print "'; + if ($amounts[$facturestatic->id] && $amounts[$facturestatic->id] > $amountsresttopay[$facturestatic->id]) + { + print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay")); + } + print '
'; - $facturestatic->ref=$objp->facnumber; - $facturestatic->id=$objp->rowid; - $facturestatic->type=$objp->type; - print $facturestatic->getNomUrl(1,''); - print "'; - print dolibarr_print_date($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).' 
'.$langs->trans('TotalTTC').':'.price($total_ttc).''.price($totalrecu).''.price($total_ttc - $totalrecu).' 
'; - print "\n"; + } + print '
'; + + + // Message d'erreur + if ($fiche_erreur_message) + { + print ''.$fiche_erreur_message.''; + } + + // Formulaire confirmation + if ($_POST["action"] == 'add_paiement') + { +// print ''; + print '
'; + $text=$langs->trans('ConfirmCustomerPayment',$totalpaiement,$langs->trans("Currency".$conf->monnaie)); + $html->form_confirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type,$langs->trans('ReceivedCustomersPayments'),$text,'confirm_paiement',$formquestion); +// print ''; + } + + print "\n"; } } @@ -411,7 +478,7 @@ if (! $_GET['action'] && ! $_POST['action']) print_barre_liste($langs->trans('Payments'), $page, 'paiement.php','',$sortfield,$sortorder,'',$num); print ''; print ''; - print_liste_field_titre($langs->trans('Bill'),'paiement.php','facnumber','','','',$sortfield); + print_liste_field_titre($langs->trans('Invoice'),'paiement.php','facnumber','','','',$sortfield); print_liste_field_titre($langs->trans('Date'),'paiement.php','dp','','','',$sortfield); print_liste_field_titre($langs->trans('Type'),'paiement.php','libelle','','','',$sortfield); print_liste_field_titre($langs->trans('Amount'),'paiement.php','fa_amount','','','align="right"',$sortfield); diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php index 1b4179a28f7..048e4d2dd3f 100644 --- a/htdocs/compta/paiement/fiche.php +++ b/htdocs/compta/paiement/fiche.php @@ -129,7 +129,7 @@ dolibarr_fiche_head($head, $hselected, $langs->trans("Payment").": ".$paiement-> */ if ($_GET['action'] == 'delete') { - $html->form_confirm('fiche.php?id='.$paiement->id, 'Supprimer le paiement', 'Etes-vous sûr de vouloir supprimer ce paiement ?', 'confirm_delete'); + $html->form_confirm('fiche.php?id='.$paiement->id, $langs->trans("DeletePayment"), 'Etes-vous sûr de vouloir supprimer ce paiement ?', 'confirm_delete'); print '
'; } @@ -139,7 +139,7 @@ if ($_GET['action'] == 'delete') if ($_GET['action'] == 'valide') { $facid = $_GET['facid']; - $html->form_confirm('fiche.php?id='.$paiement->id.'&facid='.$facid, 'Valider le paiement', 'Etes-vous sûr de vouloir valider ce paiment, auncune modification n\'est possible une fois le paiement validé ?', 'confirm_valide'); + $html->form_confirm('fiche.php?id='.$paiement->id.'&facid='.$facid, $langs->trans("ValidatePayment"), 'Etes-vous sûr de vouloir valider ce paiment, auncune modification n\'est possible une fois le paiement validé ?', 'confirm_valide'); print '
'; } @@ -168,14 +168,26 @@ if ($conf->banque->enabled) print ''; } } + +// Date print ''; -print ''; -if ($paiement->numero) -{ + +// Mode +print ''; + +// Numero +//if ($paiement->montant) +//{ print ''; -} +//} + +// Montant print ''; + + +// Note print ''; + print '
'.$langs->trans('Date').''.dolibarr_print_date($paiement->date).'
'.$langs->trans('Type').''.$paiement->type_libelle.'
'.$langs->trans('Mode').''.$langs->trans("PaymentType".$paiement->type_code).'
'.$langs->trans('Numero').''.$paiement->numero.'
'.$langs->trans('Amount').''.price($paiement->montant).' '.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('Note').''.nl2br($paiement->note).'
'; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index dc435366088..20bc1d8d4f1 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -2278,7 +2278,7 @@ class Facture extends CommonObject * \param socid Id societe * \return array Tableau des factures ($id => $ref) */ - function list_avoir_invoices($socid=0) + function list_qualified_avoir_invoices($socid=0) { global $conf; @@ -2287,13 +2287,13 @@ class Facture extends CommonObject $sql = "SELECT f.rowid as rowid, f.facnumber"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON f.rowid = ff.fk_facture_source AND ff.type=1"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON (f.rowid = ff.fk_facture_source AND ff.type=1)"; $sql.= " WHERE f.fk_statut >= 1 AND f.paye = 0"; $sql.= " AND ff.type IS NULL"; // Renvoi vrai si pas facture de remplacement if ($socid > 0) $sql.=" AND f.fk_soc = ".$socid; $sql.= " ORDER BY f.facnumber"; - dolibarr_syslog("Facture.class::list_avoir_invoices sql=$sql"); + dolibarr_syslog("Facture.class::list_qualified_avoir_invoices sql=$sql"); $resql=$this->db->query($sql); if ($resql) { diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 87fdc754785..fdd35623c18 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -1174,7 +1174,7 @@ class Form print ''; + if ($input['type'] == 'text') + { + print ''.$input['label'].''; + } + if ($input['type'] == 'select') + { + // TODO + } if ($input['type'] == 'radio') { $i=0; @@ -1541,19 +1548,26 @@ class Form } } } - print ''; - print ''; + print ''; + print ''; } // Ligne message - print ''.$question.''; + print ''; + print ''.$question.''; print ''; $this->selectyesno("confirm","no"); print ''; - print ''; + print ''; + print ''; print ''; - + + foreach ($formquestion as $key => $input) + { + if ($input['type'] == 'hidden') print ''; + } + print "\n"; } diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index f69bd2b17ba..9d725bfacbb 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -40,13 +40,15 @@ Payments=Payments PaymentType=Payment type PaymentTypes=Payment types ReceivedPayments=Received payments -ReceivedCustomersPayments=Received customers payments +ReceivedCustomersPayments=Payments received from customers ReceivedCustomersPaymentsToValid=Received customers payments to validate PaymentsReportsForYear=Payments reports for %s PaymentsReports=Payments reports PaymentsAlreadyDone=Payments already done PaymentMode=Payment mode PaymentConditionsShort=Payment conditions +PaymentAmount=Payment amount +PaymentHigherThanReminderToPay=Payment higher than reminder to pay ClassifyPayed=Classify 'Payed' ClassifyPayedPartially=Classify 'Payed partially' ClassifyCanceled=Classify 'Abandonned' @@ -119,6 +121,7 @@ ConfirmClassifyPayedPartiallyNoVat=Ce choix est possible si votre facture ConfirmClassifyPayedPartiallyVat=Ce choix est possible si votre facture était munie de la mention adéquate. (Exemple: «seule la taxe correspondant au prix effectivement payé ouvre droit à déduction») ConfirmClassifyPayedPartiallyAvoir=Ce choix est le choix à prendre si les autres ne sont pas applicables ConfirmClassifyPayedPartiallyAbandon=Ce choix sera celui dans le cas d'un mauvais payeur sans aucun espoir de recouvrement +ConfirmCustomerPayment=Do you confirm this paiement input for %s %s ? ValidateBill=Validate invoice NumberOfBills=Nb of invoices NumberOfBillsByMonth=Nb of invoices by month diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index 8f780ab4458..d927efc9c9e 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -40,13 +40,15 @@ Payments=Paiements PaymentType=Type de paiement PaymentTypes=Types de paiements ReceivedPayments=Paiements reçus -ReceivedCustomersPayments=Paiements clients reçus +ReceivedCustomersPayments=Paiements reçus du client ReceivedCustomersPaymentsToValid=Paiements clients reçus à valider PaymentsReportsForYear=Rapports de paiements pour %s PaymentsReports=Rapports de paiements PaymentsAlreadyDone=Versements déjà effectués PaymentMode=Mode règlement PaymentConditionsShort=Conditions règlement +PaymentAmount=Montant paiement +PaymentHigherThanReminderToPay=Paiement supérieur au reste à payer ClassifyPayed=Classer 'Payée' ClassifyPayedPartially=Classer 'Payée partiellement' ClassifyCanceled=Classer 'Abandonnée' @@ -119,6 +121,7 @@ ConfirmClassifyPayedPartiallyAvoir=Ce choix est le choix ConfirmClassifyPayedPartiallyNoVat=Ce choix est possible si votre facture était munie de la mention adéquate. (Exemple: «escompte net de taxe») ConfirmClassifyPayedPartiallyVat=Ce choix est possible si votre facture était munie de la mention adéquate. (Exemple: mention définissant l'escompte ou du genre «seule la taxe correspondant au prix effectivement payé ouvre droit à déduction») ConfirmClassifyPayedPartiallyAbandon=Ce choix sera celui dans le cas d'un mauvais payeur sans aucun espoir de recouvrement +ConfirmCustomerPayment=Confirmez-vous la saisie de ce paiement de %s %s ? ValidateBill=Valider facture NumberOfBills=Nb de factures NumberOfBillsByMonth=Nb de factures par mois diff --git a/htdocs/paiement.class.php b/htdocs/paiement.class.php index 02fd50314ae..197ae4c43fa 100644 --- a/htdocs/paiement.class.php +++ b/htdocs/paiement.class.php @@ -73,12 +73,12 @@ class Paiement function fetch($id) { $sql = 'SELECT p.rowid,'.$this->db->pdate('p.datep').' as dp, p.amount, p.statut, p.fk_bank'; - $sql .=', c.libelle as paiement_type'; - $sql .= ', p.num_paiement, p.note, b.fk_account'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement as p'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid '; - $sql .= ' WHERE p.fk_paiement = c.id'; - $sql .= ' AND p.rowid = '.$id; + $sql.= ', c.code as type_code, c.libelle as type_libelle'; + $sql.= ', p.num_paiement, p.note, b.fk_account'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement as p'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid '; + $sql.= ' WHERE p.fk_paiement = c.id'; + $sql.= ' AND p.rowid = '.$id; if ($this->db->query($sql)) { @@ -93,7 +93,8 @@ class Paiement $this->bank_line = $obj->fk_bank; $this->montant = $obj->amount; $this->note = $obj->note; - $this->type_libelle = $obj->paiement_type; + $this->type_libelle = $obj->type_libelle; + $this->type_code = $obj->type_code; $this->statut = $obj->statut; return 1; } diff --git a/mysql/migration/2.0.0-2.1.0.sql b/mysql/migration/2.0.0-2.1.0.sql index 967a0854310..ae56cd9eb7c 100644 --- a/mysql/migration/2.0.0-2.1.0.sql +++ b/mysql/migration/2.0.0-2.1.0.sql @@ -479,6 +479,9 @@ alter table llx_facturedet_rec add column total_tva real; alter table llx_facturedet_rec add column total_ttc real; +update llx_facture set fk_facture_source=null where fk_facture_source is not null and type = 0; + + update llx_boxes set fk_user = 0 where fk_user IS NULL; ALTER TABLE llx_boxes modify fk_user integer default 0 NOT NULL;