*
* 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 '';
+ print '
';
+
+ print '';
// Accountancy
- if ($conf->accounting->enabled)
+ if (! empty($conf->accounting->enabled))
{
- print '
';
-
- print '';
-
+ // Accountancy_account_capital
+ print '| '.$langs->trans("LoanAccountancyCapitalCode").' | ';
+ print '';
+ print $formaccountancy->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1);
+ print ' |
';
+
+ // Accountancy_account_insurance
+ print '| '.$langs->trans("LoanAccountancyInsuranceCode").' | ';
+ print '';
+ print $formaccountancy->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1);
+ print ' |
';
+
+ // Accountancy_account_interest
+ print '| '.$langs->trans("LoanAccountancyInterestCode").' | ';
+ print '';
+ print $formaccountancy->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1);
+ print ' |
';
+ }
+ else // For external software
+ {
+ // Accountancy_account_capital
print '| '.$langs->trans("LoanAccountancyCapitalCode").' | ';
print '';
print ' |
';
-
+
+ // Accountancy_account_insurance
print '| '.$langs->trans("LoanAccountancyInsuranceCode").' | ';
print '';
print ' |
';
-
+
+ // Accountancy_account_interest
print '| '.$langs->trans("LoanAccountancyInterestCode").' | ';
print '';
print ' |
';
print '
';
}
+ print '
';
dol_fiche_end();
@@ -375,6 +405,39 @@ if ($id > 0)
// Note Public
print '| '.$langs->trans('NotePublic').' | '.nl2br($object->note_public).' |
';
+ // Accountancy account capital
+ print '| ';
+ print $langs->trans("LoanAccountancyCapitalCode");
+ print ' | ';
+ if (! empty($conf->accounting->enabled)) {
+ print length_accountg($object->account_capital);
+ } else {
+ print $object->account_capital;
+ }
+ print ' |
';
+
+ // Accountancy account insurance
+ print '| ';
+ print $langs->trans("LoanAccountancyInsuranceCode");
+ print ' | ';
+ if (! empty($conf->accounting->enabled)) {
+ print length_accountg($object->account_insurance);
+ } else {
+ print $object->account_insurance;
+ }
+ print ' |
';
+
+ // Accountancy account interest
+ print '| ';
+ print $langs->trans("LoanAccountancyInterestCode");
+ print ' | ';
+ if (! empty($conf->accounting->enabled)) {
+ print length_accountg($object->account_interest);
+ } else {
+ print $object->account_interest;
+ }
+ print ' |
';
+
// Status
print '| '.$langs->trans("Status").' | '.$object->getLibStatut(4, $totalpaye).' |
';
@@ -444,13 +507,11 @@ if ($id > 0)
print ''.price($objp->amount_interest, 0, $langs, 0, 0, -1, $conf->currency)." | \n";
print ''.price($objp->amount_capital, 0, $langs, 0, 0, -1, $conf->currency)." | \n";
print "";
- $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)
{
diff --git a/htdocs/loan/class/loan.class.php b/htdocs/loan/class/loan.class.php
index 66809b60720..60d4050148a 100644
--- a/htdocs/loan/class/loan.class.php
+++ b/htdocs/loan/class/loan.class.php
@@ -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;
}
diff --git a/htdocs/loan/index.php b/htdocs/loan/index.php
index 51f4e74e119..655372516b9 100644
--- a/htdocs/loan/index.php
+++ b/htdocs/loan/index.php
@@ -2,7 +2,7 @@
/* Copyright (C) 2014 Alexandre Spangaro
* Copyright (C) 2015 Frederic France
* Copyright (C) 2015 Juanjo Menent
- * Copyright (C) 2016 Laurent Destailleur
+ * Copyright (C) 2016 Laurent Destailleur
*
* 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
diff --git a/htdocs/loan/note.php b/htdocs/loan/note.php
index 969d5ecb436..155dacf460b 100644
--- a/htdocs/loan/note.php
+++ b/htdocs/loan/note.php
@@ -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)
{
diff --git a/htdocs/loan/payment/payment.php b/htdocs/loan/payment/payment.php
index 06061da5c22..e735480e414 100644
--- a/htdocs/loan/payment/payment.php
+++ b/htdocs/loan/payment/payment.php
@@ -1,5 +1,5 @@
+/* Copyright (C) 2014-2016 Alexandre Spangaro
* Copyright (C) 2015 Frederic France
*
* 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 "
\n";
print '\n";
}