Merge pull request #3969 from FHenry/3.8

FIX : better fix for #3805
This commit is contained in:
Laurent Destailleur 2015-11-12 15:08:34 +01:00
commit 924db5b8aa

View File

@ -3677,22 +3677,22 @@ class Facture extends CommonInvoice
*/ */
function is_last_in_cycle() function is_last_in_cycle()
{ {
if (empty($this->situation_cycle_ref)) { if (!empty($this->situation_cycle_ref)) {
// No point in testing anything if we're not inside a cycle // No point in testing anything if we're not inside a cycle
return false; $sql = 'SELECT max(situation_counter) FROM ' . MAIN_DB_PREFIX . 'facture WHERE situation_cycle_ref = ' . $this->situation_cycle_ref;
} $resql = $this->db->query($sql);
$sql = 'SELECT max(situation_counter) FROM ' . MAIN_DB_PREFIX . 'facture WHERE situation_cycle_ref = ' . $this->situation_cycle_ref; if ($resql && $resql->num_rows > 0) {
$resql = $this->db->query($sql); $res = $this->db->fetch_array($resql);
$last = $res['max(situation_counter)'];
if ($resql && $resql->num_rows > 0) { return ($last == $this->situation_counter);
$res = $this->db->fetch_array($resql); } else {
$last = $res['max(situation_counter)']; $this->error = $this->db->lasterror();
return ($last == $this->situation_counter); dol_syslog(get_class($this) . "::select Error " . $this->error, LOG_ERR);
return false;
}
} else { } else {
$this->error = $this->db->lasterror(); return true;
dol_syslog(get_class($this) . "::select Error " . $this->error, LOG_ERR);
return false;
} }
} }