diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 6b803372b5b..0c738696e4d 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -23,10 +23,10 @@ */ /** - \file htdocs/fourn/facture/fiche.php - \ingroup facture - \brief Page des la fiche facture fournisseur - \version $Revision$ + \file htdocs/fourn/facture/fiche.php + \ingroup facture + \brief Page des la fiche facture fournisseur + \version $Revision$ */ require("./pre.inc.php"); @@ -39,9 +39,7 @@ $langs->load("bills"); $langs->load("suppliers"); $langs->load("companies"); -/* - * Sécurité accés client - */ +// Sécurité accés client if ($user->societe_id > 0) { $action = ''; @@ -222,469 +220,471 @@ if ($_GET["action"] == 'add_ligne') if ($_GET["action"] == 'create' or $_GET["action"] == 'copy') { - llxHeader(); - - print_titre($langs->trans("NewBill")); + llxHeader(); - if ($mesg) { print "$mesg
"; } + print_titre($langs->trans("NewBill")); - if ($_GET["action"] == 'copy') + if ($mesg) { print "$mesg
"; } + + if ($_GET["action"] == 'copy') { - $fac_ori = new FactureFournisseur($db); - $fac_ori->fetch($_GET["facid"]); - } - - print '
'; - print ''; - print ''; - print ''; - - print '
'.$langs->trans("Company").''; + print ''; + print ''; - $sql .= " ORDER BY s.nom ASC"; + print ''; - print ''; + $sql .= " ORDER BY s.nom ASC"; - print ''; - - print ''; - if ($_GET["action"] == 'copy') + if ( $db->query($sql) ) { - print ''; + $num = $db->num_rows(); + $i = 0; + while ($i < $num) + { + $obj = $db->fetch_object(); + print ''; + } + else + { + print '">'.$obj->nom.''; + } + $i++; + } } - else + print ''; + print ''; + + print ''; + + print ''; + if ($_GET["action"] == 'copy') { - print ''; + print ''; } - print ''; - - print ''; - - print "
'.$langs->trans("Company").''.$langs->trans("Comments").'
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
'.$langs->trans("Comments").'
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
'.$langs->trans("Label").'
'.$langs->trans("Date").''; - $html->select_date(); - print '
'.$langs->trans("DateEcheance").''; - $html->select_date('','ech'); - print '

"; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - for ($i = 1 ; $i < 9 ; $i++) + else { - if ($_GET["action"] == 'copy') - { - $value_label = $fac_ori->lignes[$i-1][0]; - $value_pu = $fac_ori->lignes[$i-1][1]; - $value_qty = $fac_ori->lignes[$i-1][3]; - } - else - { - $value_qty = "1"; - } - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + } + print ''; + + print ''; + + print "
 '.$langs->trans("Label").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("VATRate").''.$langs->trans("PriceUTTC").'
'.$i.''; - $html->select_tva("tauxtva".$i); - print '
'.$langs->trans("Label").'
'.$langs->trans("Date").''; + $html->select_date(); + print '
'.$langs->trans("DateEcheance").''; + $html->select_date('','ech'); + print '

"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + for ($i = 1 ; $i < 9 ; $i++) + { + if ($_GET["action"] == 'copy') + { + $value_label = $fac_ori->lignes[$i-1][0]; + $value_pu = $fac_ori->lignes[$i-1][1]; + $value_qty = $fac_ori->lignes[$i-1][3]; + } + else + { + $value_qty = "1"; + } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; } - print "
 '.$langs->trans("Label").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("VATRate").''.$langs->trans("PriceUTTC").'
'.$i.''; + $html->select_tva("tauxtva".$i); + print '
"; - print '

'; - print ""; - + print "
"; + print '

