2
0
forked from Wavyzz/dolibarr

New: Gestion des avoirs la saisie des factures

This commit is contained in:
Laurent Destailleur
2006-04-04 00:12:45 +00:00
parent f0ca61ce1c
commit b9b4fc5ff6
12 changed files with 613 additions and 375 deletions

View File

@@ -1,6 +1,6 @@
<?PHP
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -172,7 +172,8 @@ if ($_socid > 0)
/*
* Liste de l'historique des remises
*/
$sql = "SELECT rc.rowid,rc.remise_client,".$db->pdate("rc.datec")." as dc, u.code";
$sql = "SELECT rc.rowid,rc.remise_client,".$db->pdate("rc.datec")." as dc,";
$sql.= " u.rowid as user_id, u.code";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE rc.fk_soc =". $objsoc->id;
$sql.= " AND u.rowid = rc.fk_user_author";
@@ -186,7 +187,7 @@ if ($_socid > 0)
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Date").'</td>';
print '<td>'.$langs->trans("Discount").'</td>';
print '<td>'.$langs->trans("User").'</td>';
print '<td align="center">'.$langs->trans("User").'</td>';
print '</tr>';
$i = 0 ;
$num = $db->num_rows($resql);
@@ -198,7 +199,7 @@ if ($_socid > 0)
print '<tr '.$bc[$tag].'>';
print '<td>'.dolibarr_print_date($obj->dc,"%d %B %Y %H:%M").'</td>';
print '<td>'.$obj->remise_client.' %</td>';
print '<td>'.$obj->code.'</td>';
print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->code.'</a></td>';
print '</tr>';
$i++;
}

View File

