NEW Add a status enabled/disabled on recurring invoices

This commit is contained in:
Laurent Destailleur 2017-11-18 00:54:23 +01:00
parent cf0d67d71c
commit 03cc685037
2 changed files with 103 additions and 44 deletions

View File

@ -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 '<span class="xhideonsmartphone">'.$langs->trans('Suspended').' </span>'.img_picto($langs->trans('Suspended'),'statut6');
if ($status == 1) return '<span class="xhideonsmartphone">'.$langs->trans('Disabled').' </span>'.img_picto($langs->trans('Disabled'),'statut6');
else return '<span class="xhideonsmartphone">'.$langs->trans('Active').' </span>'.img_picto($langs->trans('Active'),'statut4');
}
else return $langs->trans('Draft').' '.img_picto($langs->trans('Active'),'statut0');

View File

@ -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 '<div class="tabsAction">';
//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 '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("MaxGenerationReached")).'">'.$langs->trans("CreateBill").'</a></div>';
@ -1644,19 +1692,31 @@ else
{
if (empty($object->frequency) || $object->date_when <= $today)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;socid='.$object->thirdparty->id.'&amp;fac_rec='.$object->id.'">'.$langs->trans("CreateBill").'</a></div>';
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&socid='.$object->thirdparty->id.'&fac_rec='.$object->id.'">'.$langs->trans("CreateBill").'</a></div>';
}
else
{
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("DateIsNotEnough")).'">'.$langs->trans("CreateBill").'</a></div>';
}
}
}
}
else
{
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("CreateBill").'</a></div>';
}
//}
}
}
if ($user->rights->facture->creer)
{
if (empty($object->suspended))
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.'/compta/facture/fiche-rec.php?action=disable&id='.$object->id.'">'.$langs->trans("Disable").'</a></div>';
}
else
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/fiche-rec.php?action=enable&id='.$object->id.'">'.$langs->trans("Enable").'</a></div>';
}
}
//if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->supprimer)
if ($user->rights->facture->supprimer)