add date field

This commit is contained in:
John BOTELLA 2018-08-08 17:36:39 +02:00
parent 3036c94198
commit 06be98c638
6 changed files with 199 additions and 14 deletions

View File

@ -81,7 +81,7 @@ print '<table class="noborder" width="100%">';
_print_on_off('INVOICE_USE_SITUATION',$langs->trans('UseSituationInvoices'));
_print_on_off('INVOICE_USE_SITUATION_CREDIT_NOTE',$langs->trans('UseSituationInvoicesCreditNote'));
_print_on_off('INVOICE_USE_SITUATION_RETAINED_WARANTY',$langs->trans('Retainedwarranty'));
_print_on_off('INVOICE_USE_SITUATION_RETAINED_WARRANTY',$langs->trans('Retainedwarranty'));
$metas = array(
'type' => 'number',
@ -89,7 +89,7 @@ $metas = array(
'min' => 0,
'max' => 100
);
_print_input_form_part('INVOICE_SITUATION_DEFAULT_RETAINED_WARANTY_PERCENT',$langs->trans('RetainedwarrantyDefaultPercent'),'',$metas);
_print_input_form_part('INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT',$langs->trans('RetainedwarrantyDefaultPercent'),'',$metas);

View File

@ -288,6 +288,23 @@ if (empty($reshook))
if ($result < 0)
dol_print_error($db, $object->error);
}
else if ($action == 'setretainedwarranty' && $user->rights->facture->creer)
{
$object->fetch($id);
$result = $object->setRetainedWarranty(GETPOST('retained_warranty', 'float'));
if ($result < 0)
dol_print_error($db, $object->error);
}
else if ($action == 'setretainedwarrantydatelimit' && $user->rights->facture->creer)
{
$object->fetch($id);
$result = $object->setRetainedWarrantyDateLimit(GETPOST('retained_warranty_date_limit', 'float'));
if ($result < 0)
dol_print_error($db, $object->error);
}
// Multicurrency Code
else if ($action == 'setmulticurrencycode' && $user->rights->facture->creer) {
@ -1152,6 +1169,7 @@ if (empty($reshook))
$object->situation_counter = 1;
$object->situation_final = 0;
$object->situation_cycle_ref = $object->newCycle();
$object->retained_warranty = !empty($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY)?$conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY:0;
}
$object->fetch_thirdparty();
@ -3919,6 +3937,70 @@ else if ($id > 0 || ! empty($ref))
print '</td></tr>';
}
if($object->type == Facture::TYPE_SITUATION && (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY)) )
{
// Retained Warranty
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('RetainedWarranty');
print '</td>';
if ($action != 'editretainedwarranty' && $user->rights->facture->creer){
print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editretainedwarranty&amp;facid=' . $object->id . '">' . img_edit($langs->trans('setretainedwarranty'), 1) . '</a></td>';
}
print '</tr></table>';
print '</td><td>';
if ($action == 'editretainedwarranty')
{
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'">';
print '<input type="hidden" name="action" value="setretainedwarranty">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.'" >';
print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
print '</form>';
}
else
{
print price($object->retained_warranty).'%';
}
print '</td></tr>';
// Retained Warranty payment date limit
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('RetainedWarrantyDateLimit');
print '</td>';
if ($action != 'editretainedwarrantydatelimit' && $user->rights->facture->creer){
print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editretainedwarrantydatelimit&amp;facid=' . $object->id . '">' . img_edit($langs->trans('setretainedwarrantyDateLimit'), 1) . '</a></td>';
}
print '</tr></table>';
print '</td><td>';
$defaultDate = !empty($object->retained_warranty_date_limit)?$object->retained_warranty_date_limit:strtotime('-1 years', $object->date_lim_reglement);
if($object->date > $defaultDate){
$defaultDate = $object->date;
}
if ($action == 'editretainedwarrantydatelimit')
{
//date('Y-m-d',$object->date_lim_reglement)
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'">';
print '<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input name="retained_warranty_date_limit" type="date" step="1" min="'.dol_print_date($object->date,'%Y-%m-%d' ).'" value="'.dol_print_date($defaultDate,'%Y-%m-%d' ).'" >';
print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
print '</form>';
}
else
{
print dol_print_date($defaultDate);
}
print '</td></tr>';
}
// Other attributes
$cols = 2;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
@ -4360,6 +4442,20 @@ else if ($id > 0 || ! empty($ref))
// Billed
print '<tr><td colspan="' . $nbcols . '" align="right">' . $langs->trans("Billed") . ' :</td><td align="right">' . price($object->total_ttc) . '</td><td>&nbsp;</td></tr>';
if(!empty($object->retained_warranty)){
// Billed - retained warranty
$retainedWarranty = $object->total_ttc * $object->retained_warranty / 100;
$billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty ;
print '<tr><td colspan="' . $nbcols . '" align="right">' . $langs->trans("ToPayOn", dol_print_date($object->date_lim_reglement)) . ' :</td><td align="right">' . price($billedWithRetainedWarranty) . '</td><td>&nbsp;</td></tr>';
// retained warranty
print '<tr><td colspan="' . $nbcols . '" align="right">';
print $langs->trans("RetainedWarranty") . ' ('.$object->retained_warranty.'%)';
print !empty($object->retained_warranty_date_limit)?' '.$langs->trans("ToPayOn", dol_print_date($object->retained_warranty_date_limit)):'';
print ' :</td><td align="right">' . price($retainedWarranty) . '</td><td>&nbsp;</td></tr>';
}
// Remainder to pay
print '<tr><td colspan="' . $nbcols . '" align="right">';
if ($resteapayeraffiche >= 0)

