diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 21698339c67..123f47b3db2 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -109,7 +109,7 @@ class FactureRec extends CommonInvoice $this->nb_gen_max=empty($this->nb_gen_max)?0:$this->nb_gen_max; $this->auto_validate=empty($this->auto_validate)?0:$this->auto_validate; $this->generate_pdf = empty($this->generate_pdf)?0:$this->generate_pdf; - + $this->db->begin(); // Charge facture modele @@ -356,7 +356,7 @@ class FactureRec extends CommonInvoice $this->usenewprice = $obj->usenewprice; $this->auto_validate = $obj->auto_validate; $this->generate_pdf = $obj->generate_pdf; - + if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; // Retreive all extrafield for thirdparty @@ -902,6 +902,7 @@ class FactureRec extends CommonInvoice $sql.= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency $sql.= " AND (date_when IS NULL OR date_when <= '".$db->idate($today)."')"; $sql.= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)'; + $sql.= ' AND suspended = 0'; $sql.= $db->order('entity', 'ASC'); //print $sql;exit; @@ -940,7 +941,6 @@ class FactureRec extends CommonInvoice $facture->brouillon = 1; $facture->date = $facturerec->date_when; // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later. $facture->socid = $facturerec->socid; - $facture->suspended = 0; $invoiceidgenerated = $facture->create($user); if ($invoiceidgenerated <= 0) @@ -1035,9 +1035,9 @@ class FactureRec extends CommonInvoice * @param integer $alreadypaid Not used * @return string Label */ - function getLibStatut($mode=0,$alreadypaid=-1) + function getLibStatut($mode=0) { - return $this->LibStatut($this->frequency?1:0, $this->suspended, $mode, $alreadypaid, $this->type); + return $this->LibStatut($this->frequency?1:0, $this->suspended, $mode, empty($this->type)?0:$this->type); } /** @@ -1046,22 +1046,21 @@ class FactureRec extends CommonInvoice * @param int $recur Is it a recurring invoice ? * @param int $status Id status (suspended or not) * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=long label + picto - * @param int $alreadypaid Not used * @param int $type Type invoice * @return string Libelle du statut */ - function LibStatut($recur,$status,$mode=0,$alreadypaid=-1,$type=0) + function LibStatut($recur, $status, $mode=0, $type=0) { global $langs; $langs->load('bills'); - //print "$recur,$status,$mode,$alreadypaid,$type"; + //print "$recur,$status,$mode,$type"; if ($mode == 0) { $prefix=''; if ($recur) { - if ($status == 1) return $langs->trans('Suspended'); // credit note + if ($status == 1) return $langs->trans('Disabled'); // credit note else return $langs->trans('Active'); } else return $langs->trans("Draft"); @@ -1071,7 +1070,7 @@ class FactureRec extends CommonInvoice $prefix='Short'; if ($recur) { - if ($status == 1) return $langs->trans('Suspended'); + if ($status == 1) return $langs->trans('Disabled'); else return $langs->trans('Active'); } else return $langs->trans("Draft"); @@ -1080,7 +1079,7 @@ class FactureRec extends CommonInvoice { if ($recur) { - if ($status == 1) return img_picto($langs->trans('Suspended'),'statut6').' '.$langs->trans('Suspended'); + if ($status == 1) return img_picto($langs->trans('Disabled'),'statut6').' '.$langs->trans('Disabled'); else return img_picto($langs->trans('Active'),'statut4').' '.$langs->trans('Active'); } else return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft'); @@ -1090,7 +1089,7 @@ class FactureRec extends CommonInvoice if ($recur) { $prefix='Short'; - if ($status == 1) return img_picto($langs->trans('Suspended'),'statut6'); + if ($status == 1) return img_picto($langs->trans('Disabled'),'statut6'); else return img_picto($langs->trans('Active'),'statut4'); } else return img_picto($langs->trans('Draft'),'statut0'); @@ -1100,7 +1099,7 @@ class FactureRec extends CommonInvoice $prefix=''; if ($recur) { - if ($type == 1) return img_picto($langs->trans('Suspended'),'statut6').' '.$langs->trans('Suspended'); + if ($status == 1) return img_picto($langs->trans('Disabled'),'statut6').' '.$langs->trans('Disabled'); else return img_picto($langs->trans('Active'),'statut4').' '.$langs->trans('Active'); } else return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft'); @@ -1111,7 +1110,7 @@ class FactureRec extends CommonInvoice if ($mode == 5) $prefix='Short'; if ($recur) { - if ($status == 1) return ''.$langs->trans('Suspended').' '.img_picto($langs->trans('Suspended'),'statut6'); + if ($status == 1) return ''.$langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut6'); else return ''.$langs->trans('Active').' '.img_picto($langs->trans('Active'),'statut4'); } else return $langs->trans('Draft').' '.img_picto($langs->trans('Active'),'statut0'); diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 4db3040c9c7..8008a814bae 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -359,6 +359,54 @@ if (empty($reshook)) $object->setModelpdf(GETPOST('modelpdf', 'alpha')); } + // Set status disabled + elseif ($action == 'disable' && $user->rights->facture->creer) + { + $db->begin(); + + $object->fetch($id); + + $res = $object->setValueFrom('suspended', 1); + if ($res <= 0) + { + $error++; + } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + // Set status enabled + elseif ($action == 'enable' && $user->rights->facture->creer) + { + $db->begin(); + + $object->fetch($id); + + $res = $object->setValueFrom('suspended', 0); + if ($res <= 0) + { + $error++; + } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + setEventMessages($object->error, $object->errors, 'errors'); + } + } + // Delete line if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer) { @@ -831,30 +879,30 @@ if (empty($reshook)) // Update line if (! $error) - { - $result = $object->updateline( - GETPOST('lineid'), - $description, - $pu_ht, - $qty, - $vat_rate, - $localtax1_rate, - $localtax1_rate, - GETPOST('productid'), - GETPOST('remise_percent'), - 'HT', - $info_bits, - 0, - 0, - $type, - 0, - $special_code, - $label, - GETPOST('units') - ); - - if ($result >= 0) { + $result = $object->updateline( + GETPOST('lineid'), + $description, + $pu_ht, + $qty, + $vat_rate, + $localtax1_rate, + $localtax1_rate, + GETPOST('productid'), + GETPOST('remise_percent'), + 'HT', + $info_bits, + 0, + 0, + $type, + 0, + $special_code, + $label, + GETPOST('units') + ); + + if ($result >= 0) + { /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { // Define output language $outputlangs = $langs; @@ -1632,10 +1680,10 @@ else */ print '
'; - //if ($object->statut == Facture::STATUS_DRAFT) // there is no draft status on templates. - //{ - if ($user->rights->facture->creer) + if (empty($object->suspended)) { + if ($user->rights->facture->creer) + { if (! empty($object->frequency) && $object->nb_gen_max > 0 && ($object->nb_gen_done >= $object->nb_gen_max)) { print '
'.$langs->trans("CreateBill").'
'; @@ -1644,19 +1692,31 @@ else { if (empty($object->frequency) || $object->date_when <= $today) { - print '
'.$langs->trans("CreateBill").'
'; + print '
'.$langs->trans("CreateBill").'
'; } else { print '
'.$langs->trans("CreateBill").'
'; - } } + } } else { print '
'.$langs->trans("CreateBill").'
'; - } - //} + } + } + + if ($user->rights->facture->creer) + { + if (empty($object->suspended)) + { + print '
'.$langs->trans("Disable").'
'; + } + else + { + print '
'.$langs->trans("Enable").'
'; + } + } //if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->supprimer) if ($user->rights->facture->supprimer)