Fix: Suite correction bug gestion avoirs

This commit is contained in:
Laurent Destailleur 2007-12-02 19:26:00 +00:00
parent bc6754033c
commit 05efee5db8
7 changed files with 105 additions and 73 deletions

View File

@ -124,10 +124,7 @@ if ($_socid > 0)
dolibarr_fiche_head($head, 'absolutediscount', $objsoc->nom); dolibarr_fiche_head($head, 'absolutediscount', $objsoc->nom);
/*
*
*
*/
print '<form method="POST" action="remx.php?id='.$objsoc->id.'">'; print '<form method="POST" action="remx.php?id='.$objsoc->id.'">';
print '<input type="hidden" name="action" value="setremise">'; print '<input type="hidden" name="action" value="setremise">';
@ -138,7 +135,7 @@ if ($_socid > 0)
$sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user"; $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
$sql.= " WHERE rc.fk_soc =". $objsoc->id; $sql.= " WHERE rc.fk_soc =". $objsoc->id;
$sql.= " AND fk_facture IS NULL"; $sql.= " AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
$sql.= " GROUP BY rc.fk_user"; $sql.= " GROUP BY rc.fk_user";
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
@ -181,7 +178,7 @@ if ($_socid > 0)
/* /*
* Liste remises fixes restant en cours * Liste remises fixes restant en cours (= liees a acune facture ni ligne de facture)
*/ */
$sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,"; $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
$sql.= $db->pdate("rc.datec")." as dc, rc.description,"; $sql.= $db->pdate("rc.datec")." as dc, rc.description,";
@ -191,7 +188,8 @@ if ($_socid > 0)
$sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
$sql.= " WHERE rc.fk_soc =". $objsoc->id; $sql.= " WHERE rc.fk_soc =". $objsoc->id;
$sql.= " AND u.rowid = rc.fk_user AND rc.fk_facture IS NULL"; $sql.= " AND u.rowid = rc.fk_user";
$sql.= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
$sql.= " ORDER BY rc.datec DESC"; $sql.= " ORDER BY rc.datec DESC";
$resql=$db->query($sql); $resql=$db->query($sql);
@ -252,10 +250,11 @@ if ($_socid > 0)
print '<br />'; print '<br />';
/* /*
* Liste ristournes appliquées * Liste ristournes appliquées (=liees a une ligne de facture ou facture)
*/ */
$sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,"; // Remises liees a lignes de factures
$sql.= $db->pdate("rc.datec")." as dc, rc.description, rc.fk_facture,"; $sql = "(SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
$sql.= $db->pdate("rc.datec")." as dc, rc.description, rc.fk_facture_line, rc.fk_facture,";
$sql.= " rc.fk_facture_source,"; $sql.= " rc.fk_facture_source,";
$sql.= " u.login, u.rowid as user_id,"; $sql.= " u.login, u.rowid as user_id,";
$sql.= " f.rowid, f.facnumber,"; $sql.= " f.rowid, f.facnumber,";
@ -266,10 +265,26 @@ if ($_socid > 0)
$sql.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc"; $sql.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
$sql.= " WHERE rc.fk_soc =". $objsoc->id; $sql.= " WHERE rc.fk_soc =". $objsoc->id;
$sql.= " AND rc.fk_facture = fc.rowid"; $sql.= " AND rc.fk_facture_line = fc.rowid";
$sql.= " AND fc.fk_facture = f.rowid"; $sql.= " AND fc.fk_facture = f.rowid";
$sql.= " AND rc.fk_user = u.rowid"; $sql.= " AND rc.fk_user = u.rowid)";
$sql.= " ORDER BY rc.datec DESC"; $sql.= " UNION ";
// Remises liees a factures
$sql.= "(SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
$sql.= $db->pdate("rc.datec")." as dc, rc.description, rc.fk_facture_line, rc.fk_facture,";
$sql.= " rc.fk_facture_source,";
$sql.= " u.login, u.rowid as user_id,";
$sql.= " f.rowid, f.facnumber,";
$sql.= " fa.facnumber as ref, fa.type as type";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " , ".MAIN_DB_PREFIX."user as u";
$sql.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
$sql.= " WHERE rc.fk_soc =". $objsoc->id;
$sql.= " AND rc.fk_facture = f.rowid";
$sql.= " AND rc.fk_user = u.rowid)";
$sql.= " ORDER BY dc DESC";
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)

View File

