Enhance code for template invoices

This commit is contained in:
Laurent Destailleur 2018-03-22 21:42:19 +01:00
parent 72cedcf9f3
commit 171ad5dce2
2 changed files with 66 additions and 28 deletions

View File

@ -68,6 +68,13 @@ class FactureRec extends CommonInvoice
var $usenewprice=0; var $usenewprice=0;
var $suspended; // status
const STATUS_NOTSUSPENDED = 0;
const STATUS_SUSPENDED = 1;
/** /**
* Constructor * Constructor
* *
@ -95,6 +102,7 @@ class FactureRec extends CommonInvoice
// Clean parameters // Clean parameters
$this->titre=trim($this->titre); $this->titre=trim($this->titre);
$this->usenewprice=empty($this->usenewprice)?0:$this->usenewprice; $this->usenewprice=empty($this->usenewprice)?0:$this->usenewprice;
if (empty($this->suspended)) $this->suspended=0;
// No frequency defined then no next date to execution // No frequency defined then no next date to execution
if (empty($this->frequency)) if (empty($this->frequency))
@ -147,6 +155,7 @@ class FactureRec extends CommonInvoice
$sql.= ", fk_multicurrency"; $sql.= ", fk_multicurrency";
$sql.= ", multicurrency_code"; $sql.= ", multicurrency_code";
$sql.= ", multicurrency_tx"; $sql.= ", multicurrency_tx";
$sql.= ", suspended";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= "'".$this->db->escape($this->titre)."'"; $sql.= "'".$this->db->escape($this->titre)."'";
$sql.= ", ".$facsrc->socid; $sql.= ", ".$facsrc->socid;
@ -167,13 +176,14 @@ class FactureRec extends CommonInvoice
$sql.= ", '".$this->db->escape($this->unit_frequency)."'"; $sql.= ", '".$this->db->escape($this->unit_frequency)."'";
$sql.= ", ".(!empty($this->date_when)?"'".$this->db->idate($this->date_when)."'":'NULL'); $sql.= ", ".(!empty($this->date_when)?"'".$this->db->idate($this->date_when)."'":'NULL');
$sql.= ", ".(!empty($this->date_last_gen)?"'".$this->db->idate($this->date_last_gen)."'":'NULL'); $sql.= ", ".(!empty($this->date_last_gen)?"'".$this->db->idate($this->date_last_gen)."'":'NULL');
$sql.= ", ".$this->nb_gen_done; $sql.= ", ".$this->db->escape($this->nb_gen_done);
$sql.= ", ".$this->nb_gen_max; $sql.= ", ".$this->db->escape($this->nb_gen_max);
$sql.= ", ".$this->auto_validate; $sql.= ", ".$this->db->escape($this->auto_validate);
$sql.= ", ".$this->generate_pdf; $sql.= ", ".$this->db->escape($this->generate_pdf);
$sql.= ", ".$facsrc->fk_multicurrency; $sql.= ", ".$this->db->escape($facsrc->fk_multicurrency);
$sql.= ", '".$facsrc->multicurrency_code."'"; $sql.= ", '".$this->db->escape($facsrc->multicurrency_code)."'";
$sql.= ", ".$facsrc->multicurrency_tx; $sql.= ", ".$this->db->escape($facsrc->multicurrency_tx);
$sql.= ", ".$this->db->escape($this->suspended);
$sql.= ")"; $sql.= ")";
if ($this->db->query($sql)) if ($this->db->query($sql))
@ -1149,49 +1159,69 @@ class FactureRec extends CommonInvoice
$prefix=''; $prefix='';
if ($recur) if ($recur)
{ {
if ($status == 1) return $langs->trans('Disabled'); // credit note if ($status == self::STATUS_SUSPENDED) return $langs->trans('Disabled');
else return $langs->trans('Active'); else return $langs->trans('Active');
} }
else return $langs->trans("Draft"); else
{
if ($status == self::STATUS_SUSPENDED) return $langs->trans('Disabled');
else return $langs->trans("Draft");
}
} }
if ($mode == 1) if ($mode == 1)
{ {
$prefix='Short'; $prefix='Short';
if ($recur) if ($recur)
{ {
if ($status == 1) return $langs->trans('Disabled'); if ($status == self::STATUS_SUSPENDED) return $langs->trans('Disabled');
else return $langs->trans('Active'); else return $langs->trans('Active');
} }
else return $langs->trans("Draft"); else
{
if ($status == self::STATUS_SUSPENDED) return $langs->trans('Disabled');
else return $langs->trans("Draft");
}
} }
if ($mode == 2) if ($mode == 2)
{ {
if ($recur) if ($recur)
{ {
if ($status == 1) return img_picto($langs->trans('Disabled'),'statut6').' '.$langs->trans('Disabled'); if ($status == self::STATUS_SUSPENDED) 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('Active'),'statut4').' '.$langs->trans('Active');
} }
else return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft'); else
{
if ($status == self::STATUS_SUSPENDED) return img_picto($langs->trans('Disabled'),'statut6').' '.$langs->trans('Disabled');
else return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft');
}
} }
if ($mode == 3) if ($mode == 3)
{ {
if ($recur) if ($recur)
{ {
$prefix='Short'; $prefix='Short';
if ($status == 1) return img_picto($langs->trans('Disabled'),'statut6'); if ($status == self::STATUS_SUSPENDED) return img_picto($langs->trans('Disabled'),'statut6');
else return img_picto($langs->trans('Active'),'statut4'); else return img_picto($langs->trans('Active'),'statut4');
} }
else return img_picto($langs->trans('Draft'),'statut0'); else
{
if ($status == self::STATUS_SUSPENDED) return img_picto($langs->trans('Disabled'),'statut6');
else return img_picto($langs->trans('Draft'),'statut0');
}
} }
if ($mode == 4) if ($mode == 4)
{ {
$prefix=''; $prefix='';
if ($recur) if ($recur)
{ {
if ($status == 1) return img_picto($langs->trans('Disabled'),'statut6').' '.$langs->trans('Disabled'); if ($status == self::STATUS_SUSPENDED) 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('Active'),'statut4').' '.$langs->trans('Active');
} }
else return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft'); else
{
if ($status == self::STATUS_SUSPENDED) return img_picto($langs->trans('Disabled'),'statut6').' '.$langs->trans('Disabled');
else return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft');
}
} }
if ($mode == 5 || $mode == 6) if ($mode == 5 || $mode == 6)
{ {
@ -1199,10 +1229,14 @@ class FactureRec extends CommonInvoice
if ($mode == 5) $prefix='Short'; if ($mode == 5) $prefix='Short';
if ($recur) if ($recur)
{ {
if ($status == 1) return '<span class="xhideonsmartphone">'.$langs->trans('Disabled').' </span>'.img_picto($langs->trans('Disabled'),'statut6'); if ($status == self::STATUS_SUSPENDED) 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 '<span class="xhideonsmartphone">'.$langs->trans('Active').' </span>'.img_picto($langs->trans('Active'),'statut4');
} }
else return $langs->trans('Draft').' '.img_picto($langs->trans('Active'),'statut0'); else
{
if ($status == self::STATUS_SUSPENDED) return '<span class="xhideonsmartphone">'.$langs->trans('Disabled').' </span>'.img_picto($langs->trans('Disabled'),'statut6');
else return $langs->trans('Draft').' '.img_picto($langs->trans('Active'),'statut0');
}
} }
} }

View File

@ -2841,7 +2841,6 @@ abstract class CommonObject
$sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')";
} }
$sql .= ' ORDER BY sourcetype'; $sql .= ' ORDER BY sourcetype';
//print $sql;
dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -3086,9 +3085,10 @@ abstract class CommonObject
* @param int $status Status to set * @param int $status Status to set
* @param int $elementId Id of element to force (use this->id by default) * @param int $elementId Id of element to force (use this->id by default)
* @param string $elementType Type of element to force (use this->table_element by default) * @param string $elementType Type of element to force (use this->table_element by default)
* @param string $trigkey Trigger key to use for trigger
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function setStatut($status,$elementId=null,$elementType='') function setStatut($status, $elementId=null, $elementType='', $trigkey='')
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
@ -3100,6 +3100,7 @@ abstract class CommonObject
$this->db->begin(); $this->db->begin();
$fieldstatus="fk_statut"; $fieldstatus="fk_statut";
if ($elementTable == 'facture_rec') $fieldstatus="suspended";
if ($elementTable == 'mailing') $fieldstatus="statut"; if ($elementTable == 'mailing') $fieldstatus="statut";
if ($elementTable == 'cronjob') $fieldstatus="status"; if ($elementTable == 'cronjob') $fieldstatus="status";
if ($elementTable == 'user') $fieldstatus="statut"; if ($elementTable == 'user') $fieldstatus="statut";
@ -3117,13 +3118,16 @@ abstract class CommonObject
{ {
$error = 0; $error = 0;
$trigkey=''; // Try autoset of trigkey
if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class if (empty($trigkey))
if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class {
if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class
if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class
if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class
if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE';
if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED';
if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED';
}
if ($trigkey) if ($trigkey)
{ {