'; + print ""; + } else { - /* - * Fiche facture en mode visu ou edition - * - */ - if ($_GET["facid"] > 0) + /* + * Fiche facture en mode visu ou edition + * + */ + if ($_GET["facid"] > 0) { - $fac = new FactureFournisseur($db); - $fac->fetch($_GET["facid"]); + $fac = new FactureFournisseur($db); + $fac->fetch($_GET["facid"]); - $societe = new Fournisseur($db); + $societe = new Fournisseur($db); - if ( $societe->fetch($fac->socidp) ) - { - $addons[0][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$fac->socidp; - $addons[0][1] = $societe->nom; - } - llxHeader('','', $addons); + if ( $societe->fetch($fac->socidp) ) + { + $addons[0][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$fac->socidp; + $addons[0][1] = $societe->nom; + } + llxHeader('','', $addons); - if ($mesg) { print "
$mesg
"; } + if ($mesg) { print "
$mesg
"; } - if ($_GET["action"] == "edit") - { + if ($_GET["action"] == "edit") + { - print_titre($langs->trans("Bill").': '.$fac->ref); - - print '
'; - print ''; - - print ''; - print ''; - - print ''; - print ''; - - print ''; - - print ''; - - print ''; + print_titre($langs->trans("Bill").': '.$fac->ref); - print ''; - print ''; + print ''; + print ''; - print '"; - - print '"; + print '
'.$langs->trans("Company").''.stripslashes($fac->socnom).''.$langs->trans("Comments").'
'.$langs->trans("Ref").''; - print ''; - print '
'.$langs->trans("Label").''; - print '
'.$langs->trans("AmountHT").' / '.$langs->trans("AmountTTC").''.price($fac->total_ht).' / '.price($fac->total_ttc).'
'.$langs->trans("Date").''; - $html->select_date($fac->datep); - print "
'.$langs->trans("Date").''; - $html->select_date($fac->date_echeance,'ech'); - print "
'; + print ''; - $authorfullname=" "; - if ($fac->author) - { - $author = new User($db, $fac->author); - $author->fetch(''); - $authorfullname=$author->fullname; - } - print ""; - print '"; - print ""; - print "
'.$langs->trans("Company").'
".$langs->trans("Author")."$authorfullname
'.$langs->trans("Status").''.$fac->LibStatut($fac->paye,$fac->statut)."
trans("Save")."\">
"; - print "
"; - - /* - * Lignes - * - */ - print '
'; - - print "
id&action=add_ligne\" method=\"post\">"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) - { - print "".'"; - print '"; - print '"; - print '"; - print '"; - print '"; - print '"; - print '"; - print ''; - print ''; - } - - /* Nouvelle ligne */ - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "
'.$langs->trans("Label").''.$langs->trans("PriceUHT").''.$langs->trans("PriceUTTC").''.$langs->trans("Qty").''.$langs->trans("TotalHT").''.$langs->trans("VATRate").''.$langs->trans("VAT").''.$langs->trans("TotalTTC").' 
'.$fac->lignes[$i][0]."'.price($fac->lignes[$i][1])."'.price($fac->lignes[$i][1] * (1+($fac->lignes[$i][2]/100)))."'.$fac->lignes[$i][3]."'.price($fac->lignes[$i][4])."'.$fac->lignes[$i][2]."'.price($fac->lignes[$i][5])."'.price($fac->lignes[$i][6])."'; - print ''.img_delete().'
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '-'; - $html->select_tva("tauxtva"); - print ''; - print ' '; - print '
"; - print "
"; - } - else - { - /* - * - */ - $h=0; - - $head[$h][0] = "fiche.php?facid=".$fac->id; - $head[$h][1] = $langs->trans("SupplierBill").': '.$fac->ref; - $hselected = $h; - $h++; - - dolibarr_fiche_head($head, $hselected); + print ''.stripslashes($fac->socnom).''; + print ''.$langs->trans("Comments").''; + + print ''.$langs->trans("Ref").''; + print ''; + + print ''; + print ''; + + print ''.$langs->trans("Label").''; + print ''; + + print ''.$langs->trans("AmountHT").' / '.$langs->trans("AmountTTC").''; + print ''.price($fac->total_ht).' / '.price($fac->total_ttc).''; + + print ''.$langs->trans("Date").''; + $html->select_date($fac->datep); + print ""; + + print ''.$langs->trans("Date").''; + $html->select_date($fac->date_echeance,'ech'); + print ""; + + $authorfullname=" "; + if ($fac->author) + { + $author = new User($db, $fac->author); + $author->fetch(''); + $authorfullname=$author->fullname; + } + print "".$langs->trans("Author")."$authorfullname"; + print ''.$langs->trans("Status").''.$fac->LibStatut($fac->paye,$fac->statut).""; + print "trans("Save")."\">"; + print ""; + print ""; + + /* + * Lignes + * + */ + print '
'; + + print "
id&action=add_ligne\" method=\"post\">"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) + { + print "".'"; + print '"; + print '"; + print '"; + print '"; + print '"; + print '"; + print '"; + print ''; + print ''; + } + + /* Nouvelle ligne */ + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "
'.$langs->trans("Label").''.$langs->trans("PriceUHT").''.$langs->trans("PriceUTTC").''.$langs->trans("Qty").''.$langs->trans("TotalHT").''.$langs->trans("VATRate").''.$langs->trans("VAT").''.$langs->trans("TotalTTC").' 
'.$fac->lignes[$i][0]."'.price($fac->lignes[$i][1])."'.price($fac->lignes[$i][1] * (1+($fac->lignes[$i][2]/100)))."'.$fac->lignes[$i][3]."'.price($fac->lignes[$i][4])."'.$fac->lignes[$i][2]."'.price($fac->lignes[$i][5])."'.price($fac->lignes[$i][6])."'; + print ''.img_delete().'
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '-'; + $html->select_tva("tauxtva"); + print ''; + print ' '; + print '
"; + print "
"; + } + else + { + /* + * + */ + $h=0; + + $head[$h][0] = "fiche.php?facid=".$fac->id; + $head[$h][1] = $langs->trans("SupplierBill").': '.$fac->ref; + $hselected = $h; + $h++; + + dolibarr_fiche_head($head, $hselected); - /* - * Confirmation de la validation - * - */ - if ($_GET["action"] == 'valid') - { - $html->form_confirm("fiche.php?facid=$fac->id",$langs->trans("ValidateBill"),$langs->trans("ConfirmValidateBill"),"confirm_valid"); - print '
'; - } - - print ""; - print '"; - print "
'; + /* + * Confirmation de la validation + * + */ + if ($_GET["action"] == 'valid') + { + $html->form_confirm("fiche.php?facid=$fac->id",$langs->trans("ValidateBill"),$langs->trans("ConfirmValidateBill"),"confirm_valid"); + print '
'; + } - /* - * Facture - */ - print ''; - print ""; - print "\n"; - print ""; + print "
".$langs->trans("Company")."socidp\">$fac->socnomsocidp\">".$langs->trans("OtherBills")."
"; + print '\n"; - print ''; - print ''; - - $authorfullname=" "; - if ($fac->author) - { - $author = new User($db, $fac->author); - $author->fetch(''); - $authorfullname=$author->fullname; - } - print ""; - print '"; - - print '"; - print '"; - print '"; - if (strlen($fac->note)) - { - print ''; - } - print "
'; - print '
'.$langs->trans("Date").""; - print dolibarr_print_date($fac->datep,"%A %e %B %Y")."
'.$langs->trans("Label").''; - print $fac->libelle; - print '
".$langs->trans("Author")."$authorfullname
'.$langs->trans("Status").''.$fac->LibStatut($fac->paye,$fac->statut)."
'.$langs->trans("TotalHT").''.price($fac->total_ht)."'.$langs->trans("VAT").''.price($fac->total_tva)."
'.$langs->trans("TotalTTC").''.price($fac->total_ttc)."
'.$langs->trans("Comments").''; - print nl2br(stripslashes($fac->note)); - print '
"; - - print "
"; - + /* + * Facture + */ + print ''; + print ""; + print "\n"; + print ""; - /* - * Paiements - */ + print '\n"; + print ''; + print ''; - print '
".$langs->trans("Company")."socidp\">$fac->socnomsocidp\">".$langs->trans("OtherBills")."
'.$langs->trans("Date").""; + print dolibarr_print_date($fac->datep,"%A %d %B %Y")."
'.$langs->trans("Label").''; + print $fac->libelle; + print '
'; - print '"; + print '"; - $sql = "SELECT ".$db->pdate("datep")." as dp, p.amount, c.libelle as paiement_type, p.num_paiement, p.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p, ".MAIN_DB_PREFIX."c_paiement as c "; - $sql .= " WHERE p.fk_facture_fourn = ".$fac->id." AND p.fk_paiement = c.id"; + print '"; + print '"; + print '"; + if (strlen($fac->note)) + { + print ''; + } + print "
'; + $authorfullname=" "; + if ($fac->author) + { + $author = new User($db, $fac->author); + $author->fetch(''); + $authorfullname=$author->fullname; + } + print "
".$langs->trans("Author")."$authorfullname
'.$langs->trans("Status").''.$fac->LibStatut($fac->paye,$fac->statut)."
'.$langs->trans("TotalHT").''.price($fac->total_ht)."'.$langs->trans("VAT").''.price($fac->total_tva)."
'.$langs->trans("TotalTTC").''.price($fac->total_ttc)."
'.$langs->trans("Comments").''; + print nl2br(stripslashes($fac->note)); + print '
"; - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; $total = 0; - - print ''; - print ''; - print '\n"; - print ""; - print ''; - print ''; - - if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) - { - $tdsup=' colspan="2"'; - } - print " "; - print "\n"; - - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print ""; - print "\n"; - print "\n"; - print "\n"; - - if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) - { - print ''; - } - - print ""; - $total = $total + $objp->amount; - $i++; - } - print "".$langs->trans("Currency".$conf->monnaie)."\n"; - - - if ($fac->statut > 0) - { - $resteapayer = abs($fac->total_ttc - $total); - print ""; - print '".$langs->trans("Currency".$conf->monnaie).""; - print "\n"; - } - - print "
'.$langs->trans("Payments").' :'.$langs->trans("DateEcheance")." : "; - print dolibarr_print_date($fac->date_echeance,"%A %e %B %Y")."
'.$langs->trans("Date").''.$langs->trans("Type").'".$langs->trans("AmountTTC")."
".img_object($langs->trans("Payment"),"payment").' '.dolibarr_print_date($objp->dp)."$objp->paiement_type $objp->num_paiement".price($objp->amount)."".$langs->trans("Currency".$conf->monnaie)."'; - print ''; - print img_delete(); - print '
".$langs->trans("Total")." :".price($total)."
".$langs->trans("RemainderToPay")." :'.price($resteapayer)."
"; - $db->free(); - } - else - { - dolibarr_print_error($db); - } - print "
"; - + print ""; - print ""; - print ""; + /* + * Liste des paiements + */ + + print ''; + + print ''; + print '\n"; + + print ''; + + $sql = "SELECT ".$db->pdate("datep")." as dp, p.amount, c.libelle as paiement_type, p.num_paiement, p.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p, ".MAIN_DB_PREFIX."c_paiement as c "; + $sql .= " WHERE p.fk_facture_fourn = ".$fac->id." AND p.fk_paiement = c.id"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; $total = 0; + + print '
'.$langs->trans("DateEcheance").''; + print dolibarr_print_date($fac->date_echeance,"%A %d %B %Y")."
'.$langs->trans("Payments").'
'; + print ''; + + print ""; + print ''; + print ''; + + if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) + { + $tdsup=' colspan="2"'; + } + print " "; + print "\n"; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print ""; + print "\n"; + print "\n"; + print "\n"; + + if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) + { + print ''; + } + + print ""; + $total = $total + $objp->amount; + $i++; + } + print "".$langs->trans("Currency".$conf->monnaie)."\n"; - /* - * Lignes - * - */ - print '

'.$langs->trans("Date").''.$langs->trans("Type").'".$langs->trans("AmountTTC")."
".img_object($langs->trans("Payment"),"payment").' '.dolibarr_print_date($objp->dp)."$objp->paiement_type $objp->num_paiement".price($objp->amount)."".$langs->trans("Currency".$conf->monnaie)."'; + print ''; + print img_delete(); + print '
".$langs->trans("Total")." :".price($total)."
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $var=1; - for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) - { - $var=!$var; - print "".'"; - print '"; - print '"; - print '"; - print '"; - print '"; - print '"; + if ($fac->statut > 0) + { + $resteapayer = abs($fac->total_ttc - $total); + print ""; + print '".$langs->trans("Currency".$conf->monnaie).""; + print "\n"; + } - print ''; - } - print "
'.$langs->trans("Label").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("TotalHT").''.$langs->trans("VATRate").''.$langs->trans("VAT").''.$langs->trans("TotalTTC").'
'.$fac->lignes[$i][0]."'.price($fac->lignes[$i][1])."'.$fac->lignes[$i][3]."'.price($fac->lignes[$i][4])."'.$fac->lignes[$i][2]." %'.price($fac->lignes[$i][5])."'.price($fac->lignes[$i][6])."
".$langs->trans("RemainderToPay")." :'.price($resteapayer)."
"; - - print "\n"; - } + print "
"; + $db->free(); + } + else + { + dolibarr_print_error($db); + } + print ""; + print ""; - /* - * Boutons actions - */ - print "
\n"; - - if ($fac->statut == 0 && $user->societe_id == 0) - { - if ($_GET["action"] == "edit") - { - print ''.$langs->trans("Cancel").''; - } - else - { - print ''.$langs->trans('Edit').''; - } - } - - if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) - { - print ''.$langs->trans("DoPaiement").''; - } - - if ($fac->statut == 1 && price($resteapayer) <= 0 && $fac->paye == 0 && $user->societe_id == 0) - { - print "id&action=payed\">".$langs->trans('ClassifyPayed').""; - } - - if ($fac->statut == 0 && $user->rights->fournisseur->facture->valider) - { - if ($_GET["action"] <> "edit") - print "id&action=valid\">".$langs->trans('Valid').""; - } - else + print ""; + print ""; + + + /* + * Lignes + * + */ + print '

