git push origin developMerge branch 'Franck-MOREAU-develop' into develop

This commit is contained in:
Laurent Destailleur 2017-01-07 17:45:50 +01:00
commit d23aa8ef3c
9 changed files with 336 additions and 234 deletions

View File

@ -223,7 +223,7 @@ if (empty($reshook))
} }
} }
// Categorisation dans projet // Link to a project
else if ($action == 'classin' && $user->rights->commande->creer) else if ($action == 'classin' && $user->rights->commande->creer)
{ {
$object->setProject(GETPOST('projectid')); $object->setProject(GETPOST('projectid'));

View File

@ -79,7 +79,7 @@ class FormProjets
$project->fetch($selected); $project->fetch($selected);
$selected_input_value=$project->ref; $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( $out.=ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array(
// 'update' => array( // 'update' => array(
// 'projectid' => 'id' // 'projectid' => 'id'

View File

@ -43,3 +43,6 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_MODIFY','Product or service modified','Executed when a product or sevice is modified','product',30); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_MODIFY','Product or service modified','Executed when a product or sevice is modified','product',30);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_DELETE','Product or service deleted','Executed when a product or sevice is deleted','product',30); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_DELETE','Product or service deleted','Executed when a product or sevice is deleted','product',30);
ALTER TABLE llx_loan ADD COLUMN fk_projet integer DEFAULT NULL;

View File

@ -45,7 +45,9 @@ create table llx_loan
accountancy_account_insurance varchar(32), accountancy_account_insurance varchar(32),
accountancy_account_interest varchar(32), accountancy_account_interest varchar(32),
fk_projet integer DEFAULT NULL,
fk_user_author integer DEFAULT NULL, fk_user_author integer DEFAULT NULL,
fk_user_modif integer DEFAULT NULL, fk_user_modif integer DEFAULT NULL
active tinyint DEFAULT 1 NOT NULL active tinyint DEFAULT 1 NOT NULL
)ENGINE=innodb; )ENGINE=innodb;

View File

