NEW: Add project and Hook to Loan

BUG: Correct discard_closed parametters management in project
This commit is contained in:
moreauf 2016-11-14 19:25:50 +01:00
parent bfd1ce0095
commit 081be37787
6 changed files with 198 additions and 141 deletions

View File

@ -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'

View File

@ -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;

View File

@ -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;

View File

@ -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 '<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
print '<tr>';
print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
@ -283,8 +311,8 @@ if ($action == 'create')
print '<td>';
print $formaccountancy->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1);
print '</td></tr>';
}
else // For external software
}
else // For external software
{
// Accountancy_account_capital
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
@ -300,11 +328,11 @@ if ($action == 'create')
print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>';
print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">';
print '</td></tr>';
print '</table>';
}
print '</table>';
dol_fiche_end();
print '<div align="center"><input class="button" type="submit" value="'.$langs->trans("Save").'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
@ -438,6 +466,23 @@ if ($id > 0)
}
print '</td></tr>';
// projet
if (! empty($conf->projet->enabled)){
print '<tr><td class="nowrap">';
print $langs->trans("Project");
print '</td><td>';
if ($action == 'edit') {
$formproject=new FormProjets($db);
$numproject=$formproject->select_projects(-1,$object->fk_project,'fk_project',16,0,1,1);
} else {
$project=new Project($db);
$project->fetch($object->fk_project);
print $project->getNomUrl(1,'',1);;
}
print '</td></tr>';
}
// Status
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4, $totalpaye).'</td></tr>';
@ -445,7 +490,7 @@ if ($id > 0)
dol_fiche_end();
if ($action == 'edit')
{
print '<div align="center">';
@ -455,7 +500,7 @@ if ($id > 0)
print '</div>';
print '</form><br><br>';
}
print '<table class="border" width="100%">';
print '<tr><td>';
@ -537,33 +582,38 @@ if ($id > 0)
*/
if ($action != 'edit')
{
print '<div class="tabsAction">';
$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">';
// Edit
if ($user->rights->loan->write)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
// Edit
if ($user->rights->loan->write)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
}
// 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 '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&amp;action=create">'.$langs->trans("DoPayment").'</a>';
}
// Classify 'paid'
if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=paid">'.$langs->trans("ClassifyPaid").'</a>';
}
// Delete
if ($user->rights->loan->delete)
{
print '<a class="butActionDelete" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
}
print "</div>";
}
// 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 '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&amp;action=create">'.$langs->trans("DoPayment").'</a>';
}
// Classify 'paid'
if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=paid">'.$langs->trans("ClassifyPaid").'</a>';
}
// Delete
if ($user->rights->loan->delete)
{
print '<a class="butActionDelete" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
}
print "</div>";
}
}
else

View File

@ -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;

View File

@ -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();