Merge remote-tracking branch 'origin/3.3' into develop

Conflicts:
	htdocs/compta/facture/class/facture.class.php
This commit is contained in:
Laurent Destailleur 2013-05-03 10:13:31 +02:00
commit 7382a97223
4 changed files with 77 additions and 46 deletions

View File

@ -114,6 +114,7 @@ WARNING: If you used external modules, some of them may need to be upgraded due
- Fix: [ bug #861 ] Impossible to create a new event in agenda - Fix: [ bug #861 ] Impossible to create a new event in agenda
- Fix: [ bug #827 ] AJAX search does not respect multiprice level - Fix: [ bug #827 ] AJAX search does not respect multiprice level
- Fix: [ bug #865 ] Dolibarr navigation array in project/task do not work - Fix: [ bug #865 ] Dolibarr navigation array in project/task do not work
- Fix: [ bug #866 ] Standing order from an invoice suggests invoice total amount instead of remaining to pay
- Fix: [ bug #788 ] Date of linked interventions are not shown - Fix: [ bug #788 ] Date of linked interventions are not shown

View File

@ -2867,46 +2867,57 @@ class Facture extends CommonInvoice
{ {
$now=dol_now(); $now=dol_now();
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande'; $totalpaye = $this->getSommePaiement();
$sql .= ' (fk_facture, amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib)'; $totalcreditnotes = $this->getSumCreditNotesUsed();
$sql .= ' VALUES ('.$this->id; $totaldeposits = $this->getSumDepositsUsed();
$sql .= ",'".price2num($this->total_ttc)."'"; //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
$sql .= ",".$this->db->idate($now).",".$user->id;
$sql .= ",'".$soc->bank_account->code_banque."'"; // We can also use bcadd to avoid pb with floating points
$sql .= ",'".$soc->bank_account->code_guichet."'"; // For example print 239.2 - 229.3 - 9.9; does not return 0.
$sql .= ",'".$soc->bank_account->number."'"; //$resteapayer=bcadd($this->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
$sql .= ",'".$soc->bank_account->cle_rib."')"; //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
if ( $this->db->query($sql)) $resteapayer = price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
{
return 1; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande';
} $sql .= ' (fk_facture, amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib)';
else $sql .= ' VALUES ('.$this->id;
{ $sql .= ",'".price2num($resteapayer)."'";
$this->error=$this->db->error(); $sql .= ",".$this->db->idate($now).",".$user->id;
dol_syslog(get_class($this).'::demandeprelevement Erreur'); $sql .= ",'".$soc->bank_account->code_banque."'";
return -1; $sql .= ",'".$soc->bank_account->code_guichet."'";
} $sql .= ",'".$soc->bank_account->number."'";
} $sql .= ",'".$soc->bank_account->cle_rib."')";
else if ( $this->db->query($sql))
{ {
$this->error="A request already exists"; return 1;
dol_syslog(get_class($this).'::demandeprelevement Impossible de creer une demande, demande deja en cours'); }
} else
} {
else $this->error=$this->db->error();
{ dol_syslog(get_class($this).'::demandeprelevement Erreur');
$this->error=$this->db->error(); return -1;
dol_syslog(get_class($this).'::demandeprelevement Erreur -2'); }
return -2; }
} else
} {
else $this->error="A request already exists";
{ dol_syslog(get_class($this).'::demandeprelevement Impossible de creer une demande, demande deja en cours');
$this->error="Status of invoice does not allow this"; }
dol_syslog(get_class($this)."::demandeprelevement ".$this->error." $this->statut, $this->paye, $this->mode_reglement_id"); }
return -3; else
} {
} $this->error=$this->db->error();
dol_syslog(get_class($this).'::demandeprelevement Erreur -2');
return -2;
}
}
else
{
$this->error="Status of invoice does not allow this";
dol_syslog(get_class($this)."::demandeprelevement ".$this->error." $this->statut, $this->paye, $this->mode_reglement_id");
return -3;
}
}
/** /**
* Supprime une demande de prelevement * Supprime une demande de prelevement

View File

@ -404,6 +404,15 @@ if ($object->id > 0)
print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right" colspan="2" nowrap>'.price($object->total_ttc).'</td>'; print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right" colspan="2" nowrap>'.price($object->total_ttc).'</td>';
print '<td>'.$langs->trans('Currency'.$conf->currency).'</td></tr>'; print '<td>'.$langs->trans('Currency'.$conf->currency).'</td></tr>';
// We can also use bcadd to avoid pb with floating points
// For example print 239.2 - 229.3 - 9.9; does not return 0.
//$resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
//$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
$resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
print '<tr><td>'.$langs->trans('RemainderToPay').'</td><td align="right" colspan="2" nowrap>'.price($resteapayer).'</td>';
print '<td>'.$langs->trans('Currency'.$conf->currency).'</td></tr>';
// Statut // Statut
print '<tr><td>'.$langs->trans('Status').'</td>'; print '<tr><td>'.$langs->trans('Status').'</td>';
print '<td align="left" colspan="3">'.($object->getLibStatut(4,$totalpaye)).'</td></tr>'; print '<td align="left" colspan="3">'.($object->getLibStatut(4,$totalpaye)).'</td></tr>';

View File

@ -426,14 +426,14 @@ class BonPrelevement extends CommonObject
$facs = array(); $facs = array();
$amounts = array(); $amounts = array();
$facs = $this->getListInvoices(); $facs = $this->getListInvoices(1);
$num=count($facs); $num=count($facs);
for ($i = 0; $i < $num; $i++) for ($i = 0; $i < $num; $i++)
{ {
$fac = new Facture($this->db); $fac = new Facture($this->db);
$fac->fetch($facs[$i]); $fac->fetch($facs[$i][0]);
$amounts[$fac->id] = $fac->total_ttc; $amounts[$fac->id] = $facs[$i][1];
$result = $fac->set_paid($user); $result = $fac->set_paid($user);
} }
$paiement = new Paiement($this->db); $paiement = new Paiement($this->db);
@ -576,9 +576,10 @@ class BonPrelevement extends CommonObject
/** /**
* Get invoice list * Get invoice list
* *
* @param $amounts If you want to get the amount of the order for each invoice
* @return array id of invoices * @return array id of invoices
*/ */
private function getListInvoices() private function getListInvoices($amounts=0)
{ {
global $conf; global $conf;
@ -589,6 +590,7 @@ class BonPrelevement extends CommonObject
* dans un bon de prelevement * dans un bon de prelevement
*/ */
$sql = "SELECT fk_facture"; $sql = "SELECT fk_facture";
if ($amounts) $sql .= ", SUM(pl.amount)";
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
$sql.= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl"; $sql.= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
$sql.= " , ".MAIN_DB_PREFIX."prelevement_facture as pf"; $sql.= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
@ -596,6 +598,7 @@ class BonPrelevement extends CommonObject
$sql.= " AND pl.fk_prelevement_bons = p.rowid"; $sql.= " AND pl.fk_prelevement_bons = p.rowid";
$sql.= " AND p.rowid = ".$this->id; $sql.= " AND p.rowid = ".$this->id;
$sql.= " AND p.entity = ".$conf->entity; $sql.= " AND p.entity = ".$conf->entity;
if ($amounts) $sql.= " GROUP BY fk_facture";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -608,7 +611,14 @@ class BonPrelevement extends CommonObject
while ($i < $num) while ($i < $num)
{ {
$row = $this->db->fetch_row($resql); $row = $this->db->fetch_row($resql);
$arr[$i] = $row[0]; if (!$amounts) $arr[$i] = $row[0];
else
{
$arr[$i] = array(
$row[0],
$row[1]
);
}
$i++; $i++;
} }
} }
@ -1650,4 +1660,4 @@ class BonPrelevement extends CommonObject
} }
?> ?>