mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-16 14:31:29 +01:00
Merge branch '6.0' of git@github.com:Dolibarr/dolibarr.git into develop
Conflicts: htdocs/core/actions_sendmails.inc.php htdocs/loan/card.php htdocs/loan/class/loan.class.php
This commit is contained in:
@@ -2259,6 +2259,7 @@ class Facture extends CommonInvoice
|
|||||||
else $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr",$num));
|
else $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr",$num));
|
||||||
if ($result < 0) {
|
if ($result < 0) {
|
||||||
$error++;
|
$error++;
|
||||||
|
$this->error = $mouvP->error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,9 +243,9 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu
|
|||||||
{
|
{
|
||||||
foreach($feature2 as $subfeature)
|
foreach($feature2 as $subfeature)
|
||||||
{
|
{
|
||||||
if (empty($user->rights->$feature->$subfeature->creer)
|
if (empty($user->rights->$feature->$subfeature->creer)
|
||||||
&& empty($user->rights->$feature->$subfeature->write)
|
&& empty($user->rights->$feature->$subfeature->write)
|
||||||
&& empty($user->rights->$feature->$subfeature->create)) { $createok=0; $nbko++; }
|
&& empty($user->rights->$feature->$subfeature->create)) { $createok=0; $nbko++; }
|
||||||
else { $createok=1; break; } // Break to bypass second test if the first is ok
|
else { $createok=1; break; } // Break to bypass second test if the first is ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -308,6 +308,9 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu
|
|||||||
else if ($feature == 'ftp')
|
else if ($feature == 'ftp')
|
||||||
{
|
{
|
||||||
if (! $user->rights->ftp->write) $deleteok=0;
|
if (! $user->rights->ftp->write) $deleteok=0;
|
||||||
|
}else if ($feature == 'salaries')
|
||||||
|
{
|
||||||
|
if (! $user->rights->salaries->delete) $deleteok=0;
|
||||||
}
|
}
|
||||||
else if ($feature == 'salaries')
|
else if ($feature == 'salaries')
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -559,7 +559,7 @@ if (! empty($valid_dashboardlines))
|
|||||||
$boxwork.='<tr class="nohover"><td class="tdboxstats nohover flexcontainer centpercent">';
|
$boxwork.='<tr class="nohover"><td class="tdboxstats nohover flexcontainer centpercent">';
|
||||||
foreach($valid_dashboardlines as $board)
|
foreach($valid_dashboardlines as $board)
|
||||||
{
|
{
|
||||||
if (empty($boad->nbtodo)) $nbworkboardempty++;
|
if (empty($board->nbtodo)) $nbworkboardempty++;
|
||||||
|
|
||||||
$textlate = $langs->trans("NActionsLate",$board->nbtodolate);
|
$textlate = $langs->trans("NActionsLate",$board->nbtodolate);
|
||||||
$textlate.= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($board->warning_delay) >= 0 ? '+' : '').ceil($board->warning_delay).' '.$langs->trans("days").')';
|
$textlate.= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($board->warning_delay) >= 0 ? '+' : '').ceil($board->warning_delay).' '.$langs->trans("days").')';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2014-2017 Alexandre Spangaro <aspangaro@zendsi.com>
|
/* Copyright (C) 2014-2017 Alexandre Spangaro <aspangaro@zendsi.com>
|
||||||
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
|
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
|
||||||
* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
@@ -18,9 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file htdocs/loan/card.php
|
* \file htdocs/loan/card.php
|
||||||
* \ingroup loan
|
* \ingroup loan
|
||||||
* \brief Loan card
|
* \brief Loan card
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require '../main.inc.php';
|
require '../main.inc.php';
|
||||||
@@ -61,68 +61,68 @@ $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action
|
|||||||
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||||
if (empty($reshook))
|
if (empty($reshook))
|
||||||
{
|
{
|
||||||
// Classify paid
|
// Classify paid
|
||||||
if ($action == 'confirm_paid' && $confirm == 'yes')
|
if ($action == 'confirm_paid' && $confirm == 'yes')
|
||||||
{
|
{
|
||||||
$object->fetch($id);
|
$object->fetch($id);
|
||||||
$result = $object->set_paid($user);
|
$result = $object->set_paid($user);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
setEventMessages($langs->trans('LoanPaid'), null, 'mesgs');
|
setEventMessages($langs->trans('LoanPaid'), null, 'mesgs');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setEventMessages($loan->error, null, 'errors');
|
setEventMessages($loan->error, null, 'errors');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete loan
|
// Delete loan
|
||||||
if ($action == 'confirm_delete' && $confirm == 'yes')
|
if ($action == 'confirm_delete' && $confirm == 'yes')
|
||||||
{
|
{
|
||||||
$object->fetch($id);
|
$object->fetch($id);
|
||||||
$result=$object->delete($user);
|
$result=$object->delete($user);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
setEventMessages($langs->trans('LoanDeleted'), null, 'mesgs');
|
setEventMessages($langs->trans('LoanDeleted'), null, 'mesgs');
|
||||||
header("Location: index.php");
|
header("Location: index.php");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setEventMessages($loan->error, null, 'errors');
|
setEventMessages($loan->error, null, 'errors');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add loan
|
// Add loan
|
||||||
if ($action == 'add' && $user->rights->loan->write)
|
if ($action == 'add' && $user->rights->loan->write)
|
||||||
{
|
{
|
||||||
if (! $cancel)
|
if (! $cancel)
|
||||||
{
|
{
|
||||||
$datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
|
$datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
|
||||||
$dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
|
$dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
|
||||||
$capital = price2num(GETPOST('capital'));
|
$capital = price2num(GETPOST('capital'));
|
||||||
$rate = GETPOST('rate');
|
$rate = GETPOST('rate');
|
||||||
|
|
||||||
if (! $capital)
|
if (! $capital)
|
||||||
{
|
{
|
||||||
$error++; $action = 'create';
|
$error++; $action = 'create';
|
||||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
|
||||||
}
|
}
|
||||||
if (! $datestart)
|
if (! $datestart)
|
||||||
{
|
{
|
||||||
$error++; $action = 'create';
|
$error++; $action = 'create';
|
||||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateStart")), null, 'errors');
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateStart")), null, 'errors');
|
||||||
}
|
}
|
||||||
if (! $dateend)
|
if (! $dateend)
|
||||||
{
|
{
|
||||||
$error++; $action = 'create';
|
$error++; $action = 'create';
|
||||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateEnd")), null, 'errors');
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateEnd")), null, 'errors');
|
||||||
}
|
}
|
||||||
if ($rate == '')
|
if ($rate == '')
|
||||||
{
|
{
|
||||||
$error++; $action = 'create';
|
$error++; $action = 'create';
|
||||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rate")), null, 'errors');
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rate")), null, 'errors');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
@@ -161,29 +161,29 @@ if (empty($reshook))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update record
|
// Update record
|
||||||
else if ($action == 'update' && $user->rights->loan->write)
|
else if ($action == 'update' && $user->rights->loan->write)
|
||||||
{
|
{
|
||||||
if (! $cancel)
|
if (! $cancel)
|
||||||
{
|
{
|
||||||
$result = $object->fetch($id);
|
$result = $object->fetch($id);
|
||||||
|
|
||||||
$datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
|
$datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
|
||||||
$dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
|
$dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
|
||||||
$capital = price2num(GETPOST('capital'));
|
$capital = price2num(GETPOST('capital'));
|
||||||
|
|
||||||
if (! $capital)
|
if (! $capital)
|
||||||
{
|
{
|
||||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
|
||||||
$action = 'edit';
|
$action = 'edit';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$object->datestart = $datestart;
|
$object->datestart = $datestart;
|
||||||
$object->dateend = $dateend;
|
$object->dateend = $dateend;
|
||||||
$object->capital = $capital;
|
$object->capital = $capital;
|
||||||
$object->nbterm = GETPOST("nbterm");
|
$object->nbterm = GETPOST("nbterm");
|
||||||
$object->rate = GETPOST("rate");
|
$object->rate = GETPOST("rate");
|
||||||
|
|
||||||
$accountancy_account_capital = GETPOST('accountancy_account_capital');
|
$accountancy_account_capital = GETPOST('accountancy_account_capital');
|
||||||
$accountancy_account_insurance = GETPOST('accountancy_account_insurance');
|
$accountancy_account_insurance = GETPOST('accountancy_account_insurance');
|
||||||
@@ -192,43 +192,44 @@ if (empty($reshook))
|
|||||||
if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; }
|
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_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; }
|
if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; }
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $object->update($user);
|
$result = $object->update($user);
|
||||||
|
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
|
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
$error++;
|
||||||
}
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
|
{
|
||||||
exit;
|
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
|
||||||
}
|
exit;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Link to a project
|
// Link to a project
|
||||||
if ($action == 'classin' && $user->rights->loan->write)
|
if ($action == 'classin' && $user->rights->loan->write)
|
||||||
{
|
{
|
||||||
$object->fetch($id);
|
$object->fetch($id);
|
||||||
$result = $object->setProject($projectid);
|
$result = $object->setProject($projectid);
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == 'setlabel' && $user->rights->loan->write)
|
if ($action == 'setlabel' && $user->rights->loan->write)
|
||||||
{
|
{
|
||||||
$object->fetch($id);
|
$object->fetch($id);
|
||||||
$result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY');
|
$result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY');
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -249,19 +250,19 @@ llxHeader("",$title,$help_url);
|
|||||||
if ($action == 'create')
|
if ($action == 'create')
|
||||||
{
|
{
|
||||||
//WYSIWYG Editor
|
//WYSIWYG Editor
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||||
|
|
||||||
print load_fiche_titre($langs->trans("NewLoan"), '', 'title_accountancy.png');
|
print load_fiche_titre($langs->trans("NewLoan"), '', 'title_accountancy.png');
|
||||||
|
|
||||||
$datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
|
$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 '<form name="loan" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
|
||||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||||
print '<input type="hidden" name="action" value="add">';
|
print '<input type="hidden" name="action" value="add">';
|
||||||
|
|
||||||
dol_fiche_head();
|
dol_fiche_head();
|
||||||
|
|
||||||
print '<table class="border" width="100%">';
|
print '<table class="border" width="100%">';
|
||||||
|
|
||||||
// Label
|
// Label
|
||||||
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Label").'</td><td><input name="label" size="40" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label')).'"></td></tr>';
|
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Label").'</td><td><input name="label" size="40" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label')).'"></td></tr>';
|
||||||
@@ -280,97 +281,97 @@ if ($action == 'create')
|
|||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Capital
|
// Capital
|
||||||
print '<tr><td class="fieldrequired">'.$langs->trans("LoanCapital").'</td><td><input name="capital" size="10" value="' . dol_escape_htmltag(GETPOST("capital")) . '"></td></tr>';
|
print '<tr><td class="fieldrequired">'.$langs->trans("LoanCapital").'</td><td><input name="capital" size="10" value="' . dol_escape_htmltag(GETPOST("capital")) . '"></td></tr>';
|
||||||
|
|
||||||
// Date Start
|
// Date Start
|
||||||
print "<tr>";
|
print "<tr>";
|
||||||
print '<td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
|
print '<td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
|
||||||
print $form->select_date($datestart?$datestart:-1,'start','','','','add',1,1,1);
|
print $form->select_date($datestart?$datestart:-1,'start','','','','add',1,1,1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Date End
|
// Date End
|
||||||
print "<tr>";
|
print "<tr>";
|
||||||
print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
|
print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
|
||||||
print $form->select_date($dateend?$dateend:-1,'end','','','','add',1,1,1);
|
print $form->select_date($dateend?$dateend:-1,'end','','','','add',1,1,1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Number of terms
|
// Number of terms
|
||||||
print '<tr><td class="fieldrequired">'.$langs->trans("Nbterms").'</td><td><input name="nbterm" size="5" value="' . dol_escape_htmltag(GETPOST('nbterm')) . '"></td></tr>';
|
print '<tr><td class="fieldrequired">'.$langs->trans("Nbterms").'</td><td><input name="nbterm" size="5" value="' . dol_escape_htmltag(GETPOST('nbterm')) . '"></td></tr>';
|
||||||
|
|
||||||
// Rate
|
// Rate
|
||||||
print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="' . dol_escape_htmltag(GETPOST("rate")) . '"> %</td></tr>';
|
print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="' . dol_escape_htmltag(GETPOST("rate")) . '"> %</td></tr>';
|
||||||
|
|
||||||
// Project
|
// Project
|
||||||
if (! empty($conf->projet->enabled))
|
if (! empty($conf->projet->enabled))
|
||||||
{
|
{
|
||||||
$formproject=new FormProjets($db);
|
$formproject=new FormProjets($db);
|
||||||
|
|
||||||
// Projet associe
|
// Projet associe
|
||||||
$langs->load("projects");
|
$langs->load("projects");
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("Project").'</td><td>';
|
print '<tr><td>'.$langs->trans("Project").'</td><td>';
|
||||||
|
|
||||||
$numproject=$formproject->select_projects(-1, $projectid, 'projectid', 16, 0, 1, 1);
|
$numproject=$formproject->select_projects(-1, $projectid, 'projectid', 16, 0, 1, 1);
|
||||||
|
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note Private
|
// Note Private
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
|
print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
|
|
||||||
$doleditor = new DolEditor('note_private', GETPOST('note_private', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%');
|
$doleditor = new DolEditor('note_private', GETPOST('note_private', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%');
|
||||||
print $doleditor->Create(1);
|
print $doleditor->Create(1);
|
||||||
|
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Note Public
|
// Note Public
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
|
print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
$doleditor = new DolEditor('note_public', GETPOST('note_public', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%');
|
$doleditor = new DolEditor('note_public', GETPOST('note_public', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%');
|
||||||
print $doleditor->Create(1);
|
print $doleditor->Create(1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Accountancy
|
// Accountancy
|
||||||
if (! empty($conf->accounting->enabled))
|
if (! empty($conf->accounting->enabled))
|
||||||
{
|
{
|
||||||
// Accountancy_account_capital
|
// Accountancy_account_capital
|
||||||
print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
|
print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print $formaccounting->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1);
|
print $formaccounting->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Accountancy_account_insurance
|
// Accountancy_account_insurance
|
||||||
print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
|
print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print $formaccounting->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1);
|
print $formaccounting->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Accountancy_account_interest
|
// Accountancy_account_interest
|
||||||
print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>';
|
print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print $formaccounting->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1);
|
print $formaccounting->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
}
|
}
|
||||||
else // For external software
|
else // For external software
|
||||||
{
|
{
|
||||||
// Accountancy_account_capital
|
// Accountancy_account_capital
|
||||||
print '<tr><td class="titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
|
print '<tr><td class="titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
|
||||||
print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
|
print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Accountancy_account_insurance
|
// Accountancy_account_insurance
|
||||||
print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
|
print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
|
||||||
print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">';
|
print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">';
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Accountancy_account_interest
|
// Accountancy_account_interest
|
||||||
print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>';
|
print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>';
|
||||||
print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">';
|
print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">';
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
}
|
}
|
||||||
print '</table>';
|
print '</table>';
|
||||||
|
|
||||||
@@ -382,14 +383,14 @@ if ($action == 'create')
|
|||||||
print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
|
print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
|
|
||||||
print '</form>';
|
print '</form>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// View
|
// View
|
||||||
if ($id > 0)
|
if ($id > 0)
|
||||||
{
|
{
|
||||||
$object = new Loan($db);
|
$object = new Loan($db);
|
||||||
$result = $object->fetch($id);
|
$result = $object->fetch($id);
|
||||||
|
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
@@ -413,9 +414,9 @@ if ($id > 0)
|
|||||||
if ($action == 'edit')
|
if ($action == 'edit')
|
||||||
{
|
{
|
||||||
print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
|
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="token" value="'.$_SESSION['newtoken'].'">';
|
||||||
print '<input type="hidden" name="action" value="update">';
|
print '<input type="hidden" name="action" value="update">';
|
||||||
print '<input type="hidden" name="id" value="'.$id.'">';
|
print '<input type="hidden" name="id" value="'.$id.'">';
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_fiche_head($head, 'card', $langs->trans("Loan"), -1, 'bill');
|
dol_fiche_head($head, 'card', $langs->trans("Loan"), -1, 'bill');
|
||||||
@@ -441,40 +442,40 @@ if ($id > 0)
|
|||||||
$morehtmlref.=$form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', 0, 1);
|
$morehtmlref.=$form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', 0, 1);
|
||||||
$morehtmlref.=$form->editfieldval("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', null, null, '', 1);
|
$morehtmlref.=$form->editfieldval("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', null, null, '', 1);
|
||||||
// Project
|
// Project
|
||||||
if (! empty($conf->projet->enabled))
|
if (! empty($conf->projet->enabled))
|
||||||
{
|
{
|
||||||
$langs->load("projects");
|
$langs->load("projects");
|
||||||
$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
|
$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
|
||||||
if ($user->rights->loan->write)
|
if ($user->rights->loan->write)
|
||||||
{
|
{
|
||||||
if ($action != 'classify')
|
if ($action != 'classify')
|
||||||
$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
|
$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
|
||||||
if ($action == 'classify') {
|
if ($action == 'classify') {
|
||||||
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
|
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
|
||||||
$morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
|
$morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
|
||||||
$morehtmlref.='<input type="hidden" name="action" value="classin">';
|
$morehtmlref.='<input type="hidden" name="action" value="classin">';
|
||||||
$morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
$morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||||
$morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
|
$morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
|
||||||
$morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
$morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
||||||
$morehtmlref.='</form>';
|
$morehtmlref.='</form>';
|
||||||
} else {
|
} else {
|
||||||
$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
|
$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (! empty($object->fk_project)) {
|
if (! empty($object->fk_project)) {
|
||||||
$proj = new Project($db);
|
$proj = new Project($db);
|
||||||
$proj->fetch($object->fk_project);
|
$proj->fetch($object->fk_project);
|
||||||
$morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
|
$morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
|
||||||
$morehtmlref.=$proj->ref;
|
$morehtmlref.=$proj->ref;
|
||||||
$morehtmlref.='</a>';
|
$morehtmlref.='</a>';
|
||||||
} else {
|
} else {
|
||||||
$morehtmlref.='';
|
$morehtmlref.='';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$morehtmlref.='</div>';
|
$morehtmlref.='</div>';
|
||||||
|
|
||||||
$object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
|
$object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
|
||||||
|
|
||||||
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
|
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
|
||||||
|
|
||||||
@@ -496,7 +497,7 @@ if ($id > 0)
|
|||||||
print '<tr><td class="titlefield">'.$langs->trans("LoanCapital").'</td><td>'.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
|
print '<tr><td class="titlefield">'.$langs->trans("LoanCapital").'</td><td>'.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Date start
|
// Date start
|
||||||
print '<tr><td>'.$langs->trans("DateStart")."</td>";
|
print '<tr><td>'.$langs->trans("DateStart")."</td>";
|
||||||
print "<td>";
|
print "<td>";
|
||||||
if ($action == 'edit')
|
if ($action == 'edit')
|
||||||
@@ -548,15 +549,15 @@ if ($id > 0)
|
|||||||
}
|
}
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Accountancy account capital
|
// Accountancy account capital
|
||||||
print '<tr><td class="nowrap">';
|
print '<tr><td class="nowrap">';
|
||||||
print $langs->trans("LoanAccountancyCapitalCode");
|
print $langs->trans("LoanAccountancyCapitalCode");
|
||||||
print '</td><td>';
|
print '</td><td>';
|
||||||
if ($action == 'edit')
|
if ($action == 'edit')
|
||||||
{
|
{
|
||||||
if (! empty($conf->accounting->enabled))
|
if (! empty($conf->accounting->enabled))
|
||||||
{
|
{
|
||||||
print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 0, 1);
|
print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 1, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -573,15 +574,15 @@ if ($id > 0)
|
|||||||
}
|
}
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Accountancy account insurance
|
// Accountancy account insurance
|
||||||
print '<tr><td class="nowrap">';
|
print '<tr><td class="nowrap">';
|
||||||
print $langs->trans("LoanAccountancyInsuranceCode");
|
print $langs->trans("LoanAccountancyInsuranceCode");
|
||||||
print '</td><td>';
|
print '</td><td>';
|
||||||
if ($action == 'edit')
|
if ($action == 'edit')
|
||||||
{
|
{
|
||||||
if (! empty($conf->accounting->enabled))
|
if (! empty($conf->accounting->enabled))
|
||||||
{
|
{
|
||||||
print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 0, 1);
|
print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 1, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -600,13 +601,13 @@ if ($id > 0)
|
|||||||
|
|
||||||
// Accountancy account interest
|
// Accountancy account interest
|
||||||
print '<tr><td class="nowrap">';
|
print '<tr><td class="nowrap">';
|
||||||
print $langs->trans("LoanAccountancyInterestCode");
|
print $langs->trans("LoanAccountancyInterestCode");
|
||||||
print '</td><td>';
|
print '</td><td>';
|
||||||
if ($action == 'edit')
|
if ($action == 'edit')
|
||||||
{
|
{
|
||||||
if (! empty($conf->accounting->enabled))
|
if (! empty($conf->accounting->enabled))
|
||||||
{
|
{
|
||||||
print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 0, 1);
|
print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 1, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -649,9 +650,9 @@ if ($id > 0)
|
|||||||
{
|
{
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$total_insurance = 0;
|
$total_insurance = 0;
|
||||||
$total_interest = 0;
|
$total_interest = 0;
|
||||||
$total_capital = 0;
|
$total_capital = 0;
|
||||||
print '<table class="noborder paymenttable">';
|
print '<table class="noborder paymenttable">';
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
print '<td>'.$langs->trans("RefPayment").'</td>';
|
print '<td>'.$langs->trans("RefPayment").'</td>';
|
||||||
@@ -659,8 +660,8 @@ if ($id > 0)
|
|||||||
print '<td>'.$langs->trans("Type").'</td>';
|
print '<td>'.$langs->trans("Type").'</td>';
|
||||||
print '<td align="right">'.$langs->trans("Insurance").'</td>';
|
print '<td align="right">'.$langs->trans("Insurance").'</td>';
|
||||||
print '<td align="right">'.$langs->trans("Interest").'</td>';
|
print '<td align="right">'.$langs->trans("Interest").'</td>';
|
||||||
print '<td align="right">'.$langs->trans("LoanCapital").'</td>';
|
print '<td align="right">'.$langs->trans("LoanCapital").'</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
$var=True;
|
$var=True;
|
||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
@@ -671,11 +672,11 @@ if ($id > 0)
|
|||||||
print '<td><a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
|
print '<td><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>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
|
||||||
print "<td>".$objp->paiement_type.' '.$objp->num_payment."</td>\n";
|
print "<td>".$objp->paiement_type.' '.$objp->num_payment."</td>\n";
|
||||||
print '<td align="right">'.price($objp->amount_insurance, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n";
|
print '<td align="right">'.price($objp->amount_insurance, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n";
|
||||||
print '<td align="right">'.price($objp->amount_interest, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n";
|
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 '<td align="right">'.price($objp->amount_capital, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n";
|
||||||
print "</tr>";
|
print "</tr>";
|
||||||
$total_capital += $objp->amount_capital;
|
$total_capital += $objp->amount_capital;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,47 +716,47 @@ if ($id > 0)
|
|||||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
|
|
||||||
print '</form>';
|
print '</form>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Buttons actions
|
* Buttons actions
|
||||||
*/
|
*/
|
||||||
if ($action != 'edit')
|
if ($action != 'edit')
|
||||||
{
|
{
|
||||||
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||||
if (empty($reshook))
|
if (empty($reshook))
|
||||||
{
|
{
|
||||||
print '<div class="tabsAction">';
|
print '<div class="tabsAction">';
|
||||||
|
|
||||||
// Edit
|
// Edit
|
||||||
if ($user->rights->loan->write)
|
if ($user->rights->loan->write)
|
||||||
{
|
{
|
||||||
print '<a href="javascript:popEcheancier()" class="butAction">'.$langs->trans('CreateCalcSchedule').'</a>';
|
print '<a href="javascript:popEcheancier()" class="butAction">'.$langs->trans('CreateCalcSchedule').'</a>';
|
||||||
|
|
||||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>';
|
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit payment
|
// Emit payment
|
||||||
if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write)
|
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.'&action=create">'.$langs->trans("DoPayment").'</a>';
|
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&action=create">'.$langs->trans("DoPayment").'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Classify 'paid'
|
// Classify 'paid'
|
||||||
if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write)
|
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.'&action=paid">'.$langs->trans("ClassifyPaid").'</a>';
|
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=paid">'.$langs->trans("ClassifyPaid").'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
if ($user->rights->loan->delete)
|
if ($user->rights->loan->delete)
|
||||||
{
|
{
|
||||||
print '<a class="butActionDelete" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a>';
|
print '<a class="butActionDelete" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</div>";
|
print "</div>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -17,128 +17,128 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file htdocs/loan/class/loan.class.php
|
* \file htdocs/loan/class/loan.class.php
|
||||||
* \ingroup loan
|
* \ingroup loan
|
||||||
* \brief Class for loan module
|
* \brief Class for loan module
|
||||||
*/
|
*/
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loan
|
* Loan
|
||||||
*/
|
*/
|
||||||
class Loan extends CommonObject
|
class Loan extends CommonObject
|
||||||
{
|
{
|
||||||
public $element='loan';
|
public $element='loan';
|
||||||
public $table='loan';
|
public $table='loan';
|
||||||
public $table_element='loan';
|
public $table_element='loan';
|
||||||
|
|
||||||
public $picto = 'bill';
|
public $picto = 'bill';
|
||||||
|
|
||||||
public $rowid;
|
public $rowid;
|
||||||
public $datestart;
|
public $datestart;
|
||||||
public $dateend;
|
public $dateend;
|
||||||
public $label;
|
public $label;
|
||||||
public $capital;
|
public $capital;
|
||||||
public $nbterm;
|
public $nbterm;
|
||||||
public $rate;
|
public $rate;
|
||||||
public $paid;
|
public $paid;
|
||||||
public $account_capital;
|
public $account_capital;
|
||||||
public $account_insurance;
|
public $account_insurance;
|
||||||
public $account_interest;
|
public $account_interest;
|
||||||
public $date_creation;
|
public $date_creation;
|
||||||
public $date_modification;
|
public $date_modification;
|
||||||
public $date_validation;
|
public $date_validation;
|
||||||
public $fk_bank;
|
public $fk_bank;
|
||||||
public $fk_user_creat;
|
public $fk_user_creat;
|
||||||
public $fk_user_modif;
|
public $fk_user_modif;
|
||||||
public $fk_project;
|
public $fk_project;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param DoliDB $db Database handler
|
* @param DoliDB $db Database handler
|
||||||
*/
|
*/
|
||||||
function __construct($db)
|
function __construct($db)
|
||||||
{
|
{
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load object in memory from database
|
* Load object in memory from database
|
||||||
*
|
*
|
||||||
* @param int $id id object
|
* @param int $id id object
|
||||||
* @return int <0 error , >=0 no error
|
* @return int <0 error , >=0 no error
|
||||||
*/
|
*/
|
||||||
function fetch($id)
|
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 = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public,";
|
||||||
$sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest, l.fk_projet as fk_project";
|
$sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest, l.fk_projet as fk_project";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."loan as l";
|
$sql.= " FROM ".MAIN_DB_PREFIX."loan as l";
|
||||||
$sql.= " WHERE l.rowid = ".$id;
|
$sql.= " WHERE l.rowid = ".$id;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
if ($this->db->num_rows($resql))
|
if ($this->db->num_rows($resql))
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
$this->id = $obj->rowid;
|
$this->id = $obj->rowid;
|
||||||
$this->ref = $obj->rowid;
|
$this->ref = $obj->rowid;
|
||||||
$this->datestart = $this->db->jdate($obj->datestart);
|
$this->datestart = $this->db->jdate($obj->datestart);
|
||||||
$this->dateend = $this->db->jdate($obj->dateend);
|
$this->dateend = $this->db->jdate($obj->dateend);
|
||||||
$this->label = $obj->label;
|
$this->label = $obj->label;
|
||||||
$this->capital = $obj->capital;
|
$this->capital = $obj->capital;
|
||||||
$this->nbterm = $obj->nbterm;
|
$this->nbterm = $obj->nbterm;
|
||||||
$this->rate = $obj->rate;
|
$this->rate = $obj->rate;
|
||||||
$this->note_private = $obj->note_private;
|
$this->note_private = $obj->note_private;
|
||||||
$this->note_public = $obj->note_public;
|
$this->note_public = $obj->note_public;
|
||||||
$this->paid = $obj->paid;
|
$this->paid = $obj->paid;
|
||||||
|
|
||||||
$this->account_capital = $obj->accountancy_account_capital;
|
$this->account_capital = $obj->accountancy_account_capital;
|
||||||
$this->account_insurance = $obj->accountancy_account_insurance;
|
$this->account_insurance = $obj->accountancy_account_insurance;
|
||||||
$this->account_interest = $obj->accountancy_account_interest;
|
$this->account_interest = $obj->accountancy_account_interest;
|
||||||
$this->fk_project = $obj->fk_project;
|
$this->fk_project = $obj->fk_project;
|
||||||
|
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
$this->error=$this->db->lasterror();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a loan into database
|
* Create a loan into database
|
||||||
*
|
*
|
||||||
* @param User $user User making creation
|
* @param User $user User making creation
|
||||||
* @return int <0 if KO, id if OK
|
* @return int <0 if KO, id if OK
|
||||||
*/
|
*/
|
||||||
function create($user)
|
function create($user)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
$now=dol_now();
|
$now=dol_now();
|
||||||
|
|
||||||
// clean parameters
|
// clean parameters
|
||||||
$newcapital=price2num($this->capital,'MT');
|
$newcapital=price2num($this->capital,'MT');
|
||||||
if (isset($this->note_private)) $this->note_private = trim($this->note_private);
|
if (isset($this->note_private)) $this->note_private = trim($this->note_private);
|
||||||
if (isset($this->note_public)) $this->note_public = trim($this->note_public);
|
if (isset($this->note_public)) $this->note_public = trim($this->note_public);
|
||||||
if (isset($this->account_capital)) $this->account_capital = trim($this->account_capital);
|
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_insurance)) $this->account_insurance = trim($this->account_insurance);
|
||||||
if (isset($this->account_interest)) $this->account_interest = trim($this->account_interest);
|
if (isset($this->account_interest)) $this->account_interest = trim($this->account_interest);
|
||||||
@@ -147,177 +147,187 @@ class Loan extends CommonObject
|
|||||||
if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif);
|
if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif);
|
||||||
if (isset($this->fk_project)) $this->fk_project=trim($this->fk_project);
|
if (isset($this->fk_project)) $this->fk_project=trim($this->fk_project);
|
||||||
|
|
||||||
// Check parameters
|
// Check parameters
|
||||||
if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend))
|
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=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Accounting"));
|
$this->error="ErrorBadParameter";
|
||||||
return -2;
|
return -2;
|
||||||
|
}
|
||||||
|
if (($conf->accounting->enabled) && empty($this->account_capital))
|
||||||
|
{
|
||||||
|
$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyCapitalCode"));
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
if (($conf->accounting->enabled) && empty($this->account_insurance))
|
||||||
|
{
|
||||||
|
$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInsuranceCode"));
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
if (($conf->accounting->enabled) && empty($this->account_interest))
|
||||||
|
{
|
||||||
|
$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInterestCode"));
|
||||||
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public,";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public,";
|
||||||
$sql.= " accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity,";
|
$sql.= " accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity,";
|
||||||
$sql.= " datec, fk_projet, fk_user_author)";
|
$sql.= " datec, fk_projet, fk_user_author)";
|
||||||
$sql.= " VALUES ('".$this->db->escape($this->label)."',";
|
$sql.= " VALUES ('".$this->db->escape($this->label)."',";
|
||||||
$sql.= " '".$this->db->escape($this->fk_bank)."',";
|
$sql.= " '".$this->db->escape($this->fk_bank)."',";
|
||||||
$sql.= " '".price2num($newcapital)."',";
|
$sql.= " '".price2num($newcapital)."',";
|
||||||
$sql.= " '".$this->db->idate($this->datestart)."',";
|
$sql.= " '".$this->db->idate($this->datestart)."',";
|
||||||
$sql.= " '".$this->db->idate($this->dateend)."',";
|
$sql.= " '".$this->db->idate($this->dateend)."',";
|
||||||
$sql.= " '".$this->db->escape($this->nbterm)."',";
|
$sql.= " '".$this->db->escape($this->nbterm)."',";
|
||||||
$sql.= " '".$this->db->escape($this->rate)."',";
|
$sql.= " '".$this->db->escape($this->rate)."',";
|
||||||
$sql.= " '".$this->db->escape($this->note_private)."',";
|
$sql.= " '".$this->db->escape($this->note_private)."',";
|
||||||
$sql.= " '".$this->db->escape($this->note_public)."',";
|
$sql.= " '".$this->db->escape($this->note_public)."',";
|
||||||
$sql.= " '".$this->db->escape($this->account_capital)."',";
|
$sql.= " '".$this->db->escape($this->account_capital)."',";
|
||||||
$sql.= " '".$this->db->escape($this->account_insurance)."',";
|
$sql.= " '".$this->db->escape($this->account_insurance)."',";
|
||||||
$sql.= " '".$this->db->escape($this->account_interest)."',";
|
$sql.= " '".$this->db->escape($this->account_interest)."',";
|
||||||
$sql.= " ".$conf->entity.",";
|
$sql.= " ".$conf->entity.",";
|
||||||
$sql.= " '".$this->db->idate($now)."',";
|
$sql.= " '".$this->db->idate($now)."',";
|
||||||
$sql.= " ".(empty($this->fk_project)?'NULL':$this->fk_project).",";
|
$sql.= " ".(empty($this->fk_project)?'NULL':$this->fk_project).",";
|
||||||
$sql.= " ".$user->id;
|
$sql.= " ".$user->id;
|
||||||
$sql.= ")";
|
$sql.= ")";
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."loan");
|
$this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."loan");
|
||||||
|
|
||||||
//dol_syslog("Loans::create this->id=".$this->id);
|
//dol_syslog("Loans::create this->id=".$this->id);
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
$this->error=$this->db->error();
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a loan
|
* Delete a loan
|
||||||
*
|
*
|
||||||
* @param User $user Object user making delete
|
* @param User $user Object user making delete
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function delete($user)
|
function delete($user)
|
||||||
{
|
{
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Get bank transaction lines for this loan
|
// Get bank transaction lines for this loan
|
||||||
include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||||
$account=new Account($this->db);
|
$account=new Account($this->db);
|
||||||
$lines_url=$account->get_url('',$this->id,'loan');
|
$lines_url=$account->get_url('',$this->id,'loan');
|
||||||
|
|
||||||
// Delete bank urls
|
// Delete bank urls
|
||||||
foreach ($lines_url as $line_url)
|
foreach ($lines_url as $line_url)
|
||||||
{
|
{
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$accountline=new AccountLine($this->db);
|
$accountline=new AccountLine($this->db);
|
||||||
$accountline->fetch($line_url['fk_bank']);
|
$accountline->fetch($line_url['fk_bank']);
|
||||||
$result=$accountline->delete_urls($user);
|
$result=$accountline->delete_urls($user);
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete payments
|
// Delete payments
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan=".$this->id;
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan=".$this->id;
|
||||||
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if (! $resql)
|
if (! $resql)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
$this->error=$this->db->lasterror();
|
$this->error=$this->db->lasterror();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid=".$this->id;
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid=".$this->id;
|
||||||
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if (! $resql)
|
if (! $resql)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
$this->error=$this->db->lasterror();
|
$this->error=$this->db->lasterror();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update loan
|
* Update loan
|
||||||
*
|
*
|
||||||
* @param User $user User who modified
|
* @param User $user User who modified
|
||||||
* @return int <0 if error, >0 if ok
|
* @return int <0 if error, >0 if ok
|
||||||
*/
|
*/
|
||||||
function update($user)
|
function update($user)
|
||||||
{
|
{
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."loan";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."loan";
|
||||||
$sql.= " SET label='".$this->db->escape($this->label)."',";
|
$sql.= " SET label='".$this->db->escape($this->label)."',";
|
||||||
$sql.= " capital='".price2num($this->db->escape($this->capital))."',";
|
$sql.= " capital='".price2num($this->db->escape($this->capital))."',";
|
||||||
$sql.= " datestart='".$this->db->idate($this->datestart)."',";
|
$sql.= " datestart='".$this->db->idate($this->datestart)."',";
|
||||||
$sql.= " dateend='".$this->db->idate($this->dateend)."',";
|
$sql.= " dateend='".$this->db->idate($this->dateend)."',";
|
||||||
$sql.= " fk_projet=".(empty($this->fk_project)?'NULL':$this->fk_project).",";
|
$sql.= " fk_projet=".(empty($this->fk_project)?'NULL':$this->fk_project).",";
|
||||||
$sql.= " fk_user_modif = ".$user->id;
|
$sql.= " fk_user_modif = ".$user->id;
|
||||||
$sql.= " WHERE rowid=".$this->id;
|
$sql.= " WHERE rowid=".$this->id;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
$this->error=$this->db->error();
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag loan as payed completely
|
* Tag loan as payed completely
|
||||||
*
|
*
|
||||||
* @param User $user Object user making change
|
* @param User $user Object user making change
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_paid($user)
|
function set_paid($user)
|
||||||
{
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."loan SET";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."loan SET";
|
||||||
$sql.= " paid = 1";
|
$sql.= " paid = 1";
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
$return = $this->db->query($sql);
|
$return = $this->db->query($sql);
|
||||||
if ($return) {
|
if ($return) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -326,145 +336,145 @@ class Loan extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return label of loan status (unpaid, paid)
|
* 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 int $mode 0=label, 1=short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label
|
||||||
* @param integer $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)
|
* @param integer $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
|
* @return string Label
|
||||||
*/
|
*/
|
||||||
function getLibStatut($mode=0,$alreadypaid=-1)
|
function getLibStatut($mode=0,$alreadypaid=-1)
|
||||||
{
|
{
|
||||||
return $this->LibStatut($this->paid,$mode,$alreadypaid);
|
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 integer $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');
|
|
||||||
}
|
|
||||||
if ($mode == 6)
|
|
||||||
{
|
|
||||||
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 getNomUrl($withpicto=0,$maxlen=0)
|
|
||||||
{
|
|
||||||
global $langs;
|
|
||||||
|
|
||||||
$result='';
|
|
||||||
|
|
||||||
$tooltip = '<u>' . $langs->trans("ShowLoan") . '</u>';
|
|
||||||
if (! empty($this->ref))
|
|
||||||
$tooltip .= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
|
|
||||||
if (! empty($this->label))
|
|
||||||
$tooltip .= '<br><b>' . $langs->trans('Label') . ':</b> ' . $this->label;
|
|
||||||
|
|
||||||
$linkstart = '<a href="'.DOL_URL_ROOT.'/loan/card.php?id='.$this->id.'" title="'.str_replace('\n', '', dol_escape_htmltag($tooltip, 1)).'" class="classfortooltip">';
|
|
||||||
$linkend = '</a>';
|
|
||||||
|
|
||||||
$result .= $linkstart;
|
|
||||||
if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
|
|
||||||
if ($withpicto != 2) $result.= ($maxlen?dol_trunc($this->ref,$maxlen):$this->ref);
|
|
||||||
$result .= $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
|
* Return label for given status
|
||||||
*
|
*
|
||||||
* @param int $id Id of record
|
* @param int $statut Id statut
|
||||||
* @return integer|null
|
* @param int $mode 0=Label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label, 5=Short label + Picto
|
||||||
|
* @param integer $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');
|
||||||
|
}
|
||||||
|
if ($mode == 6)
|
||||||
|
{
|
||||||
|
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 getNomUrl($withpicto=0,$maxlen=0)
|
||||||
|
{
|
||||||
|
global $langs;
|
||||||
|
|
||||||
|
$result='';
|
||||||
|
|
||||||
|
$tooltip = '<u>' . $langs->trans("ShowLoan") . '</u>';
|
||||||
|
if (! empty($this->ref))
|
||||||
|
$tooltip .= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
|
||||||
|
if (! empty($this->label))
|
||||||
|
$tooltip .= '<br><b>' . $langs->trans('Label') . ':</b> ' . $this->label;
|
||||||
|
|
||||||
|
$linkstart = '<a href="'.DOL_URL_ROOT.'/loan/card.php?id='.$this->id.'" title="'.str_replace('\n', '', dol_escape_htmltag($tooltip, 1)).'" class="classfortooltip">';
|
||||||
|
$linkend = '</a>';
|
||||||
|
|
||||||
|
$result .= $linkstart;
|
||||||
|
if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
|
||||||
|
if ($withpicto != 2) $result.= ($maxlen?dol_trunc($this->ref,$maxlen):$this->ref);
|
||||||
|
$result .= $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 integer|null
|
||||||
*/
|
*/
|
||||||
function info($id)
|
function info($id)
|
||||||
{
|
{
|
||||||
@@ -494,17 +504,17 @@ class Loan extends CommonObject
|
|||||||
$muser->fetch($obj->fk_user_modif);
|
$muser->fetch($obj->fk_user_modif);
|
||||||
$this->user_modification = $muser;
|
$this->user_modification = $muser;
|
||||||
}
|
}
|
||||||
$this->date_creation = $this->db->jdate($obj->datec);
|
$this->date_creation = $this->db->jdate($obj->datec);
|
||||||
if (empty($obj->fk_user_modif)) $obj->tms = "";
|
if (empty($obj->fk_user_modif)) $obj->tms = "";
|
||||||
$this->date_modification = $this->db->jdate($obj->tms);
|
$this->date_modification = $this->db->jdate($obj->tms);
|
||||||
|
|
||||||
$this->db->free($result);
|
$this->db->free($result);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->free($result);
|
$this->db->free($result);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user