diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 04337bf8a72..374444e0fbc 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2147,6 +2147,65 @@ if (empty($reshook)) header('Location: ' . $_SERVER["PHP_SELF"] . '?facid=' . $id); // Pour reaffichage de la fiche en cours d'edition exit(); } + + // Outing situation invoice from cycle + elseif ($action == 'confirm_situationout' && $confirm == 'yes' && $user->rights->facture->creer) + { + $object->fetch($id); + + if ($object->statut == Facture::STATUS_VALIDATED + && $user->rights->facture->creer + && !$objectidnext + && $object->is_last_in_cycle() + && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) + //&& ($object->total_ttc - $totalcreditnotes) == 0 + ) + { + $outingError = 0; + $newCycle = $object->newCycle(); // we need to keep the "situation behavior" so we place it on a new situation cycle + if($newCycle > 1) + { + $lastCycle = $object->situation_cycle_ref; + $object->situation_cycle_ref = $newCycle; + $object->situation_counter = 1; + $object->situation_final = 1; + if($object->update($user) > 0) + { + + // now, credit note must follow + $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture '; + $sql.= ' SET situation_cycle_ref='.intval($newCycle); + $sql.= ' AND situation_counter='.$object->situation_counter; + $sql.= ' WHERE situation_cycle_ref='.intval($lastCycle); + //$sql.= ' AND situation_counter='.$object->situation_counter; + $sql.= ' AND fk_facture_source='.$object->id; + $sql.= ' AND type='.Facture::TYPE_CREDIT_NOTE; + + // TODO : change each progression persent on each lines + + $resql=$db->query($sql); + if ($resql) + { + setEventMessages($langs->trans('Updated')); + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + } + else + { + setEventMessages($langs->trans('ErrorOutingSituationInvoiceCreditNote'), array(), 'errors'); + } + } + else + { + setEventMessages($langs->trans('ErrorOutingSituationInvoiceOnUpdate'), array(), 'errors'); + } + } + else + { + setEventMessages($langs->trans('ErrorFindNextSituationInvoice'), array(), 'errors'); + } + } + } // Actions when printing a doc from card include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; @@ -3108,6 +3167,24 @@ else if ($id > 0 || ! empty($ref)) $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('DeleteBill'), $text, 'confirm_delete', '', 'no', 1); } } + + // Confirmation to remove invoice from cycle + if ($action == 'situationout') { + $text = $langs->trans('ConfirmRemoveSituationFromCycle', $object->ref); + $label = $langs->trans("ConfirmOuting"); + $formquestion = array(); + // remove situation from cycle + if ($object->statut == Facture::STATUS_VALIDATED + && $user->rights->facture->creer + && !$objectidnext + && $object->is_last_in_cycle() + && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) + ) + { + $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $label, $text, 'confirm_situationout', $formquestion, "yes", 1); + } + } // Confirmation of validation if ($action == 'valid') @@ -3798,23 +3875,27 @@ else if ($id > 0 || ! empty($ref)) if ($object->type == Facture::TYPE_SITUATION && ! empty($conf->global->INVOICE_USE_SITUATION)) { - if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0) - print '
| ' . $langs->trans('ListOfSituationInvoices') . ' | '; + print ''; + print ' | ' . $langs->trans('Situation') . ' | '; + if (! empty($conf->banque->enabled)) print ''; + print ' | ' . $langs->trans('AmountHT') . ' | '; + print '' . $langs->trans('AmountTTC') . ' | '; + print ''; + print ' |
| ' . $langs->trans('ListOfSituationInvoices') . ' | '; - print ''; - print ' | ' . $langs->trans('Situation') . ' | '; - if (! empty($conf->banque->enabled)) print ''; - print ' | ' . $langs->trans('AmountHT') . ' | '; - print '' . $langs->trans('AmountTTC') . ' | '; - print ''; - print ' |