Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2015-03-23 23:29:14 +01:00
commit 6c4369b7ba
31 changed files with 3581 additions and 13 deletions

View File

@ -182,6 +182,12 @@ source_file = htdocs/langs/en_US/link.lang
source_lang = en_US
type = MOZILLAPROPERTIES
[dolibarr.loan]
file_filter = htdocs/langs/<lang>/loan.lang
source_file = htdocs/langs/en_US/loan.lang
source_lang = en_US
type = MOZILLAPROPERTIES
[dolibarr.mailmanspip]
file_filter = htdocs/langs/<lang>/mailmanspip.lang
source_file = htdocs/langs/en_US/mailmanspip.lang

View File

@ -221,7 +221,7 @@ class Skeleton_Class extends CommonObject
$line->prop1 = $obj->field1;
$line->prop2 = $obj->field2;
$this->line[]=$line;
$this->lines[]=$line;
//...
}
$this->db->free($resql);

119
htdocs/admin/loan.php Normal file
View File

@ -0,0 +1,119 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
/**
* \file htdocs/admin/loan.php
* \ingroup loan
* \brief Setup page to configure loan module
*/
require '../main.inc.php';
// Class
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
$langs->load("admin");
$langs->load("loan");
// Security check
if (!$user->admin)
accessforbidden();
$action = GETPOST('action', 'alpha');
// Other parameters LOAN_*
$list = array (
'LOAN_ACCOUNTING_ACCOUNT_CAPITAL',
'LOAN_ACCOUNTING_ACCOUNT_INTEREST',
'LOAN_ACCOUNTING_ACCOUNT_INSURANCE'
);
/*
* Actions
*/
if ($action == 'update')
{
$error = 0;
foreach ($list as $constname) {
$constvalue = GETPOST($constname, 'alpha');
if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
$error++;
}
}
if (! $error)
{
setEventMessage($langs->trans("SetupSaved"));
}
else
{
setEventMessage($langs->trans("Error"),'errors');
}
}
/*
* View
*/
llxHeader();
$form = new Form($db);
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans('ConfigLoan'),$linkback,'setup');
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
/*
* Params
*/
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="3">' . $langs->trans('Options') . '</td>';
print "</tr>\n";
foreach ($list as $key)
{
$var=!$var;
print '<tr '.$bc[$var].' class="value">';
// Param
$label = $langs->trans($key);
print '<td><label for="'.$key.'">'.$label.'</label></td>';
// Value
print '<td>';
print '<input type="text" size="20" id="'.$key.'" name="'.$key.'" value="'.$conf->global->$key.'">';
print '</td></tr>';
}
print '</tr>';
print '</form>';
print "</table>\n";
print '<br /><div style="text-align:center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
llxFooter();
$db->close();

View File

@ -37,6 +37,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
@ -44,6 +45,7 @@ $langs->load("banks");
$langs->load("categories");
$langs->load("bills");
$langs->load("companies");
$langs->load("loan");
$id = (GETPOST('id','int') ? GETPOST('id','int') : GETPOST('account','int'));
$ref = GETPOST('ref','alpha');
@ -148,6 +150,7 @@ llxHeader();
$societestatic=new Societe($db);
$userstatic=new User($db);
$chargestatic=new ChargeSociales($db);
$loanstatic=new Loan($db);
$memberstatic=new Adherent($db);
$paymentstatic=new Paiement($db);
$paymentsupplierstatic=new PaiementFourn($db);
@ -606,6 +609,12 @@ if ($id > 0 || ! empty($ref))
$paymentsalstatic->ref=$links[$key]['url_id'];
print ' '.$paymentsalstatic->getNomUrl(2);
}
elseif ($links[$key]['type']=='payment_loan')
{
print '<a href="'.DOL_URL_ROOT.'/compta/loan/payment/card.php?id='.$links[$key]['url_id'].'">';
print ' '.img_object($langs->trans('ShowPayment'),'payment').' ';
print '</a>';
}
elseif ($links[$key]['type']=='banktransfert')
{
// Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
@ -705,6 +714,21 @@ if ($id > 0 || ! empty($ref))
$chargestatic->ref=$chargestatic->lib;
print $chargestatic->getNomUrl(1,16);
}
else if ($links[$key]['type']=='loan')
{
$loanstatic->id=$links[$key]['url_id'];
if (preg_match('/^\((.*)\)$/i',$links[$key]['label'],$reg))
{
if ($reg[1]=='loan') $reg[1]='Loan';
$loanstatic->label=$langs->trans($reg[1]);
}
else
{
$loanstatic->label=$links[$key]['label'];
}
$loanstatic->ref=$loanstatic->label;
print $loanstatic->getLinkUrl(1,16);
}
else if ($links[$key]['type']=='member')
{
$memberstatic->id=$links[$key]['url_id'];

View File

@ -127,7 +127,7 @@ if ($result)
print '<td class="liste_titre">&nbsp;</td>';
print '</tr>';
print '<form action="list.php" method="GET">';
print '<form action="'.$_SERVER["PHP_SELF"].'" method="GET">';
print '<tr class="liste_titre">';
print '<td class="liste_titre"><input type="text" class="flat" name="search_line" value="'. dol_escape_htmltag($search_line).'" size="6"></td>';
print '<td class="liste_titre"><input type="text" class="flat" name="search_bon" value="'. dol_escape_htmltag($search_bon).'" size="8"></td>';

View File

@ -211,7 +211,7 @@ if ($action == 'create')
$datesp=dol_get_first_day($pastmonthyear,$pastmonth,false); $dateep=dol_get_last_day($pastmonthyear,$pastmonth,false);
}
print "<form name='add' action=\"card.php\" method=\"post\">\n";
print '<form name="salary" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';

View File

@ -0,0 +1,66 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/lib/loan.lib.php
* \ingroup loan
* \brief Library for loan module
*/
/**
* Prepare array with list of tabs
*
* @param Object $object Object related to tabs
* @return array Array of tabs to show
*/
function loan_prepare_head($object)
{
global $langs, $conf;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/loan/card.php?id='.$object->id;
$head[$h][1] = $langs->trans('Card');
$head[$h][2] = 'card';
$h++;
// 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
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf,$langs,$object,$head,$h,'loan');
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$upload_dir = $conf->loan->dir_output . "/" . dol_sanitizeFileName($object->ref);
$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$'));
$head[$h][0] = DOL_URL_ROOT.'/loan/document.php?id='.$object->id;
$head[$h][1] = $langs->trans("Documents");
if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')';
$head[$h][2] = 'documents';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/loan/info.php?id='.$object->id;
$head[$h][1] = $langs->trans("Info");
$head[$h][2] = 'info';
$h++;
complete_head_from_modules($conf,$langs,$object,$head,$h,'loan','remove');
return $head;
}

View File

@ -12,7 +12,7 @@ insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, left
insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('societe|fournisseur', '( ! empty($conf->societe->enabled) && (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))) || ! empty($conf->fournisseur->enabled)', 2__+MAX_llx_menu__, __HANDLER__, 'top', 'companies', '', 0, '/societe/index.php?mainmenu=companies&amp;leftmenu=', 'ThirdParties', -1, 'companies', '$user->rights->societe->lire || $user->rights->societe->contact->lire', '', 2, 20, __ENTITY__);
insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('product|service', '$conf->product->enabled || $conf->service->enabled', 3__+MAX_llx_menu__, __HANDLER__, 'top', 'products', '', 0, '/product/index.php?mainmenu=products&amp;leftmenu=', 'Products/Services', -1, 'products', '$user->rights->produit->lire||$user->rights->service->lire', '', 0, 30, __ENTITY__);
insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('propal|commande|fournisseur|contrat|ficheinter', '$conf->propal->enabled || $conf->commande->enabled || $conf->fournisseur->enabled || $conf->contrat->enabled || $conf->ficheinter->enabled', 5__+MAX_llx_menu__, __HANDLER__, 'top', 'commercial', '', 0, '/comm/index.php?mainmenu=commercial&amp;leftmenu=', 'Commercial', -1, 'commercial', '$user->rights->societe->lire || $user->rights->societe->contact->lire', '', 2, 40, __ENTITY__);
insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('comptabilite|accounting|facture|deplacement|don|tax|salaries', '$conf->comptabilite->enabled || $conf->accounting->enabled || $conf->facture->enabled || $conf->deplacement->enabled || $conf->don->enabled || $conf->tax->enabled || $conf->salaries->enabled', 6__+MAX_llx_menu__, __HANDLER__, 'top', 'accountancy', '', 0, '/compta/index.php?mainmenu=accountancy&amp;leftmenu=', 'MenuFinancial', -1, 'compta', '$user->rights->compta->resultat->lire || $user->rights->accounting->plancompte->lire || $user->rights->facture->lire|| $user->rights->deplacement->lire || $user->rights->don->lire || $user->rights->tax->charges->lire || $user->rights->salaries->read', '', 2, 50, __ENTITY__);
insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('comptabilite|accounting|facture|deplacement|don|tax|salaries|loan', '$conf->comptabilite->enabled || $conf->accounting->enabled || $conf->facture->enabled || $conf->deplacement->enabled || $conf->don->enabled || $conf->tax->enabled || $conf->salaries->enabled || $conf->loan->enabled', 6__+MAX_llx_menu__, __HANDLER__, 'top', 'accountancy', '', 0, '/compta/index.php?mainmenu=accountancy&amp;leftmenu=', 'MenuFinancial', -1, 'compta', '$user->rights->compta->resultat->lire || $user->rights->accounting->plancompte->lire || $user->rights->facture->lire|| $user->rights->deplacement->lire || $user->rights->don->lire || $user->rights->tax->charges->lire || $user->rights->salaries->read || $user->rights->loan->read', '', 2, 50, __ENTITY__);
insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('banque|prelevement', '$conf->banque->enabled || $conf->prelevement->enabled', 14__+MAX_llx_menu__, __HANDLER__, 'top', 'bank', '', 0, '/compta/bank/index.php?mainmenu=bank&amp;leftmenu=bank', 'MenuBankCash', -1, 'banks', '$user->rights->banque->lire || $user->rights->prelevement->bons->lire', '', 0, 60, __ENTITY__);
insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('projet', '$conf->projet->enabled', 7__+MAX_llx_menu__, __HANDLER__, 'top', 'project', '', 0, '/projet/index.php?mainmenu=project&amp;leftmenu=', 'Projects', -1, 'projects', '$user->rights->projet->lire', '', 2, 70, __ENTITY__);
insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('mailing|export|import|opensurvey', '$conf->mailing->enabled || $conf->export->enabled || $conf->import->enabled || $conf->opensurvey->enabled', 8__+MAX_llx_menu__, __HANDLER__, 'top', 'tools', '', 0, '/core/tools.php?mainmenu=tools&amp;leftmenu=', 'Tools', -1, 'other', '$user->rights->mailing->lire || $user->rights->export->lire || $user->rights->import->run || $user->rights->opensurvey->read', '', 2, 90, __ENTITY__);
@ -181,6 +181,10 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled', __HANDLER__, 'left', 2210__+MAX_llx_menu__, 'accountancy', 'tax_sal', 2200__+MAX_llx_menu__, '/compta/salaries/index.php?leftmenu=tax_salary&amp;mainmenu=accountancy', 'Salaries', 1, 'salaries', '$user->rights->salaries->read', '', 0, 1, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled && $leftmenu=="tax_salary"', __HANDLER__, 'left', 2211__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/salaries/card.php?leftmenu=tax_salary&amp;action=create', 'NewPayment', 2, 'companies', '$user->rights->salaries->write', '', 0, 2, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled && $leftmenu=="tax_salary"', __HANDLER__, 'left', 2212__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/salaries/index.php?leftmenu=tax_salary', 'Payments', 2, 'companies', '$user->rights->salaries->read', '', 0, 3, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled', __HANDLER__, 'left', 2220__+MAX_llx_menu__, 'accountancy', 'tax_loan', 2200__+MAX_llx_menu__, '/loan/index.php?leftmenu=tax_loan&amp;mainmenu=accountancy', 'Loans', 1, 'loan', '$user->rights->loan->read', '', 0, 1, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2221__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/loan/card.php?leftmenu=tax_loan&amp;action=create', 'NewLoan', 2, 'loan', '$user->rights->loan->write', '', 0, 2, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2222__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/loan/index.php?leftmenu=tax_loan', 'Payments', 2, 'companies', '$user->rights->loan->read', '', 0, 3, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2223__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/loan/calc.php?leftmenu=tax_loan', 'Calculator', 2, 'companies', '$user->rights->loan->calc', '', 0, 4, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled', __HANDLER__, 'left', 2250__+MAX_llx_menu__, 'accountancy', 'tax_social', 2200__+MAX_llx_menu__, '/compta/sociales/index.php?leftmenu=tax_social', 'SocialContributions', 1, '', '$user->rights->tax->charges->lire', '', 0, 1, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled && $leftmenu=="tax_social"', __HANDLER__, 'left', 2251__+MAX_llx_menu__, 'accountancy', '', 2250__+MAX_llx_menu__, '/compta/sociales/charges.php?leftmenu=tax_social&amp;action=create', 'MenuNewSocialContribution', 2, '', '$user->rights->tax->charges->creer', '', 0, 2, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled && $leftmenu=="tax_social"', __HANDLER__, 'left', 2252__+MAX_llx_menu__, 'accountancy', '', 2250__+MAX_llx_menu__, '/compta/charges/index.php?leftmenu=tax_social&amp;mainmenu=accountancy&amp;mode=sconly', 'Payments', 2, '', '$user->rights->tax->charges->lire', '', 0, 3, __ENTITY__);

