Fix for situation invoice (exclude credit not when searching last

invoice to use)
This commit is contained in:
Laurent Destailleur 2020-05-25 00:20:00 +02:00
parent 84ec747109
commit 47465f4108
2 changed files with 17 additions and 17 deletions

View File

@ -3146,10 +3146,10 @@ if ($action == 'create')
print '</div></div>'; print '</div></div>';
// Next situation invoice // Next situation invoice
$opt = $form->selectSituationInvoices(GETPOST('originid'), $socid); $opt = $form->selectSituationInvoices(GETPOST('originid', 'int'), $socid);
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">'; print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
$tmp = '<input type="radio" name="type" value="5"'.(GETPOST('type') == 5 && GETPOST('originid') ? ' checked' : ''); $tmp = '<input type="radio" name="type" value="5"'.(GETPOST('type') == 5 && GETPOST('originid', 'int') ? ' checked' : '');
if ($opt == ('<option value ="0" selected>'.$langs->trans('NoSituations').'</option>') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande')) if ($opt == ('<option value ="0" selected>'.$langs->trans('NoSituations').'</option>') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande'))
$tmp .= ' disabled'; $tmp .= ' disabled';
$tmp .= '> '; $tmp .= '> ';

View File

@ -3804,27 +3804,27 @@ class Form
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture'; $sql .= ' FROM '.MAIN_DB_PREFIX.'facture';
$sql .= ' WHERE entity IN ('.getEntity('invoice').')'; $sql .= ' WHERE entity IN ('.getEntity('invoice').')';
$sql .= ' AND situation_counter>=1'; $sql .= ' AND situation_counter>=1';
$sql .= ' AND fk_soc = '.(int) $socid;
$sql .= ' AND type <> 2';
$sql .= ' ORDER by situation_cycle_ref, situation_counter desc'; $sql .= ' ORDER by situation_cycle_ref, situation_counter desc';
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql && $this->db->num_rows($resql) > 0) { if ($resql && $this->db->num_rows($resql) > 0) {
// Last seen cycle // Last seen cycle
$ref = 0; $ref = 0;
while ($obj = $this->db->fetch_object($resql)) { while ($obj = $this->db->fetch_object($resql)) {
//Same company ? //Same cycle ?
if ($socid == $obj->fk_soc) { if ($obj->situation_cycle_ref != $ref) {
//Same cycle ? // Just seen this cycle
if ($obj->situation_cycle_ref != $ref) { $ref = $obj->situation_cycle_ref;
// Just seen this cycle //not final ?
$ref = $obj->situation_cycle_ref; if ($obj->situation_final != 1) {
//not final ? //Not prov?
if ($obj->situation_final != 1) { if (substr($obj->ref, 1, 4) != 'PROV') {
//Not prov? if ($selected == $obj->rowid) {
if (substr($obj->ref, 1, 4) != 'PROV') { $opt .= '<option value="'.$obj->rowid.'" selected>'.$obj->ref.'</option>';
if ($selected == $obj->rowid) { } else {
$opt .= '<option value="'.$obj->rowid.'" selected>'.$obj->ref.'</option>'; $opt .= '<option value="'.$obj->rowid.'">'.$obj->ref.'</option>';
} else {
$opt .= '<option value="'.$obj->rowid.'">'.$obj->ref.'</option>';
}
} }
} }
} }