Qual: Le statut des factures avait un cycle de vie qui était 0=brouillon puis 1=validé. C'était un autre champ qui servait pour définir le 3eme état, facturé traité (car payé). Cet autre champ reste alimenté mais maintenant en plus le champ statut est passé à 2="traité" ou 3="abandonné" (car remplacée par une autre facture). Le suivi du cycle de vie d'une facture devient plus simple et plus rigoureux. On peut se baser sur le statut uniquement comme pour les autres entités.

This commit is contained in:
Laurent Destailleur 2007-02-20 15:22:41 +00:00
parent cf8d15fd5f
commit 2b37dea3f1
4 changed files with 505 additions and 511 deletions

View File

@ -266,20 +266,9 @@ if ($_POST['action'] == 'confirm_payed_partially' && $_POST['confirm'] == 'yes'
$close_code=$_POST["close_code"]; $close_code=$_POST["close_code"];
$close_note=$_POST["close_note"]; $close_note=$_POST["close_note"];
if ($close_code) if ($close_code)
{
if ($close_code == 'abandon')
{
$result = $fac->set_canceled($user,$close_code,$close_note);
}
elseif ($close_code == 'badcustomer')
{
$result = $fac->set_canceled($user,$close_code,$close_note);
}
else
{ {
$result = $fac->set_payed($user,$close_code,$close_note); $result = $fac->set_payed($user,$close_code,$close_note);
} }
}
else else
{ {
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).'</div>';

View File

@ -66,13 +66,14 @@ class Facture extends CommonObject
var $total; var $total;
var $note; var $note;
var $note_public; var $note_public;
//! 0=brouillon, 1=validé //! 0=brouillon, 1=validée, 2=classée payée partiellement ou complètement, 3=classée abandonnée
var $statut; var $statut;
//! 1 si facture payée COMPLETEMENT, 0 sinon //! 1 si facture payée COMPLETEMENT, 0 sinon (ce champ ne devrait plus servir car insuffisant)
var $paye; var $paye;
//! id facture source si facture de remplacement ou avoir //! id facture source si facture de remplacement ou avoir
var $fk_facture_source; var $fk_facture_source;
//! abandon, replaced, avoir, discount_vat //! Fermeture partielle: discount_vat, bad_customer, abandon
//! Fermeture car abandon suite a remplacement: replaced
var $close_code; var $close_code;
//! Commentaire si mis a paye sans paiement complet //! Commentaire si mis a paye sans paiement complet
var $close_note; var $close_note;
@ -853,10 +854,10 @@ class Facture extends CommonObject
} }
/** /**
* \brief Tag la facture comme payée complètement + appel trigger BILL_PAYED * \brief Tag la facture comme payée complètement (close_code non renseigné) ou partiellement (close_code renseigné) + appel trigger BILL_PAYED
* \param user Objet utilisateur qui modifie * \param user Objet utilisateur qui modifie
* \param close_code Code renseigné si on classe à payée alors que paiement incomplet * \param close_code Code renseigné si on classe à payée complètement alors que paiement incomplet (cas ecompte par exemple)
* \param close_note Commentaire renseigné si on classe à payée alors que paiement incomplet * \param close_note Commentaire renseigné si on classe à payée alors que paiement incomplet (cas ecompte par exemple)
* \return int <0 si ok, >0 si ok * \return int <0 si ok, >0 si ok
*/ */
function set_payed($user,$close_code='',$close_note='') function set_payed($user,$close_code='',$close_note='')
@ -865,8 +866,10 @@ class Facture extends CommonObject
dolibarr_syslog("Facture::set_payed rowid=".$this->id, LOG_DEBUG); dolibarr_syslog("Facture::set_payed rowid=".$this->id, LOG_DEBUG);
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET';
$sql.= ' paye=1'; $sql.= ' fk_statut=2';
if (! $close_code) $sql.= ', paye=1';
if ($close_code) $sql.= ", close_code='".addslashes($close_code)."'"; if ($close_code) $sql.= ", close_code='".addslashes($close_code)."'";
if ($close_note) $sql.= ", close_note='".addslashes($close_note)."'";
$sql.= ' WHERE rowid = '.$this->id; $sql.= ' WHERE rowid = '.$this->id;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -884,8 +887,10 @@ class Facture extends CommonObject
return 1; return 1;
} }
/** /**
* \brief Tag la facture comme non payée complètement + appel trigger BILL_UNPAYED * \brief Tag la facture comme non payée complètement + appel trigger BILL_UNPAYED
* Fonction utilisée quand un paiement prélevement est refusé.
* \param user Objet utilisateur qui modifie * \param user Objet utilisateur qui modifie
* \return int <0 si ok, >0 si ok * \return int <0 si ok, >0 si ok
*/ */
@ -895,7 +900,8 @@ class Facture extends CommonObject
dolibarr_syslog("Facture::set_unpayed rowid=".$this->id, LOG_DEBUG); dolibarr_syslog("Facture::set_unpayed rowid=".$this->id, LOG_DEBUG);
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
$sql.= ' SET paye=0 WHERE rowid = '.$this->id; $sql.= ' SET paye=0, fk_statut=1';
$sql.= ' WHERE rowid = '.$this->id;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
@ -912,21 +918,12 @@ class Facture extends CommonObject
return 1; return 1;
} }
/**
* \brief Tag la facture comme payer partiellement
* \param rowid id de la facture à modifier
*/
function set_paiement_started($rowid)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture set fk_statut=2 WHERE rowid = '.$rowid;
$return = $this->db->query( $sql);
}
/** /**
\brief Tag la facture comme abandonnée + appel trigger BILL_CANCEL \brief Tag la facture comme abandonnée, sans paiement dessus (exemple car facture de remplacement) + appel trigger BILL_CANCEL
\param user Objet utilisateur qui modifie \param user Objet utilisateur qui modifie
\param close_code Code renseigné si on classe à payée alors que paiement incomplet \param close_code Code de fermeture
\param close_note Commentaire renseigné si on classe à payée alors que paiement incomplet \param close_note Commentaire de fermeture
\return int <0 si ok, >0 si ok \return int <0 si ok, >0 si ok
*/ */
function set_canceled($user,$close_code='',$close_note='') function set_canceled($user,$close_code='',$close_note='')
@ -947,6 +944,7 @@ class Facture extends CommonObject
if ($resql) if ($resql)
{ {
// On désaffecte de la facture les remises liées // On désaffecte de la facture les remises liées
// car elles n'ont pas été utilisées vu que la facture est abandonnée.
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' SET fk_facture = NULL WHERE fk_facture = '.$this->id; $sql.= ' SET fk_facture = NULL WHERE fk_facture = '.$this->id;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
@ -1890,8 +1888,8 @@ class Facture extends CommonObject
if (! $paye) if (! $paye)
{ {
if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft'); if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft');
if ($statut == 3 && $alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusClosedUnpayed'); if (($statut == 3 || $statut == 2) && $alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusClosedUnpayed');
if ($statut == 3 && $alreadypayed > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPayedPartially'); if (($statut == 3 || $statut == 2) && $alreadypayed > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPayedPartially');
if ($alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPayed'); if ($alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPayed');
return $langs->trans('Bill'.$prefix.'StatusStarted'); return $langs->trans('Bill'.$prefix.'StatusStarted');
} }
@ -1906,8 +1904,8 @@ class Facture extends CommonObject
if (! $paye) if (! $paye)
{ {
if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft'); if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft');
if ($statut == 3 && $alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusCanceled'); if (($statut == 3 || $statut == 2) && $alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusCanceled');
if ($statut == 3 && $alreadypayed > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPayedPartially'); if (($statut == 3 || $statut == 2) && $alreadypayed > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPayedPartially');
if ($alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPayed'); if ($alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPayed');
return $langs->trans('Bill'.$prefix.'StatusStarted'); return $langs->trans('Bill'.$prefix.'StatusStarted');
} }
@ -1922,8 +1920,8 @@ class Facture extends CommonObject
if (! $paye) if (! $paye)
{ {
if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('Bill'.$prefix.'StatusDraft'); if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('Bill'.$prefix.'StatusDraft');
if ($statut == 3 && $alreadypayed <= 0) return img_picto($langs->trans('StatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled'); if (($statut == 3 || $statut == 2) && $alreadypayed <= 0) return img_picto($langs->trans('StatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled');
if ($statut == 3 && $alreadypayed > 0) return img_picto($langs->trans('BillStatusClosedPayedPartially'),'statut7').' '.$langs->trans('Bill'.$prefix.'StatusClosedPayedPartially'); if (($statut == 3 || $statut == 2) && $alreadypayed > 0) return img_picto($langs->trans('BillStatusClosedPayedPartially'),'statut7').' '.$langs->trans('Bill'.$prefix.'StatusClosedPayedPartially');
if ($alreadypayed <= 0) return img_picto($langs->trans('BillStatusNotPayed'),'statut1').' '.$langs->trans('Bill'.$prefix.'StatusNotPayed'); if ($alreadypayed <= 0) return img_picto($langs->trans('BillStatusNotPayed'),'statut1').' '.$langs->trans('Bill'.$prefix.'StatusNotPayed');
return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('Bill'.$prefix.'StatusStarted'); return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('Bill'.$prefix.'StatusStarted');
} }
@ -1938,8 +1936,8 @@ class Facture extends CommonObject
if (! $paye) if (! $paye)
{ {
if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0'); if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0');
if ($statut == 3 && $alreadypayed <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5'); if (($statut == 3 || $statut == 2) && $alreadypayed <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5');
if ($statut == 3 && $alreadypayed > 0) return img_picto($langs->trans('BillStatusClosedPayedPartially'),'statut7'); if (($statut == 3 || $statut == 2) && $alreadypayed > 0) return img_picto($langs->trans('BillStatusClosedPayedPartially'),'statut7');
if ($alreadypayed <= 0) return img_picto($langs->trans('BillStatusNotPayed'),'statut1'); if ($alreadypayed <= 0) return img_picto($langs->trans('BillStatusNotPayed'),'statut1');
return img_picto($langs->trans('BillStatusStarted'),'statut3'); return img_picto($langs->trans('BillStatusStarted'),'statut3');
} }
@ -1953,8 +1951,8 @@ class Facture extends CommonObject
if (! $paye) if (! $paye)
{ {
if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('BillStatusDraft'); if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('BillStatusDraft');
if ($statut == 3 && $alreadypayed <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled'); if (($statut == 3 || $statut == 2) && $alreadypayed <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled');
if ($statut == 3 && $alreadypayed > 0) return img_picto($langs->trans('BillStatusClosedPayedPartially'),'statut7').' '.$langs->trans('Bill'.$prefix.'StatusClosedPayedPartially'); if (($statut == 3 || $statut == 2) && $alreadypayed > 0) return img_picto($langs->trans('BillStatusClosedPayedPartially'),'statut7').' '.$langs->trans('Bill'.$prefix.'StatusClosedPayedPartially');
if ($alreadypayed <= 0) return img_picto($langs->trans('BillStatusNotPayed'),'statut1').' '.$langs->trans('BillStatusNotPayed'); if ($alreadypayed <= 0) return img_picto($langs->trans('BillStatusNotPayed'),'statut1').' '.$langs->trans('BillStatusNotPayed');
return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('BillStatusStarted'); return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('BillStatusStarted');
} }
@ -1969,8 +1967,8 @@ class Facture extends CommonObject
if (! $paye) if (! $paye)
{ {
if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft').' '.img_picto($langs->trans('BillStatusDraft'),'statut0'); if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft').' '.img_picto($langs->trans('BillStatusDraft'),'statut0');
if ($statut == 3 && $alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusCanceled').' '.img_picto($langs->trans('BillStatusCanceled'),'statut5'); if (($statut == 3 || $statut == 2) && $alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusCanceled').' '.img_picto($langs->trans('BillStatusCanceled'),'statut5');
if ($statut == 3 && $alreadypayed > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPayedPartially').' '.img_picto($langs->trans('BillStatusClosedPayedPartially'),'statut7'); if (($statut == 3 || $statut == 2) && $alreadypayed > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPayedPartially').' '.img_picto($langs->trans('BillStatusClosedPayedPartially'),'statut7');
if ($alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPayed').' '.img_picto($langs->trans('BillStatusNotPayed'),'statut1'); if ($alreadypayed <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPayed').' '.img_picto($langs->trans('BillStatusNotPayed'),'statut1');
return $langs->trans('Bill'.$prefix.'StatusStarted').' '.img_picto($langs->trans('BillStatusStarted'),'statut3'); return $langs->trans('Bill'.$prefix.'StatusStarted').' '.img_picto($langs->trans('BillStatusStarted'),'statut3');
} }