View File

@ -3,6 +3,7 @@
* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
*
* 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
@ -134,9 +135,9 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0)
}
// Financial
$tmpentry=array('enabled'=>(! empty($conf->comptabilite->enabled) || ! empty($conf->accounting->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->don->enabled) || ! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled)),
'perms'=>(! empty($user->rights->compta->resultat->lire) || ! empty($user->rights->accounting->plancompte->lire) || ! empty($user->rights->facture->lire) || ! empty($user->rights->don->lire) || ! empty($user->rights->tax->charges->lire) || ! empty($user->rights->salaries->read)),
'module'=>'comptabilite|accounting|facture|don|tax|salaries');
$tmpentry=array('enabled'=>(! empty($conf->comptabilite->enabled) || ! empty($conf->accounting->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->don->enabled) || ! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled) || ! empty($conf->loan->enabled)),
'perms'=>(! empty($user->rights->compta->resultat->lire) || ! empty($user->rights->accounting->plancompte->lire) || ! empty($user->rights->facture->lire) || ! empty($user->rights->don->lire) || ! empty($user->rights->tax->charges->lire) || ! empty($user->rights->salaries->read) || ! empty($user->rights->loan->read)),
'module'=>'comptabilite|accounting|facture|don|tax|salaries|loan');
$showmode=dol_eldy_showmenu($type_user, $tmpentry, $listofmodulesforexternal);
if ($showmode)
{
@ -738,8 +739,14 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills",$langs->trans("BillsCustomers"),0,$user->rights->facture->lire, '', $mainmenu, 'customers_bills');
$newmenu->add("/compta/facture.php?action=create&amp;leftmenu=customers_bills",$langs->trans("NewBill"),1,$user->rights->facture->creer);
$newmenu->add("/compta/facture/fiche-rec.php?leftmenu=customers_bills",$langs->trans("Repeatables"),1,$user->rights->facture->lire);
$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills",$langs->trans("List"),1,$user->rights->facture->lire);
$newmenu->add("/compta/facture/impayees.php?leftmenu=customers_bills",$langs->trans("Unpaid"),1,$user->rights->facture->lire);
if (empty($leftmenu) || ($leftmenu == 'customers_bills')) {
$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills&amp;search_status=0",$langs->trans("BillShortStatusDraft"),2,$user->rights->facture->lire);
$newmenu->add("/compta/facture/impayees.php?leftmenu=customers_bills",$langs->trans("BillShortStatusNotPaid"),2,$user->rights->facture->lire);
$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills&amp;search_status=2",$langs->trans("BillShortStatusPaid"),2,$user->rights->facture->lire);
$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills&amp;search_status=3",$langs->trans("BillShortStatusCanceled"),2,$user->rights->facture->lire);
}
$newmenu->add("/compta/paiement/list.php?leftmenu=customers_bills_payments",$langs->trans("Payments"),1,$user->rights->facture->lire);
@ -758,7 +765,14 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
$langs->load("bills");
$newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills", $langs->trans("BillsSuppliers"),0,$user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills');
$newmenu->add("/fourn/facture/card.php?action=create",$langs->trans("NewBill"),1,$user->rights->fournisseur->facture->creer);
$newmenu->add("/fourn/facture/impayees.php", $langs->trans("Unpaid"),1,$user->rights->fournisseur->facture->lire);
$newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills", $langs->trans("List"),1,$user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills');
if (empty($leftmenu) || ($leftmenu == 'suppliers_bills')) {
$newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills&amp;search_status=0", $langs->trans("BillShortStatusDraft"),2,$user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills');
$newmenu->add("/fourn/facture/impayees.php", $langs->trans("BillShortStatusNotPaid"),2,$user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills');
$newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills&amp;search_status=2", $langs->trans("BillShortStatusPaid"),2,$user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills');
}
$newmenu->add("/fourn/facture/paiement.php", $langs->trans("Payments"),1,$user->rights->fournisseur->facture->lire);
$newmenu->add("/compta/facture/stats/index.php?leftmenu=suppliers_bills&mode=supplier", $langs->trans("Statistics"),1,$user->rights->fournisseur->facture->lire);
@ -795,11 +809,11 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
}
// Taxes and social contributions
if (! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled))
if (! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled) || ! empty($conf->loan->enabled))
{
global $mysoc;
$permtoshowmenu=((! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) || (! empty($conf->salaries->enabled) && $user->rights->salaries->read));
$permtoshowmenu=((! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) || (! empty($conf->salaries->enabled) && $user->rights->salaries->read) || (! empty($conf->loan->enabled) && $user->rights->loan->read));
$newmenu->add("/compta/charges/index.php?leftmenu=tax&amp;mainmenu=accountancy",$langs->trans("MenuSpecialExpenses"), 0, $permtoshowmenu, '', $mainmenu, 'tax');
// Salaries
@ -810,6 +824,16 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
if (empty($leftmenu) || preg_match('/^tax_salary/i',$leftmenu)) $newmenu->add("/compta/salaries/card.php?leftmenu=tax_salary&action=create",$langs->trans("NewPayment"),2,$user->rights->salaries->write);
if (empty($leftmenu) || preg_match('/^tax_salary/i',$leftmenu)) $newmenu->add("/compta/salaries/index.php?leftmenu=tax_salary",$langs->trans("Payments"),2,$user->rights->salaries->read);
}
// Loan
if (! empty($conf->loan->enabled))
{
$langs->load("loan");
$newmenu->add("/loan/index.php?leftmenu=tax_loan&amp;mainmenu=accountancy",$langs->trans("Loans"),1,$user->rights->loan->read, '', $mainmenu, 'tax_loan');
if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/loan/card.php?leftmenu=tax_loan&action=create",$langs->trans("NewLoan"),2,$user->rights->loan->write);
if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/loan/index.php?leftmenu=tax_loan",$langs->trans("Payments"),2,$user->rights->loan->read);
if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/loan/calc.php?leftmenu=tax_loan",$langs->trans("Calculator"),2,$user->rights->loan->calc);
}
// Social contributions
if (! empty($conf->tax->enabled))

View File

