New: Gestion des factures de remplacement et debut de gestion des avoirs

This commit is contained in:
Laurent Destailleur
2006-08-26 22:45:32 +00:00
parent 9eaf26e6f8
commit 07949ce4c5
6 changed files with 730 additions and 403 deletions

View File

@@ -45,7 +45,7 @@ if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT.'/commande/commande
$user->getrights('facture'); $user->getrights('facture');
$user->getrights('banque'); $user->getrights('banque');
if (!$user->rights->facture->lire) if (! $user->rights->facture->lire)
accessforbidden(); accessforbidden();
$langs->load('bills'); $langs->load('bills');
@@ -53,9 +53,9 @@ $langs->load('companies');
$langs->load('products'); $langs->load('products');
$langs->load('main'); $langs->load('main');
$sall=isset($_GET['sall'])?$_GET['sall']:$_POST['sall']; $sall=isset($_GET['sall'])?trim($_GET['sall']):trim($_POST['sall']);
if (isset($_GET['msg'])) { $msg=urldecode($_GET['msg']); } $msg=isset($_GET['msg'])?urldecode($_GET['msg']):'';
if ($_GET['socidp']) { $socidp=$_GET['socidp']; } $socidp=isset($_GET['socidp'])?$_GET['socidp']:$_POST['socidp'];
// S<>curit<69> acc<63>s client // S<>curit<69> acc<63>s client
if ($user->societe_id > 0) if ($user->societe_id > 0)
@@ -273,10 +273,12 @@ if ($_POST['action'] == 'add')
$facture = new Facture($db, $_POST['socid']); $facture = new Facture($db, $_POST['socid']);
$facture->type = $_POST['type'];
if ($facture->type == 1) $facture->fk_facture_source = $_POST['replacement_ref'];
$facture->number = $_POST['facnumber']; $facture->number = $_POST['facnumber'];
$facture->date = $datefacture; $facture->date = $datefacture;
$facture->note_public = $_POST['note_public']; $facture->note_public = trim($_POST['note_public']);
$facture->note = $_POST['note']; $facture->note = trim($_POST['note']);
$facture->ref_client = $_POST['ref_client']; $facture->ref_client = $_POST['ref_client'];
$facture->modelpdf = $_POST['model']; $facture->modelpdf = $_POST['model'];
@@ -604,17 +606,24 @@ if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST
exit; exit;
} }
if ($_GET['action'] == 'deleteline' && $user->rights->facture->creer && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE) if ($_GET['action'] == 'deleteline' && $user->rights->facture->creer && ! $conf->global->PRODUIT_CONFIRM_DELETE_LINE)
{ {
$fac = new Facture($db,'',$_GET['facid']); $fac = new Facture($db,'',$_GET['facid']);
$fac->fetch($_GET['facid']); $fac->fetch($_GET['facid']);
$result = $fac->deleteline($_GET['rowid']); $result = $fac->deleteline($_GET['rowid']);
if ($_REQUEST['lang_id']) if ($result > 0)
{ {
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs"); if ($_REQUEST['lang_id'])
$outputlangs->setDefaultLang($_REQUEST['lang_id']); {
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
// facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs);
}
else
{
print $fac->error;
} }
facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs);
} }
if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes')
@@ -623,9 +632,15 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes')
{ {
$fac = new Facture($db); $fac = new Facture($db);
$result = $fac->delete($_GET['facid']); $result = $fac->delete($_GET['facid']);
$_GET['facid'] = 0 ; if ($result > 0)
Header('Location: '.$_SERVER["PHP_SELF"]); {
exit; Header('Location: '.$_SERVER["PHP_SELF"]);
exit;
}
else
{
$mesg='<div class="error">'.$fac->error.'</div>';
}
} }
} }
@@ -888,6 +903,8 @@ $html = new Form($db);
**********************************************************************/ **********************************************************************/
if ($_GET['action'] == 'create') if ($_GET['action'] == 'create')
{ {
$facturestatic=new Facture($db);
print_titre($langs->trans('NewBill')); print_titre($langs->trans('NewBill'));
if ($msg) print $msg; if ($msg) print $msg;
@@ -958,14 +975,46 @@ if ($_GET['action'] == 'create')
// Ref // Ref
print '<tr><td>'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans('Draft').'</td></tr>'; print '<tr><td>'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans('Draft').'</td></tr>';
// Reference client // Type de facture
$refclient = $ref_client ? $ref_client : ''; print '<tr><td valign="top">'.$langs->trans('Type').'</td><td colspan="2">';
print '<tr><td>'.$langs->trans('RefCustomer').'</td><td>'; print '<table class="nobordernopadding"><tr>';
print '<input type="text" name="ref_client" value="'.$refclient.'"></td>'; print '<td width="16px">';
print '</tr>'; print '<input type="radio" name="type" value="0"'.($_POST['type']==0?' checked=true':'').'>';
print '</td><td>';
$desc=$html->textwithhelp($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1);
print $desc;
print '</td></tr>';
print '<tr><td>';
print '<input type="radio" name="type" value="1"'.($_POST['type']==1?' checked=true':'').'>';
print '</td><td>';
$facids=$facturestatic->list_replacable_invoices($soc->id);
$options="";
foreach ($facids as $key => $value)
{
$options.='<option value="'.$key.'">'.$value.'</option>';
}
$text=$langs->trans("InvoiceReplacementAsk").' ';
$text.='<select name="replacement_ref">';
$text.='<option value="-1">&nbsp;</option>';
$text.=$options;
$text.='</select>';
$desc=$html->textwithhelp($text,$langs->transnoentities("InvoiceReplacementDesc"),1);
print $desc;
print '</td></tr>';
print '<tr><td>';
print '<input type="radio" name="type" value="2"'.($_POST['type']==2?' checked=true':'').' disabled>';
print '</td><td>';
$desc=$html->textwithhelp($langs->trans("InvoiceAvoirAsk").' ('.$langs->trans("FeatureNotYetAvailable").')',$langs->transnoentities("InvoiceAvoirDesc"),1);
print $desc;
print '</td></tr>';
print '</table>';
print '</td></tr>';
// Societe // Societe
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2">'.$soc->getNomUrl(1).'</td>'; print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2">';
print $soc->getNomUrl(1);
print '<input type="hidden" name="socidp" value="'.$soc->id.'">';
print '</td>';
print '</tr>'; print '</tr>';
// Ligne info remises tiers // Ligne info remises tiers
@@ -1044,15 +1093,29 @@ if ($_GET['action'] == 'create')
print '</td></tr>'; print '</td></tr>';
} }
// Modele PDF
print '<tr><td>'.$langs->trans('Model').'</td>'; print '<tr><td>'.$langs->trans('Model').'</td>';
print '<td>'; print '<td>';
// pdf
include_once(DOL_DOCUMENT_ROOT.'/includes/modules/facture/modules_facture.php'); include_once(DOL_DOCUMENT_ROOT.'/includes/modules/facture/modules_facture.php');
$model=new ModelePDFFactures(); $model=new ModelePDFFactures();
$liste=$model->liste_modeles($db); $liste=$model->liste_modeles($db);
$html->select_array('model',$liste,$conf->global->FACTURE_ADDON_PDF); $html->select_array('model',$liste,$conf->global->FACTURE_ADDON_PDF);
print "</td></tr>"; print "</td></tr>";
/*
\todo
L'info "Reference commande client" est une carac de la commande et non de la facture.
Elle devrait donc etre stock<63>e sur l'objet commande li<6C> <20> la facture et non sur la facture.
Pour ceux qui veulent l'utiliser au niveau de la facture, positionner la
constante FAC_USE_CUSTOMER_ORDER_REF <20> 1.
*/
if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF)
{
print '<tr><td>'.$langs->trans('RefCustomerOrder').'</td><td>';
print '<input type="text" name="ref_client" value="'.$ref_client.'">';
print '</td></tr>';
}
// Note publique // Note publique
print '<tr>'; print '<tr>';
print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>'; print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
@@ -1094,19 +1157,6 @@ if ($_GET['action'] == 'create')
print '</textarea></td></tr>'; print '</textarea></td></tr>';
} }
/*
\todo
L'info "Reference commande client" est une carac de la commande et non de la facture.
Elle devrait donc etre stock<63>e sur l'objet commande li<6C> <20> la facture et non sur la facture.
Pour ceux qui utilisent ainsi, positionner la constante FAC_USE_CUSTOMER_ORDER_REF <20> 1.
*/
if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF)
{
print '<tr><td>'.$langs->trans('RefCustomerOrder').'</td><td>';
print '<input type="text" name="ref_client" value="'.$ref_client.'">';
print '</td></tr>';
}
if ($_GET['propalid'] > 0) if ($_GET['propalid'] > 0)
{ {
print '<input type="hidden" name="amount" value="'.$propal->price.'">'."\n"; print '<input type="hidden" name="amount" value="'.$propal->price.'">'."\n";
@@ -1156,47 +1206,50 @@ if ($_GET['action'] == 'create')
} }
else else
{ {
print '<tr><td colspan="3">'; if ($conf->global->PRODUCT_SHOW_WHEN_CREATE)
// Zone de choix des produits pr<70>d<EFBFBD>finis <20> la cr<63>ation
print '<table class="noborder">';
print '<tr><td>'.$langs->trans('ProductsAndServices').'</td>';
print '<td>'.$langs->trans('Qty').'</td>';
print '<td>'.$langs->trans('ReductionShort').'</td>';
print '<td> &nbsp; &nbsp; </td>';
if ($conf->service->enabled)
{ {
print '<td>'.$langs->trans('ServiceLimitedDuration').'</td>'; print '<tr><td colspan="3">';
}
print '</tr>'; // Zone de choix des produits pr<70>d<EFBFBD>finis <20> la cr<63>ation
for ($i = 1 ; $i <= $NBLINES ; $i++) print '<table class="noborder">';
{ print '<tr><td>'.$langs->trans('ProductsAndServices').'</td>';
print '<tr>'; print '<td>'.$langs->trans('Qty').'</td>';
print '<td>'; print '<td>'.$langs->trans('ReductionShort').'</td>';
// multiprix print '<td> &nbsp; &nbsp; </td>';
if($conf->global->PRODUIT_MULTIPRICES == 1)
$html->select_produits('','idprod'.$i,'',$conf->produit->limit_size,$soc->price_level);
else
$html->select_produits('','idprod'.$i,'',$conf->produit->limit_size);
print '</td>';
print '<td><input type="text" size="2" name="qty'.$i.'" value="1"></td>';
print '<td nowrap="nowrap"><input type="text" size="1" name="remise_percent'.$i.'" value="'.$soc->remise_client.'">%</td>';
print '<td>&nbsp;</td>';
// Si le module service est actif, on propose des dates de d<>but et fin <20> la ligne
if ($conf->service->enabled) if ($conf->service->enabled)
{ {
print '<td nowrap="nowrap">'; print '<td>'.$langs->trans('ServiceLimitedDuration').'</td>';
print $langs->trans('From').' ';
print $html->select_date('','date_start'.$i,0,0,1,"add");
print '<br>'.$langs->trans('to').' ';
print $html->select_date('','date_end'.$i,0,0,1,"add");
print '</td>';
} }
print "</tr>\n"; print '</tr>';
for ($i = 1 ; $i <= $NBLINES ; $i++)
{
print '<tr>';
print '<td>';
// multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1)
$html->select_produits('','idprod'.$i,'',$conf->produit->limit_size,$soc->price_level);
else
$html->select_produits('','idprod'.$i,'',$conf->produit->limit_size);
print '</td>';
print '<td><input type="text" size="2" name="qty'.$i.'" value="1"></td>';
print '<td nowrap="nowrap"><input type="text" size="1" name="remise_percent'.$i.'" value="'.$soc->remise_client.'">%</td>';
print '<td>&nbsp;</td>';
// Si le module service est actif, on propose des dates de d<>but et fin <20> la ligne
if ($conf->service->enabled)
{
print '<td nowrap="nowrap">';
print $langs->trans('From').' ';
print $html->select_date('','date_start'.$i,0,0,1,"add");
print '<br>'.$langs->trans('to').' ';
print $html->select_date('','date_end'.$i,0,0,1,"add");
print '</td>';
}
print "</tr>\n";
}
print '</table>';
print '</td></tr>';
} }
print '</table>';
print '</td></tr>';
} }
/* /*
@@ -1483,29 +1536,24 @@ else
// Reference // Reference
print '<tr><td width="20%">'.$langs->trans('Ref').'</td><td colspan="5">'.$fac->ref.'</td></tr>'; print '<tr><td width="20%">'.$langs->trans('Ref').'</td><td colspan="5">'.$fac->ref.'</td></tr>';
// Ref client // Type
print '<tr><td>'; print '<tr><td width="20%">'.$langs->trans('Type').'</td><td colspan="5">';
print '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">'; print $fac->getLibType();
print $langs->trans('RefCustomer').'</td><td align="left">'; if ($fac->type == 1)
print '</td>';
if ($_GET['action'] != 'RefCustomerOrder' && $fac->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=RefCustomerOrder&amp;facid='.$fac->id.'">'.img_edit($langs->trans('Edit')).'</a></td>';
print '</tr></table>';
print '</td><td colspan="5">';
if ($user->rights->facture->creer && $_GET['action'] == 'RefCustomerOrder')
{ {
print '<form action="facture.php?facid='.$id.'" method="post">'; $facreplaced=new Facture($db);
print '<input type="hidden" name="action" value="set_ref_client">'; $facreplaced->fetch($fac->fk_facture_source);
print '<input type="text" class="flat" size="20" name="ref_client" value="'.$fac->ref_client.'">'; print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
print ' <input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
} }
else $facidnext=$fac->getIdNextInvoice();
if ($facidnext > 0)
{ {
print $fac->ref_client; $facthatreplace=new Facture($db);
$facthatreplace->fetch($facidnext);
print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
} }
print '</td>'; print '</td></tr>';
print '</tr>';
// Soci<63>t<EFBFBD> // Soci<63>t<EFBFBD>
print '<tr><td>'.$langs->trans('Company').'</td>'; print '<tr><td>'.$langs->trans('Company').'</td>';
print '<td colspan="5">'.$soc->getNomUrl(1,'compta').'</td>'; print '<td colspan="5">'.$soc->getNomUrl(1,'compta').'</td>';
@@ -1706,8 +1754,8 @@ else
// Projet // Projet
if ($conf->projet->enabled) if ($conf->projet->enabled)
{ {
print '<tr>';
$langs->load('projects'); $langs->load('projects');
print '<tr>';
print '<td>'; print '<td>';
print '<table class="nobordernopadding" width="100%"><tr><td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
@@ -2203,7 +2251,7 @@ else
else else
{ {
// G<>n<EFBFBD>rer // G<>n<EFBFBD>rer
if ($fac->statut == 1 && $user->rights->facture->creer) if ($fac->statut >= 1 && $user->rights->facture->creer)
{ {
if ($fac->paye == 0) if ($fac->paye == 0)
{ {
@@ -2216,12 +2264,6 @@ else
} }
} }
// On v<>rifie si la facture est supprimable. Si oui, on propose bouton supprimer
if ($fac->statut == 0 && $fac->is_erasable() && $user->rights->facture->supprimer && $_GET['action'] != 'delete')
{
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
}
// Envoyer // Envoyer
if ($fac->statut == 1 && $user->rights->facture->envoyer) if ($fac->statut == 1 && $user->rights->facture->envoyer)
{ {
@@ -2263,6 +2305,12 @@ else
// Ajouter bouton "Annuler et Cr<43>er facture remplacement" // Ajouter bouton "Annuler et Cr<43>er facture remplacement"
} }
} }
// Supprimer
if ($fac->is_erasable() && $user->rights->facture->supprimer && $_GET['action'] != 'delete')
{
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
}
print '</div>'; print '</div>';
} }
@@ -2276,7 +2324,7 @@ else
$filename=sanitize_string($fac->ref); $filename=sanitize_string($fac->ref);
$filedir=$conf->facture->dir_output . '/' . sanitize_string($fac->ref); $filedir=$conf->facture->dir_output . '/' . sanitize_string($fac->ref);
$urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id; $urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id;
$genallowed=($fac->statut == 1 && $user->rights->facture->creer); $genallowed=($fac->statut >= 1 && $user->rights->facture->creer);
$delallowed=$user->rights->facture->supprimer; $delallowed=$user->rights->facture->supprimer;
$var=true; $var=true;
@@ -2568,196 +2616,192 @@ else
* Mode Liste * * Mode Liste *
* * * *
***************************************************************************/ ***************************************************************************/
$page = $_GET['page']; $page =$_GET['page'];
$sortorder=$_GET['sortorder']; $sortorder=$_GET['sortorder'];
$sortfield=$_GET['sortfield']; $sortfield=$_GET['sortfield'];
$month=$_GET['month']; $month =$_GET['month'];
$year=$_GET['year']; $year =$_GET['year'];
$limit = $conf->liste_limit;
$offset = $limit * $page ;
if (! $sortorder) $sortorder='DESC';
if (! $sortfield) $sortfield='f.datef';
$facturestatic=new Facture($db); $facturestatic=new Facture($db);
if ($page == -1) $page = 0 ; if ($page == -1) $page = 0 ;
if ($user->rights->facture->lire) $sql = 'SELECT s.nom, s.idp,';
$sql.= ' f.rowid as facid, f.facnumber, f.increment, f.total, f.total_ttc,';
$sql.= $db->pdate('f.datef').' as df, '.$db->pdate('f.date_lim_reglement').' as datelimite, ';
$sql.= ' f.paye as paye, f.fk_statut';
if (! $sall) $sql.= ' ,sum(pf.amount) as am';
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
$sql.= ','.MAIN_DB_PREFIX.'facture as f';
if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture ';
if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON f.rowid=fd.fk_facture ';
$sql.= ' WHERE f.fk_soc = s.idp';
if ($socidp) $sql .= ' AND s.idp = '.$socidp;
if ($month > 0) $sql .= ' AND date_format(f.datef, \'%m\') = '.$month;
if ($_GET['filtre'])
{ {
$limit = $conf->liste_limit; $filtrearr = split(',', $_GET['filtre']);
$offset = $limit * $page ; foreach ($filtrearr as $fil)
if (! $sortorder) $sortorder='DESC';
if (! $sortfield) $sortfield='f.datef';
$sql = 'SELECT s.nom, s.idp,';
$sql.= ' f.rowid as facid, f.facnumber, f.increment, f.total, f.total_ttc,';
$sql.= $db->pdate('f.datef').' as df, '.$db->pdate('f.date_lim_reglement').' as datelimite, ';
$sql.= ' f.paye as paye, f.fk_statut';
if (! $sall) $sql.= ' ,sum(pf.amount) as am';
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
$sql.= ','.MAIN_DB_PREFIX.'facture as f';
if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture ';
if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON f.rowid=fd.fk_facture ';
$sql.= ' WHERE f.fk_soc = s.idp';
if ($socidp) $sql .= ' AND s.idp = '.$socidp;
if ($month > 0) $sql .= ' AND date_format(f.datef, \'%m\') = '.$month;
if ($_GET['filtre'])
{ {
$filtrearr = split(',', $_GET['filtre']); $filt = split(':', $fil);
foreach ($filtrearr as $fil) $sql .= ' AND ' . trim($filt[0]) . ' = ' . trim($filt[1]);
}
}
if ($_GET['search_ref'])
{
$sql .= ' AND f.facnumber like \'%'.addslashes(trim($_GET['search_ref'])).'%\'';
}
if ($_GET['search_societe'])
{
$sql .= ' AND s.nom like \'%'.addslashes(trim($_GET['search_societe'])).'%\'';
}
if ($_GET['search_montant_ht'])
{
$sql .= ' AND f.total = \''.addslashes(trim($_GET['search_montant_ht'])).'\'';
}
if ($_GET['search_montant_ttc'])
{
$sql .= ' AND f.total_ttc = \''.addslashes(trim($_GET['search_montant_ttc'])).'\'';
}
if ($year > 0)
{
$sql .= ' AND date_format(f.datef, \'%Y\') = '.$year;
}
if ($_POST['sf_ref'])
{
$sql .= ' AND f.facnumber like \'%'.addslashes(trim($_POST['sf_ref'])) . '%\'';
}
if ($sall)
{
$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 ';
$listfield=split(',',$sortfield);
foreach ($listfield as $key => $value)
$sql.= $listfield[$key].' '.$sortorder.',';
$sql .= ' f.rowid DESC ';
$sql .= $db->plimit($limit+1,$offset);
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
if ($socidp)
{
$soc = new Societe($db);
$soc->fetch($socidp);
}
print_barre_liste($langs->trans('BillsCustomers').' '.($socidp?' '.$soc->nom:''),$page,'facture.php','&amp;socidp='.$socidp,$sortfield,$sortorder,'',$num);
$i = 0;
print '<table class="liste" width="100%">';
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans('Ref'),$_SERVER['PHP_SELF'],'f.facnumber','','&amp;socidp='.$socidp,'',$sortfield);
print_liste_field_titre($langs->trans('Date'),$_SERVER['PHP_SELF'],'f.datef','','&amp;socidp='.$socidp,'align="center"',$sortfield);
print_liste_field_titre($langs->trans('Company'),$_SERVER['PHP_SELF'],'s.nom','','&amp;socidp='.$socidp,'',$sortfield);
print_liste_field_titre($langs->trans('AmountHT'),$_SERVER['PHP_SELF'],'f.total','','&amp;socidp='.$socidp,'align="right"',$sortfield);
print_liste_field_titre($langs->trans('AmountTTC'),$_SERVER['PHP_SELF'],'f.total_ttc','','&amp;socidp='.$socidp,'align="right"',$sortfield);
print_liste_field_titre($langs->trans('Received'),$_SERVER['PHP_SELF'],'am','','&amp;socidp='.$socidp,'align="right"',$sortfield);
print_liste_field_titre($langs->trans('Status'),$_SERVER['PHP_SELF'],'fk_statut,paye,am','','&amp;socidp='.$socidp,'align="right"',$sortfield);
print '</tr>';
// Lignes des champs de filtre
print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
print '<tr class="liste_titre">';
print '<td class="liste_titre" valign="right">';
print '<input class="flat" size="10" type="text" name="search_ref" value="'.$_GET['search_ref'].'">';
print '</td><td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" name="search_societe" value="'.$_GET['search_societe'].'">';
print '</td><td class="liste_titre" align="right">';
print '<input class="flat" type="text" size="10" name="search_montant_ht" value="'.$_GET['search_montant_ht'].'">';
print '</td><td class="liste_titre" align="right">';
print '<input class="flat" type="text" size="10" name="search_montant_ttc" value="'.$_GET['search_montant_ttc'].'">';
print '</td><td class="liste_titre" colspan="2" align="right">';
print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans('Search').'">';
print '</td>';
print '</tr>';
print '</form>';
if ($num > 0)
{
$var=True;
$total=0;
$totalrecu=0;
while ($i < min($num,$limit))
{ {
$filt = split(':', $fil); $objp = $db->fetch_object($resql);
$sql .= ' AND ' . $filt[0] . ' = ' . $filt[1]; $var=!$var;
}
}
if ($_GET['search_ref'])
{
$sql .= ' AND f.facnumber like \'%'.addslashes($_GET['search_ref']).'%\'';
}
if ($_GET['search_societe'])
{
$sql .= ' AND s.nom like \'%'.addslashes($_GET['search_societe']).'%\'';
}
if ($_GET['search_montant_ht'])
{
$sql .= ' AND f.total = \''.addslashes($_GET['search_montant_ht']).'\'';
}
if ($_GET['search_montant_ttc'])
{
$sql .= ' AND f.total_ttc = \''.addslashes($_GET['search_montant_ttc']).'\'';
}
if ($year > 0)
{
$sql .= ' AND date_format(f.datef, \'%Y\') = '.$year;
}
if ($_POST['sf_ref'])
{
$sql .= ' AND f.facnumber like \'%'.addslashes($_POST['sf_ref']) . '%\'';
}
if ($sall)
{
$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'; print '<tr '.$bc[$var].'>';
print '<td nowrap="nowrap"><a href="'.$_SERVER["PHP_SELF"].'?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').'</a> ';
print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$objp->facid.'">'.$objp->facnumber.'</a>'.$objp->increment;
if ($objp->datelimite < (time() - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $objp->am) print img_warning($langs->trans('Late'));
print '</td>';
$sql .= ' ORDER BY '; if ($objp->df > 0 )
$listfield=split(',',$sortfield);
foreach ($listfield as $key => $value)
$sql.= $listfield[$key].' '.$sortorder.',';
$sql .= ' f.rowid DESC ';
$sql .= $db->plimit($limit+1,$offset);
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
if ($socidp)
{
$soc = new Societe($db);
$soc->fetch($socidp);
}
print_barre_liste($langs->trans('BillsCustomers').' '.($socidp?' '.$soc->nom:''),$page,'facture.php','&amp;socidp='.$socidp,$sortfield,$sortorder,'',$num);
$i = 0;
print '<table class="liste" width="100%">';
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans('Ref'),$_SERVER['PHP_SELF'],'f.facnumber','','&amp;socidp='.$socidp,'',$sortfield);
print_liste_field_titre($langs->trans('Date'),$_SERVER['PHP_SELF'],'f.datef','','&amp;socidp='.$socidp,'align="center"',$sortfield);
print_liste_field_titre($langs->trans('Company'),$_SERVER['PHP_SELF'],'s.nom','','&amp;socidp='.$socidp,'',$sortfield);
print_liste_field_titre($langs->trans('AmountHT'),$_SERVER['PHP_SELF'],'f.total','','&amp;socidp='.$socidp,'align="right"',$sortfield);
print_liste_field_titre($langs->trans('AmountTTC'),$_SERVER['PHP_SELF'],'f.total_ttc','','&amp;socidp='.$socidp,'align="right"',$sortfield);
print_liste_field_titre($langs->trans('Received'),$_SERVER['PHP_SELF'],'am','','&amp;socidp='.$socidp,'align="right"',$sortfield);
print_liste_field_titre($langs->trans('Status'),$_SERVER['PHP_SELF'],'fk_statut,paye,am','','&amp;socidp='.$socidp,'align="right"',$sortfield);
print '</tr>';
// Lignes des champs de filtre
print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
print '<tr class="liste_titre">';
print '<td class="liste_titre" valign="right">';
print '<input class="flat" size="10" type="text" name="search_ref" value="'.$_GET['search_ref'].'">';
print '</td><td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" name="search_societe" value="'.$_GET['search_societe'].'">';
print '</td><td class="liste_titre" align="right">';
print '<input class="flat" type="text" size="10" name="search_montant_ht" value="'.$_GET['search_montant_ht'].'">';
print '</td><td class="liste_titre" align="right">';
print '<input class="flat" type="text" size="10" name="search_montant_ttc" value="'.$_GET['search_montant_ttc'].'">';
print '</td><td class="liste_titre" colspan="2" align="right">';
print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans('Search').'">';
print '</td>';
print '</tr>';
print '</form>';
if ($num > 0)
{
$var=True;
$total=0;
$totalrecu=0;
while ($i < min($num,$limit))
{ {
$objp = $db->fetch_object($resql); print '<td align="center" nowrap>';
$var=!$var; $y = strftime('%Y',$objp->df);
$m = strftime('%m',$objp->df);
print '<tr '.$bc[$var].'>'; print strftime('%d',$objp->df);
print '<td nowrap="nowrap"><a href="'.$_SERVER["PHP_SELF"].'?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').'</a> '; print ' <a href="'.$_SERVER["PHP_SELF"].'?year='.$y.'&amp;month='.$m.'">';
print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$objp->facid.'">'.$objp->facnumber.'</a>'.$objp->increment; print substr(strftime('%B',$objp->df),0,3).'</a>';
if ($objp->datelimite < (time() - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $objp->am) print img_warning($langs->trans('Late')); print ' <a href="'.$_SERVER["PHP_SELF"].'?year='.$y.'">';
print '</td>'; print strftime('%Y',$objp->df).'</a></td>';
if ($objp->df > 0 )
{
print '<td align="center" nowrap>';
$y = strftime('%Y',$objp->df);
$m = strftime('%m',$objp->df);
print strftime('%d',$objp->df);
print ' <a href="'.$_SERVER["PHP_SELF"].'?year='.$y.'&amp;month='.$m.'">';
print substr(strftime('%B',$objp->df),0,3).'</a>';
print ' <a href="'.$_SERVER["PHP_SELF"].'?year='.$y.'">';
print strftime('%Y',$objp->df).'</a></td>';
}
else
{
print '<td align="center"><b>!!!</b></td>';
}
print '<td><a href="fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans('ShowCompany'),'company').' '.dolibarr_trunc($objp->nom,48).'</a></td>';
print '<td align="right">'.price($objp->total).'</td>';
print '<td align="right">'.price($objp->total_ttc).'</td>';
print '<td align="right">'.price($objp->am).'</td>';
// Affiche statut de la facture
print '<td align="right" nowrap="nowrap">';
print $facturestatic->LibStatut($objp->paye,$objp->fk_statut,5,$objp->am);
print '</td>';
print '</tr>';
$total+=$objp->total;
$total_ttc+=$objp->total_ttc;
$totalrecu+=$objp->am;
$i++;
} }
else
if (($offset + $num) <= $limit)
{ {
// Print total print '<td align="center"><b>!!!</b></td>';
print '<tr class="liste_total">';
print '<td class="liste_total" colspan="3" align="left">'.$langs->trans('Total').'</td>';
print '<td class="liste_total" align="right">'.price($total).'</td>';
print '<td class="liste_total" align="right">'.price($total_ttc).'</td>';
print '<td class="liste_total" align="right">'.price($totalrecu).'</td>';
print '<td class="liste_total" align="center">&nbsp;</td>';
print '</tr>';
} }
print '<td><a href="fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans('ShowCompany'),'company').' '.dolibarr_trunc($objp->nom,48).'</a></td>';
print '<td align="right">'.price($objp->total).'</td>';
print '<td align="right">'.price($objp->total_ttc).'</td>';
print '<td align="right">'.price($objp->am).'</td>';
// Affiche statut de la facture
print '<td align="right" nowrap="nowrap">';
print $facturestatic->LibStatut($objp->paye,$objp->fk_statut,5,$objp->am);
print '</td>';
print '</tr>';
$total+=$objp->total;
$total_ttc+=$objp->total_ttc;
$totalrecu+=$objp->am;
$i++;
} }
print '</table>'; if (($offset + $num) <= $limit)
$db->free($resql); {
} // Print total
else print '<tr class="liste_total">';
{ print '<td class="liste_total" colspan="3" align="left">'.$langs->trans('Total').'</td>';
dolibarr_print_error($db); print '<td class="liste_total" align="right">'.price($total).'</td>';
print '<td class="liste_total" align="right">'.price($total_ttc).'</td>';
print '<td class="liste_total" align="right">'.price($totalrecu).'</td>';
print '<td class="liste_total" align="center">&nbsp;</td>';
print '</tr>';
}
} }
print '</table>';
$db->free($resql);
}
else
{
dolibarr_print_error($db);
} }
} }
} }

