From 1d5dd0d16ed49b2f31fcc03971e96accff3fd4eb Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 5 Jun 2016 15:21:11 +0200 Subject: [PATCH 1/6] New: Loan - Add accountancy account list --- htdocs/loan/card.php | 68 +++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index 116de7c561d..88bf17d5e57 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -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 ''; + print ''; + + // Accountancy_account_insurance + print ''; + print ''; + + // Accountancy_account_interest + print ''; + print ''; + } + else // For external software + { + // Accountancy_account_capital print ''; print ''; - + + // Accountancy_account_insurance print ''; print ''; - + + // Accountancy_account_interest print ''; print ''; print '
'.$langs->trans("LoanAccountancyCapitalCode").''; + print $formaccountancy->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1); + print '
'.$langs->trans("LoanAccountancyInsuranceCode").''; + print $formaccountancy->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1); + print '
'.$langs->trans("LoanAccountancyInterestCode").''; + print $formaccountancy->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1); + print '
'.$langs->trans("LoanAccountancyCapitalCode").''; print '
'.$langs->trans("LoanAccountancyInsuranceCode").''; print '
'.$langs->trans("LoanAccountancyInterestCode").''; print '
'; } + print ''; dol_fiche_end(); From fda07997d2b7e016821631f699e03af223fdb5c9 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 5 Jun 2016 15:25:21 +0200 Subject: [PATCH 2/6] Fix: Loan - Remove page note, already present in card --- htdocs/core/lib/loan.lib.php | 10 ---- htdocs/loan/note.php | 101 ----------------------------------- 2 files changed, 111 deletions(-) delete mode 100644 htdocs/loan/note.php diff --git a/htdocs/core/lib/loan.lib.php b/htdocs/core/lib/loan.lib.php index 9dbb2a9664b..ad578c2e7d3 100644 --- a/htdocs/core/lib/loan.lib.php +++ b/htdocs/core/lib/loan.lib.php @@ -41,16 +41,6 @@ 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].= ' '.$nbNote.''; - $head[$tab][2] = 'note'; - $tab++; - } - // Show more tabs from modules // Entries must be declared in modules descriptor with line // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab diff --git a/htdocs/loan/note.php b/htdocs/loan/note.php deleted file mode 100644 index 969d5ecb436..00000000000 --- a/htdocs/loan/note.php +++ /dev/null @@ -1,101 +0,0 @@ - - * Copyright (C) 2004-2007 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2013 Florian Henry - * Copyright (C) 2015 Frederic France - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/loan/note.php - * \brief Tab for notes on loan - * \ingroup loan - */ - -require '../main.inc.php'; -require_once(DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'); -require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; - -$action = GETPOST('action'); - -$langs->load('loan'); - -// Security check -$id = GETPOST('id','int'); -$result = restrictedArea($user, 'loan', $id, '&loan'); - -$object = new Loan($db); -if ($id > 0) $object->fetch($id); - -$permissionnote=$user->rights->loan->write; // Used by the include of actions_setnotes.inc.php - - -/* - * Actions - */ - -include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once - - -/* - * View - */ - -$form = new Form($db); - -llxHeader('',$langs->trans("LoanArea"),''); - -if ($id > 0) -{ - /* - * Affichage onglets - */ - - $head = loan_prepare_head($object); - - dol_fiche_head($head, 'note', $langs->trans("Loan"), 0, 'bill'); - - - print '
'; - print ''; - - print ''; - - // Ref - print ''; - print ''; - // Name - print ''; - print ''; - - print "
'.$langs->trans('Ref').''; - print $form->showrefnav($object,'id','',1,'rowid','ref'); - print '
'.$langs->trans("Name").''.$object->label.'
"; - - print '
'; - - //$colwidth='25'; - $cssclass='titlefield'; - $permission = $user->rights->loan->write; // Used by the include of notes.tpl.php - include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; - - - dol_fiche_end(); -} - -llxFooter(); -$db->close(); - From bc92818c1a491a7105313cfbc1fec36dbb591b20 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 5 Jun 2016 15:39:41 +0200 Subject: [PATCH 3/6] New: Loan - Show accounting account in card in view mode --- htdocs/loan/card.php | 33 ++++++++++++++++++++++++++++++++ htdocs/loan/class/loan.class.php | 29 ++++++++++++++++------------ 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index 88bf17d5e57..ef1022da306 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -405,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).''; 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; } From bfb212f61a9e98b4144ce0d12ba3f0be8c119444 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 5 Jun 2016 16:08:40 +0200 Subject: [PATCH 4/6] Fix: Loan - Add dol_fiche --- htdocs/loan/card.php | 2 +- htdocs/loan/index.php | 2 +- htdocs/loan/payment/payment.php | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index ef1022da306..57d03556bd4 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.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 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/payment/payment.php b/htdocs/loan/payment/payment.php index 06061da5c22..8c9f850ebcc 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 @@ -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 ''; print ''; @@ -165,6 +164,8 @@ if ($_GET["action"] == 'create') print ''; print ''; + dol_fiche_head(); + print ''; print ''; @@ -230,9 +231,10 @@ if ($_GET["action"] == 'create') print ''; print ''; print ''; + print '
'.$langs->trans("Loan").''.$langs->trans("NotePublic").'
'; - print '
'; + dol_fiche_end(); print ''; print ''; @@ -296,13 +298,11 @@ if ($_GET["action"] == 'create') print '
'; - print '
'; - + print '
'; print ''; print '   '; print ''; - - print '
'; + print ''; print "\n"; } From e911b32b838ab93d40c226c2d21f543cffad8350 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 5 Jun 2016 16:15:04 +0200 Subject: [PATCH 5/6] Fix: Loan - Totalpaid (Only the capital is deducted from the amount of loan to be paid off) --- htdocs/loan/card.php | 10 ++++------ htdocs/loan/payment/payment.php | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index 57d03556bd4..31de81d8b9b 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -116,9 +116,9 @@ if ($action == 'add' && $user->rights->loan->write) $object->note_private = GETPOST('note_private'); $object->note_public = GETPOST('note_public'); - $accountancy_account_capital = GETPOST('accountancy_account_capital'); - $accountancy_account_insurance = GETPOST('accountancy_account_insurance'); - $accountancy_account_interest = GETPOST('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; } @@ -507,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/payment/payment.php b/htdocs/loan/payment/payment.php index 8c9f850ebcc..e735480e414 100644 --- a/htdocs/loan/payment/payment.php +++ b/htdocs/loan/payment/payment.php @@ -138,7 +138,7 @@ if ($action == 'add_payment') } } - $_GET["action"]='create'; + $action = 'create'; } From a6a96c710d91295c9a787e30d1a7fb70ca4f0f08 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 6 Jun 2016 20:36:04 +0200 Subject: [PATCH 6/6] Restore note page --- htdocs/core/lib/loan.lib.php | 10 ++++ htdocs/loan/note.php | 101 +++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 htdocs/loan/note.php diff --git a/htdocs/core/lib/loan.lib.php b/htdocs/core/lib/loan.lib.php index ad578c2e7d3..fa80fe31a2b 100644 --- a/htdocs/core/lib/loan.lib.php +++ b/htdocs/core/lib/loan.lib.php @@ -41,6 +41,16 @@ 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].= ' '.$nbNote.''; + $head[$tab][2] = 'note'; + $tab++; + } + // Show more tabs from modules // Entries must be declared in modules descriptor with line // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab diff --git a/htdocs/loan/note.php b/htdocs/loan/note.php new file mode 100644 index 00000000000..155dacf460b --- /dev/null +++ b/htdocs/loan/note.php @@ -0,0 +1,101 @@ + + * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2015 Frederic France + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/loan/note.php + * \brief Tab for notes on loan + * \ingroup loan + */ + +require '../main.inc.php'; +require_once(DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'); +require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; + +$action = GETPOST('action'); + +$langs->load('loan'); + +// Security check +$id = GETPOST('id','int'); +$result = restrictedArea($user, 'loan', $id, '&loan'); + +$object = new Loan($db); +if ($id > 0) $object->fetch($id); + +$permissionnote=$user->rights->loan->write; // Used by the include of actions_setnotes.inc.php + + +/* + * Actions + */ + +include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once + + +/* + * View + */ + +$form = new Form($db); + +llxHeader('',$langs->trans("Loan"),''); + +if ($id > 0) +{ + /* + * Affichage onglets + */ + + $head = loan_prepare_head($object); + + dol_fiche_head($head, 'note', $langs->trans("Loan"), 0, 'bill'); + + + print '
'; + print ''; + + print ''; + + // Ref + print ''; + print ''; + // Name + print ''; + print ''; + + print "
'.$langs->trans('Ref').''; + print $form->showrefnav($object,'id','',1,'rowid','ref'); + print '
'.$langs->trans("Name").''.$object->label.'
"; + + print '
'; + + //$colwidth='25'; + $cssclass='titlefield'; + $permission = $user->rights->loan->write; // Used by the include of notes.tpl.php + include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; + + + dol_fiche_end(); +} + +llxFooter(); +$db->close(); +