@ -0,0 +1,181 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \defgroup tax Module Loans
* \brief Module to include loans management
* \file htdocs/core/modules/modLoan.class.php
* \ingroup loan
* \brief File to activate module loan
*/
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
/**
* Class to manage loan module
*/
class modLoan extends DolibarrModules
{
/**
* Constructor. Define names, constants, directories, boxes, permissions
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
global $conf;
$this->db = $db;
$this->numero = 520;
$this->family = "financial";
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
$this->name = preg_replace('/^mod/i','',get_class($this));
// Module description used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
$this->description = "Loans management";
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this->version = 'development';
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
$this->special = 0;
$this->picto='bill';
// Data directories to create when module is enabled
$this->dirs = array("/loan/temp");
// Config pages
$this->config_page_url = array('loan.php');
// Dependances
$this->depends = array();
$this->requiredby = array();
$this->conflictwith = array();
$this->langfiles = array("loan");
// Constants
$this->const = array();
$this->const[0] = array(
"LOAN_ACCOUNTING_ACCOUNT_CAPITAL",
"chaine",
"164"
);
$this->const[1] = array(
"LOAN_ACCOUNTING_ACCOUNT_INTEREST",
"chaine",
"6611"
);
$this->const[1] = array(
"LOAN_ACCOUNTING_ACCOUNT_INSURANCE",
"chaine",
"6162"
);
// Boxes
$this->boxes = array();
// Permissions
$this->rights = array();
$this->rights_class = 'loan';
$r=0;
$r++;
$this->rights[$r][0] = 520;
$this->rights[$r][1] = 'Read loans';
$this->rights[$r][2] = 'r';
$this->rights[$r][3] = 1;
$this->rights[$r][4] = 'read';
$this->rights[$r][5] = '';
$r++;
$this->rights[$r][0] = 522;
$this->rights[$r][1] = 'Create/modify loans';
$this->rights[$r][2] = 'w';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'write';
$this->rights[$r][5] = '';
$r++;
$this->rights[$r][0] = 524;
$this->rights[$r][1] = 'Delete loans';
$this->rights[$r][2] = 'd';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'delete';
$this->rights[$r][5] = '';
$r++;
$this->rights[$r][0] = 525;
$this->rights[$r][1] = 'Access loan calculator';
$this->rights[$r][2] = 'r';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'calc';
$this->rights[$r][5] = '';
$r++;
$this->rights[$r][0] = 527;
$this->rights[$r][1] = 'Export loans';
$this->rights[$r][2] = 'r';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'export';
$this->rights[$r][5] = '';
// Exports
//--------
$r=0;
}
/**
* Function called when module is enabled.
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
* It also creates data directories
*
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
function init($options='')
{
global $conf;
// Clean before activation
$this->remove($options);
$sql = array();
return $this->_init($sql,$options);
}
/**
* Function called when module is disabled.
* Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted
*
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
function remove($options='')
{
$sql = array();
return $this->_remove($sql,$options);
}
}

View File

@ -5,6 +5,7 @@
* Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
*
* 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
@ -70,6 +71,7 @@ $search_label = GETPOST("search_label","alpha");
$search_company = GETPOST("search_company","alpha");
$search_amount_no_tax = GETPOST("search_amount_no_tax","alpha");
$search_amount_all_tax = GETPOST("search_amount_all_tax","alpha");
$search_status=GETPOST('search_status','alpha');
$month = GETPOST("month","int");
$year = GETPOST("year","int");
$filter = GETPOST("filtre");
@ -188,6 +190,11 @@ if ($search_amount_all_tax != '')
$sql .= natural_search('fac.total_ttc', $search_amount_all_tax, 1);
}
if ($search_status != '')
{
$sql.= " AND fac.fk_statut = '".$db->escape($search_status)."'";
}
$nbtotalofrecords = 0;
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{

43
htdocs/install/mysql/migration/3.7.0-3.8.0.sql Executable file → Normal file
View File

@ -18,6 +18,49 @@
-- -- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user);
-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);
-- Loan
create table llx_loan
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
entity integer DEFAULT 1 NOT NULL,
datec datetime,
tms timestamp,
label varchar(80) NOT NULL,
fk_bank integer,
capital real default 0 NOT NULL,
datestart date,
dateend date,
nbterm real,
rate double NOT NULL,
note text,
capital_position real default 0,
date_position date,
paid smallint default 0 NOT NULL,
accountancy_account_capital varchar(32),
accountancy_account_insurance varchar(32),
accountancy_account_interest varchar(32),
fk_user_author integer DEFAULT NULL,
fk_user_modif integer DEFAULT NULL,
active tinyint DEFAULT 1 NOT NULL
)ENGINE=innodb;
create table llx_payment_loan
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_loan integer,
datec datetime,
tms timestamp,
datep datetime,
amount_capital real DEFAULT 0,
amount_insurance real DEFAULT 0,
amount_interest real DEFAULT 0,
fk_typepayment integer NOT NULL,
num_payment varchar(50),
note text,
fk_bank integer NOT NULL,
fk_user_creat integer,
fk_user_modif integer
)ENGINE=innodb;
ALTER TABLE llx_extrafields ADD COLUMN perms varchar(255) after fieldrequired;
ALTER TABLE llx_extrafields ADD COLUMN list integer DEFAULT 0 after perms;

View File

@ -0,0 +1,49 @@
-- ========================================================================
-- Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ========================================================================
create table llx_loan
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
entity integer DEFAULT 1 NOT NULL,
datec datetime,
tms timestamp,
label varchar(80) NOT NULL,
fk_bank integer,
capital real default 0 NOT NULL,
datestart date,
dateend date,
nbterm real,
rate double NOT NULL,
note text,
capital_position real default 0, -- If not a new loan, just have the position of capital
date_position date,
paid smallint default 0 NOT NULL,
accountancy_account_capital varchar(32),
accountancy_account_insurance varchar(32),
accountancy_account_interest varchar(32),
fk_user_author integer DEFAULT NULL,
fk_user_modif integer DEFAULT NULL,
active tinyint DEFAULT 1 NOT NULL
)ENGINE=innodb;

View File

@ -0,0 +1,35 @@
-- ===================================================================
-- Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ===================================================================
create table llx_payment_loan
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_loan integer,
datec datetime, -- creation date
tms timestamp,
datep datetime, -- payment date
amount_capital real DEFAULT 0,
amount_insurance real DEFAULT 0,
amount_interest real DEFAULT 0,
fk_typepayment integer NOT NULL,
num_payment varchar(50),
note text,
fk_bank integer NOT NULL,
fk_user_creat integer, -- creation user
fk_user_modif integer -- last modification user
)ENGINE=innodb;

View File

@ -494,6 +494,8 @@ Module500Name=Special expenses (tax, social contributions, dividends)
Module500Desc=Management of special expenses like taxes, social contribution, dividends and salaries
Module510Name=Salaries
Module510Desc=Management of employees salaries and payments
Module520Name=Loan
Module520Desc=Management of loans
Module600Name=Notifications
Module600Desc=Send EMail notifications on some Dolibarr business events to third-party contacts (setup defined on each thirdparty)
Module700Name=Donations
@ -714,6 +716,11 @@ Permission510=Read Salaries
Permission512=Create/modify salaries
Permission514=Delete salaries
Permission517=Export salaries
Permission520=Read Loans
Permission522=Create/modify loans
Permission524=Delete loans
Permission525=Access loan calculator
Permission527=Export loans
Permission531=Read services
Permission532=Create/modify services
Permission534=Delete services

View File

@ -0,0 +1,28 @@
# Dolibarr language file - Source file is en_US - loan
Loan=Loan
Loans=Loans
NewLoan=New Loan
ShowLoan=Show Loan
PaymentLoan=Loan payment
Capital=Capital
Insurance=Insurance
Interest=Interest
Nbterms=Number of terms
LoanAccountancyCapitalCode=Accountancy code capital
LoanAccountancyInsuranceCode=Accountancy code insurance
LoanAccountancyInterestCode=Accountancy code interest
LoanPayment=Loan payment
ConfirmDeleteLoan=Confirm deleting this loan
ConfirmPayLoan=Confirm classify paid this loan
ErrorLoanCapital=<font color=red>Loan amount</font> has to be numeric and greater than zero.
ErrorLoanLength=<font color=red>Loan length</font> has to be numeric and greater than zero.
ErrorLoanInterest=<font color=red>Annual interest</font> has to be numeric and greater than zero.
# Calc
Totalsforyear=Totals for year
MonthlyPayment=Monthly Payment
LoanCalcDesc=This <b>mortgage calculator</b> can be used to figure out monthly payments of a home mortgage loan, based on the home's sale price, the term of the loan desired, buyer's down payment percentage, and the loan's interest rate.<br> This calculator factors in PMI (Private Mortgage Insurance) for loans where less than 20% is put as a down payment. Also taken into consideration are the town property taxes, and their effect on the total monthly mortgage payment.<br>
# Admin
ConfigLoan=Configuration of the module loan
LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Accountancy code capital by default
LOAN_ACCOUNTING_ACCOUNT_INTEREST=Accountancy code interest by default
LOAN_ACCOUNTING_ACCOUNT_INSURANCE=Accountancy code insurance by default

View File

@ -495,6 +495,8 @@ Module500Name=Dépenses spéciales (taxes, charges, dividendes)
Module500Desc=Gestion des dépenses spéciales comme les taxes, charges sociales et dividendes
Module510Name=Salaires
Module510Desc=Gestion des paiements des salaires des employés
Module520Name=Emprunts
Module520Desc=Suivi des emprunts
Module600Name=Notifications
Module600Desc=Envoi de notifications Email sur certains événements métiers Dolibarr, aux contacts de tiers (configuration réalisé sur chaque tiers)
Module700Name=Dons
@ -715,6 +717,10 @@ Permission510=Consulter les salaires
Permission512=Créer/modifier les salaires
Permission514=Supprimer les salaires
Permission517=Exporter les salaires
Permission520=Consulter les emprunts
Permission522=Créer/modifier les emprunts
Permission524=Supprimer les emprunts
Permission527=Exporter les emprunts
Permission531=Consulter les services
Permission532=Créer/modifier les services
Permission534=Supprimer les services

View File

@ -0,0 +1,24 @@
# Dolibarr language file - Source file is en_US - loan
Loan=Emprunt
Loans=Emprunts
NewLoan=Nouvel emprunt
ShowLoan=Voir emprunt
PaymentLoan=Règlement d'emprunt
Capital=Capital
Insurance=Assurance
Interest=Intérêt
Nbterms=Nombre d'échéances
LoanAccountancyCapitalCode=Compte comptable capital
LoanAccountancyInsuranceCode=Compte comptable assurance
LoanAccountancyInterestCode=Compte comptable intérêts
LoanPayment=Règlement emprunt
ConfirmDeleteLoan=Confirmation de supression de cet emprunt
ConfirmPayLoan=Confirmation que cet emprunt est classé comme payé
ErrorLoanCapital=<font color=red>Le capital de l'emprunt</font> doit être au format numérique et supérieur à zéro.
ErrorLoanLength=<font color=red>La durée de l'emprunt</font> doit être au format numérique et supérieur à zéro.
ErrorLoanInterest=<font color=red>Les intérêts d'emprunt</font> doivent être au format numérique et supérieur à zéro.
# Admin
ConfigLoan=Configuration du module emprunt
LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Compte comptable capital par défaut
LOAN_ACCOUNTING_ACCOUNT_INTEREST=Compte comptable intérêts par défaut
LOAN_ACCOUNTING_ACCOUNT_INSURANCE=Compte comptable assurance par défaut

View File

@ -66,7 +66,7 @@ SeeHere=Buraya bak
BackgroundColorByDefault=Varsayılan arkaplan rengi
FileNotUploaded=Dosya yüklenmemiş
FileUploaded=Dosya yüklemesi başarılı
FileWasNotUploaded=Bu ekleme için bir dosya seçildi ama henüz gönderilmedi. Bunun için “Dosya ekle” ye tıklayın.
FileWasNotUploaded=Bu ekleme için bir dosya seçildi ama henüz gönderilmedi. Bunun için “Dosya ekle� ye tıklayın.
NbOfEntries=Kayıt sayısı
GoToWikiHelpPage=Çevrimiçi yardım oku (Internet erişimi gerekir)
GoToHelpPage=Yardım oku
@ -632,7 +632,7 @@ CoreErrorTitle=Sistem hatası
CoreErrorMessage=Üzgünüz, bir hata oluştu. Günlükleri kontrol edin veya sistem yöneticinize başvurun.
CreditCard=Kredi kartı
FieldsWithAreMandatory=<b>%s</b> olan alanları zorunludur
FieldsWithIsForPublic=Üyelerin genel listelerinde <b>%s</b> olan alanlar gösterilir. Bunu istemiyorsanız, “genel” kutusundan işareti kaldırın.
FieldsWithIsForPublic=Üyelerin genel listelerinde <b>%s</b> olan alanlar gösterilir. Bunu istemiyorsanız, “genel� kutusundan işareti kaldırın.
AccordingToGeoIPDatabase=(GeoIP dönüşümüne göre)
Line=Satır
NotSupported=Desteklenmez

387
htdocs/loan/calc.php Normal file
View File

@ -0,0 +1,387 @@
<?php
/* Copyright (C) 2002 David Tufts <http://dave.imarc.net>
* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
require '../main.inc.php';
$langs->load("loan");
/* --------------------------------------------------- *
* Set Form DEFAULT values
* --------------------------------------------------- */
$default_sale_price = "150000";
$default_annual_interest_percent = 7.0;
$default_year_term = 30;
$default_down_percent = 10;
$default_show_progress = TRUE;
/* --------------------------------------------------- *
* Initialize Variables
* --------------------------------------------------- */
$sale_price = 0;
$annual_interest_percent = 0;
$year_term = 0;
$down_percent = 0;
$this_year_interest_paid = 0;
$this_year_principal_paid = 0;
$form_complete = false;
$show_progress = false;
$monthly_payment = false;
$show_progress = false;
$error = false;
/* --------------------------------------------------- *
* Set the USER INPUT values
* --------------------------------------------------- */
if (isset($_REQUEST['form_complete'])) {
$sale_price = $_REQUEST['sale_price'];
$annual_interest_percent = $_REQUEST['annual_interest_percent'];
$year_term = $_REQUEST['year_term'];
$down_percent = $_REQUEST['down_percent'];
$show_progress = (isset($_REQUEST['show_progress'])) ? $_REQUEST['show_progress'] : false;
$form_complete = $_REQUEST['form_complete'];
}
// This function does the actual mortgage calculations
// by plotting a PVIFA (Present Value Interest Factor of Annuity)
// table...
function get_interest_factor($year_term, $monthly_interest_rate) {
global $base_rate;
$factor = 0;
$base_rate = 1 + $monthly_interest_rate;
$denominator = $base_rate;
for ($i=0; $i < ($year_term * 12); $i++) {
$factor += (1 / $denominator);
$denominator *= $base_rate;
}
return $factor;
}
// If the form is complete, we'll start the math
if ($form_complete) {
// We'll set all the numeric values to JUST
// numbers - this will delete any dollars signs,
// commas, spaces, and letters, without invalidating
// the value of the number
$sale_price = preg_replace( "[^0-9.]", "", $sale_price);
$annual_interest_percent = preg_replace( "[^0-9.]", "", $annual_interest_percent);
$year_term = preg_replace( "[^0-9.]", "", $year_term);
$down_percent = preg_replace( "[^0-9.]", "", $down_percent);
if ((float) $year_term <= 0) {
$errors[] = "You must enter a <b>Sale Price of Home</b>";
}
if ((float) $sale_price <= 0) {
$errors[] = "You must enter a <b>Length of Mortgage</b>";
}
if ((float) $annual_interest_percent <= 0) {
$errors[] = "You must enter an <b>Annual Interest Rate</b>";
}
if (!$errors) {
$month_term = $year_term * 12;
$down_payment = $sale_price * ($down_percent / 100);
$annual_interest_rate = $annual_interest_percent / 100;
$monthly_interest_rate = $annual_interest_rate / 12;
$financing_price = $sale_price - $down_payment;
$monthly_factor = get_interest_factor($year_term, $monthly_interest_rate);
$monthly_payment = $financing_price / $monthly_factor;
}
} else {
if (!$sale_price) { $sale_price = $default_sale_price; }
if (!$annual_interest_percent) { $annual_interest_percent = $default_annual_interest_percent; }
if (!$year_term) { $year_term = $default_year_term; }
if (!$down_percent) { $down_percent = $default_down_percent; }
if (!$show_progress) { $show_progress = $default_show_progress; }
}
if (! empty($errors)) {
setEventMessages('', $errors, 'errors');
$form_complete = false;
}
/*
* View
*/
llxHeader();
print $langs->trans('LoanCalcDesc');
print '<form method="GET" name="information" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="form_complete" value="1">';
print '<table cellpadding="2" cellspacing="0" border="0" width="100%">';
//print '<tr>';
//print '<td align="right"><img src="/images/clear.gif" width="225" height="1" border="0" alt=""></td>';
//print '<td align="smalltext" width="100%"><img src="/images/clear.gif" width="250" height="1" border="0" alt=""></td>';
//print '</tr>';
print '<tr bgcolor="#cccccc">';
print '<td align="center" colspan="2"><b>Purchase &amp; Financing Information</b></td>';
print '</tr>';
print '<tr bgcolor="#eeeeee">';
print '<td align="right">Sale Price of Home:</td>';
print '<td><input type="text" size="10" name="sale_price" value="'.$sale_price.'"> '.$langs->trans("Currency".$conf->currency).'</td>';print '</tr>';
print '<tr bgcolor="#eeeeee">';
print '<td align="right">Percentage Down:</td>';
print '<td><input type="text" size="5" name="down_percent" value="'.$down_percent.'">%</td>';
print '</tr>';
print '<tr bgcolor="#eeeeee">';
print '<td align="right">Length of Mortgage:</td>';
print '<td><input type="text" size="3" name="year_term" value="'.$year_term.'">years</td>';
print '</tr>';
print '<tr bgcolor="#eeeeee">';
print '<td align="right">Annual Interest Rate:</td>';
print '<td><input type="text" size="5" name="annual_interest_percent" value="'.$annual_interest_percent.'">%</td>';
print '</tr>';
print '<tr bgcolor="#eeeeee">';
print '<td align="right">Explain Calculations:</td>';
if (! empty($show_progress))
{
print '<td><input type="checkbox" name="show_progress" value="1" checked>Show me the calculations and amortization</td>';
}
else
{
print '<td><input type="checkbox" name="show_progress" value="1">Show me the calculations and amortization</td>';
}
print '</tr>';
print '</table>';
print '<br><center><input class="button" type="submit" value="'.$langs->trans("Calculate").'"> &nbsp; &nbsp; ';
print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
// If the form has already been calculated, the $down_payment
// and $monthly_payment variables will be figured out, so we can show them in this table
if ($form_complete && $monthly_payment)
{
print '<br>';
print '<table cellpadding="2" cellspacing="0" border="0" width="100%">';
print '<tr valign="top">';
print '<td align="center" colspan="2" bgcolor="#000000"><font color="#ffffff"><b>Mortgage Payment Information</b></font></td>';
print '</tr>';
print '<tr valign="top" bgcolor="#eeeeee">';
print '<td align="right">Down Payment:</td>';
print '<td><b>' . number_format($down_payment, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '</b></td>';
print '</tr>';
print '<tr valign="top" bgcolor="#eeeeee">';
print '<td align="right">Amount Financed:</td>';
print '<td><b>' . number_format($financing_price, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '</b></td>';
print '</tr>';
print '<tr valign="top" bgcolor="#cccccc">';
print '<td align="right">Monthly Payment:</td>';
print '<td><b>' . number_format($monthly_payment, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '</b><br><font>(Principal &amp; Interest ONLY)</font></td>';
print '</tr>';
if ($down_percent < 20)
{
$pmi_per_month = 55 * ($financing_price / 100000);
print '<tr valign="top" bgcolor="#FFFFCC">';
print '<td align="right">&nbsp;</td>';
print '<td>';
print '<br>';
echo 'Since you are putting LESS than 20% down, you will need to pay PMI
(<a href="http://www.google.com/search?hl=en&q=private+mortgage+insurance">Private Mortgage Insurance</a>), which tends
to be about $55 per month for every $100,000 financed (until you have paid off 20% of your loan). This could add
'."\$" . number_format($pmi_per_month, "2", ".", ",").' to your monthly payment.';
print '</td>';
print '</tr>';
print '<tr valign="top" bgcolor="#FFFF99">';
print '<td align="right">Monthly Payment:</td>';
print '<td><b>' . number_format(($monthly_payment + $pmi_per_month), "2", ".", ",") . $langs->trans("Currency".$conf->currency) . '</b><br><font>';
print '(Principal &amp; Interest, and PMI)</td>';
print '</tr>';
}
print '<tr valign="top" bgcolor="#CCCCFF">';
print '<td align="right">&nbsp;</td>';
print '<td>';
print '<br>';
$assessed_price = ($sale_price * .85);
$residential_yearly_tax = ($assessed_price / 1000) * 14;
$residential_monthly_tax = $residential_yearly_tax / 12;
if ($pmi_per_month)
{
$pmi_text = "PMI and ";
}
echo "Residential (or Property) Taxes are a little harder to figure out... In Massachusetts, the average resedential tax rate seems
to be around $14 per year for every $1,000 of your property's assessed value.";
print '<br><br>';
print "Let's say that your property's <i>assessed value</i> is 85% of what you actually paid for it - ";
print number_format($assessed_price, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . 'This would mean that your yearly residential taxes will be around';
print number_format($residential_yearly_tax, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency);
print 'This could add ' . number_format($residential_monthly_tax, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . 'to your monthly payment';
print '</td>';
print '</tr>';
print '<tr valign="top" bgcolor="#9999FF">';
print '<td align="right">TOTAL Monthly Payment:</td>';
print '<td><b>' . number_format(($monthly_payment + $pmi_per_month + $residential_monthly_tax), "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '</b><br><font>';
print '(including '.$pmi_text.' residential tax)</font></td>';
print '</tr>';
}
print '</table>';
print '</form>';
// This prints the calculation progress and
// the instructions of HOW everything is figured
// out
if ($form_complete && $show_progress) {
$step = 1;
print '<br><br>';
print '<table cellpadding="5" cellspacing="0" border="1" width="100%">';
print '<tr valign="top">';
print '<td><b>'. $step++ .'</b></td>';
print '<td>';
echo 'The <b>down payment</b>
= The price of the home multiplied by the percentage down divided by 100 (for 5% down becomes 5/100 or 0.05)<br><br>
' . number_format($down_payment,"2",".",",") . ' ' . $langs->trans("Currency".$conf->currency) . ' = '.number_format($sale_price,"2",".",",") . ' ' . $langs->trans("Currency".$conf->currency) . ' X
('.$down_percent.' / 100)';
print '</td>';
print '</tr>';
print '<tr valign="top">';
print '<td><b>' . $step++ . '</b></td>';
print '<td>';
print 'The <b>interest rate</b> = The annual interest percentage divided by 100<br><br>';
print $annual_interest_rate . ' = ' . $annual_interest_percent . '% / 100';
print '</td>';
print '</tr>';
print '<tr valign="top" bgcolor="#cccccc">';
print '<td colspan="2">';
print 'The <b>monthly factor</b> = The result of the following formula:';
print '</td>';
print '</tr>';
print '<tr valign="top">';
print '<td><b>' . $step++ . '</b></td>';
print '<td>';
print 'The <b>monthly interest rate</b> = The annual interest rate divided by 12 (for the 12 months in a year)<br><br>';
print $monthly_interest_rate . ' = ' . $annual_interest_rate . ' / 12';
print '</td>';
print '</tr>';
print '<tr valign="top">';
print '<td><b>' . $step++ . '</b></td>';
print '<td>';
print 'The <b>month term</b> of the loan in months = The number of years you\'ve taken the loan out for times 12<br><br>';
print $month_term . ' Months = ' . $year_term . ' Years X 12';
print '</td>';
print '</tr>';
print '<tr valign="top">';
print '<td><b>' . $step++ . '</b></td>';
print '<td>';
print 'The montly payment is figured out using the following formula:<br>';
print 'Monthly Payment = ' . number_format($financing_price, "2", "", "") . ' * ';
print $langs->trans('MonthlyPayment').' = ' . number_format($financing_price, "2", "", "") . ' * ';
print '(1 - ((1 + ' . number_format($monthly_interest_rate, "4", "", "") . ')';
print '<sup>-(' . $month_term . ')</sup>)))';
print '<br><br>';
print 'The <a href="#amortization">amortization</a> breaks down how much of your monthly payment goes towards the bank\'s interest,';
print 'and how much goes into paying off the principal of your loan.';
print '</td>';
print '</tr>';
print '</table>';
print '<br>';
// Set some base variables
$principal = $financing_price;
$current_month = 1;
$current_year = 1;
// This basically, re-figures out the monthly payment, again.
$power = -($month_term);
$denom = pow((1 + $monthly_interest_rate), $power);
$monthly_payment = $principal * ($monthly_interest_rate / (1 - $denom));
print "<br><br><a name=\"amortization\"></a>Amortization For Monthly Payment: <b>" . number_format($monthly_payment, "2", ".", ",") . "</b> over " . $year_term . " years<br>\n";
print '<table class="noborder" width="100%">';
// This LEGEND will get reprinted every 12 months
$legend = '<tr class="liste_titre">';
$legend.= '<td class="liste_titre" align="center">' . $langs->trans("Month") . '</td>';
$legend.= '<td class="liste_titre" align="center">' . $langs->trans("Interest") . '</td>';
$legend.= '<td class="liste_titre" align="center">' . $langs->trans("Capital") . '</td>';
$legend.= '<td class="liste_titre" align="center">' . $langs->trans("Position") . '</td>';
$legend.= '</tr>';
print $legend;
// Loop through and get the current month's payments for
// the length of the loan
while ($current_month <= $month_term)
{
$interest_paid = $principal * $monthly_interest_rate;
$principal_paid = $monthly_payment - $interest_paid;
$remaining_balance = $principal - $principal_paid;
$this_year_interest_paid = $this_year_interest_paid + $interest_paid;
$this_year_principal_paid = $this_year_principal_paid + $principal_paid;
$var = !$var;
print "<tr ".$bc[$var].">";
print '<td align="right">' . $current_month . '</td>';
print '<td align="right">' . number_format($interest_paid, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '</td>';
print '<td align="right">' . number_format($principal_paid, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '</td>';
print '<td align="right">' . number_format($remaining_balance, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '</td>';
print '</tr>';
($current_month % 12) ? $show_legend = FALSE : $show_legend = TRUE;
if ($show_legend) {
print '<tr>';
print '<td colspan="4"><b>' . $langs->trans("Totalsforyear") . ' ' . $current_year . '</td>';
print '</tr>';
$total_spent_this_year = $this_year_interest_paid + $this_year_principal_paid;
print '<tr>';
print '<td>&nbsp;</td>';
print '<td colspan="3">';
print 'You will spend ' . number_format($total_spent_this_year, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . ' on your house in year ' . $current_year . '<br>';
print number_format($this_year_interest_paid, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . ' will go towards INTEREST<br>';
print number_format($this_year_principal_paid, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . ' will go towards PRINCIPAL<br>';
print '</td>';
print '</tr>';
print '<tr>';
print '<td colspan="4">&nbsp;<br></td>';
print '</tr>';
$current_year++;
$this_year_interest_paid = 0;
$this_year_principal_paid = 0;
if (($current_month + 6) < $month_term)
{
echo $legend;
}
}
$principal = $remaining_balance;
$current_month++;
}
print "</table>\n";
}
llxFooter();
$db->close();

493
htdocs/loan/card.php Normal file
View File

@ -0,0 +1,493 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/loan/card.php
* \ingroup loan
* \brief Loan card
*/
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';
$langs->load("compta");
$langs->load("bills");
$langs->load("loan");
$id=GETPOST('id','int');
$action=GETPOST('action');
$confirm=GETPOST('confirm');
$cancel=GETPOST('cancel','alpha');
// Security check
$socid = GETPOST('socid','int');
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'loan', $id, '','');
$object = new Loan($db);
/*
* Actions
*/
// Classify paid
if ($action == 'confirm_paid' && $confirm == 'yes')
{
$object->fetch($id);
$result = $object->set_paid($user);
}
// Delete loan
if ($action == 'confirm_delete' && $confirm == 'yes')
{
$object->fetch($id);
$result=$object->delete($user);
if ($result > 0)
{
header("Location: index.php");
exit;
}
else
{
setEventMessage($loan->error, 'errors');
}
}
// 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 (! $datestart)
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors');
$action = 'create';
}
elseif (! $dateend)
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEnd")), 'errors');
$action = 'create';
}
elseif (! $_POST["capital"])
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Capital")), '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->account_capital = $_POST["accountancy_account_capital"];
$object->account_insurance = $_POST["accountancy_account_insurance"];
$object->account_interest = $_POST["accountancy_account_interest"];
$id=$object->create($user);
if ($id <= 0)
{
setEventMessage($object->error, '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))
{
$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");
}
$result = $object->update($user);
if ($result > 0)
{
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
exit;
}
else
{
setEventMessage($object->error, 'errors');
}
}
else
{
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
exit;
}
}
/*
* View
*/
$form = new Form($db);
$help_url='EN:Module_Loan|FR:Module_Emprunt';
llxHeader("",$langs->trans("Loan"),$help_url);
// Create mode
if ($action == 'create')
{
//WYSIWYG Editor
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
print_fiche_titre($langs->trans("NewLoan"));
$datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
print '<form name="loan" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
print '<table class="border" width="100%">';
// Label
print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("Label").'</td><td colspan="3"><input name="label" size="40" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label')).'"></td></tr>';
// Bank account
if (! empty($conf->banque->enabled))
{
print '<tr><td class="fieldrequired">'.$langs->trans("Account").'</td><td>';
$form->select_comptes($GETPOST["accountid"],"accountid",0,"courant=1",1); // Show list of bank account with courant
print '</td></tr>';
}
else
{
print '<tr><td>'.$langs->trans("Account").'</td><td>';
print $langs->trans("NoBankAccountDefined");
print '</td></tr>';
}
// Capital
print '<tr><td class="fieldrequired">'.$langs->trans("Capital").'</td><td><input name="capital" size="10" value="' . GETPOST("capital") . '"></td></tr>';
// Date Start
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
print $form->select_date($datestart?$datestart:-1,'start','','','','add',1,1);
print '</td></tr>';
// Date End
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
print $form->select_date($dateend?$dateend:-1,'end','','','','add',1,1);
print '</td></tr>';
// Number of terms
print '<tr><td class="fieldrequired">'.$langs->trans("Nbterms").'</td><td><input name="nbterm" size="5" value="' . GETPOST('nbterm') . '"></td></tr>';
// Rate
print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="' . GETPOST("rate") . '"> %</td></tr>';
// Note
print '<tr>';
print '<td class="border" valign="top">'.$langs->trans('Note').'</td>';
print '<td valign="top" colspan="2">';
$doleditor = new DolEditor('note', GETPOST('note', 'alpha'), '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, 100);
print $doleditor->Create(1);
print '</td></tr>';
print '</table>';
print '<br>';
// Accountancy
print '<table class="border" width="100%">';
if ($conf->accounting->enabled)
{
print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
print '</td></tr>';
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>';
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>';
}
else
{
print '<tr><td width="25%">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
print '</td></tr>';
print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">';
print '</td></tr>';
print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>';
print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">';
print '</td></tr>';
}
print '</table>';
print '<br><center><input class="button" type="submit" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; ';
print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
print '</form>';
}
// View
if ($id > 0)
{
$result = $object->fetch($id);
if ($result > 0)
{
$head=loan_prepare_head($object);
dol_fiche_head($head, 'card', $langs->trans("Loan"),0,'bill');
// Confirm for loan
if ($action == 'paid')
{
$text=$langs->trans('ConfirmPayLoan');
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans('PayLoan'),$text,"confirm_paid",'','',2);
}
if ($action == 'delete')
{
$text=$langs->trans('ConfirmDeleteLoan');
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteLoan'),$text,'confirm_delete','','',2);
}
if ($action == 'edit')
{
print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$id.'">';
}
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $form->showrefnav($object,'id');
print "</td></tr>";
// Label
if ($action == 'edit')
{
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">';
print '<input type="text" name="label" size="40" value="'.$object->label.'">';
print '</td></tr>';
}
else
{
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$object->label.'</td></tr>';
}
// Capital
print '<tr><td>'.$langs->trans("Capital").'</td><td>'.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
// Date start
print "<tr><td>".$langs->trans("DateStart")."</td>";
print "<td>";
if ($action == 'edit')
{
print $form->select_date($object->datestart, 'start', 0, 0, 0, 'update', 1);
}
else
{
print dol_print_date($object->datestart,"day");
}
print "</td></tr>";
// Date end
print "<tr><td>".$langs->trans("DateEnd")."</td>";
print "<td>";
if ($action == 'edit')
{
print $form->select_date($object->dateend, 'end', 0, 0, 0, 'update', 1);
}
else
{
print dol_print_date($object->dateend,"day");
}
print "</td></tr>";
// Nbterms
print '<tr><td>'.$langs->trans("Nbterms").'</td><td>'.$object->nbterm.'</td></tr>';
// Rate
print '<tr><td>'.$langs->trans("Rate").'</td><td>'.$object->rate.' %</td></tr>';
// Status
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4, $totalpaye).'</td></tr>';
print '</table>';
if ($action == 'edit')
{
print '<br><div align="center">';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>';
print '</form>';
}
dol_fiche_end();
print '<table class="border" width="100%">';
print '<tr><td>';
/*
* Payments
*/
$sql = "SELECT p.rowid, p.num_payment, datep as dp,";
$sql.= " p.amount_capital, p.amount_insurance, p.amount_interest,";
$sql.= " c.libelle as paiement_type";
$sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p";
$sql.= ", ".MAIN_DB_PREFIX."c_paiement as c ";
$sql.= ", ".MAIN_DB_PREFIX."loan as l";
$sql.= " WHERE p.fk_loan = ".$id;
$sql.= " AND p.fk_loan = l.rowid";
$sql.= " AND l.entity = ".$conf->entity;
$sql.= " AND p.fk_typepayment = c.id";
$sql.= " ORDER BY dp DESC";
//print $sql;
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0; $total = 0;
echo '<table class="nobordernopadding" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("RefPayment").'</td>';
print '<td>'.$langs->trans("Date").'</td>';
print '<td>'.$langs->trans("Type").'</td>';
print '<td align="center" colspan="2">'.$langs->trans("Insurance").'</td>';
print '<td align="center" colspan="2">'.$langs->trans("Interest").'</td>';
print '<td align="center" colspan="2">'.$langs->trans("Capital").'</td>';
print '<td>&nbsp;</td>';
print '</tr>';
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object($resql);
$var=!$var;
print "<tr ".$bc[$var]."><td>";
print '<a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
print "<td>".$objp->paiement_type.' '.$objp->num_payment."</td>\n";
print '<td align="right">'.price($objp->amount_insurance)."</td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td>\n";
print '<td align="right">'.price($objp->amount_interest)."</td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td>\n";
print '<td align="right">'.price($objp->amount_capital)."</td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td>\n";
print "</tr>";
$totalpaid += $objp->amount_capital;
$i++;
}
if ($object->paid == 0)
{
print '<tr><td colspan="7" align="right">'.$langs->trans("AlreadyPaid").' :</td><td align="right"><b>'.price($totalpaid).'</b></td><td>&nbsp;'.$langs->trans("Currency".$conf->currency).'</td></tr>';
print '<tr><td colspan="7" align="right">'.$langs->trans("AmountExpected").' :</td><td align="right" bgcolor="#d0d0d0">'.price($object->capital).'</td><td bgcolor="#d0d0d0">&nbsp;'.$langs->trans("Currency".$conf->currency).'</td></tr>';
$staytopay = $object->capital - $totalpaid;
print '<tr><td colspan="7" align="right">'.$langs->trans("RemainderToPay").' :</td>';
print '<td align="right" bgcolor="#f0f0f0"><b>'.price($staytopay).'</b></td><td bgcolor="#f0f0f0">&nbsp;'.$langs->trans("Currency".$conf->currency).'</td></tr>';
}
print "</table>";
$db->free($resql);
}
else
{
dol_print_error($db);
}
print "</td></tr>";
print "</table>";
/*
* Buttons actions
*/
if ($action != 'edit')
{
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>";
}
// 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
{
// Loan not find
dol_print_error('',$object->error);
}
}
llxFooter();
$db->close();

View File

View File

@ -0,0 +1,487 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/loan/class/loan.class.php
* \ingroup loan
* \brief Class for loan module
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
/** \class Loan
* \brief Class to manage loan
*/
class Loan extends CommonObject
{
public $element='loan';
public $table='loan';
public $table_element='loan';
var $id;
var $rowid;
var $ref;
var $datestart;
var $dateend;
var $label;
var $capital;
var $nbterm;
var $rate;
var $note;
var $paid;
var $account_capital;
var $account_insurance;
var $account_interest;
var $date_creation;
var $date_modification;
var $date_validation;
var $fk_bank;
var $fk_user_creat;
var $fk_user_modif;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db = $db;
return 1;
}
/**
* Load object in memory from database
*
* @param int $id id object
* @return int <0 error , >=0 no error
*/
function fetch($id)
{
$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note,";
$sql.= " l.paid";
$sql.= " FROM ".MAIN_DB_PREFIX."loan as l";
$sql.= " WHERE l.rowid = ".$id;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
$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 = $obj->note;
$this->paid = $obj->paid;
return 1;
}
else
{
return 0;
}
$this->db->free($resql);
}
else
{
$this->error=$this->db->lasterror();
return -1;
}
}
/**
* Create a loan into database
*
* @param User $user User making creation
* @return int <0 if KO, id if OK
*/
function create($user)
{
global $conf;
$error=0;
$now=dol_now();
// clean parameters
$newcapital=price2num($this->capital,'MT');
if (isset($this->note)) $this->note = trim($this->note);
if (isset($this->account_capital)) $this->account_capital = trim($this->account_capital);
if (isset($this->account_insurance)) $this->account_insurance = trim($this->account_insurance);
if (isset($this->account_interest)) $this->account_interest = trim($this->account_interest);
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);
// Check parameters
if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend))
{
$this->error="ErrorBadParameter";
return -2;
}
if (($conf->accounting->enabled) && empty($this->account_capital) && empty($this->account_insurance) && empty($this->account_interest))
{
$this->error="ErrorAccountingParameter";
return -2;
}
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note";
$sql.= " ,accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity";
$sql.= " ,datec, fk_user_author)";
$sql.= " VALUES ('".$this->db->escape($this->label)."',";
$sql.= " '".$this->db->escape($this->fk_bank)."',";
$sql.= " '".price2num($newcapital)."',";
$sql.= " '".$this->db->idate($this->datestart)."',";
$sql.= " '".$this->db->idate($this->dateend)."',";
$sql.= " '".$this->db->escape($this->nbterm)."',";
$sql.= " '".$this->db->escape($this->rate)."',";
$sql.= " '".$this->db->escape($this->note)."',";
$sql.= " '".$this->db->escape($this->account_capital)."',";
$sql.= " '".$this->db->escape($this->account_insurance)."',";
$sql.= " '".$this->db->escape($this->account_interest)."',";
$sql.= " ".$conf->entity.",";
$sql.= " '".$this->db->idate($now)."',";
$sql.= " ".$user->id;
$sql.= ")";
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."loan");
//dol_syslog("Loans::create this->id=".$this->id);
$this->db->commit();
return $this->id;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
}
/**
* Delete a loan
*
* @param User $user Object user making delete
* @return int <0 if KO, >0 if OK
*/
function delete($user)
{
$error=0;
$this->db->begin();
// Get bank transaction lines for this loan
include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$account=new Account($this->db);
$lines_url=$account->get_url('',$this->id,'loan');
// Delete bank urls
foreach ($lines_url as $line_url)
{
if (! $error)
{
$accountline=new AccountLine($this->db);
$accountline->fetch($line_url['fk_bank']);
$result=$accountline->delete_urls($user);
if ($result < 0)
{
$error++;
}
}
}
// Delete payments
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan='".$this->id."'";
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql=$this->db->query($sql);
if (! $resql)
{
$error++;
$this->error=$this->db->lasterror();
}
}
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid='".$this->id."'";
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql=$this->db->query($sql);
if (! $resql)
{
$error++;
$this->error=$this->db->lasterror();
}
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -1;
}
}
/**
* Update loan
*
* @param User $user User who modified
* @return int <0 if error, >0 if ok
*/
function update($user)
{
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."loan";
$sql.= " SET label='".$this->db->escape($this->label)."',";
$sql.= " datestart='".$this->db->idate($this->datestart)."',";
$sql.= " dateend='".$this->db->idate($this->dateend)."',";
$sql.= " fk_user_modif = ".$user->id;
$sql.= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
}
/**
* Tag loan as payed completely
*
* @param User $user Object user making change
* @return int <0 if KO, >0 if OK
*/
function set_paid($user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."loan SET";
$sql.= " paid = 1";
$sql.= " WHERE rowid = ".$this->id;
$return = $this->db->query($sql);
if ($return) {
return 1;
} else {
$this->error=$this->db->lasterror();
return -1;
}
}
/**
* Return label of loan status (unpaid, paid)
*
* @param int $mode 0=label, 1=short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label
* @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
* @return string Label
*/
function getLibStatut($mode=0,$alreadypaid=-1)
{
return $this->LibStatut($this->paid,$mode,$alreadypaid);
}
/**
* Return label for given status
*
* @param int $statut Id statut
* @param int $mode 0=Label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label, 5=Short label + Picto
* @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
* @return string Label
*/
function LibStatut($statut,$mode=0,$alreadypaid=-1)
{
global $langs;
$langs->load('customers');
$langs->load('bills');
if ($mode == 0)
{
if ($statut == 0) return $langs->trans("Unpaid");
if ($statut == 1) return $langs->trans("Paid");
}
if ($mode == 1)
{
if ($statut == 0) return $langs->trans("Unpaid");
if ($statut == 1) return $langs->trans("Paid");
}
if ($mode == 2)
{
if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
}
if ($mode == 3)
{
if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1');
if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3');
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6');
}
if ($mode == 4)
{
if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
}
if ($mode == 5)
{
if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
}
return "Error, mode/status not found";
}
/**
* Return clicable name (with eventually the picto)
*
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
* @param int $maxlen Label max length
* @return string Chaine with URL
*/
function getLinkUrl($withpicto=0,$maxlen=0)
{
global $langs;
$result='';
$link = '<a href="'.DOL_URL_ROOT.'/loan/card.php?id='.$this->id.'">';
$linkend='</a>';
if ($withpicto) $result.=($link.img_object($langs->trans("ShowLoan").': '.$this->label,'bill').$linkend.' ');
if ($withpicto && $withpicto != 2) $result.=' ';
if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->label,$maxlen):$this->label).$linkend;
return $result;
}
/**
* Return amount of payments already done
*
* @return int Amount of payment already done, <0 if KO
*/
function getSumPayment()
{
$table='payment_loan';
$field='fk_loan';
$sql = 'SELECT sum(amount) as amount';
$sql.= ' FROM '.MAIN_DB_PREFIX.$table;
$sql.= ' WHERE '.$field.' = '.$this->id;
dol_syslog(get_class($this)."::getSumPayment", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$amount=0;
$obj = $this->db->fetch_object($resql);
if ($obj) $amount=$obj->amount?$obj->amount:0;
$this->db->free($resql);
return $amount;
}
else
{
$this->error=$this->db->lasterror();
return -1;
}
}
/**
* Information on record
*
* @param int $id Id of record
* @return void
*/
function info($id)
{
$sql = 'SELECT l.rowid, l.datec, l.fk_user_author, l.fk_user_modif,';
$sql.= ' l.tms';
$sql.= ' FROM '.MAIN_DB_PREFIX.'loan as l';
$sql.= ' WHERE l.rowid = '.$id;
dol_syslog(get_class($this).'::info', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
if ($obj->fk_user_author)
{
$cuser = new User($this->db);
$cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser;
}
if ($obj->fk_user_modif)
{
$muser = new User($this->db);
$muser->fetch($obj->fk_user_modif);
$this->user_modification = $muser;
}
$this->date_creation = $this->db->jdate($obj->datec);
if (empty($obj->fk_user_modif)) $obj->tms = "";
$this->date_modification = $this->db->jdate($obj->tms);
return 1;
}
else
{
return 0;
}
$this->db->free($result);
}
else
{
$this->error=$this->db->lasterror();
return -1;
}
}
}