@@ -94,6 +94,22 @@ if ($_POST['action'] == 'setconditions')
if ($result < 0) dolibarr_print_error($facture->db,$facture->error);
}
if ($_POST['action'] == 'setremisepercent' && $user->rights->facture->creer)
{
$fac = new Facture($db);
$fac->fetch($_POST['facid']);
$result = $fac->set_remise($user, $_POST['remise_percent']);
$_GET['facid']=$_POST['facid'];
}
if ($_POST['action'] == 'setremiseabsolue' && $user->rights->facture->creer)
{
$fac = new Facture($db);
$fac->fetch($_POST['facid']);
$result = $fac->set_remise_absolue($user, $_POST['remise_absolue']);
$_GET['facid']=$_POST['facid'];
}
if ($_POST['action'] == 'classin')
{
$facture = new Facture($db);
@@ -108,6 +124,28 @@ if ($_POST['action'] == 'set_ref_client')
$facture->set_ref_client($_POST['ref_client']);
}
// Classe <20> "valid<69>e"
if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->facture->valider)
{
$fac = new Facture($db);
$fac->fetch($_GET['facid']);
$soc = new Societe($db);
$soc->fetch($fac->socidp);
$result = $fac->set_valid($fac->id, $user, $soc);
if ($result)
{
facture_pdf_create($db, $fac->id);
}
}
// Classe <20> "pay<61>e"
if ($_POST['action'] == 'confirm_payed' && $_POST['confirm'] == 'yes' && $user->rights->facture->paiement)
{
$fac = new Facture($db);
$fac->fetch($_GET['facid']);
$result = $fac->set_payed($user);
}
/*
* Insertion facture
*/
@@ -134,7 +172,7 @@ if ($_POST['action'] == 'add')
$facture->cond_reglement_id = $_POST['cond_reglement_id'];
$facture->mode_reglement_id = $_POST['mode_reglement_id'];
$facture->amount = $_POST['amount'];
$facture->remise = $_POST['remise'];
$facture->remise_absolue = $_POST['remise_absolue'];
$facture->remise_percent = $_POST['remise_percent'];
$facture->ref_client = $_POST['ref_client'];
@@ -303,35 +341,6 @@ if ($_POST['action'] == 'add')
}
}
// Classe <20> "valid<69>e"
if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->facture->valider)
{
$fac = new Facture($db);
$fac->fetch($_GET['facid']);
$soc = new Societe($db);
$soc->fetch($fac->socidp);
$result = $fac->set_valid($fac->id, $user, $soc);
if ($result)
{
facture_pdf_create($db, $fac->id);
}
}
// Classe <20> "pay<61>e"
if ($_POST['action'] == 'confirm_payed' && $_POST['confirm'] == 'yes' && $user->rights->facture->paiement)
{
$fac = new Facture($db);
$fac->fetch($_GET['facid']);
$result = $fac->set_payed($user);
}
if ($_POST['action'] == 'setremise' && $user->rights->facture->creer)
{
$fac = new Facture($db);
$fac->fetch($_GET['facid']);
$result = $fac->set_remise($user, $_POST['remise']);
}
if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && $user->rights->facture->creer)
{
if ($_POST['qty'] && ( $_POST['desc'] || $_POST['idprod']))
@@ -676,45 +685,77 @@ if ($_GET['action'] == 'create')
print '<form name="add" action="facture.php" method="post">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="socid" value="'.$soc->id.'">' ."\n";
print '<input name="facnumber" type="hidden" value="provisoire">';
print '<table class="border" width="100%">';
// Reference
print '<tr><td>'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans('Draft').'</td></tr>';
print '<input name="facnumber" type="hidden" value="provisoire">';
// Societe
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2">'.$soc->nom_url.'</td>';
print '</tr>';
print '<tr><td>'.$langs->trans('Author').'</td><td colspan="2">'.$user->fullname.'</td>';
print '</tr>';
print '<tr><td>'.$langs->trans('Date').'</td><td>';
// Date facture
print '<tr><td>'.$langs->trans('Date').'</td><td colspan="2">';
$html->select_date('','','','','',"add");
print '</td></tr>';
// Conditions de r<>glement
print '<tr><td nowrap>'.$langs->trans('PaymentConditions').'</td><td>';
print '<tr><td nowrap>'.$langs->trans('PaymentConditions').'</td><td colspan="2">';
$html->select_conditions_paiements($cond_reglement_id,'cond_reglement_id');
print '</td></tr>';
// Mode de r<>glement
print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>';
print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
$html->select_types_paiements($mode_reglement_id,'mode_reglement_id');
print '</td></tr>';
// Remise relative
$relative_discount=$soc->remise_client;
print '<tr><td>'.$langs->trans("CustomerRelativeDiscount").'</td>';
print '<td>';
print '<input type="text" name="remise_percent" size="1" value="'.$relative_discount.'"> %';
print '</td><td>'.img_info().' ';
if ($relative_discount)
{
print $langs->trans("CompanyHasRelativeDiscount",$relative_discount);
}
else
{
print $langs->trans("CompanyHasNoRelativeDiscount");
}
print '</td></tr>';
// Remise avoirs
$absolute_discount=$soc->getCurrentDiscount();
print '<tr><td>'.$langs->trans("CustomerAbsoluteDiscount").'</td>';
print '<td>';
print '<input type="text" name="remise_absolue" size="1" value="0"> '.$langs->trans("Currency".$conf->monnaie);
print '</td><td>'.img_info().' ';
if ($absolute_discount)
{
print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie));
}
else
{
print $langs->trans("CompanyHasNoAbsoluteDiscount");
}
print '</td></tr>';
// Projet
if ($conf->projet->enabled)
{
$langs->load('projects');
print '<tr><td>'.$langs->trans('Project').'</td><td>';
print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';
$html->select_projects($societe_id, $projet, 'projetid');
print '</td></tr>';
}
// Note publique
print '<tr>';
print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
print '<td valign="top">';
print '<td valign="top" colspan="2">';
print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">';
if (is_object($propal))
{
@@ -731,8 +772,9 @@ if ($_GET['action'] == 'create')
print '</textarea></td></tr>';
// Note priv<69>e
print '<tr>';
print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
print '<td valign="top">';
print '<td valign="top" colspan="2">';
print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">';
if (is_object($propal))
{
@@ -766,7 +808,7 @@ if ($_GET['action'] == 'create')
print '<input type="hidden" name="amount" value="'.$propal->price.'">'."\n";
print '<input type="hidden" name="total" value="'.$propal->total.'">'."\n";
print '<input type="hidden" name="tva" value="'.$propal->tva.'">'."\n";
print '<input type="hidden" name="remise" value="'.$propal->remise.'">'."\n";
print '<input type="hidden" name="remise_absolue" value="'.$propal->remise_absolue.'">'."\n";
print '<input type="hidden" name="remise_percent" value="'.$propal->remise_percent.'">'."\n";
print '<input type="hidden" name="propalid" value="'.$propal->id.'">';
@@ -781,7 +823,7 @@ if ($_GET['action'] == 'create')
print '<input type="hidden" name="amount" value="'.$commande->total_ht.'">'."\n";
print '<input type="hidden" name="total" value="'.$commande->total_ttc.'">'."\n";
print '<input type="hidden" name="tva" value="'.$commande->tva.'">'."\n";
print '<input type="hidden" name="remise" value="'.$commande->remise.'">'."\n";
print '<input type="hidden" name="remise_absolue" value="'.$commande->remise_absolue.'">'."\n";
print '<input type="hidden" name="remise_percent" value="'.$commande->remise_percent.'">'."\n";
print '<input type="hidden" name="commandeid" value="'.$commande->id.'">';
@@ -793,14 +835,14 @@ if ($_GET['action'] == 'create')
elseif ($_GET['contratid'] > 0)
{
// Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
$contrat->remise=0;
$contrat->remise_absolue=0;
$contrat->remise_percent=$soc->remise_client;
$contrat->update_price();
print '<input type="hidden" name="amount" value="'.$contrat->total_ht.'">'."\n";
print '<input type="hidden" name="total" value="'.$contrat->total_ttc.'">'."\n";
print '<input type="hidden" name="tva" value="'.$contrat->total_tva.'">'."\n";
print '<input type="hidden" name="remise" value="'.$contrat->remise.'">'."\n";
print '<input type="hidden" name="remise_absolue" value="'.$contrat->remise_absolue.'">'."\n";
print '<input type="hidden" name="remise_percent" value="'.$contrat->remise_percent.'">'."\n";
print '<input type="hidden" name="contratid" value="'.$contrat->id.'">';
@@ -813,6 +855,7 @@ if ($_GET['action'] == 'create')
{
print '<tr><td colspan="3">';
// 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><td>'.$langs->trans('Qty').'</td><td>'.$langs->trans('Discount').'</td><td> &nbsp; &nbsp; </td>';
if ($conf->service->enabled)
@@ -828,7 +871,7 @@ if ($_GET['action'] == 'create')
else
$html->select_produits('','idprod'.$i,'',$conf->produit->limit_size);
print '</td>';
print '<td><input type="text" size="3" name="qty'.$i.'" value="1"></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="0">%</td>';
print '<td>&nbsp;</td>';
// Si le module service est actif, on propose des dates de d<>but et fin <20> la ligne
@@ -882,9 +925,10 @@ if ($_GET['action'] == 'create')
// Bouton "Create Draft"
print '<tr><td colspan="3" align="center"><input type="submit" class="button" name="bouton" value="'.$langs->trans('CreateDraft').'"></td></tr>';
print "</form>\n";
print "</table>\n";
print "</form>\n";
// Si creation depuis un propal
if ($_GET['propalid'])
{
@@ -1161,6 +1205,7 @@ else
{
$soc = new Societe($db, $fac->socidp);
$soc->fetch($fac->socidp);
$avoir_en_cours=$soc->getCurrentDiscount();
$author = new User($db);
if ($fac->user_author)
@@ -1227,62 +1272,8 @@ else
// Dates
print '<tr><td>'.$langs->trans('Date').'</td>';
print '<td colspan="3">'.dolibarr_print_date($fac->date,'%A %d %B %Y').'</td>';
print '<td>'.$langs->trans('DateMaxPayment').'</td><td>' . dolibarr_print_date($fac->date_lim_reglement,'%A %d %B %Y');
if ($fac->date_lim_reglement < (time() - $conf->facture->client->warning_delay) && ! $fac->paye && $fac->statut == 1 && ! $fac->am) print img_warning($langs->trans('Late'));
print '</td></tr>';
// Conditions et modes de r<>glement
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('PaymentConditions');
print '</td>';
if ($_GET['action'] != 'editconditions' && $fac->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;facid='.$fac->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($_GET['action'] == 'editconditions')
{
$html->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->cond_reglement_id,'cond_reglement_id');
}
else
{
$html->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->cond_reglement_id,'none');
}
print '</td>';
print '<td width="25%">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('PaymentMode');
print '</td>';
if ($_GET['action'] != 'editmode' && $fac->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;facid='.$fac->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
print '</tr></table>';
print '</td><td width="25%">';
if ($_GET['action'] == 'editmode')
{
$html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'mode_reglement_id');
}
else
{
$html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'none');
}
print '</td></tr>';
// Remise globale
print '<tr><td>'.$langs->trans('GlobalDiscount').'</td>';
if ($fac->brouillon == 1 && $user->rights->facture->creer)
{
print '<td colspan="3">';
print '<form action="facture.php?facid='.$fac->id.'" method="post">';
print '<input type="hidden" name="action" value="setremise">';
print '<input type="text" name="remise" size="1" value="'.$fac->remise_percent.'">% ';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
print '</td>';
}
else
{
print '<td colspan="3">'.$fac->remise_percent.'%</td>';
}
$nbrows=5;
$nbrows=8;
if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++;
print '<td rowspan="'.$nbrows.'" colspan="2" valign="top">';
@@ -1341,6 +1332,50 @@ else
print '</td></tr>';
// Date limite reglement
print '<tr>';
print '<td>'.$langs->trans('DateMaxPayment').'</td>';
print '<td colspan="3">' . dolibarr_print_date($fac->date_lim_reglement,'%A %d %B %Y');
if ($fac->date_lim_reglement < (time() - $conf->facture->client->warning_delay) && ! $fac->paye && $fac->statut == 1 && ! $fac->am) print img_warning($langs->trans('Late'));
print '</td></tr>';
// Conditions de r<>glement
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('PaymentConditions');
print '</td>';
if ($_GET['action'] != 'editconditions' && $fac->brouillon && $user->rights->facture->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;facid='.$fac->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($_GET['action'] == 'editconditions')
{
$html->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->cond_reglement_id,'cond_reglement_id');
}
else
{
$html->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->cond_reglement_id,'none');
}
print '</td></tr>';
// Mode de reglement
print '<tr><td width="25%">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('PaymentMode');
print '</td>';
if ($_GET['action'] != 'editmode' && $fac->brouillon && $user->rights->facture->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;facid='.$fac->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($_GET['action'] == 'editmode')
{
$html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'mode_reglement_id');
}
else
{
$html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'none');
}
print '</td></tr>';
/*
\todo
L'info "Reference commande client" est une carac de la commande et non de la facture.
@@ -1365,10 +1400,37 @@ else
}
}
print '<tr><td>'.$langs->trans('AmountHT').'</td>';
print '<td align="right" colspan="2" nowrap><b>'.price($fac->total_ht).'</b></td>';
print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
// 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++;
}
}
// Montants
print '<tr><td>'.$langs->trans('AmountHT').'</td>';
print '<td align="right" colspan="2" nowrap>'.price($fac->total_ht).'</td>';
print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
print '<tr><td>'.$langs->trans('AmountVAT').'</td><td align="right" colspan="2" nowrap>'.price($fac->total_tva).'</td>';
print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right" colspan="2" nowrap>'.price($fac->total_ttc).'</td>';
@@ -1420,12 +1482,10 @@ else
$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';
if ($conf->global->FAC_ADD_PROD_DESC && !$conf->global->CHANGE_PROD_DESC)
{
$sql.= ', p.description as product_desc';
}
$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;
@@ -1585,6 +1645,100 @@ else
dolibarr_print_error($db);
}
/*
* Lignes de remise
*/
// Remise relative
$var=!$var;
print '<form name="updateligne" action="facture.php" method="post">';
print '<input type="hidden" name="action" value="setremisepercent">';
print '<input type="hidden" name="facid" value="'.$fac->id.'">';
print '<tr class="liste_total"><td>';
print $langs->trans('CustomerRelativeDiscount');
if ($fac->brouillon) print ' <font style="font-weight: normal">('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).')</font>';
print '</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td align="right"><font style="font-weight: normal">';
if ($_GET['action'] == 'editrelativediscount')
{
print '<input type="text" name="remise_percent" size="2" value="'.$fac->remise_percent.'">%';
}
else
{
print $fac->remise_percent?$fac->remise_percent.'%':'&nbsp;';
}
print '</font></td>';
print '<td align="right"><font style="font-weight: normal">';
if ($_GET['action'] != 'editrelativediscount') print $fac->remise_percent?'-'.price($fac->remise_percent*$total/100):$langs->trans("DiscountNone");
else print '&nbsp;';
print '</font></td>';
if ($_GET['action'] != 'editrelativediscount')
{
if ($fac->brouillon && $user->rights->facture->creer)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editrelativediscount&amp;facid='.$fac->id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).'</a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
}
else
{
print '<td colspan="3"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
}
print '</tr>';
print '</form>';
// Remise absolue
$var=!$var;
print '<form name="updateligne" action="facture.php" method="post">';
print '<input type="hidden" name="action" value="setremiseabsolue">';
print '<input type="hidden" name="facid" value="'.$fac->id.'">';
print '<tr class="liste_total"><td>';
print $langs->trans('CustomerAbsoluteDiscount');
if ($fac->brouillon) print ' <font style="font-weight: normal">('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).')</font>';
print '</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td align="right"><font style="font-weight: normal">';
if ($_GET['action'] == 'editabsolutediscount')
{
print '-<input type="text" name="remise_absolue" size="2" value="'.$fac->remise_absolue.'">';
}
else
{
print $fac->remise_absolue?'-'.price($fac->remise_absolue):$langs->trans("DiscountNone");
}
print '</font></td>';
if ($_GET['action'] != 'editabsolutediscount')
{
if ($fac->brouillon && $user->rights->facture->creer)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editabsolutediscount&amp;facid='.$fac->id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).'</a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
}
else
{
print '<td colspan="3"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
}
print '</tr>';
print '</form>';
/*
* Ajouter une ligne
*/