View File

@ -137,13 +137,15 @@ class Paiement
if ($this->total <> 0) // On accepte les montants négatifs pour les rejets de prélèvement if ($this->total <> 0) // On accepte les montants négatifs pour les rejets de prélèvement
{ {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)';
$sql .= ' VALUES (now(), '.$this->db->idate($this->datepaye).', \''.$this->total.'\', '.$this->paiementid.', \''.$this->num_paiement.'\', \''.$this->note.'\', '.$user->id.')'; $sql .= ' VALUES (now(), '.$this->db->idate($this->datepaye).', \''.$this->total.'\', '.$this->paiementid.', \''.$this->num_paiement.'\', \''.addslashes($this->note).'\', '.$user->id.')';
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
dolibarr_syslog("Paiement::Create sql=".$sql);
if ($resql) if ($resql)
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement'); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
// Insere tableau des montants / factures // Insere liens montants / factures
foreach ($this->amounts as $key => $amount) foreach ($this->amounts as $key => $amount)
{ {
$facid = $key; $facid = $key;
@ -152,7 +154,10 @@ class Paiement
$amount = price2num($amount); $amount = price2num($amount);
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount)'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount)';
$sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')'; $sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')';
if (! $this->db->query($sql) )
dolibarr_syslog("Paiement::Create sql=".$sql);
$resql=$this->db->query($sql);
if (! $resql)
{ {
dolibarr_syslog('Paiement::Create Erreur INSERT dans paiement_facture '.$facid); dolibarr_syslog('Paiement::Create Erreur INSERT dans paiement_facture '.$facid);
$error++; $error++;
@ -208,14 +213,14 @@ class Paiement
$this->db->begin(); $this->db->begin();
// Vérifier si paiement porte pas sur une facture à l'état payée // Vérifier si paiement porte pas sur une facture classée
// Si c'est le cas, on refuse la suppression // Si c'est le cas, on refuse la suppression
$billsarray=$this->getBillsArray('paye=1'); $billsarray=$this->getBillsArray('fk_statut > 1');
if (is_array($billsarray)) if (is_array($billsarray))
{ {
if (sizeof($billsarray)) if (sizeof($billsarray))
{ {
$this->error="Impossible de supprimer un paiement portant sur au moins une facture à l'état payé"; $this->error="Impossible de supprimer un paiement portant sur au moins une facture fermée";
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }

View File

@ -769,6 +769,8 @@ alter table llx_adherent add column phone_perso varchar(30) after phone;
alter table llx_adherent add column phone_mobile varchar(30) after phone_perso; alter table llx_adherent add column phone_mobile varchar(30) after phone_perso;
update llx_facture set fk_facture_source=null where fk_facture_source is not null and type = 0; update llx_facture set fk_facture_source=null where fk_facture_source is not null and type = 0;
update llx_facture set fk_statut=2 where paye=1;
update llx_facture set fk_statut=2 where close_code is not null and close_code != '' and close_code != 'replaced';
update llx_boxes set fk_user = 0 where fk_user IS NULL; update llx_boxes set fk_user = 0 where fk_user IS NULL;