@ -105,27 +105,29 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes')
if (($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) if (($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE)
|| ($_GET['action'] == 'deleteline' && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE)) || ($_GET['action'] == 'deleteline' && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE))
{ {
if ($user->rights->facture->creer) if ($user->rights->facture->creer)
{ {
$fac = new Facture($db); $fac = new Facture($db);
$fac->fetch($_GET['facid']); $fac->fetch($_GET['facid']);
$result = $fac->deleteline($_GET['rowid'], $user); $result = $fac->deleteline($_GET['rowid'], $user);
if ($result > 0) if ($result > 0)
{ {
if ($_REQUEST['lang_id']) if ($_REQUEST['lang_id'])
{ {
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang($_REQUEST['lang_id']);
} }
facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs);
}
else Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$_GET['facid']);
{ exit;
print $fac->error; }
} else
} {
Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$_GET['facid']); $mesg='<div clas="error">'.$fac->error.'</div>';
exit; $_GET['action']='';
}
}
} }
// Validation // Validation

View File

@ -450,7 +450,6 @@ class Facture extends CommonObject
$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->type = $obj->type;
$this->datep = $obj->dp;
$this->date = $obj->df; $this->date = $obj->df;
$this->amount = $obj->amount; $this->amount = $obj->amount;
$this->remise_percent = $obj->remise_percent; $this->remise_percent = $obj->remise_percent;
@ -1543,25 +1542,31 @@ 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
*/ * \return int <0 if KO, >0 if OK
function deleteline($rowid, $user='') */
{ function deleteline($rowid, $user='')
global $langs, $conf; {
global $langs, $conf;
dolibarr_syslog("Facture::Deleteline rowid=".$rowid, LOG_DEBUG); dolibarr_syslog("Facture::Deleteline rowid=".$rowid, LOG_DEBUG);
if ($this->brouillon) if (! $this->brouillon)
{ {
$this->db->begin(); $this->error='ErrorBadStatus';
return -1;
}
$this->db->begin();
// Libere remise liee a ligne de facture // Libere remise liee a ligne de facture
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' SET fk_facture = NULL where fk_facture = '.$rowid; $sql.= ' SET fk_facture_line = NULL where fk_facture_line = '.$rowid;
dolibarr_syslog("Facture::Deleteline sql=".$sql);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result < 0) if (! $result)
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dolibarr_syslog("Facture::Deleteline Error ".$this->error); dolibarr_syslog("Facture::Deleteline Error ".$this->error);
@ -1571,8 +1576,9 @@ class Facture extends CommonObject
// Efface ligne de facture // Efface ligne de facture
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE rowid = '.$rowid; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE rowid = '.$rowid;
dolibarr_syslog("Facture::Deleteline sql=".$sql);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result < 0) if (! $result)
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dolibarr_syslog("Facture::Deleteline Error ".$this->error); dolibarr_syslog("Facture::Deleteline Error ".$this->error);
@ -1591,8 +1597,7 @@ class Facture extends CommonObject
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
}
/** /**
\brief Mise à jour des sommes de la facture et calculs denormalises \brief Mise à jour des sommes de la facture et calculs denormalises

View File

@ -2319,7 +2319,7 @@ class Form
if (! $filter || $filter=='fk_facture_source IS NULL') print $langs->trans("CompanyHasAbsoluteDiscount",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': '; if (! $filter || $filter=='fk_facture_source IS NULL') print $langs->trans("CompanyHasAbsoluteDiscount",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': ';
else print $langs->trans("CompanyHasCreditNote",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': '; else print $langs->trans("CompanyHasCreditNote",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': ';
// print $langs->trans("AvailableGlobalDiscounts").': '; // print $langs->trans("AvailableGlobalDiscounts").': ';
$newfilter='fk_facture IS NULL'; // Remises disponibles $newfilter='fk_facture IS NULL AND fk_facture_line IS NULL'; // Remises disponibles
if ($filter) $newfilter.=' AND '.$filter; if ($filter) $newfilter.=' AND '.$filter;
print $this->select_remises('',$htmlname,$newfilter,$socid); print $this->select_remises('',$htmlname,$newfilter,$socid);
print '</td>'; print '</td>';

View File

@ -948,11 +948,12 @@ function migrate_price_facture($db,$langs,$conf)
print '<b>'.$langs->trans('MigrationInvoice')."</b><br>\n"; print '<b>'.$langs->trans('MigrationInvoice')."</b><br>\n";
// Liste des lignes facture non a jour // Liste des lignes facture non a jour
$sql = "SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_taux, "; $sql = "SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_taux, fd.total_ttc,";
$sql.= " f.rowid as facid, f.remise_percent as remise_percent_global"; $sql.= " f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
$sql.= " FROM ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."facture as f"; $sql.= " FROM ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."facture as f";
$sql.= " WHERE fd.fk_facture = f.rowid"; $sql.= " WHERE fd.fk_facture = f.rowid";
$sql.= " AND ((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL)"; $sql.= " AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
//print $sql;
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
@ -970,6 +971,7 @@ function migrate_price_facture($db,$langs,$conf)
$txtva = $obj->tva_taux; $txtva = $obj->tva_taux;
$remise_percent = $obj->remise_percent; $remise_percent = $obj->remise_percent;
$remise_percent_global = $obj->remise_percent_global; $remise_percent_global = $obj->remise_percent_global;
$total_ttc_f = $obj->total_ttc_f;
// On met a jour les 3 nouveaux champs // On met a jour les 3 nouveaux champs
$facligne= new FactureLigne($db); $facligne= new FactureLigne($db);
@ -989,28 +991,31 @@ function migrate_price_facture($db,$langs,$conf)
$facligne->update_total(); $facligne->update_total();
/* On touche pas a facture mere /* On touche a facture mere uniquement si total_ttc = 0 */
$facture = new Facture($db); if (! $total_ttc_f)
$facture->id=$obj->facid;
if ( $facture->fetch($facture->id) >= 0)
{ {
if ( $facture->update_price($facture->id) > 0 ) $facture = new Facture($db);
$facture->id=$obj->facid;
if ( $facture->fetch($facture->id) >= 0)
{ {
print ". "; if ( $facture->update_price($facture->id) > 0 )
{
print "X ";
}
else
{
print "Error id=".$facture->id;
$err++;
}
} }
else else
{ {
print "Error id=".$facture->id; print "Error #3";
$err++; $err++;
} }
} }
else
{
print "Error #3";
$err++;
}
*/
$i++; $i++;
} }
} }