View File

@@ -50,7 +50,7 @@ class DiscountAbsolute
/** /**
* \brief Charge objet remiset depuis la base * \brief Charge objet remise depuis la base
* \param rowid id du projet <20> charger * \param rowid id du projet <20> charger
* \return int <0 si ko, =0 si non trouv<75>, >0 si ok * \return int <0 si ko, =0 si non trouv<75>, >0 si ok
*/ */
@@ -91,5 +91,31 @@ class DiscountAbsolute
return -1; return -1;
} }
} }
/**
* \brief Link the discount to a particular invoice
* \param rowid Invoice id
* \return int <0 ko, >0 ok
*/
function link_to_invoice($rowid)
{
dolibarr_syslog("Discount.class::link_to_invoice link discount ".$this->id." to invoice rowid=".$rowid);
$sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
$sql.=" SET fk_facture = ".$rowid;
$sql.=" WHERE rowid = ".$this->id;
$resql = $this->db->query($sql);
if ($resql)
{
return 1;
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Discount.class::link_to_invoice ".$this->error." sql=".$sql);
return -1;
}
}
} }
?> ?>

View File

@@ -63,7 +63,8 @@ class Facture extends CommonObject
var $note_public; var $note_public;
var $statut; var $statut;
var $paye; // 1 si facture pay<61>e COMPLETEMENT, 0 sinon var $paye; // 1 si facture pay<61>e COMPLETEMENT, 0 sinon
var $close_code; // Si mis a paye sans paiement complet, code qui justifie var $fk_facture_source; // id facture source si facture de remplacement ou avoir
var $close_code; // abandon, replaced, avoir, discount_vat
var $close_note; // Commentaire si mis a paye sans paiement complet var $close_note; // Commentaire si mis a paye sans paiement complet
var $propalid; var $propalid;
var $projetid; var $projetid;
@@ -77,7 +78,7 @@ class Facture extends CommonObject
// Pour board // Pour board
var $nbtodo; var $nbtodo;
var $nbtodolate; var $nbtodolate;
var $specimen; var $specimen;
var $error; var $error;
@@ -108,21 +109,21 @@ class Facture extends CommonObject
} }
/** /**
* \brief Cr<43>ation de la facture en base * \brief Cr<43>ation de la facture en base
* \param user object utilisateur qui cr<63>e * \param user Object utilisateur qui cr<63>e
* \return int <0 si ko, >0 si ok
*/ */
function create($user) function create($user)
{ {
global $langs,$conf,$mysoc; global $langs,$conf,$mysoc;
// Nettoyage param<61>tres // Nettoyage param<61>tres
if (! $this->type) $this->type = 0 ;
$this->ref_client=trim($this->ref_client);
$this->note=trim($this->note); $this->note=trim($this->note);
$this->note_public=trim($this->note_public); $this->note_public=trim($this->note_public);
$this->ref_client=trim($this->ref_client);
if (! $this->remise) $this->remise = 0 ; if (! $this->remise) $this->remise = 0 ;
if (! $this->mode_reglement_id) $this->mode_reglement_id = 0; if (! $this->mode_reglement_id) $this->mode_reglement_id = 0;
// On positionne en mode brouillon la facture
$this->brouillon = 1; $this->brouillon = 1;
dolibarr_syslog("Facture::create"); dolibarr_syslog("Facture::create");
@@ -132,6 +133,45 @@ class Facture extends CommonObject
$this->db->begin(); $this->db->begin();
// Verification param<61>tres
if ($this->type == 1) // si remplacement
{
// Controle que facture source connue
if ($this->fk_facture_source <= 0)
{
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("InvoiceReplacement"));
$this->db->rollback();
return -10;
}
// Charge la facture source a remplacer
$facreplaced=new Facture($this->db);
$result=$facreplaced->fetch($this->fk_facture_source);
if ($result <= 0)
{
$this->error=$langs->trans("ErrorBadInvoice");
$this->db->rollback();
return -11;
}
// Controle que facture source non deja remplacee
$idreplacement=$facreplaced->getIdNextInvoice();
if ($idreplacement != 0)
{
$this->error=$langs->trans("ErrorInvoiceAlreadyReplaced",$facreplaced->ref);
$this->db->rollback();
return -12;
}
$result=$facreplaced->set_canceled($user,'replaced','');
if ($result < 0)
{
$this->error=$facreplaced->error." sql=".$sql;
$this->db->rollback();
return -13;
}
}
// Facture r<>currente // Facture r<>currente
if ($this->fac_rec > 0) if ($this->fac_rec > 0)
{ {
@@ -147,7 +187,7 @@ class Facture extends CommonObject
$this->amount = $_facrec->amount; $this->amount = $_facrec->amount;
$this->remise_absolue = $_facrec->remise_absolue; $this->remise_absolue = $_facrec->remise_absolue;
$this->remise_percent = $_facrec->remise_percent; $this->remise_percent = $_facrec->remise_percent;
$this->remise = $_facrec->remise; $this->remise = $_facrec->remise;
} }
// Definition de la date limite // Definition de la date limite
@@ -162,19 +202,20 @@ class Facture extends CommonObject
$totalht = ($amount - $remise); $totalht = ($amount - $remise);
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture ('; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture (';
$sql.= ' facnumber, fk_soc, datec, amount, remise_absolue, remise_percent,'; $sql.= ' facnumber, type, fk_soc, datec, amount, remise_absolue, remise_percent,';
$sql.= ' datef,'; $sql.= ' datef,';
$sql.= ' note,'; $sql.= ' note,';
$sql.= ' note_public,'; $sql.= ' note_public,';
$sql.= ' ref_client,'; $sql.= ' ref_client,';
$sql.= ' fk_user_author, fk_projet,'; $sql.= ' fk_facture_source, fk_user_author, fk_projet,';
$sql.= ' fk_cond_reglement, fk_mode_reglement, date_lim_reglement, model_pdf) '; $sql.= ' fk_cond_reglement, fk_mode_reglement, date_lim_reglement, model_pdf)';
$sql.= " VALUES ("; $sql.= ' VALUES (';
$sql.= "'$number','$socid', now(), '$totalht', '".$this->remise_absolue."'"; $sql.= "'$number', '".$this->type."', '$socid', now(), '$totalht', '".$this->remise_absolue."'";
$sql.= ",'".$this->remise_percent."', ".$this->db->idate($this->date); $sql.= ",'".$this->remise_percent."', ".$this->db->idate($this->date);
$sql.= ",".($this->note?"'".addslashes($this->note)."'":"null"); $sql.= ",".($this->note?"'".addslashes($this->note)."'":"null");
$sql.= ",".($this->note_public?"'".addslashes($this->note_public)."'":"null"); $sql.= ",".($this->note_public?"'".addslashes($this->note_public)."'":"null");
$sql.= ",".($this->ref_client?"'".addslashes($this->ref_client)."'":"null"); $sql.= ",".($this->ref_client?"'".addslashes($this->ref_client)."'":"null");
$sql.= ",".($this->fk_facture_source?"'".addslashes($this->fk_facture_source)."'":"null");
$sql.= ",".$user->id; $sql.= ",".$user->id;
$sql.= ",".($this->projetid?$this->projetid:"null"); $sql.= ",".($this->projetid?$this->projetid:"null");
$sql.= ','.$this->cond_reglement_id; $sql.= ','.$this->cond_reglement_id;
@@ -189,6 +230,7 @@ class Facture extends CommonObject
$sql = 'UPDATE '.MAIN_DB_PREFIX."facture SET facnumber='(PROV".$this->id.")' WHERE rowid=".$this->id; $sql = 'UPDATE '.MAIN_DB_PREFIX."facture SET facnumber='(PROV".$this->id.")' WHERE rowid=".$this->id;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
// Mise a jour lien avec propal ou commande
if ($resql && $this->id && $this->propalid) if ($resql && $this->id && $this->propalid)
{ {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'fa_pr (fk_facture, fk_propal) VALUES ('.$this->id.','.$this->propalid.')'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'fa_pr (fk_facture, fk_propal) VALUES ('.$this->id.','.$this->propalid.')';
@@ -301,6 +343,27 @@ class Facture extends CommonObject
} }
/**
* \brief Renvoie nom clicable (avec eventuellement le picto)
* \param withpicto Inclut le picto dans le lien
* \param option Sur quoi pointe le lien
* \return string Chaine avec URL
*/
function getNomUrl($withpicto=0,$option='')
{
global $langs;
$result='';
$lien = '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$this->id.'">';
$lienfin='</a>';
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowInvoice"),'bill').$lienfin.' ');
$result.=$lien.$this->ref.$lienfin;
return $result;
}
/** /**
* \brief Recup<75>re l'objet facture et ses lignes de factures * \brief Recup<75>re l'objet facture et ses lignes de factures
* \param rowid id de la facture a r<>cup<75>rer * \param rowid id de la facture a r<>cup<75>rer
@@ -311,20 +374,21 @@ class Facture extends CommonObject
{ {
//dolibarr_syslog("Facture::Fetch rowid : $rowid, societe_id : $societe_id"); //dolibarr_syslog("Facture::Fetch rowid : $rowid, societe_id : $societe_id");
$sql = 'SELECT f.fk_soc,f.facnumber,f.amount,f.tva,f.total,f.total_ttc,f.remise_percent,f.remise_absolue,f.remise'; $sql = 'SELECT f.facnumber,f.ref_client,f.type,f.fk_soc,f.amount,f.tva,f.total,f.total_ttc,f.remise_percent,f.remise_absolue,f.remise';
$sql .= ','.$this->db->pdate('f.datef').' as df, f.fk_projet'; $sql.= ','.$this->db->pdate('f.datef').' as df, f.fk_projet';
$sql .= ','.$this->db->pdate('f.date_lim_reglement').' as dlr'; $sql.= ','.$this->db->pdate('f.date_lim_reglement').' as dlr';
$sql .= ', f.note, f.note_public, f.fk_statut, f.paye, f.close_code, f.close_note, f.fk_user_author, f.model_pdf'; $sql.= ', f.note, f.note_public, f.fk_statut, f.paye, f.close_code, f.close_note, f.fk_user_author, f.model_pdf';
$sql .= ', f.fk_mode_reglement, f.ref_client, p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql.= ', f.fk_mode_reglement, p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
$sql .= ', f.fk_cond_reglement, c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_facture'; $sql.= ', f.fk_cond_reglement, c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_facture';
$sql .= ', cf.fk_commande'; $sql.= ', f.fk_facture_source';
$sql .= ' FROM '.MAIN_DB_PREFIX.'cond_reglement as c, '.MAIN_DB_PREFIX.'facture as f'; $sql.= ', cf.fk_commande';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id'; $sql.= ' FROM '.MAIN_DB_PREFIX.'cond_reglement as c, '.MAIN_DB_PREFIX.'facture as f';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'co_fa as cf ON cf.fk_facture = f.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
$sql .= ' WHERE f.rowid='.$rowid.' AND c.rowid = f.fk_cond_reglement'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'co_fa as cf ON cf.fk_facture = f.rowid';
$sql.= ' WHERE f.rowid='.$rowid.' AND c.rowid = f.fk_cond_reglement';
if ($societe_id > 0) if ($societe_id > 0)
{ {
$sql .= ' AND f.fk_soc = '.$societe_id; $sql.= ' AND f.fk_soc = '.$societe_id;
} }
$result = $this->db->query($sql); $result = $this->db->query($sql);
@@ -336,10 +400,11 @@ class Facture extends CommonObject
//print strftime('%Y%m%d%H%M%S',$obj->df).' '.$obj->df.' '.dolibarr_print_date($obj->df); //print strftime('%Y%m%d%H%M%S',$obj->df).' '.$obj->df.' '.dolibarr_print_date($obj->df);
$this->id = $rowid; $this->id = $rowid;
$this->datep = $obj->dp;
$this->date = $obj->df;
$this->ref = $obj->facnumber; $this->ref = $obj->facnumber;
$this->ref_client = $obj->ref_client; $this->ref_client = $obj->ref_client;
$this->type = $obj->type;
$this->datep = $obj->dp;
$this->date = $obj->df;
$this->amount = $obj->amount; $this->amount = $obj->amount;
$this->remise_percent = $obj->remise_percent; $this->remise_percent = $obj->remise_percent;
$this->remise_absolue = $obj->remise_absolue; $this->remise_absolue = $obj->remise_absolue;
@@ -361,6 +426,7 @@ class Facture extends CommonObject
$this->cond_reglement = $obj->cond_reglement_libelle; $this->cond_reglement = $obj->cond_reglement_libelle;
$this->cond_reglement_facture = $obj->cond_reglement_libelle_facture; $this->cond_reglement_facture = $obj->cond_reglement_libelle_facture;
$this->projetid = $obj->fk_projet; $this->projetid = $obj->fk_projet;
$this->fk_facture_source = $obj->fk_facture_source;
$this->note = $obj->note; $this->note = $obj->note;
$this->note_public = $obj->note_public; $this->note_public = $obj->note_public;
$this->user_author = $obj->fk_user_author; $this->user_author = $obj->fk_user_author;
@@ -368,15 +434,14 @@ class Facture extends CommonObject
$this->commande_id = $obj->fk_commande; $this->commande_id = $obj->fk_commande;
$this->lignes = array(); $this->lignes = array();
if ($this->commande_id) if ($this->commande_id)
{ {
$sql = "SELECT ref"; $sql = "SELECT ref";
$sql.= " FROM ".MAIN_DB_PREFIX."commande"; $sql.= " FROM ".MAIN_DB_PREFIX."commande";
$sql.= " WHERE rowid = ".$this->commande_id; $sql.= " WHERE rowid = ".$this->commande_id;
$resqlcomm = $this->db->query($sql); $resqlcomm = $this->db->query($sql);
if ($resqlcomm) if ($resqlcomm)
{ {
$objc = $this->db->fetch_object($resqlcomm); $objc = $this->db->fetch_object($resqlcomm);
@@ -465,7 +530,7 @@ class Facture extends CommonObject
/** /**
* \brief Ajout d'une ligne remise fixe dans la facture, en base * \brief Ajout en base d'une ligne remise fixe en ligne de facture
* \param idremise Id de la remise fixe * \param idremise Id de la remise fixe
* \return int >0 si ok, <0 si ko * \return int >0 si ok, <0 si ko
*/ */
@@ -480,9 +545,15 @@ class Facture extends CommonObject
$remise=new DiscountAbsolute($this->db); $remise=new DiscountAbsolute($this->db);
$result=$remise->fetch($idremise); $result=$remise->fetch($idremise);
if ($result > 0) if ($result > 0)
{ {
if ($remise->fk_facture)
{
$this->error=$langs->trans("ErrorDiscountAlreadyUsed");
$this->db->rollback();
return -5;
}
$facligne=new FactureLigne($this->db); $facligne=new FactureLigne($this->db);
$facligne->fk_facture=$this->id; $facligne->fk_facture=$this->id;
$facligne->fk_remise_except=$remise->id; $facligne->fk_remise_except=$remise->id;
@@ -502,36 +573,46 @@ class Facture extends CommonObject
$facligne->total_tva = $tabprice[1]; $facligne->total_tva = $tabprice[1];
$facligne->total_ttc = $tabprice[2]; $facligne->total_ttc = $tabprice[2];
$result=$facligne->insert(); $lineid=$facligne->insert();
if ($result > 0) if ($lineid > 0)
{ {
$result=$this->update_price($this->id); $result=$this->update_price($this->id);
if ($result > 0) if ($result > 0)
{ {
// Cr<43>e lien entre remise et ligne de facture
$result=$remise->link_to_invoice($lineid);
if ($result < 0)
{
$this->error=$remise->error;
$this->db->rollback();
return -4;
}
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->db->rollback(); $this->error=$facligne->error;
$this->db->rollback();
return -1; return -1;
} }
} }
else else
{ {
$this->error=$facligne->error; $this->error=$facligne->error;
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
return -2; return -3;
} }
} }
/** /**
* \brief Classe la facture dans un projet * \brief Classe la facture dans un projet
* \param projid Id du projet dans lequel classer la facture * \param projid Id du projet dans lequel classer la facture
@@ -574,78 +655,92 @@ class Facture extends CommonObject
} }
/** /**
* \brief Supprime la facture * \brief Supprime la facture
* \param rowid id de la facture <20> supprimer * \param rowid Id de la facture <20> supprimer
* \return int <0 si ko, >0 si ok
*/ */
function delete($rowid) function delete($rowid)
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
dolibarr_syslog("Facture.class::delete rowid=".$rowid);
$this->db->begin(); $this->db->begin();
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_tva_sum WHERE fk_facture = '.$rowid;
if ( $this->db->query( $sql) ) $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_tva_sum WHERE fk_facture = '.$rowid;
if ($this->db->query($sql))
{ {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'fa_pr WHERE fk_facture = '.$rowid; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'fa_pr WHERE fk_facture = '.$rowid;
if ($this->db->query( $sql) ) if ($this->db->query($sql))
{ {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'co_fa WHERE fk_facture = '.$rowid; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'co_fa WHERE fk_facture = '.$rowid;
if ($this->db->query( $sql) ) if ($this->db->query($sql))
{ {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.$rowid; // On d<>saffecte de la facture les remises li<6C>es
if ($this->db->query( $sql) ) $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' SET fk_facture = NULL WHERE fk_facture = '.$rowid;
if ($this->db->query($sql))
{ {
// On d<>saffecte de la facture les remises li<6C>es $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.$rowid;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except'; if ($this->db->query($sql))
$sql.= ' SET fk_facture = NULL WHERE fk_facture = '.$rowid;
if ($this->db->query( $sql) )
{ {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture WHERE rowid = '.$rowid.' AND fk_statut = 0'; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture WHERE rowid = '.$rowid;
$resql=$this->db->query($sql) ; $resql=$this->db->query($sql);
if ($resql)
if ($resql) {
{ // Appel des triggers
// Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); $interface=new Interfaces($this->db);
$interface=new Interfaces($this->db); $result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf);
$result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf); // Fin appel triggers
// Fin appel triggers
$this->db->commit();
$this->db->commit(); return 1;
return 1; }
} else
else {
{ $this->error=$this->db->error()." sql=".$sql;
$this->db->rollback(); dolibarr_syslog("Facture.class::delete ".$this->error);
return -6; $this->db->rollback();
} return -6;
} }
else }
{ else
$this->db->rollback(); {
return -5; $this->error=$this->db->error()." sql=".$sql;
} dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback();
return -4;
}
} }
else else
{ {
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback(); $this->db->rollback();
return -4; return -5;
} }
} }
else else
{ {
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback(); $this->db->rollback();
return -3; return -3;
} }
} }
else else
{ {
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
} }
else else
{ {
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
@@ -796,25 +891,48 @@ class Facture extends CommonObject
global $conf,$langs; global $conf,$langs;
dolibarr_syslog("Facture.class.php::set_canceled rowid=".$this->id); dolibarr_syslog("Facture.class.php::set_canceled rowid=".$this->id);
$this->db->begin();
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET';
$sql.= ' fk_statut=3'; $sql.= ' fk_statut=3';
if ($close_code) $sql.= ", close_code='".addslashes($close_code)."'"; if ($close_code) $sql.= ", close_code='".addslashes($close_code)."'";
if ($close_note) $sql.= ", close_note='".addslashes($close_note)."'"; if ($close_note) $sql.= ", close_note='".addslashes($close_note)."'";
$sql.= ' WHERE rowid = '.$this->id; $sql.= ' WHERE rowid = '.$this->id;
$resql = $this->db->query($sql);
$resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
$this->use_webcal=($conf->global->PHPWEBCALENDAR_BILLSTATUS=='always'?1:0); // On d<>saffecte de la facture les remises li<6C>es
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' SET fk_facture = NULL WHERE fk_facture = '.$this->id;
$resql=$this->db->query($sql);
if ($resql)
{
$this->use_webcal=($conf->global->PHPWEBCALENDAR_BILLSTATUS=='always'?1:0);
// Appel des triggers // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers('BILL_CANCEL',$this,$user,$langs,$conf); $result=$interface->run_triggers('BILL_CANCEL',$this,$user,$langs,$conf);
// Fin appel triggers // Fin appel triggers
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error()." sql=".$sql;
$this->db->rollback();
return -1;
}
}
else
{
$this->error=$this->db->error()." sql=".$sql;
$this->db->rollback();
return -2;
} }
return 1;
} }
/** /**
@@ -836,7 +954,7 @@ class Facture extends CommonObject
// on v<>rifie si la facture est en num<75>rotation provisoire // on v<>rifie si la facture est en num<75>rotation provisoire
$facref = substr($this->ref, 1, 4); $facref = substr($this->ref, 1, 4);
if ($force_number) if ($force_number)
{ {
$numfa = $force_number; $numfa = $force_number;
@@ -910,7 +1028,7 @@ class Facture extends CommonObject
{ {
// Ligne de remise // Ligne de remise
dolibarr_syslog("Facture.class::set_valid: recherche si remise ".$this->lignes[$i]->fk_remise_except." toujours dispo"); dolibarr_syslog("Facture.class::set_valid: recherche si remise ".$this->lignes[$i]->fk_remise_except." toujours dispo");
// On recherche si ligne de remise pas deja attribu<62>e // On recherche si ligne de remise pas deja attribu<62>e
$sql = 'SELECT fk_facture'; $sql = 'SELECT fk_facture';
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except'; $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except';
@@ -923,7 +1041,7 @@ class Facture extends CommonObject
if ($num >= 1) if ($num >= 1)
{ {
dolibarr_syslog("Facture.class::set_valid: top ligne de remise ".$this->lignes[$i]->fk_remise_except." pour ligne de facture ".$this->lignes[$i]->rowid); dolibarr_syslog("Facture.class::set_valid: top ligne de remise ".$this->lignes[$i]->fk_remise_except." pour ligne de facture ".$this->lignes[$i]->rowid);
// On met <20> jour ligne de remise comme utilis<69>e // On met <20> jour ligne de remise comme utilis<69>e
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' SET fk_facture = '.$this->lignes[$i]->rowid; $sql.= ' SET fk_facture = '.$this->lignes[$i]->rowid;
@@ -931,7 +1049,7 @@ class Facture extends CommonObject
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
} }
else else
{ {
@@ -947,7 +1065,7 @@ class Facture extends CommonObject
$this->error=$langs->trans("InvoiceDiscountNotAvailable"); $this->error=$langs->trans("InvoiceDiscountNotAvailable");
dolibarr_syslog("Facture.class::set_valid: Error ".$this->error); dolibarr_syslog("Facture.class::set_valid: Error ".$this->error);
break; break;
} }
} }
else else
{ {
@@ -969,7 +1087,7 @@ class Facture extends CommonObject
$sql = 'SELECT fk_product FROM '.MAIN_DB_PREFIX.'facturedet'; $sql = 'SELECT fk_product FROM '.MAIN_DB_PREFIX.'facturedet';
$sql.= ' WHERE fk_facture = '.$this->id; $sql.= ' WHERE fk_facture = '.$this->id;
$sql.= ' AND fk_product > 0'; $sql.= ' AND fk_product > 0';
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@@ -996,7 +1114,7 @@ class Facture extends CommonObject
$soc=new Societe($this->db); $soc=new Societe($this->db);
$soc->id = $this->socidp; $soc->id = $this->socidp;
$result=$soc->set_as_client(); $result=$soc->set_as_client();
$this->ref = $numfa; $this->ref = $numfa;
$this->use_webcal=($conf->global->PHPWEBCALENDAR_BILLSTATUS=='always'?1:0); $this->use_webcal=($conf->global->PHPWEBCALENDAR_BILLSTATUS=='always'?1:0);
@@ -1017,7 +1135,7 @@ class Facture extends CommonObject
} }
} }
} }
/** /**
* *
* *
@@ -1026,7 +1144,7 @@ class Facture extends CommonObject
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_statut = 0"; $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_statut = 0";
$sql .= " WHERE rowid = $this->id;"; $sql .= " WHERE rowid = $this->id;";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
return 1; return 1;
@@ -1049,7 +1167,7 @@ class Facture extends CommonObject
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET model_pdf = '$modelpdf'"; $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET model_pdf = '$modelpdf'";
$sql .= " WHERE rowid = $this->id AND fk_statut < 2 ;"; $sql .= " WHERE rowid = $this->id AND fk_statut < 2 ;";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
$this->modelpdf=$modelpdf; $this->modelpdf=$modelpdf;
@@ -1127,7 +1245,7 @@ class Facture extends CommonObject
// Calcul du total TTC et de la TVA pour la ligne a partir de // Calcul du total TTC et de la TVA pour la ligne a partir de
// qty, pu, remise_percent et txtva // qty, pu, remise_percent et txtva
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva); $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
@@ -1157,7 +1275,7 @@ class Facture extends CommonObject
$ligne->subprice=$subprice; $ligne->subprice=$subprice;
$ligne->remise=$remise; $ligne->remise=$remise;
$ligne->date_start=$date_start; $ligne->date_start=$date_start;
$ligne->date_end=$date_end; $ligne->date_end=$date_end;
$ligne->ventil=$ventil; $ligne->ventil=$ventil;
$ligne->rang=-1; $ligne->rang=-1;
$ligne->info_bits=$info_bits; $ligne->info_bits=$info_bits;
@@ -1166,12 +1284,12 @@ class Facture extends CommonObject
$ligne->total_tva=$total_tva; $ligne->total_tva=$total_tva;
$ligne->total_ttc=$total_ttc; $ligne->total_ttc=$total_ttc;
$result=$ligne->insert(); $result=$ligne->insert();
if ($result > 0) if ($result > 0)
{ {
// Mise a jour informations denormalisees au niveau de la facture meme // Mise a jour informations denormalisees au niveau de la facture meme
$result=$this->update_price($facid); $result=$this->update_price($facid);
if ($result > 0) if ($result > 0)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
@@ -1213,7 +1331,7 @@ class Facture extends CommonObject
if ($this->brouillon) if ($this->brouillon)
{ {
$this->db->begin(); $this->db->begin();
// Nettoyage param<61>tres // Nettoyage param<61>tres
$remise_percent=price2num($remise_percent); $remise_percent=price2num($remise_percent);
$qty=price2num($qty); $qty=price2num($qty);
@@ -1223,7 +1341,7 @@ class Facture extends CommonObject
// Calcul du total TTC et de la TVA pour la ligne a partir de // Calcul du total TTC et de la TVA pour la ligne a partir de
// qty, pu, remise_percent et txtva // qty, pu, remise_percent et txtva
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva); $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
@@ -1246,7 +1364,7 @@ class Facture extends CommonObject
$ligne=new FactureLigne($this->db); $ligne=new FactureLigne($this->db);
$ligne->rowid=$rowid; $ligne->rowid=$rowid;
$ligne->fetch($rowid); $ligne->fetch($rowid);
$ligne->desc=$desc; $ligne->desc=$desc;
$ligne->price=$price; $ligne->price=$price;
$ligne->qty=$qty; $ligne->qty=$qty;
@@ -1255,12 +1373,12 @@ class Facture extends CommonObject
$ligne->subprice=$subprice; $ligne->subprice=$subprice;
$ligne->remise=$remise; $ligne->remise=$remise;
$ligne->date_start=$date_start; $ligne->date_start=$date_start;
$ligne->date_end=$date_end; $ligne->date_end=$date_end;
$ligne->total_ht=$total_ht; $ligne->total_ht=$total_ht;
$ligne->total_tva=$total_tva; $ligne->total_tva=$total_tva;
$ligne->total_ttc=$total_ttc; $ligne->total_ttc=$total_ttc;
$result=$ligne->update(); $result=$ligne->update();
if ($result > 0) if ($result > 0)
{ {
// Mise a jour info denormalisees au niveau facture // Mise a jour info denormalisees au niveau facture
@@ -1282,16 +1400,45 @@ class Facture extends CommonObject
} }
/** /**
* \brief Supprime une ligne facture de la base * \brief Supprime une ligne facture de la base
* \param rowid id de la ligne de facture a supprimer * \param rowid Id de la ligne de facture a supprimer
*/ */
function deleteline($rowid) function deleteline($rowid)
{ {
dolibarr_syslog("Facture.class::deleteline rowid=".$rowid." ".$this->brouillon);
if ($this->brouillon) if ($this->brouillon)
{ {
$this->db->begin();
// Libere remise liee a ligne de facture
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' SET fk_facture = NULL where fk_facture = '.$rowid;
$result = $this->db->query($sql);
if ($result < 0)
{
$this->error=$this->db->error();
dolibarr_syslog("Facture.class::deleteline Error ".$this->error);
$this->db->rollback();
return -1;
}
// Efface ligne de facture
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE rowid = '.$rowid; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE rowid = '.$rowid;
$result = $this->db->query( $sql); $result = $this->db->query($sql);
$this->update_price($this->id); if ($result < 0)
{
$this->error=$this->db->error();
dolibarr_syslog("Facture.class::deleteline Error ".$this->error);
$this->db->rollback();
return -1;
}
$result=$this->update_price($this->id);
$this->db->commit();
return 1;
} }
} }
@@ -1522,6 +1669,50 @@ class Facture extends CommonObject
} }
} }
/**
* \brief Renvoie l'id de la facture qui la remplace
* \return int <0 si ko, 0 si aucune facture ne remplace, id facture sinon
*/
function getIdNextInvoice()
{
$sql = 'SELECT rowid';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture';
$sql.= ' WHERE fk_facture_source = '.$this->id;
$resql=$this->db->query($sql);
if ($resql)
{
$obj = $this->db->fetch_object($resql);
if ($obj)
{
// Si il y en a
return $obj->rowid;
}
else
{
// Si aucune facture ne remplace
return 0;
}
}
else
{
return -1;
}
}
/**
* \brief Retourne le libell<6C> du type de facture
* \return string Libelle
*/
function getLibType()
{
global $langs;
if ($this->type == 0) return $langs->trans("InvoiceStandard");
if ($this->type == 1) return $langs->trans("InvoiceReplacement");
if ($this->type == 2) return $langs->trans("InvoiceAvoir");
return $langs->trans("Unknown");
}
/** /**
* \brief Retourne le libell<6C> du statut d'une facture (brouillon, valid<69>e, abandonn<6E>e, pay<61>e) * \brief Retourne le libell<6C> du statut d'une facture (brouillon, valid<69>e, abandonn<6E>e, pay<61>e)
* \param mode 0=libell<6C> long, 1=libell<6C> court, 2=Picto + Libell<6C> court, 3=Picto, 4=Picto + Libell<6C> long * \param mode 0=libell<6C> long, 1=libell<6C> court, 2=Picto + Libell<6C> court, 3=Picto, 4=Picto + Libell<6C> long
@@ -1859,7 +2050,7 @@ class Facture extends CommonObject
$ventilExportCompta++; $ventilExportCompta++;
} }
} }
if ($ventilExportCompta <> 0) if ($ventilExportCompta <> 0)
{ {
return 1; return 1;
@@ -1869,8 +2060,8 @@ class Facture extends CommonObject
return 0; return 0;
} }
} }
/** /**
* \brief Renvoi si une facture peut etre supprim<69>e compl<70>tement. * \brief Renvoi si une facture peut etre supprim<69>e compl<70>tement.
* La r<>gle est la suivante: * La r<>gle est la suivante:
@@ -1886,7 +2077,7 @@ class Facture extends CommonObject
$facref = substr($this->ref, 1, 4); $facref = substr($this->ref, 1, 4);
// Si facture non brouillon et non provisoire // Si facture non brouillon et non provisoire
if ($facref != 'PROV' && $conf->compta->enabled && $conf->global->FACTURE_ENABLE_EDITDELETE) if ($facref != 'PROV' && ! $conf->comptaexpert->enabled && $conf->global->FACTURE_ENABLE_EDITDELETE)
{ {
// On ne peut supprimer que la derni<6E>re facture valid<69>e // On ne peut supprimer que la derni<6E>re facture valid<69>e
// pour ne pas avoir de trou dans la num<75>rotation // pour ne pas avoir de trou dans la num<75>rotation
@@ -1898,7 +2089,7 @@ class Facture extends CommonObject
{ {
$maxfacnumber = $this->db->fetch_row($resql); $maxfacnumber = $this->db->fetch_row($resql);
} }
$ventilExportCompta = $this->getVentilExportCompta(); $ventilExportCompta = $this->getVentilExportCompta();
// Si derniere facture et si non ventil<69>e, on peut supprimer // Si derniere facture et si non ventil<69>e, on peut supprimer
@@ -1911,16 +2102,52 @@ class Facture extends CommonObject
{ {
return 1; return 1;
} }
return 0; return 0;
} }
/** /**
* \brief Cr<43><72> une demande de pr<70>l<EFBFBD>vement * \brief Renvoi liste des factures remplacables
* Statut validee + aucun paiement + non paye
* \param socid Id societe
* \return array Tableau des factures ($id => $ref)
*/
function list_replacable_invoices($socid=0)
{
global $conf;
$return = array();
$sql = "SELECT f.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.= " WHERE f.fk_statut = 1 AND f.paye = 0 AND pf.fk_paiement IS NULL";
if ($socid > 0) $sql.=" AND f.fk_soc = ".$socid;
$sql.= " ORDER BY f.facnumber";
dolibarr_syslog("Facture.class::list_replacable_invoices sq=$sql");
$resql=$this->db->query($sql);
if ($resql)
{
while ($obj=$this->db->fetch_object($resql))
{
$return[$obj->rowid]=$obj->facnumber;
}
return $return;
}
else
{
return -1;
}
}
/**
* \brief Cr<43><72> une demande de pr<70>l<EFBFBD>vement
* \param user Utilisateur cr<63>ant la demande * \param user Utilisateur cr<63>ant la demande
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
*/ */
function demande_prelevement($user) function demande_prelevement($user)
{ {
dolibarr_syslog("Facture::demande_prelevement $this->statut $this->paye $this->mode_reglement_id"); dolibarr_syslog("Facture::demande_prelevement $this->statut $this->paye $this->mode_reglement_id");
@@ -2299,7 +2526,7 @@ class FactureLigne
var $libelle; // Label produit var $libelle; // Label produit
var $product_desc; // Description produit var $product_desc; // Description produit
/** /**
* \brief Constructeur d'objets ligne de facture * \brief Constructeur d'objets ligne de facture
* \param DB handler d'acc<63>s base de donn<6E>e * \param DB handler d'acc<63>s base de donn<6E>e
@@ -2349,7 +2576,7 @@ class FactureLigne
$this->fk_code_ventilation = $objp->fk_code_ventilation; $this->fk_code_ventilation = $objp->fk_code_ventilation;
$this->fk_export_compta = $objp->fk_export_compta; $this->fk_export_compta = $objp->fk_export_compta;
$this->rang = $objp->rang; $this->rang = $objp->rang;
$this->ref = $objp->product_ref; $this->ref = $objp->product_ref;
$this->libelle = $objp->product_libelle; $this->libelle = $objp->product_libelle;
$this->product_desc = $objp->product_desc; $this->product_desc = $objp->product_desc;
@@ -2391,7 +2618,7 @@ class FactureLigne
return -1; return -1;
} }
} }
// Insertion dans base de la ligne // Insertion dans base de la ligne
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet';
$sql.= ' (fk_facture, description, price, qty, tva_taux,'; $sql.= ' (fk_facture, description, price, qty, tva_taux,';
@@ -2429,8 +2656,10 @@ class FactureLigne
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'facturedet');
$this->db->commit(); $this->db->commit();
return 1; return $this->rowid;
} }
else else
{ {
@@ -2440,8 +2669,8 @@ class FactureLigne
return -2; return -2;
} }
} }
/** /**
* \brief Mise a jour de l'objet ligne de facture en base * \brief Mise a jour de l'objet ligne de facture en base
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
@@ -2478,7 +2707,7 @@ class FactureLigne
if ($resql) if ($resql)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
@@ -2488,7 +2717,7 @@ class FactureLigne
return -2; return -2;
} }
} }
/** /**
* \brief Mise a jour en base des champs total_xxx de ligne de facture * \brief Mise a jour en base des champs total_xxx de ligne de facture
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
@@ -2510,7 +2739,7 @@ class FactureLigne
if ($resql) if ($resql)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
@@ -2519,7 +2748,7 @@ class FactureLigne
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
} }
} }
?> ?>

View File

@@ -8,6 +8,17 @@ BillsCustomersUnpayedForCompany=Unpayed customers' invoices for %s
BillsSuppliersUnpayed=Unpayed suppliers' invoices BillsSuppliersUnpayed=Unpayed suppliers' invoices
BillsUnpayed=Unpayed BillsUnpayed=Unpayed
BillsStatistics=Invoices statistics BillsStatistics=Invoices statistics
InvoiceStandard=Standard invoice
InvoiceStandardAsk=Standard invoice
InvoiceStandardDesc=This kind of invoice is the common invoice.
InvoiceReplacement=Replacement invoice. Must replace invoice with reference
InvoiceReplacementAsk=Replacement invoice for following invoice
InvoiceReplacementDesc=<b>Replacement invoice</b> is used to cancel and replace completely an invoice with no paiement already recevided.<br>Reference of canceled invoice is required.
InvoiceAvoir=Avoir invoice
InvoiceAvoirAsk=Avoir invoice
InvoiceAvoirDesc=La <b>facture d'avoir</b> est une facture n<>gative destin<69>e <20> compenser une facture comportant un montant sup<75>rieur <20> ce qui a <20>t<EFBFBD> ou sera r<>ellement pay<61> (toutes causes possibles).
ReplaceInvoice=Replace invoice %s
ReplacedByInvoice=Replaced by invoice %s
CardBill=Invoice card CardBill=Invoice card
Invoice=Invoice Invoice=Invoice
Invoices=Invoices Invoices=Invoices
@@ -68,6 +79,8 @@ ErrorVATIntraNotConfigured=Intracommunautary VAT number not yet defined
ErrorNoPaiementModeConfigured=No paiment mode yet defined ErrorNoPaiementModeConfigured=No paiment mode yet defined
ErrorCreateBankAccount=Creat a bank account then go to Setup panel of Invoice module to define paiement modes ErrorCreateBankAccount=Creat a bank account then go to Setup panel of Invoice module to define paiement modes
ErrorBillNotFound=Invoice %s does not exists ErrorBillNotFound=Invoice %s does not exists
ErrorInvoiceAlreadyReplaced=Error, invoice %s has already been replaced
ErrorDiscountAlreadyUsed=Error, discount already used
BillFrom=From BillFrom=From
BillTo=Bill to BillTo=Bill to
ActionsOnBill=Actions on invoice ActionsOnBill=Actions on invoice
@@ -99,6 +112,7 @@ ValidateBill=Validate invoice
NumberOfBills=Nb of invoices NumberOfBills=Nb of invoices
NumberOfBillsByMonth=Nb of invoices by month NumberOfBillsByMonth=Nb of invoices by month
ShowBill=Show invoice ShowBill=Show invoice
ShowInvoice=Show invoice
ShowPayment=Show payment ShowPayment=Show payment
File=File File=File
AlreadyPayed=Already payed AlreadyPayed=Already payed

View File

@@ -8,6 +8,17 @@ BillsCustomersUnpayedForCompany=Factures clients impay
BillsSuppliersUnpayed=Factures fournisseurs impay<61>es BillsSuppliersUnpayed=Factures fournisseurs impay<61>es
BillsUnpayed=Impay<61>es BillsUnpayed=Impay<61>es
BillsStatistics=Statistiques factures BillsStatistics=Statistiques factures
InvoiceStandard=Facture standard
InvoiceStandardAsk=Facture standard
InvoiceStandardDesc=Ce type de facture est la facture traditionnelle. On l'appelle aussi <b>facture de doit</b>.
InvoiceReplacement=Facture de remplacement
InvoiceReplacementAsk=Facture de remplacement de la facture suivante
InvoiceReplacementDesc=La <b>facture de remplacement</b> sert <20> annuler et remplacer une facture existante sur laquelle aucun paiement n'a encore eu lieu.<br>La r<>f<EFBFBD>rence de la facture qui doit <20>tre annul<75>e est obligatoire.
InvoiceAvoir=Facture avoir
InvoiceAvoirAsk=Facture avoir
InvoiceAvoirDesc=La <b>facture d'avoir</b> est une facture n<>gative destin<69>e <20> compenser une facture comportant un montant sup<75>rieur <20> ce qui a <20>t<EFBFBD> ou sera r<>ellement pay<61> (toutes causes possibles).
ReplaceInvoice=Remplace la facture %s
ReplacedByInvoice=Remplac<61>e par la facture %s
CardBill=Fiche facture CardBill=Fiche facture
Invoice=Facture Invoice=Facture
Invoices=Factures Invoices=Factures
@@ -68,6 +79,8 @@ ErrorVATIntraNotConfigured=Num
ErrorNoPaiementModeConfigured=Aucun mode de r<>glement d<>fini ErrorNoPaiementModeConfigured=Aucun mode de r<>glement d<>fini
ErrorCreateBankAccount=Cr<43>er un compte bancaire puis aller dans la configuration du module facture pour d<>finir les modes de r<>glement ErrorCreateBankAccount=Cr<43>er un compte bancaire puis aller dans la configuration du module facture pour d<>finir les modes de r<>glement
ErrorBillNotFound=Facture %s inexistante ErrorBillNotFound=Facture %s inexistante
ErrorInvoiceAlreadyReplaced=Erreur, la facture %s a d<>j<EFBFBD> <20>t<EFBFBD> remplac<61>e
ErrorDiscountAlreadyUsed=Erreur, la remise a d<>j<EFBFBD> <20>t<EFBFBD> attribu<62>e
BillFrom=<3D>metteur BillFrom=<3D>metteur
BillTo=Adress<73> <20> BillTo=Adress<73> <20>
ActionsOnBill=Actions sur la facture ActionsOnBill=Actions sur la facture
@@ -99,6 +112,7 @@ ValidateBill=Valider facture
NumberOfBills=Nb de factures NumberOfBills=Nb de factures
NumberOfBillsByMonth=Nb de factures par mois NumberOfBillsByMonth=Nb de factures par mois
ShowBill=Afficher facture ShowBill=Afficher facture
ShowInvoice=Afficher facture
ShowPayment=Afficher paiement ShowPayment=Afficher paiement
File=Fichier File=Fichier
AlreadyPayed=D<>j<EFBFBD> r<>gl<67> AlreadyPayed=D<>j<EFBFBD> r<>gl<67>

View File

@@ -762,8 +762,8 @@ function img_help($usehelpcursor=1,$usealttitle=1)
$s ='<img '; $s ='<img ';
if ($usehelpcursor) $s.='style="cursor: help;" '; if ($usehelpcursor) $s.='style="cursor: help;" ';
$s.='src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/info.png" border="0"'; $s.='src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/info.png" border="0"';
if ($usealttitle) $s.=' alt="'.$langs->trans("Info").'" title="'.$langs->trans("Info"); if ($usealttitle) $s.=' alt="'.$langs->trans("Info").'" title="'.$langs->trans("Info").'"';
$s.='">'; $s.='>';
return $s; return $s;
} }