diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 32b826e5030..de9d92be88d 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -68,6 +68,7 @@ $NBLINES=4; /* * Actions */ + if ($_POST["action"] == 'classin') { $facture = new Facture($db); @@ -76,7 +77,7 @@ if ($_POST["action"] == 'classin') } /* - * + * Insertion facture */ if ($_POST["action"] == 'add') { @@ -132,7 +133,7 @@ if ($_POST["action"] == 'add') else { /* - * Propale + * Si creation depuis propale */ if ($_POST["propalid"]) { @@ -147,9 +148,10 @@ if ($_POST["action"] == 'add') { for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) { - // print "
DEBUG: la propale précédente en ligne " . $prop->lignes[$i]->libelle . " avait comme prix : " . $prop->lignes[$i]->price . " !
\n"; + $liblignefac=($prop->lignes[$i]->desc?$prop->lignes[$i]->desc:$prop->lignes[$i]->libelle); + $result = $facture->addline($facid, - addslashes($prop->lignes[$i]->libelle), + addslashes($liblignefac), $prop->lignes[$i]->subprice, $prop->lignes[$i]->qty, $prop->lignes[$i]->tva_tx, @@ -566,8 +568,7 @@ if ($_GET["action"] == 'create') $html->select_array("condid",$conds); print ""; - /* Mode de réglement */ - + // Mode de réglement print "Mode de réglement :"; $sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement ORDER BY libelle"; $result = $db->query($sql); @@ -588,6 +589,7 @@ if ($_GET["action"] == 'create') $html->select_array("mode_reglement",$modesregl); print ""; + // Projet if ($conf->projet->enabled) { $langs->load("projects"); @@ -702,20 +704,21 @@ if ($_GET["action"] == 'create') print "\n"; print "\n"; + // Si creation depuis un propal if ($_GET["propalid"]) { - /* - * Produits - */ print '
'; - print_titre($langs->trans("Products")); + print_titre($langs->trans("ProductsAndServices")); print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; // Lignes de propal produits prédéfinis - $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent"; + $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.tva_tx, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent, pt.description"; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt, ".MAIN_DB_PREFIX."product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = ".$_GET["propalid"]; $sql .= " ORDER BY pt.rowid ASC"; $result = $db->query($sql); @@ -728,16 +731,22 @@ if ($_GET["action"] == 'create') { $objp = $db->fetch_object($result); $var=!$var; - print "\n"; - print ''; - print ""; - print ''; - print "\n"; + print '\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; $i++; } } // Lignes de propal non produits prédéfinis - $sql = "SELECT pt.rowid, pt.description as product, pt.price, pt.qty, pt.remise_percent"; + $sql = "SELECT pt.rowid, pt.description as product, pt.tva_tx, pt.price, pt.qty, pt.remise_percent"; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt "; $sql .= " WHERE pt.fk_propal = ".$_GET["propalid"]; $sql .= " AND pt.fk_product = 0"; @@ -753,9 +762,11 @@ if ($_GET["action"] == 'create') $var=!$var; print "\n"; print ''; + print ''; print ''; - print ''; - print "\n"; + print ''; + print ''; + print ''; $i++; } } @@ -767,13 +778,10 @@ if ($_GET["action"] == 'create') print '
'.$langs->trans("Ref").''.$langs->trans("Product").''.$langs->trans("Price").''.$langs->trans("Discount").''.$langs->trans("Qty").'
'.$langs->trans("Ref").''.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").'
".img_object($langs->trans(""),"product")." ".$objp->ref."'.$objp->product.'".price($objp->price)."'.$objp->remise_percent.'%".$objp->qty."
'.img_object($langs->trans(""),"product")." ".$objp->ref.""; + print $objp->product?' - '.$objp->product:''; + print "'; + print $objp->description; + print ''.$objp->tva_tx.'%'.price($objp->price).''.$objp->qty.''.$objp->remise_percent.'%
 '.$objp->product.''.$objp->tva_tx.'%'.price($objp->price).''.$objp->remise_percent.'%".$objp->qty."
'.$objp->qty.''.$objp->remise_percent.'%
'; } - /* - * Produits dans la commande - * - */ + // Si creation depuis une commande if ($_GET["commandeid"]) { - print_titre("Produits"); + print_titre($langs->trans("Products")); print ''; print ''; @@ -1033,14 +1041,13 @@ else print "
'.$langs->trans("Ref").''.$langs->trans("Product").'

"; /* - * Lignes de factures - * - */ - $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux"; - $sql .= " , l.remise_percent, l.subprice,"; - $sql .= $db->pdate("l.date_start")." as date_start"; - $sql .= " , ".$db->pdate("l.date_end")." as date_end, "; - $sql .= " p.fk_product_type"; + * Lignes de factures + */ + $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux,"; + $sql .= " l.remise_percent, l.subprice,"; + $sql .= " ".$db->pdate("l.date_start")." as date_start,"; + $sql .= " ".$db->pdate("l.date_end")." as date_end, "; + $sql .= " p.ref, p.fk_product_type, p.label as product"; $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l "; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product p ON l.fk_product=p.rowid"; $sql .= " WHERE l.fk_facture = ".$fac->id; @@ -1051,51 +1058,69 @@ else { $num_lignes = $db->num_rows($resql); $i = 0; $total = 0; - + print ''; if ($num_lignes) { - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; print "\n"; } - $var=True; + $var=true; while ($i < $num_lignes) { $objp = $db->fetch_object($resql); $var=!$var; - + // Update ligne de facture if ($_GET["action"] != 'editline' || $_GET["rowid"] != $objp->rowid) { - - print ""; + print ''; if ($objp->fk_product > 0) { print ''; } else { - print "\n"; } - print ''; print '\n"; print ''; @@ -1108,7 +1133,7 @@ else print ''; } print '\n"; - + // Icone d'edition et suppression if ($fac->statut == 0 && $user->rights->facture->creer) { @@ -1118,7 +1143,7 @@ else print ''; - + print ''; } print ""; - + } - + // Update ligne de facture if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid) { @@ -1149,14 +1174,24 @@ else print ''; print ''; print ""; - print ''; + print ''; print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; print ''; print '' . "\n"; @@ -1172,11 +1207,11 @@ else } print "\n"; } - + $total = $total + ($objp->qty * $objp->price); $i++; } - + $db->free($resql); } else @@ -1185,18 +1220,18 @@ else } /* - * Ajouter une ligne - */ + * Ajouter une ligne + */ if ($fac->statut == 0 && $user->rights->facture->creer && $_GET["action"] <> 'valid') { print ""; print ""; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; print ''; print ''; @@ -1208,7 +1243,7 @@ else $var=!$var; print ''; - print ''; + print ''; print ''; @@ -1247,7 +1282,7 @@ else { if ($user->rights->facture->valider) { - print " id."&action=valid\">".$langs->trans("Valid")."\n"; + print " id."&action=valid\">".$langs->trans("Valid")."\n"; } } else @@ -1257,11 +1292,11 @@ else { if ($fac->paye == 0) { - print " id&action=pdf\">".$langs->trans("BuildPDF")."\n"; + print " id&action=pdf\">".$langs->trans("BuildPDF")."\n"; } else { - print " id&action=pdf\">".$langs->trans("RebuildPDF")."\n"; + print " id&action=pdf\">".$langs->trans("RebuildPDF")."\n"; } } } @@ -1269,38 +1304,38 @@ else // Supprimer if ($fac->statut == 0 && $user->rights->facture->supprimer && $_GET["action"] != 'delete') { - print "id&action=delete\">".$langs->trans("Delete").""; + print "id&action=delete\">".$langs->trans("Delete").""; } // Envoyer if ($fac->statut == 1 && $user->rights->facture->envoyer) { - print " id&action=presend\">".$langs->trans("Send")."\n"; + print " id&action=presend\">".$langs->trans("Send")."\n"; } // Envoyer une relance if ($fac->statut == 1 && price($resteapayer) > 0 && $user->rights->facture->envoyer) { - print " id&action=prerelance\">".$langs->trans("SendRemind")."\n"; + print " id&action=prerelance\">".$langs->trans("SendRemind")."\n"; } // Emettre paiement if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement) { - print " id."&action=create\">".$langs->trans("DoPaiement")."\n"; + print " id."&action=create\">".$langs->trans("DoPaiement")."\n"; } // Classer 'payé' if ($fac->statut == 1 && price($resteapayer) <= 0 && $fac->paye == 0 && $user->rights->facture->paiement) { - print " id&action=payed\">".$langs->trans("ClassifyPayed")."\n"; + print " id&action=payed\">".$langs->trans("ClassifyPayed")."\n"; } // Classer 'abandonnée' (possible si validée et pas encore classer payée) if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement) { - print " id&action=canceled\">".$langs->trans("ClassifyCanceled")."\n"; + print " id&action=canceled\">".$langs->trans("ClassifyCanceled")."\n"; } // Récurrente @@ -1308,7 +1343,7 @@ else { if ($fac->statut > 0) { - print " id."&action=create\">Récurrente\n"; + print " id."&action=create\">Récurrente\n"; } }
'.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").''.$langs->trans("AmountHT").'
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('Discount').''.$langs->trans('AmountHT').' 
'; - if ($objp->fk_product_type) print img_object($langs->trans("ShowService"),"service"); - else print img_object($langs->trans("ShowProduct"),"product"); - print ' '.stripslashes(nl2br($objp->description)).''; - if ($objp->date_start && $objp->date_end) { print " (Du ".dolibarr_print_date($objp->date_start)." au ".dolibarr_print_date($objp->date_end).")"; } - if ($objp->date_start && ! $objp->date_end) { print " (A partir du ".dolibarr_print_date($objp->date_start).")"; } - if (! $objp->date_start && $objp->date_end) { print " (Jusqu'au ".dolibarr_print_date($objp->date_end).")"; } + if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); + else print img_object($langs->trans('ShowProduct'),'product'); + print ' '.$objp->ref.''; + print ' - '.nl2br($objp->product); + if ($objp->date_start && $objp->date_end) + { + print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')'; + } + if ($objp->date_start && ! $objp->date_end) + { + print ' (A partir du '.dolibarr_print_date($objp->date_start).')'; + } + if (! $objp->date_start && $objp->date_end) + { + print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')'; + } + print ($objp->description&&$objp->description!=$objp->product)?'
'.$objp->description:''; print '
".stripslashes(nl2br($objp->description)); - if ($objp->date_start && $objp->date_end) { print " (Du ".dolibarr_print_date($objp->date_start)." au ".dolibarr_print_date($objp->date_end).")"; } - if ($objp->date_start && ! $objp->date_end) { print " (A partir du ".dolibarr_print_date($objp->date_start).")"; } - if (! $objp->date_start && $objp->date_end) { print " (Jusqu'au ".dolibarr_print_date($objp->date_end).")"; } + print ''.stripslashes(nl2br($objp->description)); + if ($objp->date_start && $objp->date_end) + { + print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')'; + } + if ($objp->date_start && ! $objp->date_end) + { + print ' (A partir du '.dolibarr_print_date($objp->date_start).')'; + } + if (! $objp->date_start && $objp->date_end) + { + print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')'; + } print "'.$objp->tva_taux.'%'.price($objp->subprice)."'.$objp->qty.' '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."'; print img_delete(); print ''; if ($i > 0) { @@ -1138,9 +1163,9 @@ else print ' 
'; + if ($objp->fk_product > 0) + { + print ''; + if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); + else print img_object($langs->trans('ShowProduct'),'product'); + print ' '.$objp->ref.''; + print ' - '.stripslashes(nl2br($objp->product)); + print '
'; + } + print '
'; //print $html->select_tva("tva_tx",$objp->tva_taux); print $objp->tva_taux."%"; // Taux tva dépend du produit, donc on ne doit pas pouvoir le changer ici print '%%'; print '
'.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").''.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").'   
'; print $html->select_tva("tva_tx",$conf->defaulttx); print '