View File

@ -162,7 +162,9 @@ class Facture extends CommonInvoice
public $oldcopy;
public $retained_waranty;
public $retained_warranty;
public $retained_warranty_date_limit;
/**
* Standard invoice
@ -343,7 +345,7 @@ class Facture extends CommonInvoice
$this->note_private=trim($this->note_private);
$this->note_private=dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref));
$this->retained_waranty = floatval($this->retained_waranty);
$this->retained_warranty = floatval($this->retained_warranty);
$this->array_options=$_facrec->array_options;
@ -431,7 +433,8 @@ class Facture extends CommonInvoice
$sql.= ", fk_multicurrency";
$sql.= ", multicurrency_code";
$sql.= ", multicurrency_tx";
$sql.= ", retained_waranty";
$sql.= ", retained_warranty";
$sql.= ", retained_warranty_date_limit";
$sql.= ")";
$sql.= " VALUES (";
$sql.= "'(PROV)'";
@ -464,7 +467,8 @@ class Facture extends CommonInvoice
$sql.= ", ".(int) $this->fk_multicurrency;
$sql.= ", '".$this->db->escape($this->multicurrency_code)."'";
$sql.= ", ".(double) $this->multicurrency_tx;
$sql.= ", ".(empty($this->retained_waranty)?"0":$this->db->escape($this->retained_waranty));
$sql.= ", ".(empty($this->retained_warranty)?"0":$this->db->escape($this->retained_warranty));
$sql.= ", '".$this->db->idate($this->retained_warranty_date_limit)."'";
$sql.=")";
@ -1284,7 +1288,7 @@ class Facture extends CommonInvoice
$sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
$sql.= ', f.fk_incoterms, f.location_incoterms';
$sql.= ", i.libelle as libelle_incoterms";
$sql.= ", f.retained_waranty as retained_waranty";
$sql.= ", f.retained_warranty as retained_warranty, f.retained_warranty_date_limit as retained_warranty_date_limit";
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
@ -1352,7 +1356,9 @@ class Facture extends CommonInvoice
$this->situation_cycle_ref = $obj->situation_cycle_ref;
$this->situation_counter = $obj->situation_counter;
$this->situation_final = $obj->situation_final;
$this->retained_waranty = $obj->retained_waranty;
$this->retained_warranty = $obj->retained_warranty;
$this->retained_warranty_date_limit = $this->db->jdate($obj->retained_warranty_date_limit);
$this->extraparams = (array) json_decode($obj->extraparams, true);
// Incoterms
$this->fk_incoterms = $obj->fk_incoterms;
@ -1578,7 +1584,7 @@ class Facture extends CommonInvoice
if (isset($this->note_public)) $this->note_public=trim($this->note_public);
if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
if (isset($this->import_key)) $this->import_key=trim($this->import_key);
if (isset($this->retained_waranty)) $this->retained_waranty = floatval($this->retained_waranty);
if (isset($this->retained_warranty)) $this->retained_warranty = floatval($this->retained_warranty);
// Check parameters
@ -1620,8 +1626,9 @@ class Facture extends CommonInvoice
$sql.= " import_key=".(isset($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null").",";
$sql.= " situation_cycle_ref=".(empty($this->situation_cycle_ref)?"null":$this->db->escape($this->situation_cycle_ref)).",";
$sql.= " situation_counter=".(empty($this->situation_counter)?"null":$this->db->escape($this->situation_counter)).",";
$sql.= " situation_final=".(empty($this->situation_counter)?"0":$this->db->escape($this->situation_counter));
$sql.= " retained_waranty=".(empty($this->retained_waranty)?"0":$this->db->escape($this->retained_waranty));
$sql.= " situation_final=".(empty($this->situation_counter)?"0":$this->db->escape($this->situation_counter)).",";
$sql.= " retained_warranty=".(empty($this->retained_warranty)?"0":$this->db->escape($this->retained_warranty)).",";
$sql.= " retained_warranty_date_limit=".(strval($this->retained_warranty_date_limit)!='' ? "'".$this->db->idate($this->retained_warranty_date_limit)."'" : 'null');
$sql.= " WHERE rowid=".$this->id;
$this->db->begin();
@ -4226,6 +4233,85 @@ class Facture extends CommonInvoice
return $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay);
}
/**
* Change the retained warranty
*
* @param float $value value of retained warranty
* @return int >0 if OK, <0 if KO
*/
function setRetainedWarranty($value)
{
dol_syslog(get_class($this).'::setRetainedWarranty('.$value.')');
if ($this->statut >= 0)
{
$fieldname = 'retained_warranty';
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql .= ' SET '.$fieldname.' = '.floatval($value);
$sql .= ' WHERE rowid='.$this->id;
if ($this->db->query($sql))
{
$this->retained_warranty = floatval($value);
return 1;
}
else
{
dol_syslog(get_class($this).'::setRetainedWarranty Erreur '.$sql.' - '.$this->db->error());
$this->error=$this->db->error();
return -1;
}
}
else
{
dol_syslog(get_class($this).'::setRetainedWarranty, status of the object is incompatible');
$this->error='Status of the object is incompatible '.$this->statut;
return -2;
}
}
/**
* Change the retained_warranty_date_limit
*
* @param timestamp $value value of retained warranty
* @return int >0 if OK, <0 if KO
*/
function setRetainedWarrantyDateLimit($timestamp,$dateYmd=false)
{
if(!$timestamp && $dateYmd){
$timestamp = $this->db->jdate($dateYmd);
}
dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit('.$value.')');
if ($this->statut >= 0)
{
$fieldname = 'retained_warranty_date_limit';
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql .= ' SET '.$fieldname.' = '.(strval($timestamp)!='' ? '\'' .$this->db->idate($timestamp).'\'' : 'null' );
$sql .= ' WHERE rowid='.$this->id;
if ($this->db->query($sql))
{
$this->retained_warranty_date_limit = $timestamp;
return 1;
}
else
{
dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit Erreur '.$sql.' - '.$this->db->error());
$this->error=$this->db->error();
return -1;
}
}
else
{
dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit, status of the object is incompatible');
$this->error='Status of the object is incompatible '.$this->statut;
return -2;
}
}
}
/**

View File

@ -51,7 +51,7 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
ALTER TABLE llx_payment_salary ADD COLUMN fk_projet integer DEFAULT NULL after amount;
ALTER TABLE llx_facture ADD COLUMN retained_waranty real DEFAULT NULL after situation_final;
ALTER TABLE llx_facture ADD COLUMN retained_warranty real DEFAULT NULL after situation_final;
ALTER TABLE llx_facture ADD COLUMN retained_warranty_date_limit date DEFAULT NULL after retained_warranty;

View File

@ -86,7 +86,8 @@ create table llx_facture
situation_counter smallint, -- situation counter
situation_final smallint, -- is the situation final ?
retained_waranty real DEFAULT NULL, -- % of retained warranty
retained_warranty real DEFAULT NULL, -- % of retained warranty
retained_warranty_date_limit date DEFAULT NULL,
import_key varchar(14),
extraparams varchar(255), -- for other parameters with json format

View File

@ -550,3 +550,5 @@ AutoFillDateFromShort=Set start date
AutoFillDateTo=Set end date for service line with next invoice date
AutoFillDateToShort=Set end date
MaxNumberOfGenerationReached=Max number of gen. reached
ToPayOn=To pay on %s
RetainedWarranty=Retained Warranty