From a0c9af2385727ed50082d83c7898b63458e566dc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 29 Oct 2014 20:21:24 +0100 Subject: [PATCH] New: Can filter on date into tab "Referring object" of a project. --- ChangeLog | 1 + htdocs/core/class/html.formprojet.class.php | 29 ++++++--- htdocs/core/lib/date.lib.php | 6 +- htdocs/projet/class/project.class.php | 29 +++++++-- htdocs/projet/element.php | 68 +++++++++++++++++++-- 5 files changed, 112 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 36439c46288..6d9cd5a0fef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index eafe9d9f166..1a40d938329 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -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 .=''; + $ref=$obj->ref?$obj->ref:$obj->rowid; + if (! empty($obj->ref_supplier)) $ref.=' ('.$obj->ref_supplier.')'; + $sellist .=''; $i++; } $sellist .=''; } - return $sellist ; - + /*else + { + $sellist = ''; + }*/ $this->db->free($resql); + + return $sellist ; }else { $this->error=$this->db->lasterror(); dol_syslog(get_class($this) . "::select_element " . $this->error, LOG_ERR); diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index eaf6b9e83dd..a95bbec6b72 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -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; diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 9659eb2ffe8..f294fa560ac 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -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); diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 67109c450b6..d7e56c2d295 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -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 '
'; + print ''; + print ''; + print ''; + //print ''; + print ''; + print ''; + print ''; + print '
'.$langs->trans("Filter").':'.$langs->trans("From").' '; + print $form->select_date($dates,'dates',0,0,1); + print ''.$langs->trans("to").' '; + print $form->select_date($datee,'datee',0,0,1); + print ''; + print ''; + print '
'; + print '

'; + + $showdatefilter++; + } + print '
'; print_titre($langs->trans($title)); @@ -247,6 +295,8 @@ foreach ($listofreferent as $key => $value) print '
'; print ''; print ''; + print ''; + print ''; print ''; print ''; print ''; @@ -260,11 +310,13 @@ foreach ($listofreferent as $key => $value) print ''; print ''; if (empty($value['disableamount'])) print ''; + else print ''; if (empty($value['disableamount'])) print ''; + else print ''; print ''; print ''; - $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 ''; print ''; } + else print ''; // Amount if (empty($value['disableamount'])) @@ -324,6 +377,7 @@ foreach ($listofreferent as $key => $value) if (! $qualifiedfortotal) print ''; print ''; } + else print ''; // Status print ''; @@ -343,6 +397,10 @@ foreach ($listofreferent as $key => $value) print ''; print ''; } + else // error + { + print $elementarray; + } print "
'.$langs->trans("SelectElement").''.$selectList.''.$langs->trans("Date").''.$langs->trans("ThirdParty").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("Status").'
'.$element->getLibStatut(5).' 
";