@ -28,6 +28,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.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.'/core/lib/accounting.lib.php';
if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php';
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("compta");
$langs->load("bills"); $langs->load("bills");
@ -45,13 +47,20 @@ $result = restrictedArea($user, 'loan', $id, '','');
$object = new Loan($db); $object = new Loan($db);
$hookmanager->initHooks(array('loancard','globalcard'));
/* /*
* Actions * Actions
*/ */
// Classify paid $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($action == 'confirm_paid' && $confirm == 'yes') if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook))
{ {
// Classify paid
if ($action == 'confirm_paid' && $confirm == 'yes')
{
$object->fetch($id); $object->fetch($id);
$result = $object->set_paid($user); $result = $object->set_paid($user);
if ($result > 0) if ($result > 0)
@ -62,11 +71,11 @@ if ($action == 'confirm_paid' && $confirm == 'yes')
{ {
setEventMessages($loan->error, null, 'errors'); setEventMessages($loan->error, null, 'errors');
} }
} }
// Delete loan // Delete loan
if ($action == 'confirm_delete' && $confirm == 'yes') if ($action == 'confirm_delete' && $confirm == 'yes')
{ {
$object->fetch($id); $object->fetch($id);
$result=$object->delete($user); $result=$object->delete($user);
if ($result > 0) if ($result > 0)
@ -79,11 +88,11 @@ if ($action == 'confirm_delete' && $confirm == 'yes')
{ {
setEventMessages($loan->error, null, 'errors'); setEventMessages($loan->error, null, 'errors');
} }
} }
// Add loan // Add loan
if ($action == 'add' && $user->rights->loan->write) if ($action == 'add' && $user->rights->loan->write)
{ {
if (! $cancel) if (! $cancel)
{ {
$datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int')); $datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
@ -116,6 +125,7 @@ if ($action == 'add' && $user->rights->loan->write)
$object->rate = GETPOST('rate'); $object->rate = GETPOST('rate');
$object->note_private = GETPOST('note_private'); $object->note_private = GETPOST('note_private');
$object->note_public = GETPOST('note_public'); $object->note_public = GETPOST('note_public');
$object->fk_project = GETPOST('fk_project');
$accountancy_account_capital = GETPOST('accountancy_account_capital'); $accountancy_account_capital = GETPOST('accountancy_account_capital');
$accountancy_account_insurance = GETPOST('accountancy_account_insurance'); $accountancy_account_insurance = GETPOST('accountancy_account_insurance');
@ -137,16 +147,15 @@ if ($action == 'add' && $user->rights->loan->write)
header("Location: index.php"); header("Location: index.php");
exit(); exit();
} }
} }
// Update record // Update record
else if ($action == 'update' && $user->rights->loan->write) else if ($action == 'update' && $user->rights->loan->write)
{ {
if (! $cancel) if (! $cancel)
{ {
$result = $object->fetch($id); $result = $object->fetch($id);
if ($result > 0)
if ($object->fetch($id))
{ {
$object->datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int')); $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->dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
@ -172,21 +181,33 @@ else if ($action == 'update' && $user->rights->loan->write)
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
exit; exit;
} }
} }
if ($action == 'setlabel' && $user->rights->loan->write) // Link to a project
{ if ($action == 'classin' && $user->rights->loan->write)
{
$object->fetch($id);
$result = $object->setProject(GETPOST('projectid'));
if ($result < 0)
setEventMessages($object->error, $object->errors, 'errors');
}
if ($action == 'setlabel' && $user->rights->loan->write)
{
$object->fetch($id); $object->fetch($id);
$result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY'); $result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY');
if ($result < 0) if ($result < 0)
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
}
} }
/* /*
* View * View
*/ */
$form = new Form($db); $form = new Form($db);
$formproject = new FormProjets($db);
if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db); if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
$title = $langs->trans("Loan") . ' - ' . $langs->trans("Card"); $title = $langs->trans("Loan") . ' - ' . $langs->trans("Card");
@ -250,6 +271,21 @@ if ($action == 'create')
// Rate // Rate
print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="' . GETPOST("rate") . '"> %</td></tr>'; print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="' . GETPOST("rate") . '"> %</td></tr>';
// Project
if (! empty($conf->projet->enabled))
{
$formproject=new FormProjets($db);
// Projet associe
$langs->load("projects");
print '<tr><td>'.$langs->trans("Project").'</td><td>';
$numproject=$formproject->select_projects(-1,GETPOST("fk_project"),'fk_project',16,0,1,1);
print '</td></tr>';
}
// Note Private // Note Private
print '<tr>'; print '<tr>';
print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>'; print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
@ -354,14 +390,48 @@ if ($id > 0)
dol_fiche_head($head, 'card', $langs->trans("Loan"), 0, 'bill'); dol_fiche_head($head, 'card', $langs->trans("Loan"), 0, 'bill');
// Loan card
$linkback = '<a href="' . DOL_URL_ROOT . '/loan/index.php">' . $langs->trans("BackToList") . '</a>';
$morehtmlref='<div class="refidno">'; $morehtmlref='<div class="refidno">';
// Ref loan // Ref loan
$morehtmlref.=$form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', 0, 1); $morehtmlref.=$form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', 0, 1);
$morehtmlref.=$form->editfieldval("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', null, null, '', 1); $morehtmlref.=$form->editfieldval("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', null, null, '', 1);
// Project
if (! empty($conf->projet->enabled))
{
$langs->load("projects");
$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
if ($user->rights->commande->creer)
{
if ($action != 'classify')
$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
if ($action == 'classify') {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
$morehtmlref.='<input type="hidden" name="action" value="classin">';
$morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
$morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref.='</form>';
} else {
$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
}
} else {
if (! empty($object->fk_project)) {
$proj = new Project($db);
$proj->fetch($object->fk_project);
$morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
$morehtmlref.=$proj->ref;
$morehtmlref.='</a>';
} else {
$morehtmlref.='';
}
}
}
$morehtmlref.='</div>'; $morehtmlref.='</div>';
$linkback = '<a href="' . DOL_URL_ROOT . '/loan/index.php">' . $langs->trans("BackToList") . '</a>';
$object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
@ -468,6 +538,7 @@ if ($id > 0)
} }
print '</td></tr>'; print '</td></tr>';
// Status // Status
// print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4, $totalpaye).'</td></tr>'; // print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4, $totalpaye).'</td></tr>';
@ -571,6 +642,9 @@ if ($id > 0)
* Buttons actions * Buttons actions
*/ */
if ($action != 'edit') if ($action != 'edit')
{
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
@ -601,6 +675,7 @@ if ($id > 0)
print "</div>"; print "</div>";
} }
} }
}
else else
{ {
// Loan not found // Loan not found

View File

@ -32,6 +32,7 @@ class Loan extends CommonObject
public $element='loan'; public $element='loan';
public $table='loan'; public $table='loan';
public $table_element='loan'; public $table_element='loan';
public $picto = 'bill'; public $picto = 'bill';
public $rowid; public $rowid;
@ -51,6 +52,7 @@ class Loan extends CommonObject
public $fk_bank; public $fk_bank;
public $fk_user_creat; public $fk_user_creat;
public $fk_user_modif; public $fk_user_modif;
public $fk_project;
/** /**
@ -73,7 +75,7 @@ class Loan extends CommonObject
function fetch($id) 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 = "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_projet as fk_project";
$sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; $sql.= " FROM ".MAIN_DB_PREFIX."loan as l";
$sql.= " WHERE l.rowid = ".$id; $sql.= " WHERE l.rowid = ".$id;
@ -100,6 +102,7 @@ class Loan extends CommonObject
$this->account_capital = $obj->accountancy_account_capital; $this->account_capital = $obj->accountancy_account_capital;
$this->account_insurance = $obj->accountancy_account_insurance; $this->account_insurance = $obj->accountancy_account_insurance;
$this->account_interest = $obj->accountancy_account_interest; $this->account_interest = $obj->accountancy_account_interest;
$this->fk_project = $obj->fk_project;
$this->db->free($resql); $this->db->free($resql);
return 1; return 1;
@ -142,6 +145,7 @@ class Loan extends CommonObject
if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); 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_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_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 // Check parameters
if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend)) if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend))
@ -157,9 +161,9 @@ class Loan extends CommonObject
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public"; $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.= " accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity,";
$sql.= " ,datec, fk_user_author)"; $sql.= " datec, fk_projet, fk_user_author)";
$sql.= " VALUES ('".$this->db->escape($this->label)."',"; $sql.= " VALUES ('".$this->db->escape($this->label)."',";
$sql.= " '".$this->db->escape($this->fk_bank)."',"; $sql.= " '".$this->db->escape($this->fk_bank)."',";
$sql.= " '".price2num($newcapital)."',"; $sql.= " '".price2num($newcapital)."',";
@ -174,6 +178,7 @@ class Loan extends CommonObject
$sql.= " '".$this->db->escape($this->account_interest)."',"; $sql.= " '".$this->db->escape($this->account_interest)."',";
$sql.= " ".$conf->entity.","; $sql.= " ".$conf->entity.",";
$sql.= " '".$this->db->idate($now)."',"; $sql.= " '".$this->db->idate($now)."',";
$sql.= " ".(empty($this->fk_project)?'NULL':$this->fk_project).",";
$sql.= " ".$user->id; $sql.= " ".$user->id;
$sql.= ")"; $sql.= ")";
@ -282,6 +287,7 @@ class Loan extends CommonObject
$sql.= " capital='".price2num($this->db->escape($this->capital))."',"; $sql.= " capital='".price2num($this->db->escape($this->capital))."',";
$sql.= " datestart='".$this->db->idate($this->datestart)."',"; $sql.= " datestart='".$this->db->idate($this->datestart)."',";
$sql.= " dateend='".$this->db->idate($this->dateend)."',"; $sql.= " dateend='".$this->db->idate($this->dateend)."',";
$sql.= " fk_projet=".(empty($this->fk_project)?'NULL':$this->fk_project).",";
$sql.= " fk_user_modif = ".$user->id; $sql.= " fk_user_modif = ".$user->id;
$sql.= " WHERE rowid=".$this->id; $sql.= " WHERE rowid=".$this->id;

View File

@ -37,6 +37,7 @@ $htmlname=GETPOST('htmlname','alpha');
$socid=GETPOST('socid','int'); $socid=GETPOST('socid','int');
$action=GETPOST('action', 'alpha'); $action=GETPOST('action', 'alpha');
$id=GETPOST('id', 'int'); $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):'')); $searchkey=(GETPOST($idprod)?GETPOST($idprod):(GETPOST($htmlname)?GETPOST($htmlname):''));
$form = new FormProjets($db); $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(); $db->close();

View File

@ -47,6 +47,7 @@ if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compt
if (! empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; if (! empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
if (! empty($conf->don->enabled)) require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; if (! empty($conf->don->enabled)) require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
if (! empty($conf->loan->enabled)) require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
$langs->load("projects"); $langs->load("projects");
$langs->load("companies"); $langs->load("companies");
@ -58,6 +59,7 @@ if (! empty($conf->ficheinter->enabled)) $langs->load("interventions");
if (! empty($conf->deplacement->enabled)) $langs->load("trips"); if (! empty($conf->deplacement->enabled)) $langs->load("trips");
if (! empty($conf->expensereport->enabled)) $langs->load("trips"); if (! empty($conf->expensereport->enabled)) $langs->load("trips");
if (! empty($conf->don->enabled)) $langs->load("donations"); if (! empty($conf->don->enabled)) $langs->load("donations");
if (! empty($conf->loan->enabled)) $langs->load("loan");
$id=GETPOST('id','int'); $id=GETPOST('id','int');
$ref=GETPOST('ref','alpha'); $ref=GETPOST('ref','alpha');
@ -370,6 +372,19 @@ $listofreferent=array(
'buttonnew'=>'AddDonation', 'buttonnew'=>'AddDonation',
'testnew'=>$user->rights->don->creer, 'testnew'=>$user->rights->don->creer,
'test'=>$conf->don->enabled && $user->rights->don->lire), 'test'=>$conf->don->enabled && $user->rights->don->lire),
'loan'=>array(
'name'=>"Loan",
'title'=>"ListLoanAssociatedProject",
'class'=>'Loan',
'margin'=>'add',
'table'=>'Loan',
'datefieldname'=>'datestart',
'disableamount'=>0,
'urlnew'=>DOL_URL_ROOT.'/loan/card.php?action=create&projectid='.$id.'&socid='.$socid,
'lang'=>'loan',
'buttonnew'=>'AddLoan',
'testnew'=>$user->rights->loan->creer,
'test'=>$conf->loan->enabled && $user->rights->loan->lire),
'project_task'=>array( 'project_task'=>array(
'name'=>"TaskTimeValorised", 'name'=>"TaskTimeValorised",
'title'=>"ListTaskTimeUserProject", 'title'=>"ListTaskTimeUserProject",