View File

@ -0,0 +1,526 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/loan/class/paymentloan.class.php
* \ingroup facture
* \brief File of class to manage payment of loans
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
/** \class PaymentLoan
* \brief Class to manage payments of loans
*/
class PaymentLoan extends CommonObject
{
public $element='payment_loan'; //!< Id that identify managed objects
public $table_element='payment_loan'; //!< Name of table without prefix where object is stored
var $id;
var $ref;
var $fk_loan;
var $datec='';
var $tms='';
var $datep='';
var $amounts=array(); // Array of amounts
var $amount_capital; // Total amount of payment
var $amount_insurance;
var $amount_interest;
var $fk_typepayment;
var $num_payment;
var $note;
var $fk_bank;
var $fk_user_creat;
var $fk_user_modif;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db = $db;
}
/**
* Create payment of loan into database.
* Use this->amounts to have list of lines for the payment
*
* @param User $user User making payment
* @return int <0 if KO, id of payment if OK
*/
function create($user)
{
global $conf, $langs;
$error=0;
$now=dol_now();
// Validate parameters
if (! $this->datepaid)
{
$this->error='ErrorBadValueForParameter';
return -1;
}
// Clean parameters
if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan);
if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital);
if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance);
if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest);
if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment);
if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
if (isset($this->note)) $this->note = trim($this->note);
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);
$totalamount = 0;
foreach ($this->amounts as $key => $value) // How payment is dispatch
{
$newvalue = price2num($value,'MT');
$this->amounts[$key] = $newvalue;
$totalamount += $newvalue;
}
$totalamount = price2num($totalamount);
// Check parameters
if ($totalamount == 0) return -1; // Negative amounts are accepted for reject prelevement but not null
$this->db->begin();
if ($totalamount != 0)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_loan (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,";
$sql.= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
$sql.= " VALUES ($this->chid, '".$this->db->idate($now)."',";
$sql.= " '".$this->db->idate($this->datepaid)."',";
$sql.= " ".$totalamount.",";
$sql.= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".$user->id.",";
$sql.= " 0)";
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_loan");
}
else
{
$error++;
}
}
if ($totalamount != 0 && ! $error)
{
$this->amount_capital=$totalamount;
$this->total=$totalamount; // deprecated
$this->db->commit();
return $this->id;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
}
/**
* Load object in memory from database
*
* @param int $id Id object
* @return int <0 if KO, >0 if OK
*/
function fetch($id)
{
global $langs;
$sql = "SELECT";
$sql.= " t.rowid,";
$sql.= " t.fk_loan,";
$sql.= " t.datec,";
$sql.= " t.tms,";
$sql.= " t.datep,";
$sql.= " t.amount_capital,";
$sql.= " t.amount_insurance,";
$sql.= " t.amount_interest,";
$sql.= " t.fk_typepayment,";
$sql.= " t.num_payment,";
$sql.= " t.note,";
$sql.= " t.fk_bank,";
$sql.= " t.fk_user_creat,";
$sql.= " t.fk_user_modif,";
$sql.= " pt.code as type_code, pt.libelle as type_libelle,";
$sql.= ' b.fk_account';
$sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."payment_loan as t)";
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
$sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id";
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
$this->fk_loan = $obj->fk_loan;
$this->datec = $this->db->jdate($obj->datec);
$this->tms = $this->db->jdate($obj->tms);
$this->datep = $this->db->jdate($obj->datep);
$this->amount_capital = $obj->amount_capital;
$this->amount_insurance = $obj->amount_insurance;
$this->amount_interest = $obj->amount_interest;
$this->fk_typepayment = $obj->fk_typepayment;
$this->num_payment = $obj->num_payment;
$this->note = $obj->note;
$this->fk_bank = $obj->fk_bank;
$this->fk_user_creat = $obj->fk_user_creat;
$this->fk_user_modif = $obj->fk_user_modif;
$this->type_code = $obj->type_code;
$this->type_libelle = $obj->type_libelle;
$this->bank_account = $obj->fk_account;
$this->bank_line = $obj->fk_bank;
}
$this->db->free($resql);
return 1;
}
else
{
$this->error="Error ".$this->db->lasterror();
return -1;
}
}
/**
* Update database
*
* @param User $user User that modify
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
function update($user=0, $notrigger=0)
{
global $conf, $langs;
$error=0;
// Clean parameters
if (isset($this->fk_loan)) $this->fk_loan=trim($this->fk_loan);
if (isset($this->amount_capital)) $this->amount_capital=trim($this->amount_capital);
if (isset($this->amount_insurance)) $this->amount_insurance=trim($this->amount_insurance);
if (isset($this->amount_interest)) $this->amount_interest=trim($this->amount_interest);
if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment);
if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment);
if (isset($this->note)) $this->note=trim($this->note);
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);
// Check parameters
// Put here code to add control on parameters values
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."payment_loan SET";
$sql.= " fk_loan=".(isset($this->fk_loan)?$this->fk_loan:"null").",";
$sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
$sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').",";
$sql.= " amount_capital=".(isset($this->amount_capital)?$this->amount_capital:"null").",";
$sql.= " amount_insurance=".(isset($this->amount_insurance)?$this->amount_insurance:"null").",";
$sql.= " amount_interest=".(isset($this->amount_interest)?$this->amount_interest:"null").",";
$sql.= " fk_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").",";
$sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").",";
$sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").",";
$sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").",";
$sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").",";
$sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null")."";
$sql.= " WHERE rowid=".$this->id;
$this->db->begin();
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
if (! $error)
{
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you
// want this action call a trigger.
//// Call triggers
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
//$interface=new Interfaces($this->db);
//$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return 1;
}
}
/**
* Delete object in database
*
* @param User $user User that delete
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
function delete($user, $notrigger=0)
{
global $conf, $langs;
$error=0;
$this->db->begin();
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url";
$sql.= " WHERE type='payment_loan' AND url_id=".$this->id;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
}
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan";
$sql.= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
}
if (! $error)
{
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you
// want this action call a trigger.
//// Call triggers
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
//$interface=new Interfaces($this->db);
//$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return 1;
}
}
/**
* Add record into bank for payment with links between this bank record and invoices of payment.
* All payment properties must have been set first like after a call to create().
*
* @param User $user Object of user making payment
* @param string $mode 'payment_loan'
* @param string $label Label to use in bank record
* @param int $accountid Id of bank account to do link with
* @param string $emetteur_nom Name of transmitter
* @param string $emetteur_banque Name of bank
* @return int <0 if KO, >0 if OK
*/
function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque)
{
global $conf;
$error=0;
if (! empty($conf->banque->enabled))
{
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$acc = new Account($this->db);
$acc->fetch($accountid);
$total=$this->total;
if ($mode == 'payment_loan') $total=-$total;
// Insert payment into llx_bank
$bank_line_id = $acc->addline(
$this->datepaid,
$this->paymenttype, // Payment mode id or code ("CHQ or VIR for example")
$label,
$total,
$this->num_payment,
'',
$user,
$emetteur_nom,
$emetteur_banque
);
// Update fk_bank into llx_paiement.
// We know the payment who generated the account write
if ($bank_line_id > 0)
{
$result=$this->update_fk_bank($bank_line_id);
if ($result <= 0)
{
$error++;
dol_print_error($this->db);
}
// Add link 'payment_loan' in bank_url between payment and bank transaction
$url='';
if ($mode == 'payment_loan') $url=DOL_URL_ROOT.'/loan/payment/card.php?id=';
if ($url)
{
$result=$acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $mode);
if ($result <= 0)
{
$error++;
dol_print_error($this->db);
}
}
// Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
$linkaddedforthirdparty=array();
foreach ($this->amounts as $key => $value)
{
if ($mode == 'payment_loan')
{
$loan = new Loan($this->db);
$loan->fetch($key);
$result=$acc->add_url_line($bank_line_id, $loan->id, DOL_URL_ROOT.'/loan/card.php?id=', $loan->type_libelle.(($loan->lib && $loan->lib!=$loan->type_libelle)?' ('.$loan->lib.')':''),'loan');
if ($result <= 0) dol_print_error($this->db);
}
}
}
else
{
$this->error=$acc->error;
$error++;
}
}
if (! $error)
{
return 1;
}
else
{
return -1;
}
}
/**
* Update link between loan's payment and the line generate in llx_bank
*
* @param int $id_bank Id if bank
* @return int >0 if OK, <=0 if KO
*/
function update_fk_bank($id_bank)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."payment_loan SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
return 1;
}
else
{
$this->error=$this->db->error();
return 0;
}
}
/**
* Return clicable name (with eventually a picto)
*
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=No picto
* @param int $maxlen Max length label
* @return string Chaine with URL
*/
function getNameUrl($withpicto=0,$maxlen=0)
{
global $langs;
$result='';
if (empty($this->ref)) $this->ref=$this->lib;
if (!empty($this->id))
{
$link = '<a href="'.DOL_URL_ROOT.'/compta/payment/card.php?id='.$this->id.'">';
$linkend='</a>';
if ($withpicto) $result.=($link.img_object($langs->trans("ShowPayment").': '.$this->ref,'payment').$linkend.' ');
if ($withpicto && $withpicto != 2) $result.=' ';
if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend;
}
return $result;
}
}

