New: Can filter on date into tab "Referring object" of a project.

This commit is contained in:
Laurent Destailleur 2014-10-29 20:21:24 +01:00
parent 3243958a70
commit a0c9af2385
5 changed files with 112 additions and 21 deletions

View File

@ -5,6 +5,7 @@ English Dolibarr ChangeLog
***** ChangeLog for 3.7 compared to 3.6.* *****
For users:
- New: Can filter on date into tab "Referring object" of a project.
- New: Module notification has been enhanced:
EMail use now language of target contact.
Can also define a fixed email for notifications.

View File

@ -167,15 +167,15 @@ class FormProjets
}
/**
* Build Select List of element associable to a project
* Build a HTML select list of element of same thirdparty to suggest to link them to project
*
* @param string $table_element Table of the element to update
* @param int $socid socid to filter
* @return string The HTML select list of element
* @param string $table_element Table of the element to update
* @param int $socid socid to filter
* @return string The HTML select list of element
*/
function select_element($table_element,$socid=0)
{
global $conf;
global $conf, $langs;
$projectkey="fk_projet";
switch ($table_element)
@ -184,7 +184,10 @@ class FormProjets
$sql = "SELECT rowid, facnumber as ref";
break;
case "facture_fourn":
$sql = "SELECT rowid, ref";
$sql = "SELECT rowid, ref, ref_supplier";
break;
case "commande_fourn":
$sql = "SELECT rowid, ref, ref_supplier";
break;
case "facture_rec":
$sql = "SELECT rowid, titre as ref";
@ -219,14 +222,22 @@ class FormProjets
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$sellist .='<option value="'.$obj->rowid.'">'.$obj->ref.'</option>';
$ref=$obj->ref?$obj->ref:$obj->rowid;
if (! empty($obj->ref_supplier)) $ref.=' ('.$obj->ref_supplier.')';
$sellist .='<option value="'.$obj->rowid.'">'.$ref.'</option>';
$i++;
}
$sellist .='</select>';
}
return $sellist ;
/*else
{
$sellist = '<select class="flat" name="elementselect">';
$sellist.= '<option value="0" disabled="disabled">'.$langs->trans("None").'</option>';
$sellist.= '</select>';
}*/
$this->db->free($resql);
return $sellist ;
}else {
$this->error=$this->db->lasterror();
dol_syslog(get_class($this) . "::select_element " . $this->error, LOG_ERR);

View File

@ -443,10 +443,11 @@ function dol_get_next_week($day, $week, $month, $year)
* @param mixed $gm False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
* Exemple: dol_get_first_day(1970,1,false) will return -3600 with TZ+1, after a dol_print_date will return 1970-01-01 00:00:00
* Exemple: dol_get_first_day(1970,1,true) will return 0 whatever is TZ, after a dol_print_date will return 1970-01-01 00:00:00
* @return int Date for first day
* @return int Date for first day, '' if error
*/
function dol_get_first_day($year,$month=1,$gm=false)
{
if ($year > 9999) return '';
return dol_mktime(0,0,0,$month,1,$year,$gm);
}
@ -456,10 +457,11 @@ function dol_get_first_day($year,$month=1,$gm=false)
* @param int $year Year
* @param int $month Month
* @param boolean $gm False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
* @return int Date for first day
* @return int Date for first day, '' if error
*/
function dol_get_last_day($year,$month=12,$gm=false)
{
if ($year > 9999) return '';
if ($month == 12)
{
$month = 1;

View File

@ -388,19 +388,38 @@ class Project extends CommonObject
/**
* Return list of elements for type linked to project
*
* @param string $type 'propal','order','invoice','order_supplier','invoice_supplier'
* @param string $tablename name of table associated of the type
* @return array List of orders linked to project, <0 if error
* @param string $type 'propal','order','invoice','order_supplier','invoice_supplier'
* @param string $tablename name of table associated of the type
* @param string $datefieldname name of table associated of the type
* @param string $dates Start date (at 00:00:00)
* @param string $datee End date (at 23:00:00)
* @return mixed List of orders linked to project, < 0 or string if error
*/
function get_element_list($type, $tablename)
function get_element_list($type, $tablename, $datefieldname='', $dates='', $datee='')
{
$elements = array();
if ($type == 'agenda')
{
$sql = "SELECT id as rowid FROM " . MAIN_DB_PREFIX . "actioncomm WHERE fk_project=" . $this->id;
}
else
{
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . $tablename." WHERE fk_projet=" . $this->id;
if (! $sql) return -1;
}
if ($dates > 0)
{
if (empty($datefieldname) && ! empty($this->table_element_date)) $datefieldname=$this->table_element_date;
if (empty($datefieldname)) return 'Error this object has no date field defined';
$sql.=" AND ".$datefieldname." >= '".$this->db->jdate($dates)."'";
}
if ($datee > 0)
{
if (empty($datefieldname) && ! empty($this->table_element_date)) $datefieldname=$this->table_element_date;
if (empty($datefieldname)) return 'Error this object has no date field defined';
$sql.=" AND ".$datefieldname." <= '".$this->db->jdate($datee)."'";
}
if (! $sql) return -1;
//print $sql;
dol_syslog(get_class($this)."::get_element_list", LOG_DEBUG);

View File

@ -28,6 +28,7 @@ require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
@ -50,7 +51,20 @@ if (! empty($conf->ficheinter->enabled)) $langs->load("interventions");
$projectid=GETPOST('id','int');
$ref=GETPOST('ref','alpha');
$action=GETPOST('action','alpha');
$datesrfc=GETPOST('datesrfc');
$dateerfc=GETPOST('dateerfc');
$dates=dol_mktime(0, 0, 0, GETPOST('datesmonth'), GETPOST('datesday'), GETPOST('datesyear'));
$datee=dol_mktime(23, 59, 59, GETPOST('dateemonth'), GETPOST('dateeday'), GETPOST('dateeyear'));
if (empty($dates) && ! empty($datesrfc)) $dates=dol_stringtotime($datesrfc);
if (empty($datee) && ! empty($dateerfc)) $datee=dol_stringtotime($dateerfc);
if (! isset($_POST['datesrfc']) && ! isset($_POST['datesday']))
{
$new=dol_now();
$tmp=dol_getdate($new);
//$datee=$now
//$dates=dol_time_plus_duree($datee, -1, 'y');
$dates=dol_get_first_day($tmp['year'],1);
}
if ($projectid == '' && $ref == '')
{
dol_print_error('','Bad parameter');
@ -153,49 +167,58 @@ $listofreferent=array(
'title'=>"ListProposalsAssociatedProject",
'class'=>'Propal',
'table'=>'propal',
'datefieldname'=>'datep',
'test'=>$conf->propal->enabled && $user->rights->propale->lire),
'order'=>array(
'title'=>"ListOrdersAssociatedProject",
'class'=>'Commande',
'table'=>'commande',
'datefieldname'=>'date_commande',
'test'=>$conf->commande->enabled && $user->rights->commande->lire),
'invoice'=>array(
'title'=>"ListInvoicesAssociatedProject",
'class'=>'Facture',
'margin'=>'add',
'table'=>'facture',
'datefieldname'=>'datef',
'test'=>$conf->facture->enabled && $user->rights->facture->lire),
'invoice_predefined'=>array(
'title'=>"ListPredefinedInvoicesAssociatedProject",
'class'=>'FactureRec',
'table'=>'facture_rec',
'datefieldname'=>'datec',
'test'=>$conf->facture->enabled && $user->rights->facture->lire),
'order_supplier'=>array(
'title'=>"ListSupplierOrdersAssociatedProject",
'class'=>'CommandeFournisseur',
'table'=>'commande_fournisseur',
'datefieldname'=>'date_commande',
'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire),
'invoice_supplier'=>array(
'title'=>"ListSupplierInvoicesAssociatedProject",
'class'=>'FactureFournisseur',
'margin'=>'minus',
'table'=>'facture_fourn',
'datefieldname'=>'datef',
'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire),
'contract'=>array(
'title'=>"ListContractAssociatedProject",
'class'=>'Contrat',
'table'=>'contrat',
'datefieldname'=>'date_contrat',
'test'=>$conf->contrat->enabled && $user->rights->contrat->lire),
'intervention'=>array(
'title'=>"ListFichinterAssociatedProject",
'class'=>'Fichinter',
'table'=>'fichinter',
'datefieldname'=>'date_valid',
'disableamount'=>1,
'test'=>$conf->ficheinter->enabled && $user->rights->ficheinter->lire),
'trip'=>array(
'title'=>"ListTripAssociatedProject",
'class'=>'Deplacement',
'table'=>'deplacement',
'datefieldname'=>'dated',
'margin'=>'minus',
'disableamount'=>1,
'test'=>$conf->deplacement->enabled && $user->rights->deplacement->lire),
@ -203,6 +226,7 @@ $listofreferent=array(
'title'=>"ListActionsAssociatedProject",
'class'=>'ActionComm',
'table'=>'actioncomm',
'datefieldname'=>'datep',
'disableamount'=>1,
'test'=>$conf->agenda->enabled && $user->rights->agenda->allactions->lire)
);
@ -216,25 +240,49 @@ if ($action=="addelement")
setEventMessage($mailchimp->error,'errors');
}
}elseif ($action == "unlink") {
$tablename = GETPOST("tablename");
$elementselectid = GETPOST("elementselect");
$result = $project->remove_element($tablename, $elementselectid);
if ($result < 0) {
setEventMessage($project->error, 'errors');
}
}
$showdatefilter=0;
foreach ($listofreferent as $key => $value)
{
$title=$value['title'];
$classname=$value['class'];
$tablename=$value['table'];
$datefieldname=$value['datefieldname'];
$qualified=$value['test'];
if ($qualified)
{
if (! $showdatefilter)
{
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$projectid.'" method="post">';
print '<input type="hidden" name="tablename" value="'.$tablename.'">';
print '<input type="hidden" name="action" value="addelement">';
print '<table><tr>';
//print '<td>'.$langs->trans("Filter").':</td>';
print '<td>'.$langs->trans("From").' ';
print $form->select_date($dates,'dates',0,0,1);
print '</td>';
print '<td>'.$langs->trans("to").' ';
print $form->select_date($datee,'datee',0,0,1);
print '</td>';
print '<td>';
print '<input type="submit" name="refresh" value="'.$langs->trans("Refresh").'" class="button">';
print '</td>';
print '</tr></table>';
print '</form><br>';
$showdatefilter++;
}
print '<br>';
print_titre($langs->trans($title));
@ -247,6 +295,8 @@ foreach ($listofreferent as $key => $value)
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$projectid.'" method="post">';
print '<input type="hidden" name="tablename" value="'.$tablename.'">';
print '<input type="hidden" name="action" value="addelement">';
print '<input type="hidden" name="datesrfc" value="'.dol_print_date($dates,'dayhourrfc').'">';
print '<input type="hidden" name="dateerfc" value="'.dol_print_date($datee,'dayhourrfc').'">';
print '<table><tr><td>'.$langs->trans("SelectElement").'</td>';
print '<td>'.$selectList.'</td>';
print '<td><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("AddElement")).'"></td>';
@ -260,11 +310,13 @@ foreach ($listofreferent as $key => $value)
print '<td width="100" align="center">'.$langs->trans("Date").'</td>';
print '<td>'.$langs->trans("ThirdParty").'</td>';
if (empty($value['disableamount'])) print '<td align="right" width="120">'.$langs->trans("AmountHT").'</td>';
else print '<td width="120"></td>';
if (empty($value['disableamount'])) print '<td align="right" width="120">'.$langs->trans("AmountTTC").'</td>';
else print '<td width="120"></td>';
print '<td align="right" width="200">'.$langs->trans("Status").'</td>';
print '</tr>';
$elementarray = $project->get_element_list($key, $tablename);
if (count($elementarray)>0 && is_array($elementarray))
$elementarray = $project->get_element_list($key, $tablename, $datefieldname, $dates, $datee);
if (is_array($elementarray) && count($elementarray)>0)
{
$var=true;
$total_ht = 0;
@ -314,6 +366,7 @@ foreach ($listofreferent as $key => $value)
if (! $qualifiedfortotal) print '</strike>';
print '</td>';
}
else print '<td></td>';
// Amount
if (empty($value['disableamount']))
@ -324,6 +377,7 @@ foreach ($listofreferent as $key => $value)
if (! $qualifiedfortotal) print '</strike>';
print '</td>';
}
else print '<td></td>';
// Status
print '<td align="right">'.$element->getLibStatut(5).'</td>';
@ -343,6 +397,10 @@ foreach ($listofreferent as $key => $value)
print '<td>&nbsp;</td>';
print '</tr>';
}
else // error
{
print $elementarray;
}
print "</table>";