diff --git a/htdocs/compta/deplacement/list.php b/htdocs/compta/deplacement/list.php index 497de98fa72637d892dc4607d8a28d1176141f3a..66fab1b92792ff34600ec9beb1593cb73672817d 100644 --- a/htdocs/compta/deplacement/list.php +++ b/htdocs/compta/deplacement/list.php @@ -80,7 +80,7 @@ $childids[]=$user->id; llxHeader(); -$sql = "SELECT s.nom, s.rowid as socid,"; // Ou +$sql = "SELECT s.nom, d.fk_user, s.rowid as socid,"; // Ou $sql.= " d.rowid, d.type, d.dated as dd, d.km,"; // Comment $sql.= " d.fk_statut,"; $sql.= " u.lastname, u.firstname"; // Qui @@ -91,7 +91,7 @@ if (!$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_ $sql.= " WHERE d.fk_user = u.rowid"; $sql.= " AND d.entity = ".$conf->entity; if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql.=' AND d.fk_user IN ('.join(',',$childids).')'; -if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; +if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id." OR d.fk_soc IS NULL) "; if ($socid) $sql.= " AND s.rowid = ".$socid; if ($search_ref) $sql.=" AND d.rowid=".$search_ref; @@ -188,7 +188,7 @@ if ($resql) print '<td align="center">'.dol_print_date($db->jdate($obj->dd),'day').'</td>'; // User print '<td>'; - $userstatic->id = $obj->rowid; + $userstatic->id = $obj->fk_user; $userstatic->lastname = $obj->lastname; $userstatic->firstname = $obj->firstname; print $userstatic->getNomUrl(1); diff --git a/htdocs/core/lib/loan.lib.php b/htdocs/core/lib/loan.lib.php index 9dbb2a9664bcc73373f3ac88bda0869bbbbb5cb9..fa80fe31a2be9f38b30ff6e7e8e5f2f2d3c1cf1c 100644 --- a/htdocs/core/lib/loan.lib.php +++ b/htdocs/core/lib/loan.lib.php @@ -41,15 +41,15 @@ function loan_prepare_head($object) $head[$tab][2] = 'card'; $tab++; - if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) - { - $nbNote = (empty($object->note_private)?0:1)+(empty($object->note_public)?0:1); - $head[$tab][0] = DOL_URL_ROOT."/loan/note.php?id=".$object->id; - $head[$tab][1] = $langs->trans("Notes"); - if($nbNote > 0) $head[$tab][1].= ' <span class="badge">'.$nbNote.'</span>'; - $head[$tab][2] = 'note'; - $tab++; - } + if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) + { + $nbNote = (empty($object->note_private)?0:1)+(empty($object->note_public)?0:1); + $head[$tab][0] = DOL_URL_ROOT."/loan/note.php?id=".$object->id; + $head[$tab][1] = $langs->trans("Notes"); + if($nbNote > 0) $head[$tab][1].= ' <span class="badge">'.$nbNote.'</span>'; + $head[$tab][2] = 'note'; + $tab++; + } // Show more tabs from modules // Entries must be declared in modules descriptor with line diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index 116de7c561d4e45bba9fb0d48c0c15e3ba3d0b71..31de81d8b9baec045260e491496806e44330f6ce 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -1,5 +1,5 @@ <?php -/* Copyright (C) 2014-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> +/* Copyright (C) 2014-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2015 Frederic France <frederic.france@free.fr> * * This program is free software; you can redistribute it and/or modify @@ -26,6 +26,8 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; +if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php'; $langs->load("compta"); $langs->load("bills"); @@ -104,19 +106,23 @@ if ($action == 'add' && $user->rights->loan->write) } else { - $object->label = $_POST["label"]; - $object->fk_bank = $_POST["accountid"]; - $object->capital = $_POST["capital"]; - $object->datestart = $datestart; - $object->dateend = $dateend; - $object->nbterm = $_POST["nbterm"]; - $object->rate = $_POST["rate"]; - $object->note_private = GETPOST('note_private'); - $object->note_public = GETPOST('note_public'); - - $object->account_capital = $_POST["accountancy_account_capital"]; - $object->account_insurance = $_POST["accountancy_account_insurance"]; - $object->account_interest = $_POST["accountancy_account_interest"]; + $object->label = $_POST["label"]; + $object->fk_bank = $_POST["accountid"]; + $object->capital = $_POST["capital"]; + $object->datestart = $datestart; + $object->dateend = $dateend; + $object->nbterm = $_POST["nbterm"]; + $object->rate = $_POST["rate"]; + $object->note_private = GETPOST('note_private'); + $object->note_public = GETPOST('note_public'); + + $accountancy_account_capital = GETPOST('accountancy_account_capital'); + $accountancy_account_insurance = GETPOST('accountancy_account_insurance'); + $accountancy_account_interest = GETPOST('accountancy_account_interest'); + + if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; } + if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; } + if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; } $id=$object->create($user); if ($id <= 0) @@ -172,6 +178,7 @@ else if ($action == 'update' && $user->rights->loan->write) */ $form = new Form($db); +if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db); $help_url='EN:Module_Loan|FR:Module_Emprunt'; llxHeader("",$langs->trans("Loan"),$help_url); @@ -253,27 +260,50 @@ if ($action == 'create') print '</table>'; + print '<br>'; + + print '<table class="border" width="100%">'; // Accountancy - if ($conf->accounting->enabled) + if (! empty($conf->accounting->enabled)) { - print '<br>'; - - print '<table class="border" width="100%">'; - + // Accountancy_account_capital + print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>'; + print '<td>'; + print $formaccountancy->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1); + print '</td></tr>'; + + // Accountancy_account_insurance + print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>'; + print '<td>'; + print $formaccountancy->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1); + print '</td></tr>'; + + // Accountancy_account_interest + print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("LoanAccountancyInterestCode").'</td>'; + print '<td>'; + print $formaccountancy->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1); + print '</td></tr>'; + } + else // For external software + { + // Accountancy_account_capital print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>'; print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">'; print '</td></tr>'; - + + // Accountancy_account_insurance print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>'; print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">'; print '</td></tr>'; - + + // Accountancy_account_interest print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>'; print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">'; print '</td></tr>'; print '</table>'; } + print '</table>'; dol_fiche_end(); @@ -375,6 +405,39 @@ if ($id > 0) // Note Public print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($object->note_public).'</td></tr>'; + // Accountancy account capital + print '<tr><td class="nowrap">'; + print $langs->trans("LoanAccountancyCapitalCode"); + print '</td><td>'; + if (! empty($conf->accounting->enabled)) { + print length_accountg($object->account_capital); + } else { + print $object->account_capital; + } + print '</td></tr>'; + + // Accountancy account insurance + print '<tr><td class="nowrap">'; + print $langs->trans("LoanAccountancyInsuranceCode"); + print '</td><td>'; + if (! empty($conf->accounting->enabled)) { + print length_accountg($object->account_insurance); + } else { + print $object->account_insurance; + } + print '</td></tr>'; + + // Accountancy account interest + print '<tr><td class="nowrap">'; + print $langs->trans("LoanAccountancyInterestCode"); + print '</td><td>'; + if (! empty($conf->accounting->enabled)) { + print length_accountg($object->account_interest); + } else { + print $object->account_interest; + } + print '</td></tr>'; + // Status print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4, $totalpaye).'</td></tr>'; @@ -444,13 +507,11 @@ if ($id > 0) print '<td align="right">'.price($objp->amount_interest, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n"; print '<td align="right">'.price($objp->amount_capital, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n"; print "</tr>"; - $total_insurance += $objp->amount_insurance; - $total_interest += $objp->amount_interest; $total_capital += $objp->amount_capital; $i++; } - $totalpaid = $total_insurance + $total_interest + $total_capital; + $totalpaid = $total_capital; if ($object->paid == 0) { diff --git a/htdocs/loan/class/loan.class.php b/htdocs/loan/class/loan.class.php index 66809b60720e9b78fad66fdff65e8a802f8fea74..60d4050148ae38ded956254f020ae5fdbdbb31d0 100644 --- a/htdocs/loan/class/loan.class.php +++ b/htdocs/loan/class/loan.class.php @@ -72,7 +72,7 @@ class Loan extends CommonObject function fetch($id) { $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public,"; - $sql.= " l.paid"; + $sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest"; $sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; $sql.= " WHERE l.rowid = ".$id; @@ -84,17 +84,22 @@ class Loan extends CommonObject { $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - $this->datestart = $this->db->jdate($obj->datestart); - $this->dateend = $this->db->jdate($obj->dateend); - $this->label = $obj->label; - $this->capital = $obj->capital; - $this->nbterm = $obj->nbterm; - $this->rate = $obj->rate; - $this->note_private = $obj->note_private; - $this->note_public = $obj->note_public; - $this->paid = $obj->paid; + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->datestart = $this->db->jdate($obj->datestart); + $this->dateend = $this->db->jdate($obj->dateend); + $this->label = $obj->label; + $this->capital = $obj->capital; + $this->nbterm = $obj->nbterm; + $this->rate = $obj->rate; + $this->note_private = $obj->note_private; + $this->note_public = $obj->note_public; + $this->paid = $obj->paid; + + $this->account_capital = $obj->accountancy_account_capital; + $this->account_insurance = $obj->accountancy_account_insurance; + $this->account_interest = $obj->accountancy_account_interest; + return 1; } diff --git a/htdocs/loan/index.php b/htdocs/loan/index.php index e1aa61396788ca02c4fbd93088fc9d278970fcc6..abf4e9470c1b075adf822fed5e06fbb3e0b93c5b 100644 --- a/htdocs/loan/index.php +++ b/htdocs/loan/index.php @@ -2,7 +2,7 @@ /* Copyright (C) 2014 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2015 Frederic France <frederic.france@free.fr> * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es> - * Copyright (C) 2016 Laurent Destailleur <jmenent@2byte.es> + * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/loan/note.php b/htdocs/loan/note.php index 969d5ecb436dc3ba04624c7cb5ea2741280a139e..155dacf460b155d707a6cd729a62dda5a0f94b26 100644 --- a/htdocs/loan/note.php +++ b/htdocs/loan/note.php @@ -56,7 +56,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, $form = new Form($db); -llxHeader('',$langs->trans("LoanArea"),''); +llxHeader('',$langs->trans("Loan"),''); if ($id > 0) { diff --git a/htdocs/loan/payment/payment.php b/htdocs/loan/payment/payment.php index 06061da5c2276e1edc601961a0fae79972cd0497..e735480e414282e32fe72ecb26038f87e9714ba3 100644 --- a/htdocs/loan/payment/payment.php +++ b/htdocs/loan/payment/payment.php @@ -1,5 +1,5 @@ <?php -/* Copyright (C) 2014 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> +/* Copyright (C) 2014-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2015 Frederic France <frederic.france@free.fr> * * This program is free software; you can redistribute it and/or modify @@ -138,7 +138,7 @@ if ($action == 'add_payment') } } - $_GET["action"]='create'; + $action = 'create'; } @@ -152,12 +152,11 @@ $form=new Form($db); // Form to create loan's payment -if ($_GET["action"] == 'create') +if ($action == 'create') { $total = $loan->capital; print load_fiche_titre($langs->trans("DoPayment")); - print "<br>\n"; print '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="post">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; @@ -165,6 +164,8 @@ if ($_GET["action"] == 'create') print '<input type="hidden" name="chid" value="'.$chid.'">'; print '<input type="hidden" name="action" value="add_payment">'; + dol_fiche_head(); + print '<table cellspacing="0" class="border" width="100%" cellpadding="2">'; print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Loan").'</td>'; @@ -230,9 +231,10 @@ if ($_GET["action"] == 'create') print '<td valign="top">'.$langs->trans("NotePublic").'</td>'; print '<td valign="top" colspan="2"><textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_3.'"></textarea></td>'; print '</tr>'; + print '</table>'; - print '<br>'; + dol_fiche_end(); print '<table class="noborder" width="100%">'; print '<tr class="liste_titre">'; @@ -296,13 +298,11 @@ if ($_GET["action"] == 'create') print '</table>'; - print '<br><center>'; - + print '<br><div class="center">'; print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">'; print ' '; print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">'; - - print '</center>'; + print '</div>'; print "</form>\n"; }