'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $var=1; + for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) + { + $var=!$var; + print "".'"; + print '"; + print '"; + print '"; + print '"; + print '"; + print '"; + + print ''; + } + print "
'.$langs->trans("Label").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("TotalHT").''.$langs->trans("VATRate").''.$langs->trans("VAT").''.$langs->trans("TotalTTC").'
'.$fac->lignes[$i][0]."'.price($fac->lignes[$i][1])."'.$fac->lignes[$i][3]."'.price($fac->lignes[$i][4])."'.$fac->lignes[$i][2]." %'.price($fac->lignes[$i][5])."'.price($fac->lignes[$i][6])."
"; + + print "

\n"; + } + + + /* + * Boutons actions + */ + + print "
\n"; + + if ($fac->statut == 0 && $user->societe_id == 0) + { + if ($_GET["action"] == "edit") + { + print ''.$langs->trans("Cancel").''; + } + else + { + print ''.$langs->trans('Edit').''; + } + } + + if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) + { + print ''.$langs->trans("DoPaiement").''; + } + + if ($fac->statut == 1 && price($resteapayer) <= 0 && $fac->paye == 0 && $user->societe_id == 0) + { + print "id&action=payed\">".$langs->trans('ClassifyPayed').""; + } + + if ($fac->statut == 0 && $user->rights->fournisseur->facture->valider) + { + if ($_GET["action"] <> "edit") + print "id&action=valid\">".$langs->trans('Valid').""; + } + else + + if ($user->rights->fournisseur->facture->creer) + { + print "id&action=copy&socid=$fac->socidp\">".$langs->trans('Copy').""; + } + + if ($_GET["action"] != "edit" && $fac->statut == 0 && $user->rights->fournisseur->facture->creer) + { + print ''.$langs->trans("Delete").''; + } + + print "
"; - if ($user->rights->fournisseur->facture->creer) - { - print "id&action=copy&socid=$fac->socidp\">".$langs->trans('Copy').""; - } - - if ($_GET["action"] != "edit" && $fac->statut == 0 && $user->rights->fournisseur->facture->creer) - { - print ''.$langs->trans("Delete").''; - } - - print ""; - } }