diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index a2786da6d82..b29f09b503a 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -22,10 +22,10 @@ */ /** - \file htdocs/compta/facture.php - \ingroup facture - \brief Page de création/visu facture - \version $Id$ + * \file htdocs/compta/facture.php + * \ingroup facture + * \brief Page de création/visu facture + * \version $Id$ */ require('./pre.inc.php'); @@ -124,7 +124,7 @@ if (($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'ye $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } - + $result=facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); if ($result > 0) { @@ -449,7 +449,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $error=1; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'
'; } - + if (! ($_POST['fac_replacement'] > 0)) { $error=1; @@ -496,9 +496,9 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $error=1; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'
'; } - + if (! $error) - { + { // Si facture avoir $datefacture = dolibarr_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); @@ -554,9 +554,9 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $error=1; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'
'; } - + if (! $error) - { + { // Si facture standard $facture->socid = $_POST['socid']; @@ -573,7 +573,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $facture->amount = $_POST['amount']; $facture->remise_absolue = $_POST['remise_absolue']; $facture->remise_percent = $_POST['remise_percent']; - + if (! $_POST['propalid'] && ! $_POST['commandeid'] && ! $_POST['contratid']) { for ($i = 1; $i <= $NBLINES; $i++) @@ -591,7 +591,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $facture->add_product($_POST['idprod'.$i],$_POST['qty'.$i],$_POST['remise_percent'.$i],$startday,$endday); } } - + $facid = $facture->create($user); } else @@ -603,7 +603,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) { $facture->propalid = $_POST['propalid']; $facid = $facture->create($user); - + if ($facid > 0) { $prop = New Propal($db); @@ -612,7 +612,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) { $desc=($prop->lignes[$i]->desc?$prop->lignes[$i]->desc:$prop->lignes[$i]->libelle); - + $result = $facture->addline( $facid, $desc, @@ -627,7 +627,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $prop->lignes[$i]->info_bits, $prop->lignes[$i]->fk_remise_except ); - + if ($result < 0) { $error++; @@ -645,7 +645,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $error++; } } - + /* * Si création depuis commande */ @@ -653,7 +653,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) { $facture->commandeid = $_POST['commandeid']; $facid = $facture->create($user); - + if ($facid > 0) { $comm = New Commande($db); @@ -664,7 +664,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) for ($i = 0 ; $i < sizeof($lines) ; $i++) { $desc=($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle); - + $result = $facture->addline( $facid, $desc, @@ -679,7 +679,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $lines[$i]->info_bits, $lines[$i]->fk_remise_except ); - + if ($result < 0) { $error++; @@ -697,7 +697,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $error++; } } - + /* * Si création depuis contrat */ @@ -705,24 +705,24 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) { $facture->contratid = $_POST['contratid']; $facid = $facture->create($user); - + if ($facid > 0) { $contrat = New Contrat($db); if ($contrat->fetch($_POST['contratid']) > 0) { $lines = $contrat->fetch_lignes(); - + for ($i = 0 ; $i < sizeof($lines) ; $i++) { $desc=($contrat->lignes[$i]->desc?$contrat->lignes[$i]->desc:$contrat->lignes[$i]->libelle); - + // Plage de dates $date_start=$contrat->lignes[$i]->date_debut_prevue; if ($contrat->lignes[$i]->date_debut_reel) $date_start=$contrat->lignes[$i]->date_debut_reel; $date_end=$contrat->lignes[$i]->date_fin_prevue; if ($contrat->lignes[$i]->date_fin_reel) $date_end=$contrat->lignes[$i]->date_fin_reel; - + $result = $facture->addline( $facid, $desc, @@ -737,7 +737,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $lines[$i]->info_bits, $lines[$i]->fk_remise_except ); - + if ($result < 0) { $error++; @@ -833,7 +833,7 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && $tva_tx = get_default_tva($mysoc,$fac->client,$prod->tva_tx); $tva_npr = get_default_npr($mysoc,$fac->client,$prod->tva_tx); - + // On defini prix unitaire if ($conf->global->PRODUIT_MULTIPRICES == 1) { @@ -861,7 +861,7 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); } } - + $desc = $prod->description; $desc.= $prod->description && $_POST['np_desc'] ? "\n" : ""; $desc.= $_POST['np_desc']; @@ -1050,7 +1050,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['a if (is_readable($file)) { $fac->fetch_client(); - + if ($_POST['sendto']) { // Le destinataire a été fourni via le champ libre @@ -1115,10 +1115,10 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['a $formmail = new FormMail($db); $attachedfiles=$formmail->get_attached_files(); - $filepath = $attachedfiles['paths']; - $filename = $attachedfiles['names']; - $mimetype = $attachedfiles['mimes']; - + $filepath = $attachedfiles['paths']; + $filename = $attachedfiles['names']; + $mimetype = $attachedfiles['mimes']; + // Send mail require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php'); $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt); @@ -1301,7 +1301,7 @@ if ($_GET['action'] == 'create') $mode_reglement_id = $soc->mod_reglement; $remise_percent = $soc->remise_client; $remise_absolue = 0; - $dateinvoice=$contrat->date_contrat; + $dateinvoice=empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; } else { @@ -1524,7 +1524,7 @@ if ($_GET['action'] == 'create') //print ''."\n"; //print ''."\n"; print ''; - + print ''.$langs->trans('Proposal').''.img_object($langs->trans("ShowPropal"),'propal').' '.$propal->ref.''; print ''.$langs->trans('TotalHT').''.price($propal->price).''; print ''.$langs->trans('TotalVAT').''.price($propal->total_tva).""; @@ -1538,7 +1538,7 @@ if ($_GET['action'] == 'create') //print ''."\n"; //print ''."\n"; print ''; - + print ''.$langs->trans('Order').''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.''; print ''.$langs->trans('TotalHT').''.price($commande->total_ht).''; print ''.$langs->trans('TotalVAT').''.price($commande->total_tva).""; @@ -1805,7 +1805,7 @@ else if ($user->societe_id>0 && $user->societe_id!=$fac->socid) accessforbidden('',0); $result=$fac->fetch_client(); - + $soc = new Societe($db, $fac->socid); $soc->fetch($fac->socid); @@ -1817,21 +1817,21 @@ else $resteapayer = $fac->total_ttc - $totalpaye - $totalavoir; if ($fac->paye) $resteapayer=0; $resteapayeraffiche=$resteapayer; - + $author = new User($db); if ($fac->user_author) { $author->id = $fac->user_author; $author->fetch(); } - + $facidnext=$fac->getIdReplacingInvoice(); - - + + $head = facture_prepare_head($fac); - + dolibarr_fiche_head($head, 'compta', $langs->trans('InvoiceCustomer')); - + /* * Confirmation de la conversion de l'avoir en reduc */ @@ -1841,7 +1841,7 @@ else $html->form_confirm($_SERVER['PHP_SELF'].'?facid='.$fac->id,$langs->trans('ConvertToReduc'),$text,'confirm_converttoreduc'); print '
'; } - + /* * Confirmation de la suppression de la facture */ @@ -1851,7 +1851,7 @@ else $html->form_confirm($_SERVER['PHP_SELF'].'?facid='.$fac->id,$langs->trans('DeleteBill'),$text,'confirm_delete'); print '
'; } - + /* * Confirmation de la validation */ @@ -1880,7 +1880,7 @@ else $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ValidateBill'),$text,'confirm_valid'); print '
'; } - + /* * Confirmation du classement payé */ @@ -1925,7 +1925,7 @@ else $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ClassifyPayed'),$langs->trans('ConfirmClassifyPayedPartially',$fac->ref),'confirm_payed_partially',$formquestion); print '
'; } - + /* * Confirmation du classement abandonne */ @@ -1969,7 +1969,7 @@ else print '
'; } } - + /* * Confirmation de la suppression d'une ligne produit */ @@ -1978,13 +1978,13 @@ else $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id.'&rowid='.$_GET["rowid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline'); print '
'; } - + /* * Facture */ - + print ''; - + // Reference print ''; print ''; - + // Ref client /* - \todo - L'info "Reference commande client" est une carac de la commande et non de la facture. - Elle devrait donc etre stockée sur l'objet commande lié à la facture et non sur la facture. - Pour ceux qui utilisent ainsi, positionner la constante FAC_USE_CUSTOMER_ORDER_REF à 1. - */ + \todo + L'info "Reference commande client" est une carac de la commande et non de la facture. + Elle devrait donc etre stockée sur l'objet commande lié à la facture et non sur la facture. + Pour ceux qui utilisent ainsi, positionner la constante FAC_USE_CUSTOMER_ORDER_REF à 1. + */ if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) { print ''; print ''; } - + // Tiers Société print ''; print ''; print ''; - + // Type 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++; - + print ''; $i++; } - + // Already payed print ''; @@ -2199,7 +2199,7 @@ else { dolibarr_print_error($db); } - + // Payé partiellement 'escompte' if (($fac->statut == 2 || $fac->statut == 3) && $fac->close_code == 'discount_vat') { @@ -2254,9 +2254,9 @@ else { dolibarr_print_error($db); } - + print ''; - + // Date limite reglement print ''; print ''; @@ -2271,7 +2271,7 @@ else print ' '; } print ''; - + // Conditions de règlement print '
'.$langs->trans('Ref').''.$fac->ref; @@ -1999,14 +1999,14 @@ else dolibarr_print_error('',$discount->error); } print '
'; @@ -2031,12 +2031,12 @@ else print '
'.$langs->trans('Company').''.$soc->getNomUrl(1,'compta').'
'.$langs->trans('Type').''; print $fac->getLibType(); @@ -2074,7 +2074,7 @@ else print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')'; } print '
'.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); @@ -2111,17 +2111,17 @@ else } if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; print '
'.$langs->trans('Date').''.dolibarr_print_date($fac->date,'daytext').''; - + /* * Liste des paiements */ @@ -2162,7 +2162,7 @@ else print '
'.$langs->trans('AlreadyPayed').' :'.price($totalpaye).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('DateMaxPayment').'
'; print ''; - + // Lit lignes de facture pour déterminer montant // On s'en sert pas mais ca sert pour debuggage /* - $sql = 'SELECT l.price as price, l.qty, l.rowid, l.tva_taux,'; - $sql .= ' l.remise_percent, l.subprice'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet as l '; - $sql .= ' WHERE l.fk_facture = '.$fac->id; - $resql = $db->query($sql); - if ($resql) - { - $num_lignes = $db->num_rows($resql); - $i=0; - $total_lignes_ht=0; - $total_lignes_vat=0; - $total_lignes_ttc=0; - while ($i < $num_lignes) - { - $obj=$db->fetch_object($resql); - $ligne_ht=($obj->price*$obj->qty); - $ligne_vat=($ligne_ht*$obj->tva_taux/100); - $ligne_ttc=($ligne_ht+$ligne_vat); - $total_lignes_ht+=$ligne_ht; - $total_lignes_vat+=$ligne_vat; - $total_lignes_ttc+=$ligne_ttc; - $i++; - } - } - */ - + $sql = 'SELECT l.price as price, l.qty, l.rowid, l.tva_taux,'; + $sql .= ' l.remise_percent, l.subprice'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet as l '; + $sql .= ' WHERE l.fk_facture = '.$fac->id; + $resql = $db->query($sql); + if ($resql) + { + $num_lignes = $db->num_rows($resql); + $i=0; + $total_lignes_ht=0; + $total_lignes_vat=0; + $total_lignes_ttc=0; + while ($i < $num_lignes) + { + $obj=$db->fetch_object($resql); + $ligne_ht=($obj->price*$obj->qty); + $ligne_vat=($ligne_ht*$obj->tva_taux/100); + $ligne_ttc=($ligne_ht+$ligne_vat); + $total_lignes_ht+=$ligne_ht; + $total_lignes_vat+=$ligne_vat; + $total_lignes_ttc+=$ligne_ttc; + $i++; + } + } + */ + // Montants print ''; print ''; @@ -2352,11 +2352,11 @@ else print ''; print ''; print ''; - + // Statut print ''; print ''; - + // Projet if ($conf->projet->enabled) { @@ -2443,7 +2443,7 @@ else { print ''; print ''; print ''; - + print ''; print ''; print ''; @@ -2735,9 +2735,9 @@ else { $html->select_produits('','idprod','',$conf->produit->limit_size); } - + if (! $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) print '
'; - + // éditeur wysiwyg if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) { @@ -2805,8 +2805,8 @@ else // Reopen a classified invoice if ($fac->statut == 3 && // A abandonned invoice - $fac->getIdReplacingInvoice() == 0 && // Not replaced by another invoice - ($fac->close_code == 'badcustomer' || $fac->close_code == 'abandon')) + $fac->getIdReplacingInvoice() == 0 && // Not replaced by another invoice + ($fac->close_code == 'badcustomer' || $fac->close_code == 'abandon')) { if (! $facidnext) { @@ -2817,7 +2817,7 @@ else print ''.$langs->trans('ReOpen').''; } } - + // Récurrente if (! $conf->global->FACTURE_DISABLE_RECUR && $fac->type == 0) { @@ -2846,7 +2846,7 @@ else $num = $fac->ref; } $url = $_SERVER["PHP_SELF"].'?facid='.$fac->id.'&action=confirm_valid&confirm=yes'; - print 'href="#" onClick="dialogConfirm(\''.$url.'\',\''.dol_escape_js($langs->trans('ConfirmValidateBill',$num)).'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'validate\')"'; + print 'href="#" onClick="dialogConfirm(\''.$url.'\',\''.dol_escape_js($langs->trans('ConfirmValidateBill',$num)).'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'validate\')"'; } else { @@ -2855,7 +2855,7 @@ else print '>'.$langs->trans('Validate').''; } } - + // Envoyer if (($fac->statut == 1 || $fac->statut == 2) && $user->rights->facture->envoyer) { @@ -2961,8 +2961,8 @@ else print ''; } } - - + + if ($_GET['action'] != 'prerelance' && $_GET['action'] != 'presend') { print '
'; @@ -2314,36 +2314,36 @@ else $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).'
'.$langs->trans('Status').''.($fac->getLibStatut(4,$totalpaye)).'
'; print ''; // ancre pour retourner sur la ligne - + // Affiche ligne produit $text = ''; if ($objp->fk_product_type==1) $text.= img_object($langs->trans('ShowService'),'service'); @@ -2465,7 +2465,7 @@ else { print ''; print ''; // ancre pour retourner sur la ligne - + if (($objp->info_bits & 2) == 2) { print ''; @@ -2718,7 +2718,7 @@ else print ''.$langs->trans('ReductionShort').' 
'; + //print ''; print ''; // Lignes des champs de filtre @@ -3367,13 +3367,13 @@ else print ''; + print ''; + //print ' '.$langs->trans('Year').': '; + $max_year = date("Y"); + $syear = $year; + //if ($syear == '') $syear = date("Y"); + $html->select_year($syear,'year',1, '', $max_year); + print ''; print ''; - print ''; + print ''; print '\n"; @@ -3400,11 +3400,11 @@ else print ''; print '
'; @@ -3050,7 +3050,7 @@ else if ($num) { $langs->load("orders"); - + $i = 0; $total = 0; if ($somethingshown) print '
'; $somethingshown=1; @@ -3304,13 +3304,13 @@ else { $sql .= ' AND f.total_ttc = \''.addslashes(trim($_GET['search_montant_ttc'])).'\''; } - if ($month > 0) - { - if ($year > 0) - $sql .= " AND date_format(f.datef, '%Y-%m') = '$year-$month'"; - else - $sql .= " AND date_format(f.datef, '%m') = '$month'"; - } + if ($month > 0) + { + if ($year > 0) + $sql .= " AND date_format(f.datef, '%Y-%m') = '$year-$month'"; + else + $sql .= " AND date_format(f.datef, '%m') = '$month'"; + } if ($year > 0) { $sql .= ' AND date_format(f.datef, \'%Y\') = '.$year; @@ -3323,7 +3323,7 @@ else { $sql .= ' AND (s.nom like \'%'.addslashes($sall).'%\' OR f.facnumber like \'%'.addslashes($sall).'%\' OR f.note like \'%'.addslashes($sall).'%\' OR fd.description like \'%'.addslashes($sall).'%\')'; } - + $sql .= ' GROUP BY f.rowid'; $sql .= ' ORDER BY '; @@ -3358,7 +3358,7 @@ else print_liste_field_titre($langs->trans('AmountTTC'),$_SERVER['PHP_SELF'],'f.total_ttc','','&socid='.$socid.'&month='.$month.'&year=' . $year,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans('Received'),$_SERVER['PHP_SELF'],'am','','&socid='.$socid.'&month='.$month.'&year=' . $year,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans('Status'),$_SERVER['PHP_SELF'],'fk_statut,paye,am','','&socid='.$socid.'&month='.$month.'&year=' . $year,'align="right"',$sortfield,$sortorder); - //print '
  
'; print ''; print ''; - print ''; - //print ' '.$langs->trans('Year').': '; - $max_year = date("Y"); - $syear = $year; - //if ($syear == '') $syear = date("Y"); - $html->select_year($syear,'year',1, '', $max_year); - print ''; print ''; print ''; @@ -3381,9 +3381,9 @@ else print ''; print ''; print ''; - print ' '; - print ''; + print ' '; + print ''; print "
'; - + $facturestatic->id=$objp->facid; $facturestatic->ref=$objp->facnumber; $facturestatic->type=$objp->type; - + print ''; print '"; - //print ""; - print "\n"; + //print ""; + print "\n"; $total+=$objp->total; $total_ttc+=$objp->total_ttc; $totalrecu+=$objp->am;
'; print $facturestatic->getNomUrl(1); @@ -3450,8 +3450,8 @@ else print ''; print $facturestatic->LibStatut($objp->paye,$objp->fk_statut,5,$objp->am,$objp->type); print "