diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index 1112d34d13f..ddc26d0bb91 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -79,7 +79,7 @@ class FormProjets $project->fetch($selected); $selected_input_value=$project->ref; } - $urloption='socid='.$socid.'&htmlname='.$htmlname; + $urloption='socid='.$socid.'&htmlname='.$htmlname.'&discardclosed='.$discard_closed; $out.=ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array( // 'update' => array( // 'projectid' => 'id' diff --git a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql index fb862457b45..76aa7d85928 100644 --- a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql +++ b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql @@ -221,4 +221,4 @@ drop table tmp_links_double; ALTER TABLE llx_links ADD UNIQUE INDEX uk_links (objectid,label); - +ALTER TABLE llx_loan ADD COLUMN fk_project integer DEFAULT NULL; diff --git a/htdocs/install/mysql/tables/llx_loan.sql b/htdocs/install/mysql/tables/llx_loan.sql index 6fd3c0d2099..64d1de5dc29 100644 --- a/htdocs/install/mysql/tables/llx_loan.sql +++ b/htdocs/install/mysql/tables/llx_loan.sql @@ -47,5 +47,6 @@ create table llx_loan fk_user_author integer DEFAULT NULL, fk_user_modif integer DEFAULT NULL, - active tinyint DEFAULT 1 NOT NULL + active tinyint DEFAULT 1 NOT NULL, + fk_project integer DEFAULT NULL )ENGINE=innodb; diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index 0894447d485..b24f9c75253 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -28,6 +28,11 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php'; +if (! empty($conf->projet->enabled)) +{ + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; +} $langs->load("compta"); $langs->load("bills"); @@ -45,134 +50,143 @@ $result = restrictedArea($user, 'loan', $id, '',''); $object = new Loan($db); +$hookmanager->initHooks(array('loancard','globalcard')); + /* * Actions */ -// Classify paid -if ($action == 'confirm_paid' && $confirm == 'yes') -{ - $object->fetch($id); - $result = $object->set_paid($user); - if ($result > 0) - { - setEventMessages($langs->trans('LoanPaid'), null, 'mesgs'); - } - else - { - setEventMessages($loan->error, null, 'errors'); - } -} +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -// Delete loan -if ($action == 'confirm_delete' && $confirm == 'yes') +if (empty($reshook)) { - $object->fetch($id); - $result=$object->delete($user); - if ($result > 0) + // Classify paid + if ($action == 'confirm_paid' && $confirm == 'yes') { - setEventMessages($langs->trans('LoanDeleted'), null, 'mesgs'); - header("Location: index.php"); - exit; + $object->fetch($id); + $result = $object->set_paid($user); + if ($result > 0) + { + setEventMessages($langs->trans('LoanPaid'), null, 'mesgs'); + } + else + { + setEventMessages($loan->error, null, 'errors'); + } } - else - { - setEventMessages($loan->error, null, 'errors'); - } -} -// Add loan -if ($action == 'add' && $user->rights->loan->write) -{ - if (! $cancel) + // Delete loan + if ($action == 'confirm_delete' && $confirm == 'yes') { - $datestart=@dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); - $dateend=@dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); - - if (! $datestart) + $object->fetch($id); + $result=$object->delete($user); + if ($result > 0) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateStart")), null, 'errors'); - $action = 'create'; - } - elseif (! $dateend) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateEnd")), null, 'errors'); - $action = 'create'; - } - elseif (! $_POST["capital"]) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors'); - $action = 'create'; + setEventMessages($langs->trans('LoanDeleted'), null, 'mesgs'); + header("Location: index.php"); + exit; } else { - $object->label = $_POST["label"]; - $object->fk_bank = $_POST["accountid"]; - $object->capital = $_POST["capital"]; - $object->datestart = $datestart; - $object->dateend = $dateend; - $object->nbterm = $_POST["nbterm"]; - $object->rate = $_POST["rate"]; - $object->note_private = GETPOST('note_private'); - $object->note_public = GETPOST('note_public'); + setEventMessages($loan->error, null, 'errors'); + } + } - $accountancy_account_capital = GETPOST('accountancy_account_capital'); - $accountancy_account_insurance = GETPOST('accountancy_account_insurance'); - $accountancy_account_interest = GETPOST('accountancy_account_interest'); + // Add loan + if ($action == 'add' && $user->rights->loan->write) + { + if (! $cancel) + { + $datestart=@dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); + $dateend=@dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); - if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; } - if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; } - if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; } - - $id=$object->create($user); - if ($id <= 0) + if (! $datestart) { - setEventMessages($object->error, $object->errors, 'errors'); + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateStart")), null, 'errors'); + $action = 'create'; + } + elseif (! $dateend) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateEnd")), null, 'errors'); + $action = 'create'; + } + elseif (! $_POST["capital"]) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors'); + $action = 'create'; + } + else + { + $object->label = $_POST["label"]; + $object->fk_bank = $_POST["accountid"]; + $object->capital = $_POST["capital"]; + $object->datestart = $datestart; + $object->dateend = $dateend; + $object->nbterm = $_POST["nbterm"]; + $object->rate = $_POST["rate"]; + $object->note_private = GETPOST('note_private'); + $object->note_public = GETPOST('note_public'); + $object->fk_project = GETPOST('fk_project'); + + $accountancy_account_capital = GETPOST('accountancy_account_capital'); + $accountancy_account_insurance = GETPOST('accountancy_account_insurance'); + $accountancy_account_interest = GETPOST('accountancy_account_interest'); + + if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; } + if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; } + if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; } + + $id=$object->create($user); + if ($id <= 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + } } } - } - else - { - header("Location: index.php"); - exit(); - } -} - -// Update record -else if ($action == 'update' && $user->rights->loan->write) -{ - if (! $cancel) - { - $result = $object->fetch($id); - - if ($object->fetch($id)) + else { - $object->label = GETPOST("label"); - $object->datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int')); - $object->dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int')); - $object->nbterm = GETPOST("nbterm"); - $object->rate = GETPOST("rate"); + header("Location: index.php"); + exit(); } + } - $result = $object->update($user); + // Update record + else if ($action == 'update' && $user->rights->loan->write) + { + if (! $cancel) + { + $result = $object->fetch($id); - if ($result > 0) - { - header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); - exit; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - else - { - header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); - exit; - } + if ($object->fetch($id)) + { + $object->label = GETPOST("label"); + $object->datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int')); + $object->dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int')); + $object->nbterm = GETPOST("nbterm"); + $object->rate = GETPOST("rate"); + $object->fk_project = GETPOST("fk_project"); + } + + $result = $object->update($user); + + if ($result > 0) + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + else + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } + } } - /* * View */ @@ -240,6 +254,20 @@ if ($action == 'create') // Rate print '
| ';
@@ -537,33 +582,38 @@ if ($id > 0)
*/
if ($action != 'edit')
{
- print ' ';
+ $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
+ // modified by hook
+ if (empty($reshook))
+ {
+ print ' ";
}
}
else
diff --git a/htdocs/loan/class/loan.class.php b/htdocs/loan/class/loan.class.php
index 5c57764bf97..8ed6e682ce6 100644
--- a/htdocs/loan/class/loan.class.php
+++ b/htdocs/loan/class/loan.class.php
@@ -50,6 +50,7 @@ class Loan extends CommonObject
var $fk_bank;
var $fk_user_creat;
var $fk_user_modif;
+ var $fk_project;
/**
@@ -72,7 +73,7 @@ class Loan extends CommonObject
function fetch($id)
{
$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public,";
- $sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest";
+ $sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest,l.fk_project";
$sql.= " FROM ".MAIN_DB_PREFIX."loan as l";
$sql.= " WHERE l.rowid = ".$id;
@@ -99,6 +100,7 @@ class Loan extends CommonObject
$this->account_capital = $obj->accountancy_account_capital;
$this->account_insurance = $obj->accountancy_account_insurance;
$this->account_interest = $obj->accountancy_account_interest;
+ $this->fk_project = $obj->fk_project;
$this->db->free($resql);
return 1;
@@ -141,6 +143,7 @@ class Loan extends CommonObject
if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank);
if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat);
if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif);
+ if (isset($this->fk_project)) $this->fk_project=trim($this->fk_project);
// Check parameters
if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend))
@@ -158,7 +161,7 @@ class Loan extends CommonObject
$sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public";
$sql.= " ,accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity";
- $sql.= " ,datec, fk_user_author)";
+ $sql.= " ,datec,fk_project,fk_user_author)";
$sql.= " VALUES ('".$this->db->escape($this->label)."',";
$sql.= " '".$this->db->escape($this->fk_bank)."',";
$sql.= " '".price2num($newcapital)."',";
@@ -173,6 +176,7 @@ class Loan extends CommonObject
$sql.= " '".$this->db->escape($this->account_interest)."',";
$sql.= " ".$conf->entity.",";
$sql.= " '".$this->db->idate($now)."',";
+ $sql.= " '".$this->fk_project."',";
$sql.= " ".$user->id;
$sql.= ")";
@@ -280,6 +284,7 @@ class Loan extends CommonObject
$sql.= " SET label='".$this->db->escape($this->label)."',";
$sql.= " datestart='".$this->db->idate($this->datestart)."',";
$sql.= " dateend='".$this->db->idate($this->dateend)."',";
+ $sql.= " fk_project='".$this->db->escape($this->fk_project)."',";
$sql.= " fk_user_modif = ".$user->id;
$sql.= " WHERE rowid=".$this->id;
diff --git a/htdocs/projet/ajax/projects.php b/htdocs/projet/ajax/projects.php
index 55a4597dc08..3140352bf60 100644
--- a/htdocs/projet/ajax/projects.php
+++ b/htdocs/projet/ajax/projects.php
@@ -37,6 +37,7 @@ $htmlname=GETPOST('htmlname','alpha');
$socid=GETPOST('socid','int');
$action=GETPOST('action', 'alpha');
$id=GETPOST('id', 'int');
+$discard_closed =GETPOST('discardclosed','int');
/*
@@ -63,7 +64,7 @@ if (! GETPOST($htmlname) && ! GETPOST($idprod)) return;
$searchkey=(GETPOST($idprod)?GETPOST($idprod):(GETPOST($htmlname)?GETPOST($htmlname):''));
$form = new FormProjets($db);
-$arrayresult=$form->select_projects_list($socid, '', $htmlname, 0, 0, 1, 0, 0, 0, 1, $searchkey);
+$arrayresult=$form->select_projects_list($socid, '', $htmlname, 0, 0, 1, $discard_closed, 0, 0, 1, $searchkey);
$db->close();
';
- // Edit
- if ($user->rights->loan->write)
- {
- print ''.$langs->trans("Modify").'';
+ // Edit
+ if ($user->rights->loan->write)
+ {
+ print ''.$langs->trans("Modify").'';
+ }
+
+ // Emit payment
+ if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write)
+ {
+ print ''.$langs->trans("DoPayment").'';
+ }
+
+ // Classify 'paid'
+ if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write)
+ {
+ print ''.$langs->trans("ClassifyPaid").'';
+ }
+
+ // Delete
+ if ($user->rights->loan->delete)
+ {
+ print ''.$langs->trans("Delete").'';
+ }
+
+ print " ";
}
-
- // Emit payment
- if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write)
- {
- print ''.$langs->trans("DoPayment").'';
- }
-
- // Classify 'paid'
- if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write)
- {
- print ''.$langs->trans("ClassifyPaid").'';
- }
-
- // Delete
- if ($user->rights->loan->delete)
- {
- print ''.$langs->trans("Delete").'';
- }
-
- print " |