diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 728ac102799..5dd9749d7dd 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -73,6 +73,29 @@ if ($_POST["action"] == 'classin') $facture->classin($_POST["projetid"]); } +if ($_POST["action"] == 'setmode') +{ + $facture = new Facture($db); + $facture->fetch($_GET["facid"]); + $result=$facture->mode_reglement($_POST["mode_reglement_id"]); + if ($result < 0) dolibarr_print_error($db,$facture->error); +} + +if ($_POST["action"] == 'setconditions') +{ + $facture = new Facture($db); + $facture->fetch($_GET["facid"]); + $result=$facture->cond_reglement($_POST["cond_reglement_id"]); + if ($result < 0) dolibarr_print_error($db,$facture->error); +} + +if ($_POST["action"] == 'classin') +{ + $facture = new Facture($db); + $facture->fetch($_GET["facid"]); + $facture->classin($_POST["projetid"]); +} + /* * Insertion facture */ @@ -94,12 +117,12 @@ if ($_POST["action"] == 'add') } else { - $facture->projetid = $_POST["projetid"]; - $facture->cond_reglement = $_POST["condid"]; - $facture->mode_reglement = $_POST["mode_reglement"]; - $facture->amount = $_POST["amount"]; - $facture->remise = $_POST["remise"]; - $facture->remise_percent = $_POST["remise_percent"]; + $facture->projetid = $_POST["projetid"]; + $facture->cond_reglement_id = $_POST["cond_reglement_id"]; + $facture->mode_reglement_id = $_POST["mode_reglement_id"]; + $facture->amount = $_POST["amount"]; + $facture->remise = $_POST["remise"]; + $facture->remise_percent = $_POST["remise_percent"]; if (!$_POST["propalid"] && !$_POST["commandeid"]) { @@ -555,12 +578,12 @@ if ($_GET["action"] == 'create') // Conditions de réglement $id_condition_paiements_defaut=1; print "".$langs->trans("PaymentConditions").""; - $html->select_conditions_paiements($id_condition_paiements_defaut,'condid'); + $html->select_conditions_paiements($id_condition_paiements_defaut,'cond_reglement_id'); print ""; // Mode de réglement print "".$langs->trans("PaymentMode").""; - $html->select_types_paiements('','mode_reglement'); + $html->select_types_paiements('','mode_reglement_id'); print ""; // Projet @@ -864,13 +887,13 @@ else $head[$h][1] = $langs->trans("Preview"); $h++; - if ($fac->mode_reglement == 3) + if ($fac->mode_reglement_code == 'PRE') { $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; $head[$h][1] = $langs->trans("StandingOrders"); $h++; } - + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; $head[$h][1] = $langs->trans("Note"); $h++; @@ -927,16 +950,45 @@ else print ''; // Conditions et modes de réglement - print ''.$langs->trans("PaymentConditions").''. $fac->cond_reglement . ''; - print ''.$langs->trans("PaymentMode").''. $fac->mode_reglement . ''; - + print ''; + print ''; + if ($_GET["action"] != "editconditions" && $fac->brouillon) print ''; + print '
'; + print $langs->trans("PaymentConditions"); + print ''.img_edit($langs->trans("SetConditions")).'
'; + print ''; + if ($_GET["action"] == "editconditions") + { + $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"cond_reglement_id"); + } + else + { + $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"none"); + } + print ''; + print ''; + print ''; + if ($_GET["action"] != "editmode" && $fac->brouillon) print ''; + print '
'; + print $langs->trans("PaymentMode"); + print ''.img_edit($langs->trans("SetMode")).'
'; + print ''; + if ($_GET["action"] == "editmode") + { + $html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"mode_reglement_id"); + } + else + { + $html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none"); + } + print ''; print ''; // Projet if ($conf->projet->enabled) { $langs->load("projects"); - print ''; + print ''; print ''; @@ -952,8 +1004,10 @@ else $html->form_project($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->fk_soc,$fac->projetid,"none"); } print ""; - } else { - print ''; + } + else + { + print ''; } print '"; - print ""; + print ""; - print ''; + print ''; if ($fac->brouillon == 1 && $user->rights->facture->creer) { print ''; @@ -1027,17 +1081,17 @@ else } print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; // Statut - print ''; + print ''; if ($fac->note) { diff --git a/htdocs/compta/facture/apercu.php b/htdocs/compta/facture/apercu.php index f7a0252d044..8c8c111ff59 100644 --- a/htdocs/compta/facture/apercu.php +++ b/htdocs/compta/facture/apercu.php @@ -66,188 +66,194 @@ $html = new Form($db); /* *************************************************************************** */ if ($_GET["facid"] > 0) -{ - $fac = New Facture($db); - if ( $fac->fetch($_GET["facid"], $user->societe_id) > 0) - { - $soc = new Societe($db, $fac->socidp); - $soc->fetch($fac->socidp); - $author = new User($db); - $author->id = $fac->user_author; - $author->fetch(); - - $h = 0; - - $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("CardBill"); - $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("Preview"); - $hselected = $h; - $h++; +{ + $fac = New Facture($db); + if ( $fac->fetch($_GET["facid"], $user->societe_id) > 0) + { + $soc = new Societe($db, $fac->socidp); + $soc->fetch($fac->socidp); + $author = new User($db); + $author->id = $fac->user_author; + $author->fetch(); - if ($fac->mode_reglement == 3) - { - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("StandingOrders"); - $h++; - } + $h = 0; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("Note"); - $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("Info"); - $h++; - - dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); + $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("CardBill"); + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Preview"); + $hselected = $h; + $h++; - - /* - * Facture - */ - print '
'; print $langs->trans("Project"); print '    '; @@ -1011,9 +1065,9 @@ else print "
".$langs->trans("Author")."$author->fullname
".$langs->trans("Author")."$author->fullname
'.$langs->trans("GlobalDiscount").'
'.$langs->trans("GlobalDiscount").'
'.$langs->trans("AmountHT").'
'.$langs->trans("AmountHT").''.price($fac->total_ht).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("VAT").''.price($fac->total_tva).'
'.$langs->trans("VAT").''.price($fac->total_tva).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("AmountTTC").''.price($fac->total_ttc).'
'.$langs->trans("AmountTTC").''.price($fac->total_ttc).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("Status").''.($fac->getLibStatut()).'
'.$langs->trans("Status").''.($fac->getLibStatut()).'
'; - print ''; - print ''; - print ''; - - // Dates - print ''; - print ''; - print '"; + if ($fac->mode_reglement_code == 'PRE') + { + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("StandingOrders"); + $h++; + } - // Conditions et modes de réglement - print ''; - print ''; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Note"); + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Info"); + $h++; - print ''; - if ($conf->projet->enabled) - { - $langs->load("projects"); - print '"; - } - else - { - print '"; - } - print '"; - - print ""; - - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - - print '
'.$langs->trans("Company").''; - print ''.$soc->nom.'
'.$langs->trans("Date").''.dolibarr_print_date($fac->date,"%A %d %B %Y").''.$langs->trans("DateClosing").'' . dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y"); - if ($fac->paye == 0 && $fac->date_lim_reglement < (time() - $warning_delay)) print img_warning($langs->trans("Late")); - print "
'.$langs->trans("PaymentConditions").''. $fac->cond_reglement . ''.$langs->trans("PaymentMode").''. $fac->mode_reglement . '
'.$langs->trans("Project").''; - if ($fac->projetid > 0) - { - $projet = New Project($db); - $projet->fetch($fac->projetid); - print ''.$projet->title.''; - } - else - { - print ' '; - } - print "  '; - print " '; - - /* - * Documents - * - */ - $facref = sanitize_string($fac->ref); - $file = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf"; - $filedetail = $conf->facture->dir_output . "/" . $facref . "/" . $facref . "-detail.pdf"; - $relativepath = "${facref}/${facref}.pdf"; - $relativepathdetail = "${facref}/${facref}-detail.pdf"; - $relativepathimage = "${facref}/${facref}.pdf.png"; - - $fileimage = $file.".png"; - - $var=true; - - // Si fichier PDF existe - if (file_exists($file)) - { - $encfile = urlencode($file); - print_titre($langs->trans("Documents")); + dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); + + + /* + * Facture + */ print ''; - print ""; - - print ''; - print ''; - print ''; + // Societe + print ''; + print ''; print ''; - - // Si fichier detail PDF existe - if (file_exists($filedetail)) // facture détaillée supplémentaire - { - print ""; - - print ''; - print ''; - print ''; - print ''; - } - - print "
".$langs->trans("Bill")." PDF'.$fac->ref.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
'.$langs->trans("Company").''; + print ''.$soc->nom.'
Facture détaillée'.$fac->ref.'-detail.pdf'.filesize($filedetail). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($filedetail)).'
\n"; - - // Conversion du PDF en image png si fichier png non existant - if (!file_exists($fileimage)) - { - if (function_exists(imagick_readimage)) { - $handle = imagick_readimage( $file ) ; - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - - imagick_convert( $handle, "PNG" ) ; - - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - - imagick_writeimage( $handle, $file .".png"); - } - else { - $langs->load("other"); - print $langs->trans("ErrorNoImagickReadimage"); - } - } - - } - /* - * - * - */ - - print "
".$langs->trans("Author")."$author->fullname
'.$langs->trans("GlobalDiscount").''.$fac->remise_percent.'%
'.$langs->trans("AmountHT").''.price($fac->total_ht).''.$langs->trans("Currency".$conf->monnaie).'
'; - + // Dates + print ''.$langs->trans("Date").''; + print ''.dolibarr_print_date($fac->date,"%A %d %B %Y").''; + print ''.$langs->trans("DateClosing").'' . dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y"); + if ($fac->paye == 0 && $fac->date_lim_reglement < (time() - $warning_delay)) print img_warning($langs->trans("Late")); + print ""; + + // Conditions et modes de réglement + print ''.$langs->trans("PaymentConditions").''; + $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"none"); + print ''; + print ''.$langs->trans("PaymentMode").''; + $html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none"); + print ''; + + print ''; + if ($conf->projet->enabled) + { + $langs->load("projects"); + print ''.$langs->trans("Project").''; + if ($fac->projetid > 0) + { + $projet = New Project($db); + $projet->fetch($fac->projetid); + print ''.$projet->title.''; + } + else + { + print ' '; + } + print " "; + } + else + { + print ' '; + print " "; + } + print ''; + + /* + * Documents + * + */ + $facref = sanitize_string($fac->ref); + $file = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf"; + $filedetail = $conf->facture->dir_output . "/" . $facref . "/" . $facref . "-detail.pdf"; + $relativepath = "${facref}/${facref}.pdf"; + $relativepathdetail = "${facref}/${facref}-detail.pdf"; + $relativepathimage = "${facref}/${facref}.pdf.png"; + + $fileimage = $file.".png"; + + $var=true; + + // Si fichier PDF existe + if (file_exists($file)) + { + $encfile = urlencode($file); + print_titre($langs->trans("Documents")); + print ''; + + print ""; + + print ''; + print ''; + print ''; + print ''; + + // Si fichier detail PDF existe + if (file_exists($filedetail)) // facture détaillée supplémentaire + { + print ""; + + print ''; + print ''; + print ''; + print ''; + } + + print "
".$langs->trans("Bill")." PDF'.$fac->ref.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
Facture détaillée'.$fac->ref.'-detail.pdf'.filesize($filedetail). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($filedetail)).'
\n"; + + // Conversion du PDF en image png si fichier png non existant + if (!file_exists($fileimage)) + { + if (function_exists(imagick_readimage)) { + $handle = imagick_readimage( $file ) ; + if ( imagick_iserror( $handle ) ) + { + $reason = imagick_failedreason( $handle ) ; + $description = imagick_faileddescription( $handle ) ; + + print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; + } + + imagick_convert( $handle, "PNG" ) ; + + if ( imagick_iserror( $handle ) ) + { + $reason = imagick_failedreason( $handle ) ; + $description = imagick_faileddescription( $handle ) ; + + print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; + } + + imagick_writeimage( $handle, $file .".png"); + } + else { + $langs->load("other"); + print $langs->trans("ErrorNoImagickReadimage"); + } + } + + } + + /* + * + * + */ + + print ""; + + print "".$langs->trans("Author")."$author->fullname"; + + print ''.$langs->trans("GlobalDiscount").''; + print ''.$fac->remise_percent.''; + print '%'; + + print ''.$langs->trans("AmountHT").''; + print ''.price($fac->total_ht).''; + print ''.$langs->trans("Currency".$conf->monnaie).''; + + print ''; + } - else + else { - // Facture non trouvée - print $langs->trans("ErrorBillNotFound",$_GET["facid"]); + // Facture non trouvée + print $langs->trans("ErrorBillNotFound",$_GET["facid"]); } -} +} if (file_exists($fileimage)) { diff --git a/htdocs/compta/facture/info.php b/htdocs/compta/facture/info.php index 2e1005e3f7f..e57b57ba115 100644 --- a/htdocs/compta/facture/info.php +++ b/htdocs/compta/facture/info.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004 Laurent Destailleur +/* Copyright (C) 2004 Rodolphe Quiedeville + * Copyright (C) 2004-2005 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,6 @@ * * $Id$ * $Source$ - * */ /** @@ -40,33 +39,43 @@ llxHeader(); * */ -$facture = new Facture($db); -$facture->fetch($_GET["facid"]); -$facture->info($_GET["facid"]); -$soc = new Societe($db, $facture->socidp); -$soc->fetch($facture->socidp); +$fac = new Facture($db); +$fac->fetch($_GET["facid"]); +$fac->info($_GET["facid"]); +$soc = new Societe($db, $fac->socidp); +$soc->fetch($fac->socidp); $h = 0; -$head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$facture->id; +$head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; $head[$h][1] = $langs->trans("CardBill"); $h++; -$head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$facture->id; + +$head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; $head[$h][1] = $langs->trans("Preview"); $h++; -$head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$facture->id; + +if ($fac->mode_reglement_code == 'PRE') +{ + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("StandingOrders"); + $h++; +} + +$head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; $head[$h][1] = $langs->trans("Note"); $h++; -$head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$facture->id; + +$head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; $head[$h][1] = $langs->trans("Info"); $hselected = $h; $h++; -dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $facture->ref"); +dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); print '
'; -dolibarr_print_object_info($facture); +dolibarr_print_object_info($fac); print '
'; print ''; diff --git a/htdocs/compta/facture/note.php b/htdocs/compta/facture/note.php index ca8783cdef7..3ab1a36adb6 100644 --- a/htdocs/compta/facture/note.php +++ b/htdocs/compta/facture/note.php @@ -47,8 +47,8 @@ if ($user->societe_id > 0) } -$facture = new Facture($db); -$facture->fetch($_GET["facid"]); +$fac = new Facture($db); +$fac->fetch($_GET["facid"]); /******************************************************************************/ @@ -57,7 +57,7 @@ $facture->fetch($_GET["facid"]); if ($_POST["action"] == 'update' && $user->rights->facture->creer) { - $facture->update_note($_POST["note"]); + $fac->update_note($_POST["note"]); } @@ -68,83 +68,91 @@ if ($_POST["action"] == 'update' && $user->rights->facture->creer) llxHeader(); +$html = new Form($db); if ($_GET["facid"]) { - $soc = new Societe($db, $facture->socidp); - $soc->fetch($facture->socidp); + $soc = new Societe($db, $fac->socidp); + $soc->fetch($fac->socidp); - $h=0; - - $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$facture->id; - $head[$h][1] = $langs->trans("CardBill"); - $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$facture->id; - $head[$h][1] = $langs->trans("Preview"); - $h++; + $h=0; - if ($facture->mode_reglement == 3) - { - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$facture->id; - $head[$h][1] = $langs->trans("StandingOrders"); - $h++; - } - - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$facture->id; - $head[$h][1] = $langs->trans("Note"); - $hselected = $h; - $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$facture->id; - $head[$h][1] = $langs->trans("Info"); - $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("CardBill"); + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Preview"); + $h++; - dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $facture->ref"); - - - print ''; + if ($fac->mode_reglement_code == 'PRE') + { + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("StandingOrders"); + $h++; + } - print ''; - print ''; - - print ''; - print '\n"; - print '"; - - // Conditions et modes de réglement - print ''; - print ''; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Note"); + $hselected = $h; + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Info"); + $h++; - print ''; + dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); + + + print '
'.$langs->trans("Company").''; - print ''.$soc->nom.'
'.$langs->trans("Date").''.dolibarr_print_date($facture->date,"%A %d %B %Y")."'.$langs->trans("DateClosing").''.dolibarr_print_date($facture->date_lim_reglement,"%A %d %B %Y") ."
'.$langs->trans("PaymentConditions").''. $facture->cond_reglement . ''.$langs->trans("PaymentMode").''. $facture->mode_reglement . '
'.$langs->trans("Note").' :
'; + + print ''; + print ''; + + // Dates + print ''; + print ''; + print '"; + + // Conditions et modes de réglement + print ''; + print ''; + + print ''; + + print '"; + + if ($_GET["action"] == 'edit') + { + print ''; + print ''; + print '"; + print ''; + print ''; + } + + print "
'.$langs->trans("Company").''; + print ''.$soc->nom.'
'.$langs->trans("Date").''.dolibarr_print_date($fac->date,"%A %d %B %Y").''.$langs->trans("DateClosing").'' . dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y"); + if ($fac->paye == 0 && $fac->date_lim_reglement < (time() - $warning_delay)) print img_warning($langs->trans("Late")); + print "
'.$langs->trans("PaymentConditions").''; + $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"none"); + print ''.$langs->trans("PaymentMode").''; + $html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none"); + print '
'.$langs->trans("Note").' :
'.($fac->note?nl2br($fac->note):" ")."
"; + + + /* + * Actions + */ + print ''; + print '
'; + + if ($user->rights->facture->creer && $_GET["action"] <> 'edit') + { + print "id&action=edit\">".$langs->trans('Edit').""; + } + + print "
"; - print ''.($facture->note?nl2br($facture->note):" ").""; - - if ($_GET["action"] == 'edit') - { - print '
'; - print ''; - print '"; - print ''; - print '
'; - } - - print ""; - - /* - * Actions - */ - print ''; - print '
'; - - if ($user->rights->facture->creer && $_GET["action"] <> 'edit') - { - print "id&action=edit\">".$langs->trans('Edit').""; - } - - print "
"; - - } $db->close(); diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index 4d87b495dee..a18f938d563 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -19,14 +19,13 @@ * * $Id$ * $Source$ - * */ /** - \file htdocs/compta/facture/prelevement.php - \ingroup facture - \brief Gestion des prelevement d'une facture - \version $Revision$ + \file htdocs/compta/facture/prelevement.php + \ingroup facture + \brief Gestion des prelevement d'une facture + \version $Revision$ */ require("./pre.inc.php"); @@ -40,6 +39,18 @@ $langs->load("banks"); require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); +// Sécurité accés client +if ($user->societe_id > 0) +{ + $action = ''; + $socidp = $user->societe_id; +} + + +/* + * Actions + */ + if ($_GET["action"] == "new") { $fact = new Facture($db); @@ -66,14 +77,7 @@ if ($_GET["action"] == "delete") } } -/* - * Sécurité accés client - */ -if ($user->societe_id > 0) -{ - $action = ''; - $socidp = $user->societe_id; -} + llxHeader('',$langs->trans("Bill")); @@ -86,201 +90,219 @@ $html = new Form($db); /* *************************************************************************** */ if ($_GET["facid"] > 0) -{ - $fac = New Facture($db); - if ( $fac->fetch($_GET["facid"], $user->societe_id) > 0) - { - $soc = new Societe($db, $fac->socidp); - $soc->fetch($fac->socidp); - $author = new User($db); - $author->id = $fac->user_author; - $author->fetch(); - - $h = 0; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("CardBill"); - $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("Preview"); - $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("StandingOrders"); - $hselected = $h; - $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("Note"); - $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("Info"); - $h++; - - dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); - - /* - * Facture - */ - print ''; - print ''; - print ''; - - print ""; - - print ''; - print "\n"; - print ''; - - print ''; - - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - - print ''; - - print "
'.$langs->trans("Company").''; - print ''.$soc->nom.'Conditions de réglement : " . $fac->cond_reglement ."
'.$langs->trans("Date").'".dolibarr_print_date($fac->date,"%A %d %B %Y")."'.$langs->trans("DateClosing").dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y").'
'.$langs->trans("Author").''.$author->fullname.'
'.$langs->trans("AmountHT").''.price($fac->total_ht).''.$langs->trans("Currency".$conf->monnaie).' 
'.$langs->trans("AmountTTC").''.price($fac->total_ttc).''.$langs->trans("Currency".$conf->monnaie).' 
RIB'; - print $soc->display_rib(); - print '
"; - - /* - * Demande de prélèvement - * - */ - - $sql = "SELECT pfd.rowid, pfd.traite,".$db->pdate("pfd.date_demande")." as date_demande"; - $sql .= " ,".$db->pdate("pfd.date_traite")." as date_traite"; - $sql .= " , pfd.amount"; - $sql .= " , u.name, u.firstname"; - $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; - $sql .= " , ".MAIN_DB_PREFIX."user as u"; - $sql .= " WHERE fk_facture = ".$fac->id; - $sql .= " AND pfd.fk_user_demande = u.rowid"; - $sql .= " AND pfd.traite = 0"; - $sql .= " ORDER BY pfd.date_demande DESC"; - - $result_sql = $db->query($sql); - if ($result_sql) - { - $num = $db->num_rows($result_sql); - } - - - print "
\n"; - - // Valider - if ($fac->statut > 0 && $fac->paye == 0 && $fac->mode_reglement == 3 && $num == 0) - { - if ($user->rights->facture->creer) - { - print 'Faire une demande de prélèvement'; - } - } - print "

"; - - /* - * Prélèvement - */ - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $var=True; - - if ($result_sql) - { - $i = 0; - - while ($i < $num) - { - $obj = $db->fetch_object($result_sql); - $var=!$var; - - print ""; - print '\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - $i++; - } - - $db->free($result_sql); - } - else - { - dolibarr_print_error($db); - } - - $sql = "SELECT pfd.rowid, pfd.traite,".$db->pdate("pfd.date_demande")." as date_demande"; - $sql .= " ,".$db->pdate("pfd.date_traite")." as date_traite"; - $sql .= " , pfd.fk_prelevement_bons, pfd.amount"; - $sql .= " , u.name, u.firstname"; - $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; - $sql .= " , ".MAIN_DB_PREFIX."user as u"; - $sql .= " WHERE fk_facture = ".$fac->id; - $sql .= " AND pfd.fk_user_demande = u.rowid"; - $sql .= " AND pfd.traite = 1"; - $sql .= " ORDER BY pfd.date_demande DESC"; - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - - while ($i < $num) - { - $obj = $db->fetch_object($result); - $var=!$var; - - print ""; - - print '\n"; - - print '\n"; - print ''; - print '\n"; - - print ''; - - print ''; - - print "\n"; - $i++; - } - - $db->free($result); - } - else - { - dolibarr_print_error($db); - } - - print "
Date demandeDate traitement'.$langs->trans("Amount").'Bon prélèvement'.$langs->trans("User").'  
'.strftime("%d/%m/%Y",$obj->date_demande)."En attente de traitement'.price($obj->amount).'-'.$obj->firstname." ".$obj->name.''; - print ''; - print img_delete(); - print '
'.strftime("%d/%m/%Y",$obj->date_demande)."'.strftime("%d/%m/%Y",$obj->date_traite)."'.price($obj->amount).''; - print ''.$obj->fk_prelevement_bons."'.$obj->firstname." ".$obj->name.'-
"; - - } - else +{ + $fac = New Facture($db); + if ( $fac->fetch($_GET["facid"], $user->societe_id) > 0) { - /* Facture non trouvée */ - print $langs->trans("ErrorBillNotFound",$_GET["facid"]); + $soc = new Societe($db, $fac->socidp); + $soc->fetch($fac->socidp); + $author = new User($db); + $author->id = $fac->user_author; + $author->fetch(); + + $h = 0; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("CardBill"); + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Preview"); + $h++; + + if ($fac->mode_reglement_code == 'PRE') + { + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("StandingOrders"); + $hselected = $h; + $h++; + } + + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Note"); + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Info"); + $h++; + + dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); + + /* + * Facture + */ + print ''; + + // Societe + print ''; + print ''; + print ''; + + // Dates + print ''; + print ''; + print '"; + + // Conditions et modes de réglement + print ''; + print ''; + + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + + print ''; + + print '
'.$langs->trans("Company").''; + print ''.$soc->nom.'
'.$langs->trans("Date").''.dolibarr_print_date($fac->date,"%A %d %B %Y").''.$langs->trans("DateClosing").'' . dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y"); + if ($fac->paye == 0 && $fac->date_lim_reglement < (time() - $warning_delay)) print img_warning($langs->trans("Late")); + print "
'.$langs->trans("PaymentConditions").''; + $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"none"); + print ''.$langs->trans("PaymentMode").''; + $html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none"); + print '
'.$langs->trans("AmountHT").''.price($fac->total_ht).''.$langs->trans("Currency".$conf->monnaie).' 
'.$langs->trans("AmountTTC").''.price($fac->total_ttc).''.$langs->trans("Currency".$conf->monnaie).' 
RIB'; + print $soc->display_rib(); + print '
'; + print ''; + + /* + * Demande de prélèvement + * + */ + + $sql = "SELECT pfd.rowid, pfd.traite,".$db->pdate("pfd.date_demande")." as date_demande"; + $sql .= " ,".$db->pdate("pfd.date_traite")." as date_traite"; + $sql .= " , pfd.amount"; + $sql .= " , u.name, u.firstname"; + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; + $sql .= " , ".MAIN_DB_PREFIX."user as u"; + $sql .= " WHERE fk_facture = ".$fac->id; + $sql .= " AND pfd.fk_user_demande = u.rowid"; + $sql .= " AND pfd.traite = 0"; + $sql .= " ORDER BY pfd.date_demande DESC"; + + $result_sql = $db->query($sql); + if ($result_sql) + { + $num = $db->num_rows($result_sql); + } + + + print "
\n"; + + // Valider + if ($fac->statut > 0 && $fac->paye == 0 && $fac->mode_reglement_code == 'PRE' && $num == 0) + { + if ($user->rights->facture->creer) + { + print 'Faire une demande de prélèvement'; + } + } + print "