171
htdocs/loan/document.php Normal file
View File

@ -0,0 +1,171 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/loan/document.php
* \ingroup loan
* \brief Page with attached files on loan
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
$langs->load("other");
$langs->load("companies");
$langs->load("compta");
$langs->load("bills");
$langs->load("loan");
$id = GETPOST('id','int');
$action = GETPOST("action");
$confirm = GETPOST('confirm', 'alpha');
// Security check
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'loan', $id, '','');
// Get parameters
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page",'int');
if ($page == -1) {
$page = 0;
}
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="name";
$object = new Loan($db);
if ($id > 0) $object->fetch($id);
$upload_dir = $conf->loan->dir_output.'/'.dol_sanitizeFileName($object->ref);
$modulepart='loan';
/*
* Actions
*/
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php';
/*
* View
*/
$form = new Form($db);
$help_url='EN:Module_Loan|FR:Module_Emprunt';
llxHeader("",$langs->trans("Loan"),$help_url);
if ($object->id)
{
$alreadypayed=$object->getSumPayment();
$head = loan_prepare_head($object, $user);
dol_fiche_head($head, 'documents', $langs->trans("Loan"), 0, 'bill');
// Construit liste des fichiers
$filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
$totalsize=0;
foreach($filearray as $key => $file)
{
$totalsize+=$file['size'];
}
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>';
print $form->showrefnav($object,'id');
print "</td></tr>";
// Label
if ($action == 'edit')
{
print '<tr><td>'.$langs->trans("Label").'</td><td>';
print '<input type="text" name="label" size="40" value="'.$object->label.'">';
print '</td></tr>';
}
else
{
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
}
// Amount
print '<tr><td>'.$langs->trans("Capital").'</td><td>'.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
// Date start
print "<tr><td>".$langs->trans("DateStart")."</td>";
print "<td>";
if ($action == 'edit')
{
print $form->select_date($object->datestart, 'start', 0, 0, 0, 'loan', 1);
}
else
{
print dol_print_date($object->datestart,"day");
}
print "</td>";
print "</tr>";
// Date end
print "<tr><td>".$langs->trans("DateEnd")."</td>";
print "<td>";
if ($action == 'edit')
{
print $form->select_date($object->dateend, 'end', 0, 0, 0, 'loan', 1);
}
else
{
print dol_print_date($object->dateend,"day");
}
print "</td>";
print "</tr>";
// Status
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4,$alreadypayed).'</td></tr>';
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
print '</table>';
print '</div>';
$modulepart = 'loan';
$permission = $user->rights->loan->write;
$param = '&id=' . $object->id;
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
}
else
{
print $langs->trans("ErrorUnknown");
}
llxFooter();
$db->close();

