From 7aecce526a640ca25561ac9a448714cbf3a852a4 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sat, 20 Sep 2014 09:11:50 +0200 Subject: [PATCH 1/4] Better accountancy auto find accountacty code feature (work with several accountacy plan) --- htdocs/accountancy/customer/list.php | 5 +++-- htdocs/accountancy/supplier/list.php | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index fefed420621..fa7fc5de6e8 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -112,8 +112,9 @@ $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as l ON f.rowid = l.fk_facture"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accountingaccount as aa ON p.accountancy_code_sell = aa.account_number"; +$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_system as accsys ON accsys.pcg_version = aa.fk_pcg_version"; $sql .= " WHERE f.fk_statut > 0 AND fk_code_ventilation = 0"; - +$sql .= " AND (accsys.rowid='".$conf->global->CHARTOFACCOUNTS."' OR p.accountancy_code_sell IS NULL)"; if (! empty($conf->multicompany->enabled)) { $sql .= " AND f.entity = '" . $conf->entity . "'"; } @@ -219,7 +220,7 @@ if ($result) { // Colonne choix ligne a ventiler print ''; - print 'code_sell ? "checked" : "") . '/>'; + print 'aarowid ? "checked" : "") . '/>'; print ''; print ''; diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index 259dc5aab39..2b24e4a4b09 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -114,7 +114,9 @@ $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn_det as l ON f.rowid = l.fk_facture_fourn"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accountingaccount as aa ON p.accountancy_code_buy = aa.account_number"; +$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_system as accsys ON accsys.pcg_version = aa.fk_pcg_version"; $sql .= " WHERE f.fk_statut > 0 AND fk_code_ventilation = 0"; +$sql .= " AND (accsys.rowid='".$conf->global->CHARTOFACCOUNTS."' OR p.accountancy_code_sell IS NULL)"; if (! empty($conf->multicompany->enabled)) { $sql .= " AND f.entity = '" . $conf->entity . "'"; @@ -199,7 +201,7 @@ if ($result) { print ''; // Colonne choix ligne a ventiler print ''; - print 'code_buy ? "checked" : "") . '/>'; + print 'aarowid ? "checked" : "") . '/>'; print ''; print ""; From 565de5258f4d9e1a3ee9d22bb0a12ef0d436475d Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sat, 20 Sep 2014 09:19:26 +0200 Subject: [PATCH 2/4] Re-Add subtotal line on compta report (accidentaly remove before) --- htdocs/compta/resultat/clientfourn.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index d55930ef80f..e400a9efd8f 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -601,6 +601,11 @@ else { dol_print_error($db); } +print ''; +if ($modecompta == 'CREANCES-DETTES') + print ''.price(-$subtotal_ht).''; +print ''.price(-$subtotal_ttc).''; +print ''; /* * Dunning @@ -633,8 +638,8 @@ if ($result) $total_ht += $obj->amount; $total_ttc += $obj->amount; - $subtotal_ht -= $obj->amount; - $subtotal_ttc -= $obj->amount; + $subtotal_ht += $obj->amount; + $subtotal_ttc += $obj->amount; $var = !$var; print " "; @@ -661,8 +666,8 @@ else } print ''; if ($modecompta == 'CREANCES-DETTES') - print ''.price(-$subtotal_ht).''; -print ''.price(-$subtotal_ttc).''; + print ''.price($subtotal_ht).''; +print ''.price($subtotal_ttc).''; print ''; /* From 119be5da421e26da258eaa5c9633a79663476f9a Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sat, 20 Sep 2014 10:14:26 +0200 Subject: [PATCH 3/4] Better ressource management on project and task --- htdocs/langs/en_US/projects.lang | 2 ++ htdocs/langs/fr_FR/projects.lang | 4 ++- htdocs/projet/class/project.class.php | 46 +++++++++++++++++++++++---- htdocs/projet/element.php | 17 ++++++++-- htdocs/projet/tasks.php | 3 +- htdocs/projet/tasks/contact.php | 10 +++--- htdocs/projet/tasks/task.php | 4 +-- htdocs/projet/tasks/time.php | 29 +++++++++++------ 8 files changed, 87 insertions(+), 28 deletions(-) diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 55970f0b35c..75bc4a29f5a 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -120,6 +120,7 @@ TypeContact_project_task_internal_TASKCONTRIBUTOR=Contributor TypeContact_project_task_external_TASKCONTRIBUTOR=Contributor SelectElement=Select element AddElement=Link to element +UnlinkElement=Unlink element # Documents models DocumentModelBaleine=A complete project's report model (logo...) PlannedWorkload = Planned workload @@ -128,3 +129,4 @@ ProjectReferers=Refering objects SearchAProject=Search a project ProjectMustBeValidatedFirst=Project must be validated first ProjectDraft=Draft projects +FirstAddRessourceToAllocateTime=Associate a ressource to allocate time \ No newline at end of file diff --git a/htdocs/langs/fr_FR/projects.lang b/htdocs/langs/fr_FR/projects.lang index e76a2777161..52fd913ee29 100644 --- a/htdocs/langs/fr_FR/projects.lang +++ b/htdocs/langs/fr_FR/projects.lang @@ -119,7 +119,8 @@ TypeContact_project_task_external_TASKEXECUTIVE=Responsable TypeContact_project_task_internal_TASKCONTRIBUTOR=Contributeur TypeContact_project_task_external_TASKCONTRIBUTOR=Contributeur SelectElement=Séléctionnez l'élément -AddElement=Link to element +AddElement=Associer l'élément +UnlinkElement=Délier l'element # Documents models DocumentModelBaleine=Modèle de rapport de projet complet (logo...) PlannedWorkload = Charge de travail prévue @@ -128,3 +129,4 @@ ProjectReferers=Objets associés SearchAProject=Rechercher un projet ProjectMustBeValidatedFirst=Le projet doit être validé d'abord ProjectDraft=Projets brouillons +FirstAddRessourceToAllocateTime=Associer une ressource pour allouer du temps consomée \ No newline at end of file diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 8cbaea46c39..40ef5248a7b 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -322,6 +322,7 @@ class Project extends CommonObject $this->note_private = $obj->note_private; $this->note_public = $obj->note_public; $this->socid = $obj->fk_soc; + $this->societe=(object)array();// To avoid warning on next line $this->societe->id = $obj->fk_soc; // TODO For backward compatibility $this->user_author_id = $obj->fk_user_creat; $this->public = $obj->public; @@ -1276,23 +1277,23 @@ class Project extends CommonObject /** * Associate element to a project * - * @param string $TableName Table of the element to update - * @param int $ElementSelectId Key-rowid of the line of the element to update + * @param string $tableName Table of the element to update + * @param int $elementSelectId Key-rowid of the line of the element to update * @return int 1 if OK or < 0 if KO */ - function update_element($TableName, $ElementSelectId) + function update_element($tableName, $elementSelectId) { - $sql="UPDATE ".MAIN_DB_PREFIX.$TableName; + $sql="UPDATE ".MAIN_DB_PREFIX.$tableName; if ($TableName=="actioncomm") { $sql.= " SET fk_project=".$this->id; - $sql.= " WHERE id=".$ElementSelectId; + $sql.= " WHERE id=".$elementSelectId; } else { $sql.= " SET fk_projet=".$this->id; - $sql.= " WHERE rowid=".$ElementSelectId; + $sql.= " WHERE rowid=".$elementSelectId; } dol_syslog(get_class($this)."::update_element", LOG_DEBUG); @@ -1305,5 +1306,38 @@ class Project extends CommonObject } } + + /** + * Associate element to a project + * + * @param string $tableName Table of the element to update + * @param int $elementSelectId Key-rowid of the line of the element to update + * @return int 1 if OK or < 0 if KO + */ + function remove_element($tableName, $elementSelectId) + { + $sql="UPDATE ".MAIN_DB_PREFIX.$tableName; + + if ($TableName=="actioncomm") + { + $sql.= " SET fk_project=NULL"; + $sql.= " WHERE id=".$elementSelectId; + } + else + { + $sql.= " SET fk_projet=NULL"; + $sql.= " WHERE rowid=".$elementSelectId; + } + + dol_syslog(get_class($this)."::remove_element", LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { + $this->error=$this->db->lasterror(); + return -1; + }else { + return 1; + } + + } } diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index b5a1d089c96..da4de04b8bc 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -215,6 +215,15 @@ if ($action=="addelement") if ($result<0) { 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'); + } } foreach ($listofreferent as $key => $value) @@ -247,7 +256,7 @@ foreach ($listofreferent as $key => $value) print ''; print ''; - print ''; + print ''; print ''; print ''; if (empty($value['disableamount'])) print ''; @@ -276,7 +285,9 @@ foreach ($listofreferent as $key => $value) $var=!$var; print ""; - + print '\n"; // Ref print ''; + print ''; if (empty($value['disableamount'])) print ''; if (empty($value['disableamount'])) print ''; print ''; diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 994779fcac9..e037a7ea9ec 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -300,7 +300,8 @@ if ($action == 'create' && $user->rights->projet->creer && (empty($object->third print ''; print ''; // Date start diff --git a/htdocs/projet/tasks/contact.php b/htdocs/projet/tasks/contact.php index 3cc8b51ca1a..da002ef72d2 100644 --- a/htdocs/projet/tasks/contact.php +++ b/htdocs/projet/tasks/contact.php @@ -155,7 +155,7 @@ if ($id > 0 || ! empty($ref)) if ($object->fetch($id) > 0) { $result=$projectstatic->fetch($object->fk_project); - if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); + if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); $object->project = dol_clone($projectstatic); @@ -179,7 +179,7 @@ if ($id > 0 || ! empty($ref)) // Define a complementary filter for search of next/prev ref. if (! $user->rights->projet->all->lire) { - $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,0); + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,0); $projectstatic->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; } print $form->showrefnav($projectstatic,'project_ref','',1,'ref','ref','',$param.'&withproject=1'); @@ -188,7 +188,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; @@ -239,7 +239,7 @@ if ($id > 0 || ! empty($ref)) print '"; print ''; } diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 7337c152f4e..0ec0ab2cbe2 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -202,7 +202,7 @@ if ($id > 0 || ! empty($ref)) $res=$object->fetch_optionals($object->id,$extralabels); $result=$projectstatic->fetch($object->fk_project); - if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); + if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); $object->project = dol_clone($projectstatic); @@ -235,7 +235,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 56048ad1cf2..5c790df32f0 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -195,7 +195,7 @@ if ($id > 0 || ! empty($ref)) if ($object->fetch($id) >= 0) { $result=$projectstatic->fetch($object->fk_project); - if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); + if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); $object->project = dol_clone($projectstatic); @@ -230,7 +230,7 @@ if ($id > 0 || ! empty($ref)) // Thirdparty print ''; print ''; @@ -302,7 +302,7 @@ if ($id > 0 || ! empty($ref)) // Third party print ''; } @@ -345,13 +345,14 @@ if ($id > 0 || ! empty($ref)) // Contributor print ''; // Note @@ -440,7 +441,15 @@ if ($id > 0 || ! empty($ref)) print '
'.$langs->trans("Ref").''.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("ThirdParty").''.$langs->trans("AmountHT").'
'; + print '' . img_picto($langs->trans('Unlink'), 'editdelete') . ''; + print "'; print $element->getNomUrl(1); @@ -326,7 +337,7 @@ foreach ($listofreferent as $key => $value) } } - print '
'.$langs->trans("Number").': '.$i.'
'.$langs->trans("Number").': '.$i.''.$langs->trans("TotalHT").' : '.price($total_ht).''.$langs->trans("TotalTTC").' : '.price($total_ttc).' 
'.$langs->trans("AffectedTo").''; - print $form->select_dolusers($user->id,'userid',1); + $contactsofproject=$object->getListContactId('internal'); + $form->select_users($user->id,'userid',0,'',0,'',$contactsofproject); print '
'.$langs->trans("Label").''.$projectstatic->title.'
'.$langs->trans("ThirdParty").''; - if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1); + if (! empty($projectstatic->thridparty->id)) print $projectstatic->thridparty->getNomUrl(1); else print ' '; print '
'.$langs->trans('Ref').''; if (! GETPOST('withproject') || empty($projectstatic->id)) { - $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1); + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1); $object->next_prev_filter=" fk_projet in (".$projectsListId.")"; } else $object->next_prev_filter=" fk_projet = ".$projectstatic->id; @@ -259,7 +259,7 @@ if ($id > 0 || ! empty($ref)) // Customer print "
".$langs->trans("ThirdParty")."'; - if ($projectstatic->societe->id > 0) print $projectstatic->societe->getNomUrl(1); + if ($projectstatic->thridparty->id > 0) print $projectstatic->thridparty->getNomUrl(1); else print ' '; print '
'.$langs->trans("Label").''.$projectstatic->title.'
'.$langs->trans("ThirdParty").''; - if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1); + if (! empty($projectstatic->thirdparty->id)) print $projectstatic->thirdparty->getNomUrl(1); else print ' '; print '
'.$langs->trans("ThirdParty").''; - if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1); + if (! empty($projectstatic->thirdparty->id)) print $projectstatic->thirdparty->getNomUrl(1); else print ' '; print '
'.$langs->trans("ThirdParty").''; - if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1); + if ($projectstatic->thirdparty->id) print $projectstatic->thirdparty->getNomUrl(1); else print ' '; print '
'; - $restrictaddtimetocontactoftask=0; - if (empty($conf->global->PROJECT_TIME_ON_ALL_TASKS_MY_PROJECTS)) - { - $restrictaddtimetocontactoftask=$object->getListContactId('internal'); - } print img_object('','user'); - print $form->select_dolusers($_POST["userid"]?$_POST["userid"]:$user->id,'userid',0,'',0,'',$restrictaddtimetocontactoftask); // Note: If user is not allowed it will be disabled into combo list and userid not posted + $contactsoftask=$object->getListContactId('internal'); + if (count($contactsoftask)>0) { + $userid=$contactsoftask[0]; + $form->select_users($userid,'userid',0,'',0,'',$contactsoftask); + }else { + print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime'); + } print ''; if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid) { - print $form->select_dolusers($task_time->fk_user,'userid_line'); + $contactsoftask=$object->getListContactId('internal'); + if (!in_array($task_time->fk_user,$contactsoftask)) { + $contactsoftask[]=$task_time->fk_user; + } + if (count($contactsoftask)>0) { + $form->select_users($task_time->fk_user,'userid_line',0,'',0,'',$contactsoftask); + }else { + print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime'); + } } else { From 3602155c5e334f8d8247e57ade3754d136bda8f8 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sat, 20 Sep 2014 10:28:59 +0200 Subject: [PATCH 4/4] Fix FicheInterTest Call --- test/phpunit/AllTests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php index a8a554ca25d..eb3c1a56abb 100644 --- a/test/phpunit/AllTests.php +++ b/test/phpunit/AllTests.php @@ -126,7 +126,7 @@ class AllTests require_once dirname(__FILE__).'/ContratTest.php'; $suite->addTestSuite('ContratTest'); - require_once dirname(__FILE__).'/FichinterTest.php'; + require_once dirname(__FILE__).'/FichInterTest.php'; $suite->addTestSuite('FichinterTest'); require_once dirname(__FILE__).'/PropalTest.php';