View File

@ -1036,7 +1036,7 @@ class Societe
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
$sql.= " WHERE rc.fk_soc =". $this->id; $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"; $sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)";
if ($filter) $sql.=' AND '.$filter; if ($filter) $sql.=' AND '.$filter;
dolibarr_syslog("Societe::getCurrentDiscount sql=".$sql,LOG_DEBUG); dolibarr_syslog("Societe::getCurrentDiscount sql=".$sql,LOG_DEBUG);

View File

@ -1124,6 +1124,10 @@ insert into llx_c_pays (rowid,code,libelle) values (246, 'MF', 'Saint-Martin' )
ALTER TABLE llx_boxes ADD UNIQUE INDEX uk_boxes (box_id, position, fk_user); ALTER TABLE llx_boxes ADD UNIQUE INDEX uk_boxes (box_id, position, fk_user);
-- Nettoyage vieux enregistrement detail pourris
delete from llx_facturedet where price = 0 and subprice = 0 and remise_percent = 0 and total_ttc = 0 and total_ht = 0;
-- Drop constraints to allow rename -- Drop constraints to allow rename
ALTER TABLE llx_societe_remise_except drop foreign key fk_societe_remise_fk_facture; ALTER TABLE llx_societe_remise_except drop foreign key fk_societe_remise_fk_facture;
ALTER TABLE llx_societe_remise_except drop index idx_societe_remise_except_fk_facture; ALTER TABLE llx_societe_remise_except drop index idx_societe_remise_except_fk_facture;
@ -1141,5 +1145,6 @@ ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_factur
-- Corrige statut avoir transforme en reduc ou reduc supprime apres coup -- Corrige statut avoir transforme en reduc ou reduc supprime apres coup
-- V4.1 update llx_facture set paye=0, fk_statut=1 where paye=1 and type=2 and rowid not in (select fk_facture_source from llx_societe_remise_except); -- V4.1 update llx_facture set paye=0, fk_statut=1 where paye=1 and type=2 and rowid not in (select fk_facture_source from llx_societe_remise_except);
-- Corrige avoirs affectes en ligne a affectation sur facture -- Corrige avoirs affectes en ligne a affectation sur facture. On met total a null pour permettre recalcul par upgrade2
-- V4.1 update llx_societe_remise_except as r set fk_facture_line = NULL, fk_facture = (select fk_facture from llx_facturedet where rowid = r.fk_facture_line) -- V4.1 update llx_facture set total_ttc = NULL where rowid in (select fk_facture from llx_facturedet where description = '(CREDIT_NOTE)');
-- V4.1 delete from llx_facturedet where description = '(CREDIT_NOTE)';