0
htdocs/loan/index.html Normal file
View File

153
htdocs/loan/index.php Normal file
View File

@ -0,0 +1,153 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/loan/index.php
* \ingroup loan
* \brief Page to list all loans
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
$langs->load("loan");
$langs->load("compta");
$langs->load("banks");
$langs->load("bills");
// Security check
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'loan', '', '', '');
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page",'int');
if ($page == -1) { $page = 0; }
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortfield) $sortfield="l.rowid";
if (! $sortorder) $sortorder="DESC";
$limit = $conf->liste_limit;
$search_ref=GETPOST('search_ref','int');
$search_label=GETPOST('search_label','alpha');
$search_amount=GETPOST('search_amount','alpha');
$filtre=GETPOST("filtre");
// Purge search criteria
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
{
$search_ref="";
$search_label="";
$search_amount="";
}
/*
* View
*/
$loan_static = new Loan($db);
llxHeader();
$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend,";
$sql.= " SUM(pl.amount_capital) as alreadypayed";
$sql.= " FROM ".MAIN_DB_PREFIX."loan as l LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl";
$sql.= " ON l.rowid = pl.fk_loan";
$sql.= " WHERE l.entity = ".$conf->entity;
if ($search_amount) $sql.=" AND l.capital='".$db->escape(price2num(trim($search_amount)))."'";
if ($search_ref) $sql.=" AND l.rowid = ".$db->escape($search_ref);
if ($search_label) $sql.=" AND l.label LIKE '%".$db->escape($search_label)."%'";
if ($filtre) {
$filtre=str_replace(":","=",$filtre);
$sql .= " AND ".$filtre;
}
$sql.= " GROUP BY l.rowid, l.label, l.capital, l.datestart, l.dateend";
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit+1, $offset);
//print $sql;
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
$var=true;
print_fiche_titre($langs->trans("Loans"));
print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">'."\n";
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"l.rowid","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"l.label","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Capital"),$_SERVER["PHP_SELF"],"l.capital","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"l.datestart","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"l.paid","",$param,'align="right"',$sortfield,$sortorder);
print "</tr>\n";
// Filters lines
print '<tr class="liste_titre">';
print '<td class="liste_titre"><input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'"></td>';
print '<td class="liste_titre"><input class="flat" size="12" type="text" name="search_label" value="'.$search_label.'"></td>';
print '<td class="liste_titre" align="right" ><input class="flat" size="8" type="text" name="search_amount" value="'.$search_amount.'"></td>';
print '<td class="liste_titre">&nbsp;</td>';
print '<td align="right" class="liste_titre">';
print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'searchclear.png','','',1).'" name="button_removefilter" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
print '</td>';
print '</tr>';
while ($i < min($num,$limit))
{
$obj = $db->fetch_object($resql);
$var = !$var;
print "<tr ".$bc[$var].">";
// Ref
print '<td><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowLoan"),"label").' '.$obj->rowid.'</a></td>';
// Label
print '<td>'.dol_trunc($obj->label,42).'</td>';
// Capital
print '<td align="right" width="100">'.price($obj->capital).'</td>';
// Date start
print '<td width="110" align="center">'.dol_print_date($db->jdate($obj->datestart), 'day').'</td>';
print '<td align="right" class="nowrap">'.$loan_static->LibStatut($obj->paid,5,$obj->alreadypayed).'</a></td>';
print "</tr>\n";
$i++;
}
print "</table>";
print "</form>\n";
$db->free($resql);
}
else
{
dol_print_error($db);
}
llxFooter();
$db->close();