"; + + /* + * Prélèvement + */ + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $var=True; + + if ($result_sql) + { + $i = 0; + + while ($i < $num) + { + $obj = $db->fetch_object($result_sql); + $var=!$var; + + print ""; + print '\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + $i++; + } + + $db->free($result_sql); + } + else + { + dolibarr_print_error($db); + } + + $sql = "SELECT pfd.rowid, pfd.traite,".$db->pdate("pfd.date_demande")." as date_demande"; + $sql .= " ,".$db->pdate("pfd.date_traite")." as date_traite"; + $sql .= " , pfd.fk_prelevement_bons, pfd.amount"; + $sql .= " , u.name, u.firstname"; + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; + $sql .= " , ".MAIN_DB_PREFIX."user as u"; + $sql .= " WHERE fk_facture = ".$fac->id; + $sql .= " AND pfd.fk_user_demande = u.rowid"; + $sql .= " AND pfd.traite = 1"; + $sql .= " ORDER BY pfd.date_demande DESC"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + + while ($i < $num) + { + $obj = $db->fetch_object($result); + $var=!$var; + + print ""; + + print '\n"; + + print '\n"; + print ''; + print '\n"; + + print ''; + + print ''; + + print "\n"; + $i++; + } + + $db->free($result); + } + else + { + dolibarr_print_error($db); + } + + print "
Date demandeDate traitement'.$langs->trans("Amount").'Bon prélèvement'.$langs->trans("User").'  
'.strftime("%d/%m/%Y",$obj->date_demande)."En attente de traitement'.price($obj->amount).'-'.$obj->firstname." ".$obj->name.''; + print ''; + print img_delete(); + print '
'.strftime("%d/%m/%Y",$obj->date_demande)."'.strftime("%d/%m/%Y",$obj->date_traite)."'.price($obj->amount).''; + print ''.$obj->fk_prelevement_bons."'.$obj->firstname." ".$obj->name.'-
"; + } -} + else + { + /* Facture non trouvée */ + print $langs->trans("ErrorBillNotFound",$_GET["facid"]); + } +} print ''; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index e5a02379153..c639ad58f09 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -55,8 +55,10 @@ class Facture var $propalid; var $projetid; var $prefixe_facture; - var $cond_reglement; - var $mode_reglement; + var $cond_reglement_id; + var $cond_reglement_code; + var $mode_reglement_id; + var $mode_reglement_code; /** * \brief Constructeur de la classe @@ -100,14 +102,19 @@ class Facture $_facrec = new FactureRec($this->db, $this->fac_rec); $_facrec->fetch($this->fac_rec); - $this->projetid = $_facrec->projetid; - $this->cond_reglement = $_facrec->cond_reglement_id; - $this->amount = $_facrec->amount; - $this->remise = $_facrec->remise; - $this->remise_percent = $_facrec->remise_percent; + $this->projetid = $_facrec->projetid; + $this->cond_reglement = $_facrec->cond_reglement_id; + $this->cond_reglement_id = $_facrec->cond_reglement_id; + $this->mode_reglement = $_facrec->mode_reglement_id; + $this->mode_reglement_id = $_facrec->mode_reglement_id; + $this->amount = $_facrec->amount; + $this->remise = $_facrec->remise; + $this->remise_percent = $_facrec->remise_percent; } - $sql = "SELECT fdm,nbjour FROM ".MAIN_DB_PREFIX."cond_reglement WHERE rowid = $this->cond_reglement"; + $sql = "SELECT fdm,nbjour "; + $sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement"; + $sql.= " WHERE rowid = ".$this->cond_reglement; if ($this->db->query($sql)) { if ($this->db->num_rows()) @@ -151,7 +158,7 @@ class Facture $sql .= " VALUES ('$number','$socid', now(), '$totalht', '$remise'"; $sql .= ",'$this->remise_percent', ".$this->db->idate($this->date); $sql .= ",'".addslashes($this->note)."',$user->id, $this->projetid"; - $sql .= ",".$this->cond_reglement.",".$this->mode_reglement.",".$this->db->idate($datelim).")"; + $sql .= ",".$this->cond_reglement_id.",".$this->mode_reglement_id.",".$this->db->idate($datelim).")"; if ( $this->db->query($sql) ) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture"); @@ -654,7 +661,7 @@ class Facture */ function set_paiement_started($rowid) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut=2 WHERE rowid = $rowid ;"; + $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut=2 WHERE rowid = ".$rowid; $return = $this->db->query( $sql); } @@ -664,7 +671,7 @@ class Facture */ function set_canceled($rowid) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut=3 WHERE rowid = $rowid ;"; + $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut=3 WHERE rowid = ".$rowid; $return = $this->db->query( $sql); } @@ -742,7 +749,9 @@ class Facture { $sql .= ", datef=now()"; // du coup, il faut aussi recalculer la date limite de règlement - $sqltemp = "SELECT c.fdm,c.nbjour,c.rowid,f.fk_cond_reglement,f.rowid FROM ".MAIN_DB_PREFIX."cond_reglement as c, ".MAIN_DB_PREFIX."facture as f WHERE c.rowid=f.fk_cond_reglement AND f.rowid=$this->id"; + $sqltemp = "SELECT c.fdm,c.nbjour,c.rowid,f.fk_cond_reglement,f.rowid"; + $sqltemp.= " FROM ".MAIN_DB_PREFIX."cond_reglement as c, ".MAIN_DB_PREFIX."facture as f"; + $sqltemp.= " WHERE c.rowid=f.fk_cond_reglement AND f.rowid=".$this->id; if ($this->db->query($sqltemp)) { if ($this->db->num_rows()) @@ -1350,38 +1359,76 @@ class Facture } /** - * \brief Change le mode de réglement - * \param mode nouveau mode - */ - function mode_reglement($mode) + * \brief Change les conditions de réglement + * \param cond_reglement_id Id des nouvelles conditions + * \return int >0 si ok, <0 si ko + */ + function cond_reglement($cond_reglement_id) { - //dolibarr_syslog("Facture::ModeReglement"); - if ($this->statut > 0 && $this->paye == 0) + dolibarr_syslog("Facture::cond_reglement($cond_reglement_id)"); + if ($this->statut >= 0 && $this->paye == 0) { $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; - $sql .= " SET fk_mode_reglement = ".$mode; + $sql .= " SET fk_cond_reglement = ".$cond_reglement_id; $sql .= " WHERE rowid=".$this->id; - if ( $this->db->query( $sql) ) + if ( $this->db->query($sql) ) { - $this->mode_reglement = $mode; - return 0; + $this->cond_reglement_id = $cond_reglement_id; + return 1; } else { - dolibarr_syslog("Facture::mode_reglement Erreur -2"); - return -2; + dolibarr_syslog("Facture::cond_reglement Erreur $sql - ".$this->db->error()); + $this->error=$this->db->error(); + return -1; } } else { - dolibarr_syslog("Facture::mode_reglement, etat facture incompatible"); - return -3; + dolibarr_syslog("Facture::cond_reglement, etat facture incompatible"); + $this->error="Etat facture incompatible $this->statut $this->paye"; + return -2; } } /** + * \brief Change le mode de réglement + * \param mode Id du nouveau mode + * \return int >0 si ok, <0 si ko + */ + function mode_reglement($mode_reglement_id) + { + dolibarr_syslog("Facture::mode_reglement($mode_reglement_id)"); + if ($this->statut >= 0 && $this->paye == 0) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; + $sql .= " SET fk_mode_reglement = ".$mode_reglement_id; + $sql .= " WHERE rowid=".$this->id; + + if ( $this->db->query($sql) ) + { + $this->mode_reglement_id = $mode_reglement_id; + return 1; + } + else + { + dolibarr_syslog("Facture::mode_reglement Erreur $sql - ".$this->db->error()); + $this->error=$this->db->error(); + return -1; + } + } + else + { + dolibarr_syslog("Facture::mode_reglement, etat facture incompatible"); + $this->error="Etat facture incompatible $this->statut $this->paye"; + return -2; + } + } + + + /** * \brief Créé une demande de prélèvement * \param user utilisateur créant la demande */ diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 77b4c82c3a0..164cbb15755 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -490,12 +490,15 @@ class Form /** - * \brief Charge dans cache la liste des conditions de paiements possibles + * \brief Charge dans cache la liste des conditions de paiements possibles + * \return int Nb lignes chargées, 0 si déjà chargées, <0 si ko */ function load_cache_conditions_paiements() { global $langs; + if (sizeof($this->cache_conditions_paiements_code)) return 0; // Cache déja chargé + dolibarr_syslog('html.form.class.php::load_cache_conditions_paiements'); $sql = "SELECT rowid, libelle"; $sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement"; @@ -525,12 +528,15 @@ class Form } /** - * \brief Charge dans cache la liste des types de paiements possibles + * \brief Charge dans cache la liste des types de paiements possibles + * \return int Nb lignes chargées, 0 si déjà chargées, <0 si ko */ function load_cache_types_paiements() { global $langs; + if (sizeof($this->cache_types_paiements_code)) return 0; // Cache déja chargé + dolibarr_syslog('html.form.class.php::load_cache_types_paiements'); $sql = "SELECT id, code, libelle, type"; $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement"; @@ -552,7 +558,7 @@ class Form $this->cache_types_paiements_type[$obj->id]=$obj->type; $i++; } - return 1; + return $num; } else { dolibarr_print_error($this->db); @@ -563,25 +569,21 @@ class Form /** - * \brief Retourne la liste des types de paiements possibles - * \param selected Type de praiement présélectionné - * \param htmlname Nom de la zone select - * \param filtertype Pour filtre + * \brief Retourne la liste des types de paiements possibles + * \param selected Id du type de paiement présélectionné + * \param htmlname Nom de la zone select + * \param filtertype Pour filtre */ function select_conditions_paiements($selected='',$htmlname='condid',$filtertype=-1) { global $langs; - // Charge le cache si premier appel - if (! sizeof($this->cache_conditions_paiements_code)) - { - $this->load_cache_conditions_paiements(); - } + $this->load_cache_conditions_paiements(); print ''; foreach($this->cache_types_paiements_code as $id => $code) { @@ -627,10 +624,9 @@ class Form if ($format == 0) print '