Merge pull request #5312 from aspangaro/4.0-p32

Loan - Debug & update
This commit is contained in:
Laurent Destailleur 2016-06-07 00:28:20 +02:00
commit dcc1589d7c
6 changed files with 121 additions and 55 deletions

View File

@ -41,15 +41,15 @@ function loan_prepare_head($object)
$head[$tab][2] = 'card';
$tab++;
if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
{
$nbNote = (empty($object->note_private)?0:1)+(empty($object->note_public)?0:1);
$head[$tab][0] = DOL_URL_ROOT."/loan/note.php?id=".$object->id;
$head[$tab][1] = $langs->trans("Notes");
if($nbNote > 0) $head[$tab][1].= ' <span class="badge">'.$nbNote.'</span>';
$head[$tab][2] = 'note';
$tab++;
}
if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
{
$nbNote = (empty($object->note_private)?0:1)+(empty($object->note_public)?0:1);
$head[$tab][0] = DOL_URL_ROOT."/loan/note.php?id=".$object->id;
$head[$tab][1] = $langs->trans("Notes");
if($nbNote > 0) $head[$tab][1].= ' <span class="badge">'.$nbNote.'</span>';
$head[$tab][2] = 'note';
$tab++;
}
// Show more tabs from modules
// Entries must be declared in modules descriptor with line

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2014-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
/* Copyright (C) 2014-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -26,6 +26,8 @@ require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
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';
$langs->load("compta");
$langs->load("bills");
@ -104,19 +106,23 @@ if ($action == 'add' && $user->rights->loan->write)
}
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->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->account_capital = $_POST["accountancy_account_capital"];
$object->account_insurance = $_POST["accountancy_account_insurance"];
$object->account_interest = $_POST["accountancy_account_interest"];
$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)
@ -172,6 +178,7 @@ else if ($action == 'update' && $user->rights->loan->write)
*/
$form = new Form($db);
if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
$help_url='EN:Module_Loan|FR:Module_Emprunt';
llxHeader("",$langs->trans("Loan"),$help_url);
@ -253,27 +260,50 @@ if ($action == 'create')
print '</table>';
print '<br>';
print '<table class="border" width="100%">';
// Accountancy
if ($conf->accounting->enabled)
if (! empty($conf->accounting->enabled))
{
print '<br>';
print '<table class="border" width="100%">';
// Accountancy_account_capital
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
print '<td>';
print $formaccountancy->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1);
print '</td></tr>';
// Accountancy_account_insurance
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
print '<td>';
print $formaccountancy->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1);
print '</td></tr>';
// Accountancy_account_interest
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("LoanAccountancyInterestCode").'</td>';
print '<td>';
print $formaccountancy->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1);
print '</td></tr>';
}
else // For external software
{
// Accountancy_account_capital
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
print '</td></tr>';
// Accountancy_account_insurance
print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">';
print '</td></tr>';
// Accountancy_account_interest
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();
@ -375,6 +405,39 @@ if ($id > 0)
// Note Public
print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($object->note_public).'</td></tr>';
// Accountancy account capital
print '<tr><td class="nowrap">';
print $langs->trans("LoanAccountancyCapitalCode");
print '</td><td>';
if (! empty($conf->accounting->enabled)) {
print length_accountg($object->account_capital);
} else {
print $object->account_capital;
}
print '</td></tr>';
// Accountancy account insurance
print '<tr><td class="nowrap">';
print $langs->trans("LoanAccountancyInsuranceCode");
print '</td><td>';
if (! empty($conf->accounting->enabled)) {
print length_accountg($object->account_insurance);
} else {
print $object->account_insurance;
}
print '</td></tr>';
// Accountancy account interest
print '<tr><td class="nowrap">';
print $langs->trans("LoanAccountancyInterestCode");
print '</td><td>';
if (! empty($conf->accounting->enabled)) {
print length_accountg($object->account_interest);
} else {
print $object->account_interest;
}
print '</td></tr>';
// Status
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4, $totalpaye).'</td></tr>';
@ -444,13 +507,11 @@ if ($id > 0)
print '<td align="right">'.price($objp->amount_interest, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n";
print '<td align="right">'.price($objp->amount_capital, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n";
print "</tr>";
$total_insurance += $objp->amount_insurance;
$total_interest += $objp->amount_interest;
$total_capital += $objp->amount_capital;
$i++;
}
$totalpaid = $total_insurance + $total_interest + $total_capital;
$totalpaid = $total_capital;
if ($object->paid == 0)
{

View File

@ -72,7 +72,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";
$sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest";
$sql.= " FROM ".MAIN_DB_PREFIX."loan as l";
$sql.= " WHERE l.rowid = ".$id;
@ -84,17 +84,22 @@ class Loan extends CommonObject
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
$this->datestart = $this->db->jdate($obj->datestart);
$this->dateend = $this->db->jdate($obj->dateend);
$this->label = $obj->label;
$this->capital = $obj->capital;
$this->nbterm = $obj->nbterm;
$this->rate = $obj->rate;
$this->note_private = $obj->note_private;
$this->note_public = $obj->note_public;
$this->paid = $obj->paid;
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
$this->datestart = $this->db->jdate($obj->datestart);
$this->dateend = $this->db->jdate($obj->dateend);
$this->label = $obj->label;
$this->capital = $obj->capital;
$this->nbterm = $obj->nbterm;
$this->rate = $obj->rate;
$this->note_private = $obj->note_private;
$this->note_public = $obj->note_public;
$this->paid = $obj->paid;
$this->account_capital = $obj->accountancy_account_capital;
$this->account_insurance = $obj->accountancy_account_insurance;
$this->account_interest = $obj->accountancy_account_interest;
return 1;
}

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2014 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2016 Laurent Destailleur <jmenent@2byte.es>
* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -56,7 +56,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include,
$form = new Form($db);
llxHeader('',$langs->trans("LoanArea"),'');
llxHeader('',$langs->trans("Loan"),'');
if ($id > 0)
{

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
/* Copyright (C) 2014-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -138,7 +138,7 @@ if ($action == 'add_payment')
}
}
$_GET["action"]='create';
$action = 'create';
}
@ -152,12 +152,11 @@ $form=new Form($db);
// Form to create loan's payment
if ($_GET["action"] == 'create')
if ($action == 'create')
{
$total = $loan->capital;
print load_fiche_titre($langs->trans("DoPayment"));
print "<br>\n";
print '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -165,6 +164,8 @@ if ($_GET["action"] == 'create')
print '<input type="hidden" name="chid" value="'.$chid.'">';
print '<input type="hidden" name="action" value="add_payment">';
dol_fiche_head();
print '<table cellspacing="0" class="border" width="100%" cellpadding="2">';
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Loan").'</td>';
@ -230,9 +231,10 @@ if ($_GET["action"] == 'create')
print '<td valign="top">'.$langs->trans("NotePublic").'</td>';
print '<td valign="top" colspan="2"><textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_3.'"></textarea></td>';
print '</tr>';
print '</table>';
print '<br>';
dol_fiche_end();
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
@ -296,13 +298,11 @@ if ($_GET["action"] == 'create')
print '</table>';
print '<br><center>';
print '<br><div class="center">';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print '&nbsp; &nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</center>';
print '</div>';
print "</form>\n";
}