71
htdocs/loan/info.php Normal file
View File

@ -0,0 +1,71 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/loan/info.php
* \ingroup loan
* \brief Page with info about 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';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$langs->load("compta");
$langs->load("bills");
$langs->load("loan");
$id=GETPOST('id','int');
$action=GETPOST("action");
// Security check
$socid = GETPOST('socid','int');
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'loan', $id, '','');
/*
* View
*/
$help_url='EN:Module_Loan|FR:Module_Emprunt';
llxHeader("",$langs->trans("Loan"),$help_url);
if ($id > 0) {
$loan = new Loan($db);
$loan->fetch($id);
$loan->info($id);
$head = loan_prepare_head($loan);
dol_fiche_head($head, 'info', $langs->trans("Loan"), 0, 'bill');
print '<table width="100%"><tr><td>';
dol_print_object_info($loan);
print '</td></tr></table>';
print '</div>';
}
else
{
// $id ?
}
llxFooter();
$db->close();

View File

@ -0,0 +1,302 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/loan/payment/card.php
* \ingroup loan
* \brief Payment's card of loan
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->load('bills');
$langs->load('banks');
$langs->load('companies');
$langs->load('loan');
// Security check
$id=GETPOST("id");
$action=GETPOST("action");
$confirm=GETPOST('confirm');
if ($user->societe_id) $socid=$user->societe_id;
// TODO ajouter regle pour restreindre acces paiement
//$result = restrictedArea($user, 'facture', $id,'');
$payment = new PaymentLoan($db);
if ($id > 0)
{
$result=$payment->fetch($id);
if (! $result) dol_print_error($db,'Failed to get payment id '.$id);
}
/*
* Actions
*/
// Delete payment
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->delete)
{
$db->begin();
$result = $payment->delete($user);
if ($result > 0)
{
$db->commit();
header("Location: ".DOL_URL_ROOT."/loan/index.php");
exit;
}
else
{
setEventMessage($payment->error, 'errors');
$db->rollback();
}
}
// Create payment
if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->loan->write)
{
$db->begin();
$result=$payment->valide();
if ($result > 0)
{
$db->commit();
$factures=array(); // TODO Get all id of invoices linked to this payment
foreach($factures as $id)
{
$fac = new Facture($db);
$fac->fetch($id);
$outputlangs = $langs;
if (! empty($_REQUEST['lang_id']))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
$fac->generateDocument($fac->modelpdf, $outputlangs);
}
}
header('Location: card.php?id='.$payment->id);
exit;
}
else
{
setEventMessage($payment->error);
$db->rollback();
}
}
/*
* View
*/
llxHeader();
$loan = new Loan($db);
$form = new Form($db);
$h=0;
$head[$h][0] = DOL_URL_ROOT.'/loan/payment/card.php?id='.$_GET["id"];
$head[$h][1] = $langs->trans("Card");
$hselected = $h;
$h++;
dol_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), 0, 'payment');
/*
* Confirm deletion of the payment
*/
if ($action == 'delete')
{
print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
}
/*
* Confirm validation of the payment
*/
if ($action == 'valide')
{
$facid = $_GET['facid'];
print $form->formconfirm('card.php?id='.$payment->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
}
print '<table class="border" width="100%">';
// Ref
print '<tr><td valign="top" width="140">'.$langs->trans('Ref').'</td>';
print '<td colspan="3">';
print $form->showrefnav($payment,'id','',1,'rowid','id');
print '</td></tr>';
// Date
print '<tr><td valign="top" width="120">'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($payment->datep,'day').'</td></tr>';
// Mode
print '<tr><td valign="top">'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
// Number
print '<tr><td valign="top">'.$langs->trans('Number').'</td><td colspan="3">'.$payment->num_payment.'</td></tr>';
// Amount
print '<tr><td valign="top">'.$langs->trans('Capital').'</td><td colspan="3">'.price($payment->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
print '<tr><td valign="top">'.$langs->trans('Insurance').'</td><td colspan="3">'.price($payment->amount_insurance, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
print '<tr><td valign="top">'.$langs->trans('Interest').'</td><td colspan="3">'.price($payment->amount_interest, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
// Note
print '<tr><td valign="top">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($payment->note).'</td></tr>';
// Bank account
if (! empty($conf->banque->enabled))
{
if ($payment->bank_account)
{
$bankline=new AccountLine($db);
$bankline->fetch($payment->bank_line);
print '<tr>';
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
print '<td colspan="3">';
print $bankline->getNomUrl(1,0,'showall');
print '</td>';
print '</tr>';
}
}
print '</table>';
/*
* List of loans payed
*/
$disable_delete = 0;
$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount_capital, pl.amount_insurance, pl.amount_interest';
$sql.= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l';
$sql.= ' WHERE pl.fk_loan = l.rowid';
$sql.= ' AND l.entity = '.$conf->entity;
$sql.= ' AND pl.rowid = '.$payment->id;
dol_syslog("loan/payment/card.php", LOG_DEBUG);
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
$total = 0;
print '<br><table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Loan').'</td>';
print '<td>'.$langs->trans('Label').'</td>';
print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
print '<td align="center">'.$langs->trans('Status').'</td>';
print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
print "</tr>\n";
if ($num > 0)
{
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object($resql);
$var=!$var;
print '<tr '.$bc[$var].'>';
// Ref
print '<td>';
$loan->fetch($objp->id);
print $loan->getLinkUrl(1);
print "</td>\n";
// Label
print '<td>'.$objp->label.'</td>';
// Expected to pay
print '<td align="right">'.price($objp->capital).'</td>';
// Status
print '<td align="center">'.$loan->getLibStatut(4,$objp->amount_capital).'</td>';
// Amount payed
print '<td align="right">'.price($objp->amount_capital).'</td>';
print "</tr>\n";
if ($objp->paid == 1) // If at least one invoice is paid, disable delete
{
$disable_delete = 1;
}
$total = $total + $objp->amount_capital;
$i++;
}
}
$var=!$var;
print "</table>\n";
$db->free($resql);
}
else
{
dol_print_error($db);
}
print '</div>';
/*
* Actions buttons
*/
print '<div class="tabsAction">';
/*
if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
{
if ($user->societe_id == 0 && $payment->statut == 0 && $_GET['action'] == '')
{
if ($user->rights->facture->paiement)
{
print '<a class="butAction" href="card.php?id='.$_GET['id'].'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
}
}
}
*/
if (empty($action) && ! empty($user->rights->loan->delete))
{
if (! $disable_delete)
{
print '<a class="butActionDelete" href="card.php?id='.$_GET['id'].'&amp;action=delete">'.$langs->trans('Delete').'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
}
}
print '</div>';
llxFooter();
$db->close();

View File

View File

@ -0,0 +1,355 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/loan/payment/payment.php
* \ingroup Loan
* \brief Page to add payment of a loan
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->load("bills");
$langs->load("loan");
$chid=GETPOST('id','int');
$action=GETPOST('action');
$amounts = array();
$cancel=GETPOST('cancel','alpha');
// Security check
$socid=0;
if ($user->societe_id > 0)
{
$socid = $user->societe_id;
}
/*
* Actions
*/
if ($action == 'add_payment')
{
$error=0;
if ($cancel)
{
$loc = DOL_URL_ROOT.'/loan/card.php?id='.$chid;
header("Location: ".$loc);
exit;
}
$datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
if (! $_POST["paymenttype"] > 0)
{
$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode"));
$error++;
}
if ($datepaid == '')
{
$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Date"));
$error++;
}
if (! empty($conf->banque->enabled) && ! $_POST["accountid"] > 0)
{
$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit"));
$error++;
}
if (! $error)
{
$paymentid = 0;
// Read possible payments
foreach ($_POST as $key => $value)
{
if (substr($key,0,7) == 'amount_')
{
$other_chid = substr($key,7);
$amounts[$other_chid] = price2num($_POST[$key]);
}
}
if (count($amounts) <= 0)
{
$error++;
$errmsg='ErrorNoPaymentDefined';
}
if (! $error)
{
$db->begin();
// Create a line of payments
$payment = new PaymentLoan($db);
$payment->chid = $chid;
$payment->datepaid = $datepaid;
$payment->amounts = $amounts; // Tableau de montant
$payment->amount_capital = $_POST["amount_capital"];
$payment->amount_insurance = $_POST["amount_insurance"];
$payment->amount_interest = $_POST["amount_interest"];
$payment->paymenttype = $_POST["paymenttype"];
$payment->num_payment = $_POST["num_payment"];
$payment->note = $_POST["note"];
if (! $error)
{
$paymentid = $payment->create($user);
if ($paymentid < 0)
{
$errmsg=$payment->error;
$error++;
}
}
if (! $error)
{
$result=$payment->addPaymentToBank($user,'payment_loan','(LoanPayment)',$_POST['accountid'],'','');
if (! $result > 0)
{
$errmsg=$payment->error;
$error++;
}
}
if (! $error)
{
$db->commit();
$loc = DOL_URL_ROOT.'/loan/card.php?id='.$chid;
header('Location: '.$loc);
exit;
}
else
{
$db->rollback();
}
}
}
$_GET["action"]='create';
}
/*
* View
*/
llxHeader();
$form=new Form($db);
// Form to create loan's payment
if ($_GET["action"] == 'create')
{
$loan = new Loan($db);
$loan->fetch($chid);
$total = $loan->capital;
print_fiche_titre($langs->trans("DoPayment"));
print "<br>\n";
if ($mesg)
{
print "<div class=\"error\">$mesg</div>";
}
print '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$chid.'">';
print '<input type="hidden" name="chid" value="'.$chid.'">';
print '<input type="hidden" name="action" value="add_payment">';
print '<table cellspacing="0" class="border" width="100%" cellpadding="2">';
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Loan").'</td>';
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="2"><a href="'.DOL_URL_ROOT.'/loan/card.php?id='.$chid.'">'.$chid.'</a></td></tr>';
print '<tr><td>'.$langs->trans("DateStart").'</td><td colspan="2">'.dol_print_date($loan->datestart,'day')."</td></tr>\n";
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$loan->label."</td></tr>\n";
print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">'.price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
$sql = "SELECT sum(p.amount) as total";
$sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p";
$sql.= " WHERE p.fk_loan = ".$chid;
$resql = $db->query($sql);
if ($resql)
{
$obj=$db->fetch_object($resql);
$sumpaid = $obj->total;
$db->free();
}
print '<tr><td>'.$langs->trans("AlreadyPaid").'</td><td colspan="2">'.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
print '<tr><td valign="top">'.$langs->trans("RemainderToPay").'</td><td colspan="2">'.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
print '</tr>';
print '</table>';
print '<br>';
print '<table cellspacing="0" class="border" width="100%" cellpadding="2">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("Payment").'</td>';
print '</tr>';
print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("Date").'</td><td colspan="2">';
$datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
$datepayment = empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaye):0;
$form->select_date($datepayment,'','','','',"add_payment",1,1);
print "</td>";
print '</tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td colspan="2">';
$form->select_types_paiements(isset($_POST["paymenttype"])?$_POST["paymenttype"]:$loan->paymenttype, "paymenttype");
print "</td>\n";
print '</tr>';
print '<tr>';
print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>';
print '<td colspan="2">';
$form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$loan->accountid, "accountid", 0, '',1); // Show opend bank account list
print '</td></tr>';
// Number
print '<tr><td>'.$langs->trans('Number');
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
print '</td>';
print '<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST('num_payment').'"></td></tr>'."\n";
print '<tr>';
print '<td valign="top">'.$langs->trans("Comments").'</td>';
print '<td valign="top" colspan="2"><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_3.'"></textarea></td>';
print '</tr>';
print '</table>';
print '<br>';
/*
* Other loan unpaid
*/
$num = 1;
$i = 0;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td align="left">'.$langs->trans("DateDue").'</td>';
print '<td align="right">'.$langs->trans("Capital").'</td>';
print '<td align="right">'.$langs->trans("AlreadyPaid").'</td>';
print '<td align="right">'.$langs->trans("RemainderToPay").'</td>';
print '<td align="right">'.$langs->trans("Amount").'</td>';
print "</tr>\n";
$var=True;
$total=0;
$totalrecu=0;
while ($i < $num)
{
$objp = $loan;
$var=!$var;
print "<tr ".$bc[$var].">";
if ($objp->datestart > 0)
{
print '<td align="left" valign="center">'.dol_print_date($objp->datestart,'day').'</td>';
}
else
{
print '<td align="center" valign="center"><b>!!!</b></td>';
}
print '<td align="right" valign="center">'.price($objp->capital)."</td>";
print '<td align="right" valign="center">'.price($sumpaid)."</td>";
print '<td align="right" valign="center">'.price($objp->capital - $sumpaid)."</td>";
print '<td align="right">';
if ($sumpaid < $objp->capital)
{
$namec = "amount_capital_".$objp->id;
print $langs->trans("Capital") .': <input type="text" size="8" name="'.$namec.'">';
}
else
{
print '-';
}
print '<br>';
if ($sumpaid < $objp->capital)
{
$namea = "amount_insurance_".$objp->id;
print $langs->trans("Insurance") .': <input type="text" size="8" name="'.$namea.'">';
}
else
{
print '-';
}
print '<br>';
if ($sumpaid < $objp->capital)
{
$namei = "amount_interest_".$objp->id;
print $langs->trans("Interest") .': <input type="text" size="8" name="'.$namei.'">';
}
else
{
print '-';
}
print "</td>";
print "</tr>\n";
$total+=$objp->total;
$total_ttc+=$objp->total_ttc;
$totalrecu+=$objp->am;
$i++;
}
if ($i > 1)
{
// Print total
print "<tr ".$bc[!$var].">";
print '<td colspan="2" align="left">'.$langs->trans("Total").':</td>';
print '<td align="right"><b>"'.price($total_ttc).'"</b></td>';
print '<td align="right"><b>"'.price($totalrecu).'"</b></td>';
print '<td align="right"><b>"'.price($total_ttc - $totalrecu).'"</b></td>';
print '<td align="center">&nbsp;</td>';
print "</tr>\n";
}
print "</table>";
print '<br><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 "</form>\n";
}
$db->close();
llxFooter();