View File

@@ -285,7 +285,7 @@ if ($socid > 0)
print '</td></tr></table>';
print '</td>';
print '<td colspan="3">';
$amount_discount=$societe->getcurrentDiscount();
$amount_discount=$societe->getCurrentDiscount();
if ($amount_discount < 0) dolibarr_print_error($db,$societe->error);
if ($amount_discount > 0) print $amount_discount.'&nbsp;'.$langs->trans("Currency".$conf->monnaie);
else print $langs->trans("None");

View File

@@ -122,8 +122,9 @@ class Facture
$this->mode_reglement = $_facrec->mode_reglement_id;
$this->mode_reglement_id = $_facrec->mode_reglement_id;
$this->amount = $_facrec->amount;
$this->remise = $_facrec->remise;
$this->remise_absolue = $_facrec->remise_absolue;
$this->remise_percent = $_facrec->remise_percent;
$this->remise_absolue = $_facrec->remise;
}
// Definition de la date limite
@@ -138,15 +139,15 @@ class Facture
$totalht = ($amount - $remise);
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture (';
$sql.= ' facnumber, fk_soc, datec, amount, remise, remise_percent,';
$sql.= ' facnumber, fk_soc, datec, amount, remise_absolue, remise_percent,';
$sql.= ' datef,';
$sql.= ' note,';
$sql.= ' note_public,';
$sql.= ' fk_user_author, fk_projet,';
$sql.= ' fk_cond_reglement, fk_mode_reglement, date_lim_reglement, ref_client) ';
$sql.= " VALUES (";
$sql.= "'$number','$socid', now(), '$totalht', '$remise'";
$sql.= ",'$this->remise_percent', ".$this->db->idate($this->date);
$sql.= "'$number','$socid', now(), '$totalht', '".$this->remise_absolue."'";
$sql.= ",'".$this->remise_percent."', ".$this->db->idate($this->date);
$sql.= ",".($this->note?"'".addslashes($this->note)."'":"null");
$sql.= ",".($this->note_public?"'".addslashes($this->note_public)."'":"null");
$sql.= ",".$user->id;
@@ -154,7 +155,7 @@ class Facture
$sql.= ','.$this->cond_reglement_id;
$sql.= ",".$this->mode_reglement_id;
$sql.= ','.$this->db->idate($datelim);
$sql.= ', \''.$this->ref_client.'\')';
$sql.= ", '".$this->ref_client."')";
$resql=$this->db->query($sql);
if ($resql)
@@ -281,7 +282,7 @@ class Facture
/*
* \brief Affecte la remise exceptionnelle
* \todo Plus utilis<69>. A reprendre dans validation facture
*/
function _affect_remise_exceptionnelle()
{
@@ -289,36 +290,9 @@ class Facture
$this->db->begin();
if ($this->remise_exceptionnelle[1] > 0)
{
// Calcul valeur de remise a appliquer (remise) et reliquat
if ($this->remise_exceptionnelle[1] > ($this->total_ht * 0.9))
{
$remise = floor($this->total_ht * 0.9);
$reliquat = $this->remise_exceptionnelle[1] - $remise;
}
else
{
$remise = $this->remise_exceptionnelle[1];
$reliquat=0;
}
$result_insert = $this->addline($this->id,
'Remise exceptionnelle',
'',
(0 - $remise),
1,
'0'); // Une remise est un n<>gatif sur le TTC, on ne doit pas appliquer de TVA,
// sinon on impute une TVA n<>gative.
if ($result_insert < 0)
{
$error++;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql .= ' SET fk_facture = '.$this->id;
$sql .= " ,amount_ht = '".price2num($remise)."'";
$sql .= ' SET fk_facture = '.$this->id.',';
$sql .= " amount_ht = '".price2num($remise)."'";
$sql .= ' WHERE rowid ='.$this->remise_exceptionnelle[0];
$sql .= ' AND fk_soc ='. $this->socidp;
@@ -329,20 +303,6 @@ class Facture
if ($reliquat > 0)
{
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'societe_remise_except';
$sql .= ' (fk_soc, datec, amount_ht, fk_user) ';
$sql .= ' VALUES ';
$sql .= ' ('.$this->socidp;
$sql .= ' ,now()';
$sql .= " ,'".price2num($reliquat)."'";
$sql .= ' ,'.$this->remise_exceptionnelle[3];
$sql .= ')';
if (! $this->db->query( $sql) )
{
$error++;
}
}
}
if (! $error)
@@ -367,7 +327,7 @@ class Facture
{
//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,f.remise_percent';
$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 .= ','.$this->db->pdate('f.datef').' as df, f.fk_projet';
$sql .= ','.$this->db->pdate('f.date_lim_reglement').' as dlr';
$sql .= ', f.note, f.note_public, f.paye, f.fk_statut, f.fk_user_author';
@@ -395,12 +355,13 @@ class Facture
$this->ref = $obj->facnumber;
$this->ref_client = $obj->ref_client;
$this->amount = $obj->amount;
$this->remise_percent = $obj->remise_percent;
$this->remise_absolue = $obj->remise_absolue;
$this->remise = $obj->remise;
$this->total_ht = $obj->total;
$this->total_tva = $obj->tva;
$this->total_ttc = $obj->total_ttc;
$this->paye = $obj->paye;
$this->remise_percent = $obj->remise_percent;
$this->socidp = $obj->fk_soc;
$this->statut = $obj->fk_statut;
$this->date_lim_reglement = $obj->dlr;
@@ -492,83 +453,25 @@ class Facture
$this->client = $client;
}
/**
* \brief Valide la facture
* \param userid id de l'utilisateur qui valide
* \param userid Id de l'utilisateur qui valide
* \return int <0 si ko, >0 si ok
* \remarks Utiliser set_valid directement plutot que cette methode
* \deprecated
*/
function valid($userid)
{
$error = 0;
$user=new User($this->db);
$user->fetch($userid);
if ($this->db->begin())
{
/*
* Lecture de la remise exceptionnelle
*
*/
$sql = 'SELECT rowid, rc.amount_ht, fk_soc, fk_user';
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc';
$sql .= ' WHERE rc.fk_soc ='. $this->socidp;
$sql .= ' AND fk_facture IS NULL';
$resql = $this->db->query($sql) ;
if ( $resql)
{
$nurmx = $this->db->num_rows($resql);
if ($nurmx > 0)
{
$row = $this->db->fetch_row($resql);
$this->remise_exceptionnelle = $row;
}
$this->db->free($resql);
}
else
{
dolibarr_syslog('Facture::Valide Erreur lecture Remise');
$error++;
$soc=new Societe($this->db);
$soc->fetch($this->socidp);
return set_valid($this->rowid,$user,$soc,'');
}
/*
* Affectation de la remise exceptionnelle
*/
if ( $this->_affect_remise_exceptionnelle() <> 0)
{
$error++;
}
else
{
$this->updateprice($this->id);
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET fk_statut = 1, date_valid=now(), fk_user_valid='.$userid;
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;';
if (! $this->db->query($sql) )
{
$error++;
dolibarr_syslog('Facture::Valide Erreur ');
}
}
if ($error == 0)
{
$this->db->commit();
}
else
{
$this->db->rollback();
}
}
else
{
$error++;
}
if ($error > 0)
{
return 0;
}
else
{
return 1;
}
}
/**
* \brief Classe la facture dans un projet
@@ -633,9 +536,7 @@ class Facture
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.$rowid;
if ($this->db->query( $sql) )
{
/*
* On repositionne la remise
*/
// 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 = '.$rowid;
if ($this->db->query( $sql) )
@@ -833,6 +734,7 @@ class Facture
* \param user Utilisateur qui valide la facture
* \param soc Objet societe
* \param force_number R<>f<EFBFBD>rence <20> forcer de la facture
* \return int <0 si ko, >0 si ok
*/
function set_valid($rowid, $user, $soc, $force_number='')
{
@@ -841,6 +743,8 @@ class Facture
$error = 0;
if ($this->brouillon)
{
$this->db->begin();
$action_notify = 2; // ne pas modifier cette valeur
if ($force_number)
{
@@ -851,50 +755,14 @@ class Facture
$numfa = $this->getNextNumRef($soc);
}
$this->db->begin();
/*
* Affectation de la remise exceptionnelle
*
* \todo Appliquer la remise avoir dans les lignes quand brouillon plutot
* qu'au moment de la validation
*/
$sql = 'SELECT rowid, rc.amount_ht, fk_soc, fk_user';
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc';
$sql .= ' WHERE rc.fk_soc ='. $this->socidp;
$sql .= ' AND fk_facture IS NULL';
$resql = $this->db->query($sql) ;
if ($resql)
{
$nurmx = $this->db->num_rows($resql);
if ($nurmx > 0)
{
$row = $this->db->fetch_row($resql);
$this->remise_exceptionnelle = $row;
}
$this->db->free($resql);
}
else
{
dolibarr_syslog('Facture::Valide Erreur lecture Remise');
$error++;
}
if ( $this->_affect_remise_exceptionnelle() <> 0)
{
$error++;
}
else
{
$this->updateprice($this->id);
}
/* Validation de la facture */
// Validation de la facture
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture ';
$sql.= " SET facnumber='".$numfa."', fk_statut = 1, fk_user_valid = ".$user->id;
/* Si l'option est activ<69>e on force la date de facture */
if ($conf->global->FAC_FORCE_DATE_VALIDATION)
{
// Si l'option est activ<69>e, on force la date de facture
$this->date=time();
$datelim=$this->calculate_date_lim_reglement();
$sql.= ', datef='.$this->db->idate($this->date);
@@ -908,11 +776,78 @@ class Facture
}
else
{
dolibarr_syslog("Facture::set_valid() Echec - 10");
dolibarr_syslog("Facture::set_valid() Echec update - 10");
dolibarr_print_error($this->db);
$error++;
}
/*
* Lit les avoirs / remises absolues en cours et les d<>cr<63>mente
*/
$remise_a_decrementee=$this->remise_absolue;
if ($remise_a_decrementee)
{
$sql = 'SELECT rowid, fk_soc, datec, rc.amount_ht as amount, fk_user, description';
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc';
$sql.= ' WHERE rc.fk_soc ='. $this->socidp;
$sql.= ' AND fk_facture IS NULL';
$sql.= ' ORDER BY datec';
$resql = $this->db->query($sql) ;
if ($resql)
{
$nurmx = $this->db->num_rows($resql);
if ($nurmx > 0)
{
$i=0;
while ($i < $nurmx && $remise_a_decrementee && ! $error)
{
$obj = $this->db->fetch_object($resql);
$avoir=$obj->amount;
// On met <20> jour avoir comme affect<63> <20> facture
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' SET fk_facture = '.$this->id.',';
$sql.= " amount_ht = '".price2num(min($remise_a_decrementee,$avoir))."'";
$sql.= ' WHERE rowid ='.$obj->rowid;
dolibarr_syslog("Societe::set_valid Mise a jour avoir sql=$sql");
if (! $this->db->query($sql))
{
$error++;
}
if ($remise_a_decrementee < $avoir)
{
// L'avoir n'a pas <20>t<EFBFBD> compl<70>tement consomm<6D>e, on ins<6E>re ligne du reste
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' (fk_soc, datec, amount_ht, fk_user, fk_facture, description) ';
$sql.= ' VALUES ';
$sql.= ' ('.$this->socidp;
$sql.= ' ,'.$obj->datec;
$sql.= " ,'".price2num($avoir - $remise_a_decrementee)."'";
$sql.= ' ,'.$user->id;
$sql.= ' ,null';
$sql.= " ,'".addslashes($obj->description)."'";
$sql.= ')';
if (! $this->db->query( $sql))
{
$error++;
}
}
$remise_a_decrementee-=min($remise_a_decrementee,$avoir);
$i++;
}
}
$this->db->free($resql);
}
else
{
dolibarr_syslog('Facture::set_valid() Erreur lecture Remise');
$error++;
}
}
/*
* Pour chaque produit, on met a jour indicateur nbvente
* On cr<63>e ici une d<>normalisation des donn<6E>es pas forc<72>ment utilis<69>e.
@@ -950,10 +885,9 @@ class Facture
$result=$interface->run_triggers('BILL_VALIDATE',$this,$user,$langs,$conf);
// Fin appel triggers
$this->db->commit();
/*
* Notify
* \todo Mettre notifications dans triggers
*/
$facref = sanitize_string($this->ref);
$filepdf = $conf->facture->dir_output . '/' . $facref . '/' . $facref . '.pdf';
@@ -962,12 +896,14 @@ class Facture
$notify = New Notify($this->db);
$notify->send($action_notify, $this->socidp, $mesg, 'facture', $rowid, $filepdf);
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
}
@@ -1054,10 +990,12 @@ class Facture
$soc = new Societe($this->db);
$soc->fetch($this->socidp);
$remise_client = $soc->remise_client;
/* La remise est client n'est pas a mettre au niveau ligne de produit mais globale
if ($remise_client > $remise_percent)
{
$remise_percent = $remise_client ;
}
*/
}
if ($remise_percent > 0)
@@ -1206,12 +1144,16 @@ class Facture
/**
* \brief Mise <20> jour des sommes de la facture
* \param facid id de la facture a modifier
* \return int <0 si ko, >0 si ok
*/
function updateprice($facid)
{
include_once DOL_DOCUMENT_ROOT . '/lib/price.lib.php';
$err=0;
$sql = 'SELECT price, qty, tva_taux FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.$facid;
// Lit les lignes detail
$sql = 'SELECT qty, tva_taux, subprice, remise_percent, price';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.$facid;
$result = $this->db->query($sql);
if ($result)
{
@@ -1220,6 +1162,7 @@ class Facture
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
// qty, tva_taux, sub_price = prix unitaire HT, remise_percent, price = prix unitaire HT apres remise %
$products[$i][0] = $obj->price;
$products[$i][1] = $obj->qty;
$products[$i][2] = $obj->tva_taux;
@@ -1230,7 +1173,7 @@ class Facture
/*
*
*/
$calculs = calcul_price($products, $this->remise_percent);
$calculs = calcul_price($products, $this->remise_percent, $this->remise_absolue);
$this->total_remise = $calculs[3];
$this->amount_ht = $calculs[4];
$this->total_ht = $calculs[0];
@@ -1295,26 +1238,64 @@ class Facture
}
/**
* \brief Applique une remise
* \param user
* \brief Applique une remise relative sur facture
* \param user User qui positionne la remise
* \param remise
* \return int <0 si ko, >0 si ok
*/
function set_remise($user, $remise)
{
$remise=trim($remise)?trim($remise):0;
if ($user->rights->facture->creer)
{
$this->remise_percent = $remise ;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET remise_percent = '.price2num($remise);
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
$sql.= ' SET remise_percent = '.price2num($remise);
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;';
if ($this->db->query($sql))
{
$this->remise_percent = $remise;
$this->updateprice($this->id);
return 1;
}
else
{
dolibarr_print_error($this->db);
$this->error=$this->db->error();
return -1;
}
}
}
/**
* \brief Applique une remise absolue sur facture
* \param user User qui positionne la remise
* \param remise
* \return int <0 si ko, >0 si ok
*/
function set_remise_absolue($user, $remise)
{
$remise=trim($remise)?trim($remise):0;
if ($user->rights->facture->creer)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
$sql.= ' SET remise_absolue = '.price2num($remise);
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;';
dolibarr_syslog("Facture::set_remise_absolue sql=$sql");
if ($this->db->query($sql))
{
$this->remise_absolue = $remise;
$this->updateprice($this->id);
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
}
@@ -2239,15 +2220,16 @@ class FactureLigne
// From llx_facturedet
var $desc;
var $qty;
var $price; // Prix HT apres remise %
var $price_ttc;
var $price; // Prix unitaire HT apres remise % de ligne
//var $price_ttc;
var $subprice; // Prix unitaire HT
var $tva_taux;
var $remise;
var $remise_percent;
var $tva_taux; // Taux tva produit/service
var $remise_percent; // % de la remise
var $remise; // Montant unitaire calcul<75> de la remise %
var $produit_id;
var $date_start;
var $date_end;
var $info_bits;
/**
@@ -2268,7 +2250,8 @@ class FactureLigne
function fetch($rowid, $societe_id=0)
{
$sql = 'SELECT fk_product, description, price, qty, rowid, tva_taux, remise, remise_percent,';
$sql.= ' subprice, '.$this->db->pdate('date_start').' as date_start,'.$this->db->pdate('date_end').' as date_end';
$sql.= ' subprice, '.$this->db->pdate('date_start').' as date_start,'.$this->db->pdate('date_end').' as date_end,';
$sql.= ' info_bits';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet WHERE rowid = '.$rowid;
$result = $this->db->query($sql);
if ($result)
@@ -2277,7 +2260,7 @@ class FactureLigne
$this->desc = stripslashes($objp->description);
$this->qty = $objp->qty;
$this->price = $objp->price;
$this->price_ttc = $objp->price_ttc;
//$this->price_ttc = $objp->price_ttc;
$this->subprice = $objp->subprice;
$this->tva_taux = $objp->tva_taux;
$this->remise = $objp->remise;
@@ -2285,6 +2268,7 @@ class FactureLigne
$this->produit_id = $objp->fk_product;
$this->date_start = $objp->date_start;
$this->date_end = $objp->date_end;
$this->info_bits = $objp->info_bits;
$this->db->free($result);
}
else

View File

@@ -888,6 +888,7 @@ class Form
}
print '</select>';
}
/**
* \brief Retourne la liste des modes de paiements possibles
* \param selected Id du mode de paiement pr<70>s<EFBFBD>lectionn<6E>
@@ -917,9 +918,10 @@ class Form
if (eregi('[a-z]', $selected) && $selected == $code) print ' selected="true"';
elseif ($selected == $id) print ' selected="true"';
print '>';
if ($format == 0) print $this->cache_types_paiements_libelle[$id];
if ($format == 1) print $code;
if ($format == 2) print $this->cache_types_paiements_libelle[$id];
if ($format == 0) $value=$this->cache_types_paiements_libelle[$id];
if ($format == 1) $value=$code;
if ($format == 2) $value=$this->cache_types_paiements_libelle[$id];
print $value?$value:'&nbsp;';
print '</option>';
}
print '</select>';
@@ -1421,6 +1423,70 @@ class Form
}
/**
* \brief Affiche formulaire de selection de la remise relative
* \param page Page
* \param selected Valeur remise
* \param htmlname Nom du formulaire select. Si none, non modifiable
*/
function form_remise_percent($page, $selected='', $htmlname='remise_percent')
{
global $langs;
if ($htmlname != "none")
{
print '<form method="post" action="'.$page.'">';
print '<input type="hidden" name="action" value="setremisepercent">';
print '<table class="noborder" cellpadding="0" cellspacing="0">';
print '<tr><td>';
print '<input type="text" name="'.$htmlname.'" size="1" value="'.$selected.'">%';
print '</td>';
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
print '</tr></table></form>';
}
else
{
if ($selected)
{
print $selected;
} else {
print "0%";
}
}
}
/**
* \brief Affiche formulaire de selection de la remise avoir
* \param page Page
* \param selected Valeur <20> appliquer
* \param htmlname Nom du formulaire select. Si none, non modifiable
*/
function form_remise($page, $selected='', $htmlname='remise')
{
global $langs;
if ($htmlname != "none")
{
print '<form method="post" action="'.$page.'">';
print '<input type="hidden" name="action" value="setremise">';
print '<table class="noborder" cellpadding="0" cellspacing="0">';
print '<tr><td>';
print '<input type="text" name="'.$htmlname.'" size="1" value="'.$selected.'">';
print '</td>';
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
print '</tr></table></form>';
}
else
{
if ($selected)
{
print $selected;
} else {
print "0";
}
}
}
/**
* \brief Affiche formulaire de selection des contacts
* \param page Page

View File

@@ -64,10 +64,17 @@ Prospect=Prospect
CustomerCard=Customer Card
Customer=Customer
CustomerDiscount=Customer Discount
CustomerRelativeDiscount=Relative discount
CustomerAbsoluteDiscount=Absolute discount
CustomerAbsoluteDiscountAllUsers=Absolute discount (all users)
CustomerAbsoluteDiscountMy=Absolute discount (my)
CustomerRelativeDiscount=Relative global discount
CustomerAbsoluteDiscount=Absolute global discount
CustomerRelativeDiscountShort=Remise relative
CustomerAbsoluteDiscountShort=Remise absolue
CompanyHasRelativeDiscount=This customer has a discount of %s%%
CompanyHasNoRelativeDiscount=This customer has no discount by default
CompanyHasAbsoluteDiscount=This customer has a %s %s discount credit
CompanyHasNoAbsoluteDiscount=This customer has no discount credit available
CustomerAbsoluteDiscountAllUsers=Absolute discount (granted by all users)
CustomerAbsoluteDiscountMy=Absolute discount (granted by yourself)
DiscountNone=Aucune
Supplier=Supplier
CompanyList=Companies' list
AddContact=Add contact

View File

@@ -64,10 +64,17 @@ Prospect=Prospect
CustomerCard=Fiche Client
Customer=Client
CustomerDiscount=Remise client
CustomerRelativeDiscount=Remise relative
CustomerAbsoluteDiscount=Remise avoirs
CustomerRelativeDiscount=Remise globale relative
CustomerAbsoluteDiscount=Remise globale absolue
CustomerRelativeDiscountShort=Remise relative
CustomerAbsoluteDiscountShort=Remise absolue
CompanyHasRelativeDiscount=Ce client a une remise par d<>faut de %s%%
CompanyHasNoRelativeDiscount=Ce client n'a pas de remise par d<>faut
CompanyHasAbsoluteDiscount=Ce client a %s %s d'avoirs disponibles
CompanyHasNoAbsoluteDiscount=Ce client n'a pas ou plus d'avoirs disponibles
CustomerAbsoluteDiscountAllUsers=Remise avoirs (accord<72>e par tout utilisateur)
CustomerAbsoluteDiscountMy=Remise avoirs (accord<72> personnellement)
DiscountNone=Aucune
Supplier=Fournisseur
CompanyList=Liste des soci<63>t<EFBFBD>s
AddContact=Ajouter contact

View File

@@ -728,7 +728,7 @@ function img_info($alt = "default")
{
global $conf,$langs;
if ($alt=="default") $alt=$langs->trans("Informations");
return '<img style="cursor: help;" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/info.png" border="0" alt="'.$alt.'" title="'.$alt.'">';
return '<img src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/info.png" border="0" alt="'.$alt.'" title="'.$alt.'">';
}
/**

View File

@@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,11 +18,11 @@
*
* $Id$
* $Source$
*
*/
/*! \file htdocs/lib/price.lib.php
\brief librairie contenant les fonctions pour calculer un prix.
/**
\file htdocs/lib/price.lib.php
\brief Librairie contenant les fonctions pour calculer un prix.
\author Rodolphe Quiedeville.
\version $Revision$
@@ -29,14 +30,17 @@
*/
/*!
\brief permet de calculer un prix.
/**
\brief Permet de calculer un prix.
\param products
\param remise_percent
\return result
\param remise_absolue
\return result[0] total_ht
result[1] total_tva
result[2] total_ttc
result[5] tableau des totaux par tva
*/
function calcul_price($products, $remise_percent)
function calcul_price($products, $remise_percent, $remise_absolue=0)
{
$total_ht = 0;
$amount_ht = 0;
@@ -49,7 +53,7 @@ function calcul_price($products, $remise_percent)
{
foreach ($products as $product)
{
$prod_price = $product[0];
$prod_price = $product[0]; // Prix unitaire HT apres remise % de ligne
$prod_qty = $product[1];
$prod_txtva = $product[2];
@@ -59,7 +63,7 @@ function calcul_price($products, $remise_percent)
// incr<63>mentation montant HT hors remise de l'ensemble
$amount_ht += $line_price_ht;
// si une remise est consentie sur l'ensemble
// si une remise relative est consentie sur l'ensemble
if ($remise_percent > 0)
{
// calcul de la remise sur la ligne
@@ -77,6 +81,7 @@ function calcul_price($products, $remise_percent)
// incr<63>mentation du montant TTC de la valeur HT, on traite la TVA ensuite
$total_ttc += $line_price_ht;
// traitement de la tva non per<65>ue r<>cup<75>rable
if ( $prod_txtva >= 0 )
{
@@ -84,8 +89,10 @@ function calcul_price($products, $remise_percent)
// donc on incr<63>mente le total TTC de l'ensemble, de la valeur de TVA de la ligne
$total_ttc += $line_tva;
}
// dans tous les cas, on incr<63>mente le total de TVA
$total_tva += $line_tva;
// on incr<63>mente le tableau de diff<66>rentiation des taux de TVA
// s'il faut rassembler les tva facturables ou non, du m<>me taux
// dans un m<>me ligne du tableau, remplacer la ligne suivante par :
@@ -95,18 +102,25 @@ function calcul_price($products, $remise_percent)
$i++;
}
}
/*
* arrondis
* Si remise absolue, on la retire
*/
$total_ht -= $remise_absolue;
/*
* Gestion des arrondis sur total des prix
*/
$total_ht = round($total_ht, 2);
$total_tva = round($total_tva, 2);
$total_ttc = $total_ht + $total_tva;
/*
*
*/
// Renvoi r<>ponse
$result[0] = $total_ht;
$result[1] = $total_tva;
$result[2] = $total_ttc;
$result[3] = $total_remise;
$result[4] = $amount_ht;

View File

@@ -907,9 +907,12 @@ class Societe
$sql = "SELECT SUM(rc.amount_ht) as amount";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
$sql.= " WHERE rc.fk_soc =". $this->id;
if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id.
if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id;
$sql.= " AND rc.fk_facture IS NULL";
$resql=$this->db->query($sql);
dolibarr_syslog("Societe::getCurrentDiscount sql=$sql");
if ($resql)
{
$obj = $this->db->fetch_object($resql);

View File

@@ -22,6 +22,7 @@ alter table llx_contrat add column note text;
alter table llx_contrat add column note_public text after note;
alter table llx_facture add column note_public text after note;
alter table llx_facture add column remise_absolue real DEFAULT 0 after remise_percent;
alter table llx_propal add column note_public text after note;

View File

@@ -31,11 +31,12 @@ create table llx_facture
date_valid date, -- date de validation
paye smallint DEFAULT 0 NOT NULL,
amount real DEFAULT 0 NOT NULL,
remise_percent real DEFAULT 0, -- remise globale en pourcent
remise real DEFAULT 0,
tva real DEFAULT 0, -- montant tva apres remise globale
total real DEFAULT 0, -- montant total ht apres remise globale
total_ttc real DEFAULT 0, -- montant total ttc apres remise globale
remise_percent real DEFAULT 0, -- remise relative
remise_absolute real DEFAULT 0, -- remise absolue
remise real DEFAULT 0, -- remise totale calculee
tva real DEFAULT 0, -- montant tva apres remise totale
total real DEFAULT 0, -- montant total ht apres remise totale
total_ttc real DEFAULT 0, -- montant total ttc apres remise totale
fk_statut smallint DEFAULT 0 NOT NULL,