Merge pull request #16463 from frederic34/hrm_code_syntax

code syntax hrm imports install intracommreport loan directory
This commit is contained in:
Laurent Destailleur 2021-02-26 19:24:03 +01:00 committed by GitHub
commit 338ee6563b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 1636 additions and 1538 deletions

View File

@ -27,8 +27,9 @@ require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array('admin', 'hrm')); $langs->loadLangs(array('admin', 'hrm'));
if (!$user->admin) if (!$user->admin) {
accessforbidden(); accessforbidden();
}
$error = 0; $error = 0;
@ -52,8 +53,12 @@ llxHeader('', $langs->trans("Establishments"));
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortorder = GETPOST("sortorder", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha');
$sortfield = GETPOST("sortfield", 'alpha'); $sortfield = GETPOST("sortfield", 'alpha');
if (!$sortorder) $sortorder = "DESC"; if (!$sortorder) {
if (!$sortfield) $sortfield = "e.rowid"; $sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "e.rowid";
}
if (empty($page) || $page == -1) { if (empty($page) || $page == -1) {
$page = 0; $page = 0;
@ -79,8 +84,7 @@ $sql .= $db->order($sortfield, $sortorder);
$sql .= $db->plimit($limit + 1, $offset); $sql .= $db->plimit($limit + 1, $offset);
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result) {
{
$num = $db->num_rows($result); $num = $db->num_rows($result);
$i = 0; $i = 0;
@ -95,12 +99,10 @@ if ($result)
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "e.status", "", "", '', $sortfield, $sortorder, 'right '); print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "e.status", "", "", '', $sortfield, $sortorder, 'right ');
print "</tr>\n"; print "</tr>\n";
if ($num > 0) if ($num > 0) {
{
$establishmentstatic = new Establishment($db); $establishmentstatic = new Establishment($db);
while ($i < min($num, $limit)) while ($i < min($num, $limit)) {
{
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$establishmentstatic->id = $obj->rowid; $establishmentstatic->id = $obj->rowid;

View File

@ -27,8 +27,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array('admin', 'hrm')); $langs->loadLangs(array('admin', 'hrm'));
if (!$user->admin) if (!$user->admin) {
accessforbidden(); accessforbidden();
}
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');

View File

@ -180,7 +180,9 @@ class Establishment extends CommonObject
$this->zip = trim($this->zip); $this->zip = trim($this->zip);
$this->town = trim($this->town); $this->town = trim($this->town);
if (empty($this->ref)) $this->ref = '(PROV)'; if (empty($this->ref)) {
$this->ref = '(PROV)';
}
$this->db->begin(); $this->db->begin();
@ -248,8 +250,7 @@ class Establishment extends CommonObject
global $langs; global $langs;
// Check parameters // Check parameters
if (empty($this->label)) if (empty($this->label)) {
{
$this->error = 'ErrorBadParameter'; $this->error = 'ErrorBadParameter';
return -1; return -1;
} }
@ -296,8 +297,7 @@ class Establishment extends CommonObject
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$this->id = $obj->rowid; $this->id = $obj->rowid;
@ -334,8 +334,7 @@ class Establishment extends CommonObject
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
$this->db->commit(); $this->db->commit();
return 1; return 1;
} else { } else {
@ -367,8 +366,7 @@ class Establishment extends CommonObject
public function LibStatut($status, $mode = 0) public function LibStatut($status, $mode = 0)
{ {
// phpcs:enable // phpcs:enable
if (empty($this->labelStatus) || empty($this->labelStatusShort)) if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
{
global $langs; global $langs;
//$langs->load("mymodule"); //$langs->load("mymodule");
$this->labelStatus[self::STATUS_OPEN] = $langs->trans('Open'); $this->labelStatus[self::STATUS_OPEN] = $langs->trans('Open');
@ -378,8 +376,12 @@ class Establishment extends CommonObject
} }
$statusType = 'status'.$status; $statusType = 'status'.$status;
if ($status == self::STATUS_OPEN) $statusType = 'status4'; if ($status == self::STATUS_OPEN) {
if ($status == self::STATUS_CLOSED) $statusType = 'status6'; $statusType = 'status4';
}
if ($status == self::STATUS_CLOSED) {
$statusType = 'status6';
}
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
} }
@ -400,22 +402,18 @@ class Establishment extends CommonObject
dol_syslog(get_class($this)."::fetch info", LOG_DEBUG); dol_syslog(get_class($this)."::fetch info", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{ if ($this->db->num_rows($result)) {
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->date_creation = $this->db->jdate($obj->datec); $this->date_creation = $this->db->jdate($obj->datec);
if ($obj->fk_user_author) if ($obj->fk_user_author) {
{
$cuser = new User($this->db); $cuser = new User($this->db);
$cuser->fetch($obj->fk_user_author); $cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser; $this->user_creation = $cuser;
} }
if ($obj->fk_user_mod) if ($obj->fk_user_mod) {
{
$muser = new User($this->db); $muser = new User($this->db);
$muser->fetch($obj->fk_user_mod); $muser->fetch($obj->fk_user_mod);
$this->user_modification = $muser; $this->user_modification = $muser;
@ -449,9 +447,15 @@ class Establishment extends CommonObject
$label = '<u>'.$langs->trans("Establishment").'</u>'; $label = '<u>'.$langs->trans("Establishment").'</u>';
$label .= '<br>'.$langs->trans("Label").': '.$this->label; $label .= '<br>'.$langs->trans("Label").': '.$this->label;
if ($withpicto) $result .= ($link.img_object($label, $picto).$linkend); if ($withpicto) {
if ($withpicto && $withpicto != 2) $result .= ' '; $result .= ($link.img_object($label, $picto).$linkend);
if ($withpicto != 2) $result .= $link.$this->label.$linkend; }
if ($withpicto && $withpicto != 2) {
$result .= ' ';
}
if ($withpicto != 2) {
$result .= $link.$this->label.$linkend;
}
return $result; return $result;
} }
@ -465,10 +469,14 @@ class Establishment extends CommonObject
global $mysoc; global $mysoc;
// We return country code of bank account // We return country code of bank account
if (!empty($this->country_code)) return $this->country_code; if (!empty($this->country_code)) {
return $this->country_code;
}
// We return country code of managed company // We return country code of managed company
if (!empty($mysoc->country_code)) return $mysoc->country_code; if (!empty($mysoc->country_code)) {
return $mysoc->country_code;
}
return ''; return '';
} }

View File

@ -29,7 +29,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
$langs->loadLangs(array('admin', 'hrm')); $langs->loadLangs(array('admin', 'hrm'));
// Security check // Security check
if (!$user->admin) accessforbidden(); if (!$user->admin) {
accessforbidden();
}
$error = 0; $error = 0;
@ -44,7 +46,9 @@ static $tmpstatus2label = array(
'1'=>'OpenEtablishment' '1'=>'OpenEtablishment'
); );
$status2label = array(''); $status2label = array('');
foreach ($tmpstatus2label as $key => $val) $status2label[$key] = $langs->trans($val); foreach ($tmpstatus2label as $key => $val) {
$status2label[$key] = $langs->trans($val);
}
$object = new Establishment($db); $object = new Establishment($db);
@ -56,31 +60,25 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ
* Actions * Actions
*/ */
if ($action == 'confirm_delete' && $confirm == "yes") if ($action == 'confirm_delete' && $confirm == "yes") {
{
$result = $object->delete($id); $result = $object->delete($id);
if ($result >= 0) if ($result >= 0) {
{
header("Location: ../admin/admin_establishment.php"); header("Location: ../admin/admin_establishment.php");
exit; exit;
} else { } else {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
} elseif ($action == 'add') } elseif ($action == 'add') {
{ if (!$cancel) {
if (!$cancel)
{
$error = 0; $error = 0;
$object->label = GETPOST('label', 'alpha'); $object->label = GETPOST('label', 'alpha');
if (empty($object->label)) if (empty($object->label)) {
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
$error++; $error++;
} }
if (empty($error)) if (empty($error)) {
{
$object->address = GETPOST('address', 'alpha'); $object->address = GETPOST('address', 'alpha');
$object->zip = GETPOST('zipcode', 'alpha'); $object->zip = GETPOST('zipcode', 'alpha');
$object->town = GETPOST('town', 'alpha'); $object->town = GETPOST('town', 'alpha');
@ -92,8 +90,7 @@ if ($action == 'confirm_delete' && $confirm == "yes")
$id = $object->create($user); $id = $object->create($user);
if ($id > 0) if ($id > 0) {
{
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit; exit;
} else { } else {
@ -106,11 +103,8 @@ if ($action == 'confirm_delete' && $confirm == "yes")
header("Location: ../admin/admin_establishment.php"); header("Location: ../admin/admin_establishment.php");
exit; exit;
} }
} } elseif ($action == 'update') {
// Update record
// Update record
elseif ($action == 'update')
{
$error = 0; $error = 0;
if (!$cancel) { if (!$cancel) {
@ -120,8 +114,7 @@ elseif ($action == 'update')
$error++; $error++;
} }
if (empty($error)) if (empty($error)) {
{
$object->label = GETPOST('label', 'alphanohtml'); $object->label = GETPOST('label', 'alphanohtml');
$object->address = GETPOST('address', 'alpha'); $object->address = GETPOST('address', 'alpha');
$object->zip = GETPOST('zipcode', 'alpha'); $object->zip = GETPOST('zipcode', 'alpha');
@ -133,8 +126,7 @@ elseif ($action == 'update')
$result = $object->update($user); $result = $object->update($user);
if ($result > 0) if ($result > 0) {
{
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['id']); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['id']);
exit; exit;
} else { } else {
@ -159,8 +151,7 @@ $formcompany = new FormCompany($db);
/* /*
* Action create * Action create
*/ */
if ($action == 'create') if ($action == 'create') {
{
print load_fiche_titre($langs->trans("NewEstablishment")); print load_fiche_titre($langs->trans("NewEstablishment"));
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
@ -228,7 +219,9 @@ if ($action == 'create')
print '<td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>'; print '<td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
print '<td class="maxwidthonsmartphone">'; print '<td class="maxwidthonsmartphone">';
print $form->select_country(GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : ($object->country_id ? $object->country_id : $mysoc->country_id), 'country_id'); print $form->select_country(GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : ($object->country_id ? $object->country_id : $mysoc->country_id), 'country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); if ($user->admin) {
print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
}
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -253,15 +246,12 @@ if ($action == 'create')
} }
// Part to edit record // Part to edit record
if (($id || $ref) && $action == 'edit') if (($id || $ref) && $action == 'edit') {
{
$result = $object->fetch($id); $result = $object->fetch($id);
if ($result > 0) if ($result > 0) {
{
$head = establishment_prepare_head($object); $head = establishment_prepare_head($object);
if ($action == 'edit') if ($action == 'edit') {
{
print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), 0, 'building'); print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), 0, 'building');
print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n"; print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
@ -284,12 +274,12 @@ if (($id || $ref) && $action == 'edit')
// Entity // Entity
/* /*
if (! empty($conf->multicompany->enabled)) { if (! empty($conf->multicompany->enabled)) {
print '<tr><td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>'; print '<tr><td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
print '<td class="maxwidthonsmartphone">'; print '<td class="maxwidthonsmartphone">';
print $object->entity > 0 ? $object->entity : $conf->entity; print $object->entity > 0 ? $object->entity : $conf->entity;
print '</td></tr>'; print '</td></tr>';
}*/ }*/
// Address // Address
print '<tr><td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>'; print '<tr><td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
@ -313,7 +303,9 @@ if (($id || $ref) && $action == 'edit')
print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>'; print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
print '<td class="maxwidthonsmartphone">'; print '<td class="maxwidthonsmartphone">';
print $form->select_country($object->country_id, 'country_id'); print $form->select_country($object->country_id, 'country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); if ($user->admin) {
print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
}
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -334,19 +326,19 @@ if (($id || $ref) && $action == 'edit')
print '</form>'; print '</form>';
} }
} else dol_print_error($db); } else {
dol_print_error($db);
}
} }
if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
{
$res = $object->fetch_optionals(); $res = $object->fetch_optionals();
$head = establishment_prepare_head($object); $head = establishment_prepare_head($object);
print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), -1, 'building'); print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), -1, 'building');
// Confirmation to delete // Confirmation to delete
if ($action == 'delete') if ($action == 'delete') {
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete"); print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete");
} }
@ -404,8 +396,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans("Country").'</td>'; print '<td>'.$langs->trans("Country").'</td>';
print '<td>'; print '<td>';
if ($object->country_id > 0) if ($object->country_id > 0) {
{
$img = picto_from_langcode($object->country_code); $img = picto_from_langcode($object->country_code);
print $img ? $img.' ' : ''; print $img ? $img.' ' : '';
print getCountry($object->getCountryCode(), 0, $db); print getCountry($object->getCountryCode(), 0, $db);
@ -421,8 +412,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print dol_get_fiche_end(); print dol_get_fiche_end();
/* /*
* Barre d'actions * Barre d'actions
*/ */
print '<div class="tabsAction">'; print '<div class="tabsAction">';
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$id.'">'.$langs->trans('Modify').'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$id.'">'.$langs->trans('Modify').'</a>';

View File

@ -37,7 +37,9 @@ $backtopage = GETPOST('backtopage', 'alpha');
if (GETPOST('actioncode', 'array')) { if (GETPOST('actioncode', 'array')) {
$actioncode = GETPOST('actioncode', 'array', 3); $actioncode = GETPOST('actioncode', 'array', 3);
if (!count($actioncode)) $actioncode = '0'; if (!count($actioncode)) {
$actioncode = '0';
}
} else { } else {
$actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
} }
@ -47,12 +49,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha'); $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (!$sortfield) $sortfield = 'a.datep,a.id'; if (!$sortfield) {
if (!$sortorder) $sortorder = 'DESC,DESC'; $sortfield = 'a.datep,a.id';
}
if (!$sortorder) {
$sortorder = 'DESC,DESC';
}
// Initialize technical objects // Initialize technical objects
$object = new Establishment($db); $object = new Establishment($db);
@ -64,7 +72,9 @@ $extrafields->fetch_name_optionals_label($object->table_element);
// Load object // Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
if ($id > 0 || !empty($ref)) $upload_dir = $conf->hrm->multidir_output[$object->entity]."/".$object->id; if ($id > 0 || !empty($ref)) {
$upload_dir = $conf->hrm->multidir_output[$object->entity]."/".$object->id;
}
// Security check - Protection if external user // Security check - Protection if external user
//if ($user->socid > 0) accessforbidden(); //if ($user->socid > 0) accessforbidden();
@ -80,20 +90,19 @@ $permissiontoadd = $user->rights->hrm->write; // Used by the include of actions_
$parameters = array('id'=>$id); $parameters = array('id'=>$id);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) if (empty($reshook)) {
{
// Cancel // Cancel
if (GETPOST('cancel', 'alpha') && !empty($backtopage)) if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
{
header("Location: ".$backtopage); header("Location: ".$backtopage);
exit; exit;
} }
// Purge search criteria // Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
{
$actioncode = ''; $actioncode = '';
$search_agenda_label = ''; $search_agenda_label = '';
} }
@ -107,14 +116,15 @@ if (empty($reshook))
$form = new Form($db); $form = new Form($db);
if ($object->id > 0) if ($object->id > 0) {
{
$title = $langs->trans("Agenda"); $title = $langs->trans("Agenda");
//if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title; //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
$help_url = ''; $help_url = '';
llxHeader('', $title, $help_url); llxHeader('', $title, $help_url);
if (!empty($conf->notification->enabled)) $langs->load("mails"); if (!empty($conf->notification->enabled)) {
$langs->load("mails");
}
$head = establishment_prepare_head($object); $head = establishment_prepare_head($object);

View File

@ -33,8 +33,12 @@ require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
if ($conf->deplacement->enabled) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php'; if ($conf->deplacement->enabled) {
if ($conf->expensereport->enabled) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
}
if ($conf->expensereport->enabled) {
require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
}
require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentcandidature.class.php'; require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentcandidature.class.php';
require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
@ -47,9 +51,13 @@ $langs->loadLangs(array('users', 'holidays', 'trips', 'boxes'));
$socid = GETPOST("socid", "int"); $socid = GETPOST("socid", "int");
// Protection if external user // Protection if external user
if ($user->socid > 0) accessforbidden(); if ($user->socid > 0) {
accessforbidden();
}
if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) $setupcompanynotcomplete = 1; if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
$setupcompanynotcomplete = 1;
}
$holiday = new Holiday($db); $holiday = new Holiday($db);
$holidaystatic = new Holiday($db); $holidaystatic = new Holiday($db);
@ -63,8 +71,7 @@ $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
*/ */
// Update sold // Update sold
if (!empty($conf->holiday->enabled) && !empty($setupcompanynotcomplete)) if (!empty($conf->holiday->enabled) && !empty($setupcompanynotcomplete)) {
{
$result = $holiday->updateBalance(); $result = $holiday->updateBalance();
} }
@ -81,8 +88,7 @@ llxHeader('', $langs->trans('HRMArea'));
print load_fiche_titre($langs->trans("HRMArea"), '', 'hrm'); print load_fiche_titre($langs->trans("HRMArea"), '', 'hrm');
if (!empty($setupcompanynotcomplete)) if (!empty($setupcompanynotcomplete)) {
{
$langs->load("errors"); $langs->load("errors");
$warnpicto = img_warning($langs->trans("WarningMandatorySetupNotComplete")); $warnpicto = img_warning($langs->trans("WarningMandatorySetupNotComplete"));
print '<br><div class="warning"><a href="'.DOL_URL_ROOT.'/admin/company.php?mainmenu=home'.(empty($setupcompanynotcomplete) ? '' : '&action=edit').'">'.$warnpicto.' '.$langs->trans("WarningMandatorySetupNotComplete").'</a></div>'; print '<br><div class="warning"><a href="'.DOL_URL_ROOT.'/admin/company.php?mainmenu=home'.(empty($setupcompanynotcomplete) ? '' : '&action=edit').'">'.$warnpicto.' '.$langs->trans("WarningMandatorySetupNotComplete").'</a></div>';
@ -94,36 +100,34 @@ if (!empty($setupcompanynotcomplete))
print '<div class="fichecenter"><div class="fichethirdleft">'; print '<div class="fichecenter"><div class="fichethirdleft">';
if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is useless due to the global search combo
{ if (!empty($conf->holiday->enabled) && $user->rights->holiday->read) {
if (!empty($conf->holiday->enabled) && $user->rights->holiday->read)
{
$langs->load("holiday"); $langs->load("holiday");
$listofsearchfields['search_holiday'] = array('text'=>'TitreRequestCP'); $listofsearchfields['search_holiday'] = array('text'=>'TitreRequestCP');
} }
if (!empty($conf->deplacement->enabled) && $user->rights->deplacement->lire) if (!empty($conf->deplacement->enabled) && $user->rights->deplacement->lire) {
{
$langs->load("trips"); $langs->load("trips");
$listofsearchfields['search_deplacement'] = array('text'=>'ExpenseReport'); $listofsearchfields['search_deplacement'] = array('text'=>'ExpenseReport');
} }
if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->lire) if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->lire) {
{
$langs->load("trips"); $langs->load("trips");
$listofsearchfields['search_expensereport'] = array('text'=>'ExpenseReport'); $listofsearchfields['search_expensereport'] = array('text'=>'ExpenseReport');
} }
if (count($listofsearchfields)) if (count($listofsearchfields)) {
{
print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">'; print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<div class="div-table-responsive-no-min">'; print '<div class="div-table-responsive-no-min">';
print '<table class="noborder nohover centpercent">'; print '<table class="noborder nohover centpercent">';
$i = 0; $i = 0;
foreach ($listofsearchfields as $key => $value) foreach ($listofsearchfields as $key => $value) {
{ if ($i == 0) {
if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>'; print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
}
print '<tr '.$bc[false].'>'; print '<tr '.$bc[false].'>';
print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>'; print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>';
if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>'; if ($i == 0) {
print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
}
print '</tr>'; print '</tr>';
$i++; $i++;
} }
@ -135,10 +139,8 @@ if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useles
} }
if (!empty($conf->holiday->enabled)) if (!empty($conf->holiday->enabled)) {
{ if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) {
if (empty($conf->global->HOLIDAY_HIDE_BALANCE))
{
$user_id = $user->id; $user_id = $user->id;
print '<div class="div-table-responsive-no-min">'; print '<div class="div-table-responsive-no-min">';
@ -149,8 +151,7 @@ if (!empty($conf->holiday->enabled))
$out = ''; $out = '';
$typeleaves = $holiday->getTypes(1, 1); $typeleaves = $holiday->getTypes(1, 1);
foreach ($typeleaves as $key => $val) foreach ($typeleaves as $key => $val) {
{
$nb_type = $holiday->getCPforUser($user->id, $val['rowid']); $nb_type = $holiday->getCPforUser($user->id, $val['rowid']);
$nb_holiday += $nb_type; $nb_holiday += $nb_type;
$out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': <strong>'.($nb_type ? price2num($nb_type) : 0).'</strong><br>'; $out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': <strong>'.($nb_type ? price2num($nb_type) : 0).'</strong><br>';
@ -161,8 +162,7 @@ if (!empty($conf->holiday->enabled))
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
print '</table></div><br>'; print '</table></div><br>';
} elseif (!is_numeric($conf->global->HOLIDAY_HIDE_BALANCE)) } elseif (!is_numeric($conf->global->HOLIDAY_HIDE_BALANCE)) {
{
print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).'<br>'; print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).'<br>';
} }
} }
@ -173,22 +173,22 @@ print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
// Latest leave requests // Latest leave requests
if (!empty($conf->holiday->enabled) && $user->rights->holiday->read) if (!empty($conf->holiday->enabled) && $user->rights->holiday->read) {
{
$sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.photo, u.statut as user_status,"; $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.photo, u.statut as user_status,";
$sql .= " x.rowid, x.rowid as ref, x.fk_type, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.tms as dm, x.statut as status"; $sql .= " x.rowid, x.rowid as ref, x.fk_type, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.tms as dm, x.statut as status";
$sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE u.rowid = x.fk_user"; $sql .= " WHERE u.rowid = x.fk_user";
$sql .= " AND x.entity = ".$conf->entity; $sql .= " AND x.entity = ".$conf->entity;
if (empty($user->rights->holiday->readall)) $sql .= ' AND x.fk_user IN ('.join(',', $childids).')'; if (empty($user->rights->holiday->readall)) {
$sql .= ' AND x.fk_user IN ('.join(',', $childids).')';
}
//if (!$user->rights->societe->client->voir && !$user->socid) $sql.= " AND x.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; //if (!$user->rights->societe->client->voir && !$user->socid) $sql.= " AND x.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
//if (!empty($socid)) $sql.= " AND x.fk_soc = ".$socid; //if (!empty($socid)) $sql.= " AND x.fk_soc = ".$socid;
$sql .= $db->order("x.tms", "DESC"); $sql .= $db->order("x.tms", "DESC");
$sql .= $db->plimit($max, 0); $sql .= $db->plimit($max, 0);
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result) {
{
$var = false; $var = false;
$num = $db->num_rows($result); $num = $db->num_rows($result);
@ -208,10 +208,8 @@ if (!empty($conf->holiday->enabled) && $user->rights->holiday->read)
print '<th>'.$langs->trans("to").'</th>'; print '<th>'.$langs->trans("to").'</th>';
print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/holiday/list.php?sortfield=cp.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>'; print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/holiday/list.php?sortfield=cp.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
print '</tr>'; print '</tr>';
if ($num) if ($num) {
{ while ($i < $num && $i < $max) {
while ($i < $num && $i < $max)
{
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$holidaystatic->id = $obj->rowid; $holidaystatic->id = $obj->rowid;
@ -248,28 +246,30 @@ if (!empty($conf->holiday->enabled) && $user->rights->holiday->read)
print '</table>'; print '</table>';
print '</div>'; print '</div>';
print '<br>'; print '<br>';
} else dol_print_error($db); } else {
dol_print_error($db);
}
} }
// Latest expense report // Latest expense report
if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->lire) if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->lire) {
{
$sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.statut as user_status, u.photo,"; $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.statut as user_status, u.photo,";
$sql .= " x.rowid, x.ref, x.date_debut as date, x.tms as dm, x.total_ttc, x.fk_statut as status"; $sql .= " x.rowid, x.ref, x.date_debut as date, x.tms as dm, x.total_ttc, x.fk_statut as status";
$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as x, ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as x, ".MAIN_DB_PREFIX."user as u";
//if (!$user->rights->societe->client->voir && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc"; //if (!$user->rights->societe->client->voir && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE u.rowid = x.fk_user_author"; $sql .= " WHERE u.rowid = x.fk_user_author";
$sql .= " AND x.entity = ".$conf->entity; $sql .= " AND x.entity = ".$conf->entity;
if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $sql .= ' AND x.fk_user_author IN ('.join(',', $childids).')'; if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) {
$sql .= ' AND x.fk_user_author IN ('.join(',', $childids).')';
}
//if (!$user->rights->societe->client->voir && !$user->socid) $sql.= " AND x.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; //if (!$user->rights->societe->client->voir && !$user->socid) $sql.= " AND x.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
//if (!empty($socid)) $sql.= " AND x.fk_soc = ".$socid; //if (!empty($socid)) $sql.= " AND x.fk_soc = ".$socid;
$sql .= $db->order("x.tms", "DESC"); $sql .= $db->order("x.tms", "DESC");
$sql .= $db->plimit($max, 0); $sql .= $db->plimit($max, 0);
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result) {
{
$num = $db->num_rows($result); $num = $db->num_rows($result);
$i = 0; $i = 0;
@ -281,14 +281,12 @@ if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->lire)
print '<th class="right">'.$langs->trans("TotalTTC").'</th>'; print '<th class="right">'.$langs->trans("TotalTTC").'</th>';
print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/expensereport/list.php?sortfield=d.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>'; print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/expensereport/list.php?sortfield=d.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
print '</tr>'; print '</tr>';
if ($num) if ($num) {
{
$total_ttc = $totalam = $total = 0; $total_ttc = $totalam = $total = 0;
$expensereportstatic = new ExpenseReport($db); $expensereportstatic = new ExpenseReport($db);
$userstatic = new User($db); $userstatic = new User($db);
while ($i < $num && $i < $max) while ($i < $num && $i < $max) {
{
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$expensereportstatic->id = $obj->rowid; $expensereportstatic->id = $obj->rowid;
@ -320,26 +318,32 @@ if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->lire)
print '</table>'; print '</table>';
print '</div>'; print '</div>';
print '<br>'; print '<br>';
} else dol_print_error($db); } else {
dol_print_error($db);
}
} }
// Last modified job position // Last modified job position
if (!empty($conf->recruitment->enabled) && $user->rights->recruitment->recruitmentjobposition->read) if (!empty($conf->recruitment->enabled) && $user->rights->recruitment->recruitmentjobposition->read) {
{
$sql = "SELECT rc.rowid, rc.ref, rc.email, rc.lastname, rc.firstname, rc.date_creation, rc.tms, rc.status"; $sql = "SELECT rc.rowid, rc.ref, rc.email, rc.lastname, rc.firstname, rc.date_creation, rc.tms, rc.status";
$sql .= " FROM ".MAIN_DB_PREFIX."recruitment_recruitmentcandidature as rc"; $sql .= " FROM ".MAIN_DB_PREFIX."recruitment_recruitmentcandidature as rc";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."recruitment_recruitmentjobposition as s ON rc.fk_recruitmentjobposition = s.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."recruitment_recruitmentjobposition as s ON rc.fk_recruitmentjobposition = s.rowid";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE rc.entity IN (".getEntity($staticrecruitmentjobposition->element).")"; $sql .= " WHERE rc.entity IN (".getEntity($staticrecruitmentjobposition->element).")";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; if (!$user->rights->societe->client->voir && !$socid) {
if ($socid) $sql .= " AND s.fk_soc = $socid"; $sql .= " AND s.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND s.fk_soc = $socid";
}
$sql .= " ORDER BY rc.tms DESC"; $sql .= " ORDER BY rc.tms DESC";
$sql .= $db->plimit($max, 0); $sql .= $db->plimit($max, 0);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
@ -351,10 +355,8 @@ if (!empty($conf->recruitment->enabled) && $user->rights->recruitment->recruitme
print '</th>'; print '</th>';
print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/recruitment/recruitmentcandidature_list.php?sortfield=t.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>'; print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/recruitment/recruitmentcandidature_list.php?sortfield=t.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
print '</tr>'; print '</tr>';
if ($num) if ($num) {
{ while ($i < $num) {
while ($i < $num)
{
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
$staticrecruitmentcandidature->id = $objp->rowid; $staticrecruitmentcandidature->id = $objp->rowid;
$staticrecruitmentcandidature->ref = $objp->ref; $staticrecruitmentcandidature->ref = $objp->ref;

View File

@ -87,15 +87,17 @@ class Import
$modulesdir = dolGetModulesDirs(); $modulesdir = dolGetModulesDirs();
// Load list of modules // Load list of modules
foreach ($modulesdir as $dir) foreach ($modulesdir as $dir) {
{
$handle = @opendir(dol_osencode($dir)); $handle = @opendir(dol_osencode($dir));
if (!is_resource($handle)) continue; if (!is_resource($handle)) {
continue;
}
// Search module files // Search module files
while (($file = readdir($handle)) !== false) while (($file = readdir($handle)) !== false) {
{ if (!preg_match("/^(mod.*)\.class\.php/i", $file, $reg)) {
if (!preg_match("/^(mod.*)\.class\.php/i", $file, $reg)) continue; continue;
}
$modulename = $reg[1]; $modulename = $reg[1];
@ -103,10 +105,16 @@ class Import
$enabled = true; $enabled = true;
$part = strtolower(preg_replace('/^mod/i', '', $modulename)); $part = strtolower(preg_replace('/^mod/i', '', $modulename));
// Adds condition for propal module // Adds condition for propal module
if ($part === 'propale') $part = 'propal'; if ($part === 'propale') {
if (empty($conf->$part->enabled)) $enabled = false; $part = 'propal';
}
if (empty($conf->$part->enabled)) {
$enabled = false;
}
if (empty($enabled)) continue; if (empty($enabled)) {
continue;
}
// Init load class // Init load class
$file = $dir."/".$modulename.".class.php"; $file = $dir."/".$modulename.".class.php";
@ -114,11 +122,11 @@ class Import
require_once $file; require_once $file;
$module = new $classname($this->db); $module = new $classname($this->db);
if (isset($module->import_code) && is_array($module->import_code)) if (isset($module->import_code) && is_array($module->import_code)) {
{ foreach ($module->import_code as $r => $value) {
foreach ($module->import_code as $r => $value) if ($filter && ($filter != $module->import_code[$r])) {
{ continue;
if ($filter && ($filter != $module->import_code[$r])) continue; }
// Test if permissions are ok // Test if permissions are ok
/*$perm=$module->import_permission[$r][0]; /*$perm=$module->import_permission[$r][0];
@ -137,10 +145,8 @@ class Import
// Load lang file // Load lang file
$langtoload = $module->getLangFilesArray(); $langtoload = $module->getLangFilesArray();
if (is_array($langtoload)) if (is_array($langtoload)) {
{ foreach ($langtoload as $key) {
foreach ($langtoload as $key)
{
$langs->load($key); $langs->load($key);
} }
} }
@ -246,9 +252,15 @@ class Import
dol_syslog("Import.class.php::create"); dol_syslog("Import.class.php::create");
// Check parameters // Check parameters
if (empty($this->model_name)) { $this->error = 'ErrorWrongParameters'; return -1; } if (empty($this->model_name)) {
if (empty($this->datatoimport)) { $this->error = 'ErrorWrongParameters'; return -1; } $this->error = 'ErrorWrongParameters'; return -1;
if (empty($this->hexa)) { $this->error = 'ErrorWrongParameters'; return -1; } }
if (empty($this->datatoimport)) {
$this->error = 'ErrorWrongParameters'; return -1;
}
if (empty($this->hexa)) {
$this->error = 'ErrorWrongParameters'; return -1;
}
$this->db->begin(); $this->db->begin();
@ -259,8 +271,7 @@ class Import
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->db->commit(); $this->db->commit();
return 1; return 1;
} else { } else {
@ -285,11 +296,9 @@ class Import
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
if ($obj) if ($obj) {
{
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->hexa = $obj->field; $this->hexa = $obj->field;
$this->model_name = $obj->label; $this->model_name = $obj->label;
@ -325,26 +334,24 @@ class Import
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) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
if (!$error) if (!$error) {
{ if (!$notrigger) {
if (!$notrigger)
{
/* Not used. This is not a business object. To convert it we must herit from CommonObject /* Not used. This is not a business object. To convert it we must herit from CommonObject
// Call trigger // Call trigger
$result=$this->call_trigger('IMPORT_DELETE',$user); $result=$this->call_trigger('IMPORT_DELETE',$user);
if ($result < 0) $error++; if ($result < 0) $error++;
// End call triggers // End call triggers
*/ */
} }
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }

View File

@ -21,7 +21,9 @@
* \brief Show example of import file * \brief Show example of import file
*/ */
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on) if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
}
/** /**
@ -58,8 +60,7 @@ $format = GETPOST('format');
$langs->load("exports"); $langs->load("exports");
// Check exportkey // Check exportkey
if (empty($datatoimport)) if (empty($datatoimport)) {
{
$user->getrights(); $user->getrights();
llxHeader(); llxHeader();
@ -81,23 +82,30 @@ $fieldstarget = $objimport->array_import_fields[0];
$valuestarget = $objimport->array_import_examplevalues[0]; $valuestarget = $objimport->array_import_examplevalues[0];
$attachment = true; $attachment = true;
if (isset($_GET["attachment"])) $attachment = $_GET["attachment"]; if (isset($_GET["attachment"])) {
$attachment = $_GET["attachment"];
}
//$attachment = false; //$attachment = false;
$contenttype = dol_mimetype($format); $contenttype = dol_mimetype($format);
if (isset($_GET["contenttype"])) $contenttype = $_GET["contenttype"]; if (isset($_GET["contenttype"])) {
$contenttype = $_GET["contenttype"];
}
//$contenttype='text/plain'; //$contenttype='text/plain';
$outputencoding = 'UTF-8'; $outputencoding = 'UTF-8';
if ($contenttype) header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : '')); if ($contenttype) {
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
}
if ($attachment) {
header('Content-Disposition: attachment; filename="'.$filename.'"');
}
// List of targets fields // List of targets fields
$headerlinefields = array(); $headerlinefields = array();
$contentlinevalues = array(); $contentlinevalues = array();
$i = 0; $i = 0;
foreach ($fieldstarget as $code=>$label) foreach ($fieldstarget as $code => $label) {
{
$withoutstar = preg_replace('/\*/', '', $fieldstarget[$code]); $withoutstar = preg_replace('/\*/', '', $fieldstarget[$code]);
$headerlinefields[] = $langs->transnoentities($withoutstar).($withoutstar != $fieldstarget[$code] ? '*' : '').' ('.$code.')'; $headerlinefields[] = $langs->transnoentities($withoutstar).($withoutstar != $fieldstarget[$code] ? '*' : '').' ('.$code.')';
$contentlinevalues[] = $valuestarget[$code]; $contentlinevalues[] = $valuestarget[$code];

File diff suppressed because it is too large Load Diff

View File

@ -27,8 +27,9 @@ require_once DOL_DOCUMENT_ROOT.'/imports/class/import.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->load("exports"); $langs->load("exports");
if (!$user->socid == 0) if (!$user->socid == 0) {
accessforbidden(); accessforbidden();
}
$import = new Import($db); $import = new Import($db);
$import->load_arrays($user); $import->load_arrays($user);
@ -49,8 +50,7 @@ print '<br>';
print '<div class="center">'; print '<div class="center">';
if (count($import->array_import_code)) if (count($import->array_import_code)) {
{
print dolGetButtonTitle($langs->trans('NewImport'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/imports/import.php?leftmenu=import'); print dolGetButtonTitle($langs->trans('NewImport'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/imports/import.php?leftmenu=import');
} }
print '</div>'; print '</div>';
@ -70,8 +70,7 @@ include_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php';
$model = new ModeleImports(); $model = new ModeleImports();
$list = $model->liste_modeles($db); $list = $model->liste_modeles($db);
foreach ($list as $key) foreach ($list as $key) {
{
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td width="16">'.img_picto_common($model->getDriverLabelForKey($key), $model->getPictoForKey($key)).'</td>'; print '<td width="16">'.img_picto_common($model->getDriverLabelForKey($key), $model->getPictoForKey($key)).'</td>';
$text = $model->getDriverDescForKey($key); $text = $model->getDriverDescForKey($key);

File diff suppressed because it is too large Load Diff

View File

@ -30,7 +30,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("admin", "intracommreport")); $langs->loadLangs(array("admin", "intracommreport"));
if (!$user->admin) accessforbidden(); if (!$user->admin) {
accessforbidden();
}
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
@ -46,10 +48,8 @@ $list_DES = array(
if ($action == 'update') { if ($action == 'update') {
$error = 0; $error = 0;
if (!$error) if (!$error) {
{ foreach ($list_DEB as $constname) {
foreach ($list_DEB as $constname)
{
$constvalue = GETPOST($constname, 'alpha'); $constvalue = GETPOST($constname, 'alpha');
if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
@ -57,8 +57,7 @@ if ($action == 'update') {
} }
} }
foreach ($list_DES as $constname) foreach ($list_DES as $constname) {
{
$constvalue = GETPOST($constname, 'alpha'); $constvalue = GETPOST($constname, 'alpha');
if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
@ -110,8 +109,7 @@ print '<td>'.$langs->trans("Description").'</td>';
print '<td>'.$langs->trans("Value").'</td>'; print '<td>'.$langs->trans("Value").'</td>';
print '</tr>'; print '</tr>';
foreach ($list_DEB as $key) foreach ($list_DEB as $key) {
{
print '<tr class="oddeven value">'; print '<tr class="oddeven value">';
// Param // Param
@ -175,8 +173,7 @@ print '<td>'.$langs->trans("Description").'</td>';
print '<td>'.$langs->trans("Value").'</td>'; print '<td>'.$langs->trans("Value").'</td>';
print '</tr>'; print '</tr>';
foreach ($list_DES as $key) foreach ($list_DES as $key) {
{
print '<tr class="oddeven value">'; print '<tr class="oddeven value">';
// Param // Param

View File

@ -24,9 +24,15 @@
* \brief File to calculate loan monthly payments * \brief File to calculate loan monthly payments
*/ */
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal if (!defined('NOTOKENRENEWAL')) {
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); define('NOTOKENRENEWAL', '1'); // Disables token renewal
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); }
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
require '../main.inc.php'; require '../main.inc.php';
require DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; require DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';

View File

@ -28,8 +28,12 @@ require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.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/loan.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; if (!empty($conf->accounting->enabled)) {
if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
}
if (!empty($conf->accounting->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
}
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
@ -45,7 +49,9 @@ $projectid = GETPOST('projectid', 'int');
// Security check // Security check
$socid = GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'loan', $id, '', ''); $result = restrictedArea($user, 'loan', $id, '', '');
$object = new Loan($db); $object = new Loan($db);
@ -60,16 +66,15 @@ $error = 0;
*/ */
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) {
if (empty($reshook)) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
{ }
if (empty($reshook)) {
// Classify paid // Classify paid
if ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->loan->write) if ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->loan->write) {
{
$object->fetch($id); $object->fetch($id);
$result = $object->setPaid($user); $result = $object->setPaid($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');
@ -77,12 +82,10 @@ if (empty($reshook))
} }
// Delete loan // Delete loan
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->write) if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->write) {
{
$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: list.php"); header("Location: list.php");
exit; exit;
@ -92,44 +95,37 @@ if (empty($reshook))
} }
// 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) {
{
$object->label = GETPOST('label'); $object->label = GETPOST('label');
$object->fk_bank = GETPOST('accountid'); $object->fk_bank = GETPOST('accountid');
$object->capital = $capital; $object->capital = $capital;
$object->datestart = $datestart; $object->datestart = $datestart;
$object->dateend = $dateend; $object->dateend = $dateend;
$object->nbterm = GETPOST('nbterm'); $object->nbterm = GETPOST('nbterm');
$object->rate = $rate; $object->rate = $rate;
$object->note_private = GETPOST('note_private', 'restricthtml'); $object->note_private = GETPOST('note_private', 'restricthtml');
$object->note_public = GETPOST('note_public', 'restricthtml'); $object->note_public = GETPOST('note_public', 'restricthtml');
@ -140,13 +136,24 @@ if (empty($reshook))
$accountancy_account_insurance = GETPOST('accountancy_account_insurance'); $accountancy_account_insurance = GETPOST('accountancy_account_insurance');
$accountancy_account_interest = GETPOST('accountancy_account_interest'); $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_capital <= 0) {
if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; } $object->account_capital = '';
if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; } } 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); $id = $object->create($user);
if ($id <= 0) if ($id <= 0) {
{
$error++; $error++;
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$action = 'create'; $action = 'create';
@ -156,21 +163,16 @@ if (empty($reshook))
header("Location: list.php"); header("Location: list.php");
exit(); exit();
} }
} } elseif ($action == 'update' && $user->rights->loan->write) {
// Update record
// Update record if (!$cancel) {
elseif ($action == 'update' && $user->rights->loan->write)
{
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 {
@ -185,15 +187,26 @@ if (empty($reshook))
$accountancy_account_insurance = GETPOST('accountancy_account_insurance'); $accountancy_account_insurance = GETPOST('accountancy_account_insurance');
$accountancy_account_interest = GETPOST('accountancy_account_interest'); $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_capital <= 0) {
if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; } $object->account_capital = '';
if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; } } 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;
}
} }
$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 {
@ -207,20 +220,20 @@ if (empty($reshook))
} }
// 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');
}
} }
} }
@ -231,7 +244,9 @@ if (empty($reshook))
$form = new Form($db); $form = new Form($db);
$formproject = new FormProjets($db); $formproject = new FormProjets($db);
if (!empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); if (!empty($conf->accounting->enabled)) {
$formaccounting = new FormAccounting($db);
}
$title = $langs->trans("Loan").' - '.$langs->trans("Card"); $title = $langs->trans("Loan").' - '.$langs->trans("Card");
$help_url = 'EN:Module_Loan|FR:Module_Emprunt'; $help_url = 'EN:Module_Loan|FR:Module_Emprunt';
@ -239,8 +254,7 @@ llxHeader("", $title, $help_url);
// Create mode // Create mode
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';
@ -260,8 +274,7 @@ if ($action == 'create')
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth300" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label')).'" autofocus="autofocus"></td></tr>'; print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth300" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label')).'" autofocus="autofocus"></td></tr>';
// Bank account // Bank account
if (!empty($conf->banque->enabled)) if (!empty($conf->banque->enabled)) {
{
print '<tr><td class="fieldrequired">'.$langs->trans("Account").'</td><td>'; 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 $form->select_comptes(GETPOST("accountid"), "accountid", 0, "courant=1", 1); // Show list of bank account with courant
print '</td></tr>'; print '</td></tr>';
@ -296,8 +309,7 @@ if ($action == 'create')
print '<tr><td>'.$langs->trans("Insurance").'</td><td><input name="insurance_amount" size="10" value="'.dol_escape_htmltag(GETPOST("insurance_amount")).'" placeholder="'.$langs->trans('Amount').'"></td></tr>'; print '<tr><td>'.$langs->trans("Insurance").'</td><td><input name="insurance_amount" size="10" value="'.dol_escape_htmltag(GETPOST("insurance_amount")).'" placeholder="'.$langs->trans('Amount').'"></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
@ -329,8 +341,7 @@ if ($action == 'create')
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>';
@ -379,32 +390,27 @@ if ($action == 'create')
} }
// 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) {
{
$head = loan_prepare_head($object); $head = loan_prepare_head($object);
$totalpaid = $object->getSumPayment(); $totalpaid = $object->getSumPayment();
// Confirm for loan // Confirm for loan
if ($action == 'paid') if ($action == 'paid') {
{
$text = $langs->trans('ConfirmPayLoan'); $text = $langs->trans('ConfirmPayLoan');
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayLoan'), $text, "confirm_paid", '', '', 2); print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayLoan'), $text, "confirm_paid", '', '', 2);
} }
if ($action == 'delete') if ($action == 'delete') {
{
$text = $langs->trans('ConfirmDeleteLoan'); $text = $langs->trans('ConfirmDeleteLoan');
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteLoan'), $text, 'confirm_delete', '', '', 2); print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteLoan'), $text, 'confirm_delete', '', '', 2);
} }
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="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="update">'; print '<input type="hidden" name="action" value="update">';
@ -422,14 +428,13 @@ 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->loadLangs(array("projects")); $langs->loadLangs(array("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 class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : '; $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;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.'">';
@ -466,8 +471,7 @@ if ($id > 0)
print '<table class="border centpercent tableforfield">'; print '<table class="border centpercent tableforfield">';
// Capital // Capital
if ($action == 'edit') if ($action == 'edit') {
{
print '<tr><td class="fieldrequired titlefield">'.$langs->trans("LoanCapital").'</td><td>'; print '<tr><td class="fieldrequired titlefield">'.$langs->trans("LoanCapital").'</td><td>';
print '<input name="capital" size="10" value="'.$object->capital.'"></td></tr>'; print '<input name="capital" size="10" value="'.$object->capital.'"></td></tr>';
print '</td></tr>'; print '</td></tr>';
@ -476,8 +480,7 @@ if ($id > 0)
} }
// Insurance // Insurance
if ($action == 'edit') if ($action == 'edit') {
{
print '<tr><td class="titlefield">'.$langs->trans("Insurance").'</td><td>'; print '<tr><td class="titlefield">'.$langs->trans("Insurance").'</td><td>';
print '<input name="insurance_amount" size="10" value="'.$object->insurance_amount.'"></td></tr>'; print '<input name="insurance_amount" size="10" value="'.$object->insurance_amount.'"></td></tr>';
print '</td></tr>'; print '</td></tr>';
@ -488,8 +491,7 @@ if ($id > 0)
// 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') {
{
print $form->selectDate($object->datestart, 'start', 0, 0, 0, 'update', 1, 0); print $form->selectDate($object->datestart, 'start', 0, 0, 0, 'update', 1, 0);
} else { } else {
print dol_print_date($object->datestart, "day"); print dol_print_date($object->datestart, "day");
@ -499,8 +501,7 @@ if ($id > 0)
// Date end // Date end
print '<tr><td>'.$langs->trans("DateEnd")."</td>"; print '<tr><td>'.$langs->trans("DateEnd")."</td>";
print "<td>"; print "<td>";
if ($action == 'edit') if ($action == 'edit') {
{
print $form->selectDate($object->dateend, 'end', 0, 0, 0, 'update', 1, 0); print $form->selectDate($object->dateend, 'end', 0, 0, 0, 'update', 1, 0);
} else { } else {
print dol_print_date($object->dateend, "day"); print dol_print_date($object->dateend, "day");
@ -510,8 +511,7 @@ if ($id > 0)
// Nbterms // Nbterms
print '<tr><td>'.$langs->trans("Nbterms").'</td>'; print '<tr><td>'.$langs->trans("Nbterms").'</td>';
print '<td>'; print '<td>';
if ($action == 'edit') if ($action == 'edit') {
{
print '<input name="nbterm" size="4" value="'.$object->nbterm.'">'; print '<input name="nbterm" size="4" value="'.$object->nbterm.'">';
} else { } else {
print $object->nbterm; print $object->nbterm;
@ -521,8 +521,7 @@ if ($id > 0)
// Rate // Rate
print '<tr><td>'.$langs->trans("Rate").'</td>'; print '<tr><td>'.$langs->trans("Rate").'</td>';
print '<td>'; print '<td>';
if ($action == 'edit') if ($action == 'edit') {
{
print '<input name="rate" size="4" value="'.$object->rate.'">%'; print '<input name="rate" size="4" value="'.$object->rate.'">%';
} else { } else {
print price($object->rate).'%'; print price($object->rate).'%';
@ -531,14 +530,12 @@ if ($id > 0)
// Accountancy account capital // Accountancy account capital
print '<tr>'; print '<tr>';
if ($action == 'edit') if ($action == 'edit') {
{
print '<td class="nowrap fieldrequired">'; print '<td class="nowrap fieldrequired">';
print $langs->trans("LoanAccountancyCapitalCode"); print $langs->trans("LoanAccountancyCapitalCode");
print '</td><td>'; print '</td><td>';
if (!empty($conf->accounting->enabled)) if (!empty($conf->accounting->enabled)) {
{
print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 1, 1); print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 1, 1);
} else { } else {
print '<input name="accountancy_account_capital" size="16" value="'.$object->account_capital.'">'; print '<input name="accountancy_account_capital" size="16" value="'.$object->account_capital.'">';
@ -549,8 +546,7 @@ if ($id > 0)
print $langs->trans("LoanAccountancyCapitalCode"); print $langs->trans("LoanAccountancyCapitalCode");
print '</td><td>'; print '</td><td>';
if (!empty($conf->accounting->enabled)) if (!empty($conf->accounting->enabled)) {
{
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch('', $object->account_capital, 1); $accountingaccount->fetch('', $object->account_capital, 1);
@ -565,14 +561,12 @@ if ($id > 0)
// Accountancy account insurance // Accountancy account insurance
print '<tr>'; print '<tr>';
if ($action == 'edit') if ($action == 'edit') {
{
print '<td class="nowrap fieldrequired">'; print '<td class="nowrap fieldrequired">';
print $langs->trans("LoanAccountancyInsuranceCode"); print $langs->trans("LoanAccountancyInsuranceCode");
print '</td><td>'; print '</td><td>';
if (!empty($conf->accounting->enabled)) if (!empty($conf->accounting->enabled)) {
{
print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 1, 1); print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 1, 1);
} else { } else {
print '<input name="accountancy_account_insurance" size="16" value="'.$object->account_insurance.'">'; print '<input name="accountancy_account_insurance" size="16" value="'.$object->account_insurance.'">';
@ -583,8 +577,7 @@ if ($id > 0)
print $langs->trans("LoanAccountancyInsuranceCode"); print $langs->trans("LoanAccountancyInsuranceCode");
print '</td><td>'; print '</td><td>';
if (!empty($conf->accounting->enabled)) if (!empty($conf->accounting->enabled)) {
{
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch('', $object->account_insurance, 1); $accountingaccount->fetch('', $object->account_insurance, 1);
@ -599,14 +592,12 @@ if ($id > 0)
// Accountancy account interest // Accountancy account interest
print '<tr>'; print '<tr>';
if ($action == 'edit') if ($action == 'edit') {
{
print '<td class="nowrap fieldrequired">'; print '<td class="nowrap fieldrequired">';
print $langs->trans("LoanAccountancyInterestCode"); print $langs->trans("LoanAccountancyInterestCode");
print '</td><td>'; print '</td><td>';
if (!empty($conf->accounting->enabled)) if (!empty($conf->accounting->enabled)) {
{
print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 1, 1); print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 1, 1);
} else { } else {
print '<input name="accountancy_account_interest" size="16" value="'.$object->account_interest.'">'; print '<input name="accountancy_account_interest" size="16" value="'.$object->account_interest.'">';
@ -617,8 +608,7 @@ if ($id > 0)
print $langs->trans("LoanAccountancyInterestCode"); print $langs->trans("LoanAccountancyInterestCode");
print '</td><td>'; print '</td><td>';
if (!empty($conf->accounting->enabled)) if (!empty($conf->accounting->enabled)) {
{
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch('', $object->account_interest, 1); $accountingaccount->fetch('', $object->account_interest, 1);
@ -653,8 +643,7 @@ if ($id > 0)
//print $sql; //print $sql;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
$total_insurance = 0; $total_insurance = 0;
@ -672,8 +661,7 @@ if ($id > 0)
print '<td class="right">'.$langs->trans("LoanCapital").'</td>'; print '<td class="right">'.$langs->trans("LoanCapital").'</td>';
print '</tr>'; print '</tr>';
while ($i < $num) while ($i < $num) {
{
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
print '<tr class="oddeven">'; print '<tr class="oddeven">';
@ -690,8 +678,7 @@ if ($id > 0)
$totalpaid = $total_capital; $totalpaid = $total_capital;
if ($object->paid == 0 || $object->paid == 2) if ($object->paid == 0 || $object->paid == 2) {
{
print '<tr><td colspan="5" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="nowrap right">'.price($totalpaid, 0, $langs, 0, -1, -1, $conf->currency).'</td></tr>'; print '<tr><td colspan="5" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="nowrap right">'.price($totalpaid, 0, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
print '<tr><td colspan="5" class="right">'.$langs->trans("AmountExpected").' :</td><td class="nowrap right">'.price($object->capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>'; print '<tr><td colspan="5" class="right">'.$langs->trans("AmountExpected").' :</td><td class="nowrap right">'.price($object->capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
@ -718,8 +705,7 @@ if ($id > 0)
print dol_get_fiche_end(); print dol_get_fiche_end();
if ($action == 'edit') if ($action == 'edit') {
{
print '<div class="center">'; print '<div class="center">';
print '<input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">'; print '<input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
@ -732,34 +718,28 @@ if ($id > 0)
/* /*
* 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 (($object->paid == 0 || $object->paid == 2) && $user->rights->loan->write) if (($object->paid == 0 || $object->paid == 2) && $user->rights->loan->write) {
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>';
} }
// Emit payment // Emit payment
if (($object->paid == 0 || $object->paid == 2) && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write) if (($object->paid == 0 || $object->paid == 2) && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write) {
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&amp;action=create">'.$langs->trans("DoPayment").'</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&amp;action=create">'.$langs->trans("DoPayment").'</a></div>';
} }
// Classify 'paid' // Classify 'paid'
if (($object->paid == 0 || $object->paid == 2) && round($staytopay) <= 0 && $user->rights->loan->write) if (($object->paid == 0 || $object->paid == 2) && round($staytopay) <= 0 && $user->rights->loan->write) {
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=paid&amp;token='.newToken().'">'.$langs->trans("ClassifyPaid").'</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=paid&amp;token='.newToken().'">'.$langs->trans("ClassifyPaid").'</a></div>';
} }
// Delete // Delete
if (($object->paid == 0 || $object->paid == 2) && $user->rights->loan->delete) if (($object->paid == 0 || $object->paid == 2) && $user->rights->loan->delete) {
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans("Delete").'</a></div>'; print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
} }

View File

@ -135,10 +135,8 @@ class Loan extends CommonObject
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;
@ -188,36 +186,52 @@ class Loan extends CommonObject
// clean parameters // clean parameters
$newcapital = price2num($this->capital, 'MT'); $newcapital = price2num($this->capital, 'MT');
if (empty($this->insurance_amount)) $this->insurance_amount = 0; if (empty($this->insurance_amount)) {
$this->insurance_amount = 0;
}
$newinsuranceamount = price2num($this->insurance_amount, 'MT'); $newinsuranceamount = price2num($this->insurance_amount, 'MT');
if (isset($this->note_private)) $this->note_private = trim($this->note_private); if (isset($this->note_private)) {
if (isset($this->note_public)) $this->note_public = trim($this->note_public); $this->note_private = trim($this->note_private);
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->note_public)) {
if (isset($this->account_interest)) $this->account_interest = trim($this->account_interest); $this->note_public = trim($this->note_public);
if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; }
if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; if (isset($this->account_capital)) {
if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; $this->account_capital = trim($this->account_capital);
if (isset($this->fk_project)) $this->fk_project = (int) $this->fk_project; }
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 = (int) $this->fk_bank;
}
if (isset($this->fk_user_creat)) {
$this->fk_user_creat = (int) $this->fk_user_creat;
}
if (isset($this->fk_user_modif)) {
$this->fk_user_modif = (int) $this->fk_user_modif;
}
if (isset($this->fk_project)) {
$this->fk_project = (int) $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"; $this->error = "ErrorBadParameter";
return -2; return -2;
} }
if (($conf->accounting->enabled) && empty($this->account_capital)) if (($conf->accounting->enabled) && empty($this->account_capital)) {
{
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyCapitalCode")); $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyCapitalCode"));
return -2; return -2;
} }
if (($conf->accounting->enabled) && empty($this->account_insurance)) if (($conf->accounting->enabled) && empty($this->account_insurance)) {
{
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInsuranceCode")); $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInsuranceCode"));
return -2; return -2;
} }
if (($conf->accounting->enabled) && empty($this->account_interest)) if (($conf->accounting->enabled) && empty($this->account_interest)) {
{
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInterestCode")); $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInterestCode"));
return -2; return -2;
} }
@ -248,8 +262,7 @@ class Loan extends CommonObject
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);
@ -281,47 +294,39 @@ class Loan extends CommonObject
$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 {
@ -341,8 +346,7 @@ class Loan extends CommonObject
{ {
$this->db->begin(); $this->db->begin();
if (!is_numeric($this->nbterm)) if (!is_numeric($this->nbterm)) {
{
$this->error = 'BadValueForParameterForNbTerm'; $this->error = 'BadValueForParameterForNbTerm';
return -1; return -1;
} }
@ -364,8 +368,7 @@ class Loan extends CommonObject
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 {
@ -512,22 +515,29 @@ class Loan extends CommonObject
$langs->loadLangs(array("customers", "bills")); $langs->loadLangs(array("customers", "bills"));
unset($this->labelStatus); // Force to reset the array of status label, because label can change depending on parameters unset($this->labelStatus); // Force to reset the array of status label, because label can change depending on parameters
if (empty($this->labelStatus) || empty($this->labelStatusShort)) if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
{
global $langs; global $langs;
$this->labelStatus[self::STATUS_UNPAID] = $langs->trans('Unpaid'); $this->labelStatus[self::STATUS_UNPAID] = $langs->trans('Unpaid');
$this->labelStatus[self::STATUS_PAID] = $langs->trans('Paid'); $this->labelStatus[self::STATUS_PAID] = $langs->trans('Paid');
$this->labelStatus[self::STATUS_STARTED] = $langs->trans("BillStatusStarted"); $this->labelStatus[self::STATUS_STARTED] = $langs->trans("BillStatusStarted");
if ($status == 0 && $alreadypaid > 0) $this->labelStatus[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted"); if ($status == 0 && $alreadypaid > 0) {
$this->labelStatus[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted");
}
$this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans('Unpaid'); $this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans('Unpaid');
$this->labelStatusShort[self::STATUS_PAID] = $langs->trans('Enabled'); $this->labelStatusShort[self::STATUS_PAID] = $langs->trans('Enabled');
$this->labelStatusShort[self::STATUS_STARTED] = $langs->trans("BillStatusStarted"); $this->labelStatusShort[self::STATUS_STARTED] = $langs->trans("BillStatusStarted");
if ($status == 0 && $alreadypaid > 0) $this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted"); if ($status == 0 && $alreadypaid > 0) {
$this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted");
}
} }
$statusType = 'status1'; $statusType = 'status1';
if (($status == 0 && $alreadypaid > 0) || $status == self::STATUS_STARTED) $statusType = 'status3'; if (($status == 0 && $alreadypaid > 0) || $status == self::STATUS_STARTED) {
if ($status == 1) $statusType = 'status6'; $statusType = 'status3';
}
if ($status == 1) {
$statusType = 'status6';
}
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
} }
@ -560,33 +570,40 @@ class Loan extends CommonObject
$url = DOL_URL_ROOT.'/loan/card.php?id='.$this->id; $url = DOL_URL_ROOT.'/loan/card.php?id='.$this->id;
if ($option != 'nolink') if ($option != 'nolink') {
{
// Add param to save lastsearch_values or not // Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; $add_save_lastsearch_values = 1;
}
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
} }
$linkclose = ''; $linkclose = '';
if (empty($notooltip)) if (empty($notooltip)) {
{ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
$label = $langs->trans("ShowMyObject"); $label = $langs->trans("ShowMyObject");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
} }
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
} else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); } else {
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
$linkstart = '<a href="'.$url.'"'; $linkstart = '<a href="'.$url.'"';
$linkstart .= $linkclose.'>'; $linkstart .= $linkclose.'>';
$linkend = '</a>'; $linkend = '</a>';
$result .= $linkstart; $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) {
if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref); $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; $result .= $linkend;
return $result; return $result;
@ -638,12 +655,13 @@ class Loan extends CommonObject
dol_syslog(get_class($this)."::getSumPayment", LOG_DEBUG); dol_syslog(get_class($this)."::getSumPayment", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{
$amount = 0; $amount = 0;
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($obj) $amount = $obj->amount ? $obj->amount : 0; if ($obj) {
$amount = $obj->amount ? $obj->amount : 0;
}
$this->db->free($resql); $this->db->free($resql);
return $amount; return $amount;
@ -668,26 +686,24 @@ class Loan extends CommonObject
dol_syslog(get_class($this).'::info', LOG_DEBUG); dol_syslog(get_class($this).'::info', LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{ if ($this->db->num_rows($result)) {
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$this->id = $obj->rowid; $this->id = $obj->rowid;
if ($obj->fk_user_author) if ($obj->fk_user_author) {
{
$cuser = new User($this->db); $cuser = new User($this->db);
$cuser->fetch($obj->fk_user_author); $cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser; $this->user_creation = $cuser;
} }
if ($obj->fk_user_modif) if ($obj->fk_user_modif) {
{
$muser = new User($this->db); $muser = new User($this->db);
$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);

View File

@ -129,21 +129,36 @@ class LoanSchedule extends CommonObject
$now = dol_now(); $now = dol_now();
// Validate parameters // Validate parameters
if (!$this->datep) if (!$this->datep) {
{
$this->error = 'ErrorBadValueForParameter'; $this->error = 'ErrorBadValueForParameter';
return -1; return -1;
} }
// Clean parameters // Clean parameters
if (isset($this->fk_loan)) $this->fk_loan = (int) $this->fk_loan; if (isset($this->fk_loan)) {
if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital ? $this->amount_capital : 0); $this->fk_loan = (int) $this->fk_loan;
if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance ? $this->amount_insurance : 0); }
if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest ? $this->amount_interest : 0); if (isset($this->amount_capital)) {
if (isset($this->fk_typepayment)) $this->fk_typepayment = (int) $this->fk_typepayment; $this->amount_capital = trim($this->amount_capital ? $this->amount_capital : 0);
if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; }
if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; if (isset($this->amount_insurance)) {
if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; $this->amount_insurance = trim($this->amount_insurance ? $this->amount_insurance : 0);
}
if (isset($this->amount_interest)) {
$this->amount_interest = trim($this->amount_interest ? $this->amount_interest : 0);
}
if (isset($this->fk_typepayment)) {
$this->fk_typepayment = (int) $this->fk_typepayment;
}
if (isset($this->fk_bank)) {
$this->fk_bank = (int) $this->fk_bank;
}
if (isset($this->fk_user_creat)) {
$this->fk_user_creat = (int) $this->fk_user_creat;
}
if (isset($this->fk_user_modif)) {
$this->fk_user_modif = (int) $this->fk_user_modif;
}
$totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest; $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest;
$totalamount = price2num($totalamount); $totalamount = price2num($totalamount);
@ -157,8 +172,7 @@ class LoanSchedule extends CommonObject
$this->db->begin(); $this->db->begin();
if ($totalamount != 0) if ($totalamount != 0) {
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,"; $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,";
$sql .= " fk_typepayment, fk_user_creat, fk_bank)"; $sql .= " fk_typepayment, fk_user_creat, fk_bank)";
$sql .= " VALUES (".$this->fk_loan.", '".$this->db->idate($now)."',"; $sql .= " VALUES (".$this->fk_loan.", '".$this->db->idate($now)."',";
@ -172,8 +186,7 @@ class LoanSchedule extends CommonObject
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."payment_loan"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_loan");
} else { } else {
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
@ -181,8 +194,7 @@ class LoanSchedule extends CommonObject
} }
} }
if ($totalamount != 0 && !$error) if ($totalamount != 0 && !$error) {
{
$this->amount_capital = $totalamount; $this->amount_capital = $totalamount;
$this->db->commit(); $this->db->commit();
return $this->id; return $this->id;
@ -280,14 +292,30 @@ class LoanSchedule extends CommonObject
$error = 0; $error = 0;
// Clean parameters // Clean parameters
if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital); if (isset($this->amount_capital)) {
if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance); $this->amount_capital = trim($this->amount_capital);
if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest); }
if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); if (isset($this->amount_insurance)) {
if (isset($this->note_private)) $this->note_private = trim($this->note_private); $this->amount_insurance = trim($this->amount_insurance);
if (isset($this->note_public)) $this->note_public = trim($this->note_public); }
if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank); if (isset($this->amount_interest)) {
if (isset($this->fk_payment_loan)) $this->fk_payment_loan = (int) $this->fk_payment_loan; $this->amount_interest = trim($this->amount_interest);
}
if (isset($this->num_payment)) {
$this->num_payment = trim($this->num_payment);
}
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->fk_bank)) {
$this->fk_bank = trim($this->fk_bank);
}
if (isset($this->fk_payment_loan)) {
$this->fk_payment_loan = (int) $this->fk_payment_loan;
}
// Check parameters // Check parameters
// Put here code to add control on parameters values // Put here code to add control on parameters values
@ -317,11 +345,12 @@ class LoanSchedule extends CommonObject
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) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{
$this->db->rollback(); $this->db->rollback();
return -1 * $error; return -1 * $error;
} else { } else {
@ -351,14 +380,14 @@ class LoanSchedule extends CommonObject
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) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -423,10 +452,8 @@ class LoanSchedule extends CommonObject
dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG); dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{ while ($obj = $this->db->fetch_object($resql)) {
while ($obj = $this->db->fetch_object($resql))
{
$line = new LoanSchedule($this->db); $line = new LoanSchedule($this->db);
$line->id = $obj->rowid; $line->id = $obj->rowid;
$line->ref = $obj->rowid; $line->ref = $obj->rowid;
@ -537,14 +564,15 @@ class LoanSchedule extends CommonObject
$sql = "SELECT p.rowid"; $sql = "SELECT p.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p "; $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p ";
$sql .= " WHERE p.fk_loan = ".$loanid; $sql .= " WHERE p.fk_loan = ".$loanid;
if (!empty($datemax)) { $sql .= " AND p.datep > '".$this->db->idate($datemax)."'"; } if (!empty($datemax)) {
$sql .= " AND p.datep > '".$this->db->idate($datemax)."'";
}
$sql .= " AND p.datep <= '".$this->db->idate(dol_now())."'"; $sql .= " AND p.datep <= '".$this->db->idate(dol_now())."'";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
while ($obj = $this->db->fetch_object($resql)) while ($obj = $this->db->fetch_object($resql)) {
{
$result[] = $obj->rowid; $result[] = $obj->rowid;
} }
} }

View File

@ -126,36 +126,58 @@ class PaymentLoan extends CommonObject
$now = dol_now(); $now = dol_now();
// Validate parameters // Validate parameters
if (!$this->datep) if (!$this->datep) {
{
$this->error = 'ErrorBadValueForParameter'; $this->error = 'ErrorBadValueForParameter';
return -1; return -1;
} }
// Clean parameters // Clean parameters
if (isset($this->fk_loan)) $this->fk_loan = (int) $this->fk_loan; if (isset($this->fk_loan)) {
if (isset($this->amount_capital)) $this->amount_capital = price2num($this->amount_capital ? $this->amount_capital : 0); $this->fk_loan = (int) $this->fk_loan;
if (isset($this->amount_insurance)) $this->amount_insurance = price2num($this->amount_insurance ? $this->amount_insurance : 0); }
if (isset($this->amount_interest)) $this->amount_interest = price2num($this->amount_interest ? $this->amount_interest : 0); if (isset($this->amount_capital)) {
if (isset($this->fk_typepayment)) $this->fk_typepayment = (int) $this->fk_typepayment; $this->amount_capital = price2num($this->amount_capital ? $this->amount_capital : 0);
if (isset($this->num_payment)) $this->num_payment = (int) $this->num_payment; }
if (isset($this->note_private)) $this->note_private = trim($this->note_private); if (isset($this->amount_insurance)) {
if (isset($this->note_public)) $this->note_public = trim($this->note_public); $this->amount_insurance = price2num($this->amount_insurance ? $this->amount_insurance : 0);
if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; }
if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; if (isset($this->amount_interest)) {
if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; $this->amount_interest = price2num($this->amount_interest ? $this->amount_interest : 0);
}
if (isset($this->fk_typepayment)) {
$this->fk_typepayment = (int) $this->fk_typepayment;
}
if (isset($this->num_payment)) {
$this->num_payment = (int) $this->num_payment;
}
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->fk_bank)) {
$this->fk_bank = (int) $this->fk_bank;
}
if (isset($this->fk_user_creat)) {
$this->fk_user_creat = (int) $this->fk_user_creat;
}
if (isset($this->fk_user_modif)) {
$this->fk_user_modif = (int) $this->fk_user_modif;
}
$totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest; $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest;
$totalamount = price2num($totalamount); $totalamount = price2num($totalamount);
// Check parameters // Check parameters
if ($totalamount == 0) return -1; // Negative amounts are accepted for reject prelevement but not null if ($totalamount == 0) {
return -1; // Negative amounts are accepted for reject prelevement but not null
}
$this->db->begin(); $this->db->begin();
if ($totalamount != 0) if ($totalamount != 0) {
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_loan (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_loan (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,";
$sql .= " fk_typepayment, num_payment, note_private, note_public, fk_user_creat, fk_bank)"; $sql .= " fk_typepayment, num_payment, note_private, note_public, fk_user_creat, fk_bank)";
$sql .= " VALUES (".$this->chid.", '".$this->db->idate($now)."',"; $sql .= " VALUES (".$this->chid.", '".$this->db->idate($now)."',";
@ -168,8 +190,7 @@ class PaymentLoan extends CommonObject
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."payment_loan"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_loan");
} else { } else {
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
@ -177,8 +198,7 @@ class PaymentLoan extends CommonObject
} }
} }
if ($totalamount != 0 && !$error) if ($totalamount != 0 && !$error) {
{
$this->amount_capital = $totalamount; $this->amount_capital = $totalamount;
$this->db->commit(); $this->db->commit();
return $this->id; return $this->id;
@ -223,10 +243,8 @@ class PaymentLoan extends CommonObject
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;
@ -276,17 +294,39 @@ class PaymentLoan extends CommonObject
$error = 0; $error = 0;
// Clean parameters // Clean parameters
if (isset($this->fk_loan)) $this->fk_loan = (int) $this->fk_loan; if (isset($this->fk_loan)) {
if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital); $this->fk_loan = (int) $this->fk_loan;
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->amount_capital)) {
if (isset($this->fk_typepayment)) $this->fk_typepayment = (int) $this->fk_typepayment; $this->amount_capital = trim($this->amount_capital);
if (isset($this->num_payment)) $this->num_payment = (int) $this->num_payment; }
if (isset($this->note_private)) $this->note = trim($this->note_private); if (isset($this->amount_insurance)) {
if (isset($this->note_public)) $this->note = trim($this->note_public); $this->amount_insurance = trim($this->amount_insurance);
if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; }
if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; if (isset($this->amount_interest)) {
if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; $this->amount_interest = trim($this->amount_interest);
}
if (isset($this->fk_typepayment)) {
$this->fk_typepayment = (int) $this->fk_typepayment;
}
if (isset($this->num_payment)) {
$this->num_payment = (int) $this->num_payment;
}
if (isset($this->note_private)) {
$this->note = trim($this->note_private);
}
if (isset($this->note_public)) {
$this->note = trim($this->note_public);
}
if (isset($this->fk_bank)) {
$this->fk_bank = (int) $this->fk_bank;
}
if (isset($this->fk_user_creat)) {
$this->fk_user_creat = (int) $this->fk_user_creat;
}
if (isset($this->fk_user_modif)) {
$this->fk_user_modif = (int) $this->fk_user_modif;
}
// Check parameters // Check parameters
@ -314,13 +354,13 @@ class PaymentLoan extends CommonObject
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) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -347,35 +387,35 @@ class PaymentLoan extends CommonObject
$this->db->begin(); $this->db->begin();
if (!$error) if (!$error) {
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url";
$sql .= " WHERE type='payment_loan' AND url_id=".$this->id; $sql .= " WHERE type='payment_loan' AND url_id=".$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) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
} }
if (!$error) if (!$error) {
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan";
$sql .= " WHERE rowid=".$this->id; $sql .= " 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) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
} }
// Set loan unpaid if loan has no other payment // Set loan unpaid if loan has no other payment
if (!$error) if (!$error) {
{
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
$loan = new Loan($this->db); $loan = new Loan($this->db);
$loan->fetch($this->fk_loan); $loan->fetch($this->fk_loan);
$sum_payment = $loan->getSumPayment(); $sum_payment = $loan->getSumPayment();
if ($sum_payment == 0) if ($sum_payment == 0) {
{
dol_syslog(get_class($this)."::delete : set loan to unpaid", LOG_DEBUG); dol_syslog(get_class($this)."::delete : set loan to unpaid", LOG_DEBUG);
if ($loan->setUnpaid($user) < 1) { if ($loan->setUnpaid($user) < 1) {
$error++; $error++;
@ -401,10 +441,8 @@ class PaymentLoan extends CommonObject
//} //}
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -461,15 +499,16 @@ class PaymentLoan extends CommonObject
$error = 0; $error = 0;
$this->db->begin(); $this->db->begin();
if (!empty($conf->banque->enabled)) if (!empty($conf->banque->enabled)) {
{
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$acc = new Account($this->db); $acc = new Account($this->db);
$acc->fetch($accountid); $acc->fetch($accountid);
$total = $this->amount_capital; $total = $this->amount_capital;
if ($mode == 'payment_loan') $total = -$total; if ($mode == 'payment_loan') {
$total = -$total;
}
// Insert payment into llx_bank // Insert payment into llx_bank
$bank_line_id = $acc->addline( $bank_line_id = $acc->addline(
@ -486,23 +525,21 @@ class PaymentLoan extends CommonObject
// Update fk_bank into llx_paiement. // Update fk_bank into llx_paiement.
// We know the payment who generated the account write // We know the payment who generated the account write
if ($bank_line_id > 0) if ($bank_line_id > 0) {
{
$result = $this->update_fk_bank($bank_line_id); $result = $this->update_fk_bank($bank_line_id);
if ($result <= 0) if ($result <= 0) {
{
$error++; $error++;
dol_print_error($this->db); dol_print_error($this->db);
} }
// Add link 'payment_loan' in bank_url between payment and bank transaction // Add link 'payment_loan' in bank_url between payment and bank transaction
$url = ''; $url = '';
if ($mode == 'payment_loan') $url = DOL_URL_ROOT.'/loan/payment/card.php?id='; if ($mode == 'payment_loan') {
if ($url) $url = DOL_URL_ROOT.'/loan/payment/card.php?id=';
{ }
if ($url) {
$result = $acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $mode); $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $mode);
if ($result <= 0) if ($result <= 0) {
{
$error++; $error++;
dol_print_error($this->db); dol_print_error($this->db);
} }
@ -510,10 +547,11 @@ class PaymentLoan extends CommonObject
// Add link 'loan' in bank_url between invoice and bank transaction (for each invoice concerned by payment) // Add link 'loan' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
if ($mode == 'payment_loan') if ($mode == 'payment_loan') {
{
$result = $acc->add_url_line($bank_line_id, $fk_loan, DOL_URL_ROOT.'/loan/card.php?id=', ($this->label ? $this->label : ''), 'loan'); $result = $acc->add_url_line($bank_line_id, $fk_loan, DOL_URL_ROOT.'/loan/card.php?id=', ($this->label ? $this->label : ''), 'loan');
if ($result <= 0) dol_print_error($this->db); if ($result <= 0) {
dol_print_error($this->db);
}
} }
} else { } else {
$this->error = $acc->error; $this->error = $acc->error;
@ -523,28 +561,23 @@ class PaymentLoan extends CommonObject
// Set loan payment started if no set // Set loan payment started if no set
if (!$error) if (!$error) {
{
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
$loan = new Loan($this->db); $loan = new Loan($this->db);
$loan->fetch($fk_loan); $loan->fetch($fk_loan);
if ($loan->paid == $loan::STATUS_UNPAID) if ($loan->paid == $loan::STATUS_UNPAID) {
{
dol_syslog(get_class($this)."::addPaymentToBank : set loan payment to started", LOG_DEBUG); dol_syslog(get_class($this)."::addPaymentToBank : set loan payment to started", LOG_DEBUG);
if ($loan->setStarted($user) < 1) if ($loan->setStarted($user) < 1) {
{
$error++; $error++;
dol_print_error($this->db); dol_print_error($this->db);
} }
} }
} }
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;
} }
@ -565,8 +598,7 @@ class PaymentLoan extends CommonObject
dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG); dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
$this->fk_bank = $id_bank; $this->fk_bank = $id_bank;
return 1; return 1;
} else { } else {
@ -589,27 +621,39 @@ class PaymentLoan extends CommonObject
{ {
global $langs, $conf; global $langs, $conf;
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips if (!empty($conf->dol_no_mouse_hover)) {
$notooltip = 1; // Force disable tooltips
}
$result = ''; $result = '';
$label = '<u>'.$langs->trans("Loan").'</u>'; $label = '<u>'.$langs->trans("Loan").'</u>';
if (!empty($this->id)) { if (!empty($this->id)) {
$label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->id; $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->id;
} }
if ($moretitle) $label .= ' - '.$moretitle; if ($moretitle) {
$label .= ' - '.$moretitle;
}
$url = DOL_URL_ROOT.'/loan/payment/card.php?id='.$this->id; $url = DOL_URL_ROOT.'/loan/payment/card.php?id='.$this->id;
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; $add_save_lastsearch_values = 1;
}
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
$linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend = '</a>'; $linkend = '</a>';
$result .= $linkstart; $result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); if ($withpicto) {
if ($withpicto != 2) $result .= $this->ref; $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
}
if ($withpicto != 2) {
$result .= $this->ref;
}
$result .= $linkend; $result .= $linkend;
return $result; return $result;

View File

@ -40,7 +40,9 @@ $action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha'); $confirm = GETPOST('confirm', 'alpha');
// Security check // Security check
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'loan', $id, '', ''); $result = restrictedArea($user, 'loan', $id, '', '');
// Get parameters // Get parameters
@ -54,11 +56,17 @@ if (empty($page) || $page == -1) {
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC"; if (!$sortorder) {
if (!$sortfield) $sortfield = "name"; $sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "name";
}
$object = new Loan($db); $object = new Loan($db);
if ($id > 0) $object->fetch($id); if ($id > 0) {
$object->fetch($id);
}
$upload_dir = $conf->loan->dir_output.'/'.dol_sanitizeFileName($object->ref); $upload_dir = $conf->loan->dir_output.'/'.dol_sanitizeFileName($object->ref);
$modulepart = 'loan'; $modulepart = 'loan';
@ -81,8 +89,7 @@ $title = $langs->trans("Loan").' - '.$langs->trans("Documents");
$help_url = 'EN:Module_Loan|FR:Module_Emprunt'; $help_url = 'EN:Module_Loan|FR:Module_Emprunt';
llxHeader("", $title, $help_url); llxHeader("", $title, $help_url);
if ($object->id) if ($object->id) {
{
$totalpaid = $object->getSumPayment(); $totalpaid = $object->getSumPayment();
$head = loan_prepare_head($object); $head = loan_prepare_head($object);
@ -138,8 +145,7 @@ if ($object->id)
// Build file list // Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$totalsize = 0; $totalsize = 0;
foreach ($filearray as $key => $file) foreach ($filearray as $key => $file) {
{
$totalsize += $file['size']; $totalsize += $file['size'];
} }

View File

@ -38,7 +38,9 @@ $action = GETPOST('action', 'aZ09');
// Security check // Security check
$socid = GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'loan', $id, '', ''); $result = restrictedArea($user, 'loan', $id, '', '');

View File

@ -32,14 +32,18 @@ $langs->loadLangs(array("loan", "compta", "banks", "bills"));
// Security check // Security check
$socid = GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'loan', '', '', ''); $result = restrictedArea($user, 'loan', '', '', '');
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma'); $sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
$page = 0;
} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
@ -48,8 +52,12 @@ $pagenext = $page + 1;
$loan_static = new Loan($db); $loan_static = new Loan($db);
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
if (!$sortfield) $sortfield = "l.rowid"; if (!$sortfield) {
if (!$sortorder) $sortorder = "DESC"; $sortfield = "l.rowid";
}
if (!$sortorder) {
$sortorder = "DESC";
}
$search_ref = GETPOST('search_ref', 'int'); $search_ref = GETPOST('search_ref', 'int');
$search_label = GETPOST('search_label', 'alpha'); $search_label = GETPOST('search_label', 'alpha');
@ -63,18 +71,22 @@ $optioncss = GETPOST('optioncss', 'alpha');
* Actions * Actions
*/ */
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } if (GETPOST('cancel', 'alpha')) {
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } $action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) if (empty($reshook)) {
{
// Purge search criteria // Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
{
$search_ref = ""; $search_ref = "";
$search_label = ""; $search_label = "";
$search_amount = ""; $search_amount = "";
@ -97,35 +109,39 @@ $sql .= " SUM(pl.amount_capital) as alreadypaid";
$sql .= " FROM ".MAIN_DB_PREFIX."loan as l LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl"; $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 .= " ON l.rowid = pl.fk_loan";
$sql .= " WHERE l.entity = ".$conf->entity; $sql .= " WHERE l.entity = ".$conf->entity;
if ($search_amount) $sql .= natural_search("l.capital", $search_amount, 1); if ($search_amount) {
if ($search_ref) $sql .= " AND l.rowid = ".$db->escape($search_ref); $sql .= natural_search("l.capital", $search_amount, 1);
if ($search_label) $sql .= natural_search("l.label", $search_label); }
if ($search_ref) {
$sql .= " AND l.rowid = ".$db->escape($search_ref);
}
if ($search_label) {
$sql .= natural_search("l.label", $search_label);
}
$sql .= " GROUP BY l.rowid, l.label, l.capital, l.paid, l.datestart, l.dateend"; $sql .= " GROUP BY l.rowid, l.label, l.capital, l.paid, l.datestart, l.dateend";
$sql .= $db->order($sortfield, $sortorder); $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records // Count total nb of records
$nbtotalofrecords = ''; $nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
{
$resql = $db->query($sql); $resql = $db->query($sql);
$nbtotalofrecords = $db->num_rows($resql); $nbtotalofrecords = $db->num_rows($resql);
if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
{
$page = 0; $page = 0;
$offset = 0; $offset = 0;
} }
} }
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
{
$num = $nbtotalofrecords; $num = $nbtotalofrecords;
} else { } else {
if ($limit) $sql .= $db->plimit($limit + 1, $offset); if ($limit) {
$sql .= $db->plimit($limit + 1, $offset);
}
$resql = $db->query($sql); $resql = $db->query($sql);
if (!$resql) if (!$resql) {
{
dol_print_error($db); dol_print_error($db);
exit; exit;
} }
@ -138,24 +154,39 @@ if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit
llxHeader('', $title, $help_url); llxHeader('', $title, $help_url);
if ($resql) if ($resql) {
{
$i = 0; $i = 0;
$param = ''; $param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); $param .= '&contextpage='.urlencode($contextpage);
if ($search_ref) $param .= "&search_ref=".urlencode($search_ref); }
if ($search_label) $param .= "&search_label=".urlencode($search_label); if ($limit > 0 && $limit != $conf->liste_limit) {
if ($search_amount) $param .= "&search_amount=".urlencode($search_amount); $param .= '&limit='.urlencode($limit);
if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); }
if ($search_ref) {
$param .= "&search_ref=".urlencode($search_ref);
}
if ($search_label) {
$param .= "&search_label=".urlencode($search_label);
}
if ($search_amount) {
$param .= "&search_amount=".urlencode($search_amount);
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
$url = DOL_URL_ROOT.'/loan/card.php?action=create'; $url = DOL_URL_ROOT.'/loan/card.php?action=create';
if (!empty($socid)) $url .= '&socid='.$socid; if (!empty($socid)) {
$url .= '&socid='.$socid;
}
$newcardbutton = dolGetButtonTitle($langs->trans('NewLoan'), '', 'fa fa-plus-circle', $url, '', $user->rights->loan->write); $newcardbutton = dolGetButtonTitle($langs->trans('NewLoan'), '', 'fa fa-plus-circle', $url, '', $user->rights->loan->write);
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n"; print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">'; print '<input type="hidden" name="action" value="list">';
@ -201,10 +232,11 @@ if ($resql)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
$i = 0; $i = 0;
$totalarray = array(); $totalarray = array();
while ($i < ($limit ? min($num, $limit) : $num)) while ($i < ($limit ? min($num, $limit) : $num)) {
{
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if (empty($obj)) break; // Should not happen if (empty($obj)) {
break; // Should not happen
}
$loan_static->id = $obj->rowid; $loan_static->id = $obj->rowid;
$loan_static->ref = $obj->rowid; $loan_static->ref = $obj->rowid;
@ -240,8 +272,7 @@ if ($resql)
} }
// If no record found // If no record found
if ($num == 0) if ($num == 0) {
{
$colspan = 7; $colspan = 7;
//foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } //foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>'; print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';

View File

@ -44,7 +44,9 @@ $id = GETPOST('id', 'int');
$result = restrictedArea($user, 'loan', $id, '&loan'); $result = restrictedArea($user, 'loan', $id, '&loan');
$object = new Loan($db); $object = new Loan($db);
if ($id > 0) $object->fetch($id); if ($id > 0) {
$object->fetch($id);
}
$permissionnote = $user->rights->loan->write; // Used by the include of actions_setnotes.inc.php $permissionnote = $user->rights->loan->write; // Used by the include of actions_setnotes.inc.php
@ -66,11 +68,10 @@ $title = $langs->trans("Loan").' - '.$langs->trans("Notes");
$help_url = 'EN:Module_Loan|FR:Module_Emprunt'; $help_url = 'EN:Module_Loan|FR:Module_Emprunt';
llxHeader("", $title, $help_url); llxHeader("", $title, $help_url);
if ($id > 0) if ($id > 0) {
{
/* /*
* Affichage onglets * Affichage onglets
*/ */
$totalpaid = $object->getSumPayment(); $totalpaid = $object->getSumPayment();
$head = loan_prepare_head($object); $head = loan_prepare_head($object);

View File

@ -24,7 +24,9 @@
require '../../main.inc.php'; require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.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.'/loan/class/paymentloan.class.php';
if (!empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; if (!empty($conf->banque->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("bills", "banks", "companies", "loan")); $langs->loadLangs(array("bills", "banks", "companies", "loan"));
@ -33,15 +35,18 @@ $langs->loadLangs(array("bills", "banks", "companies", "loan"));
$id = GETPOST("id", 'int'); $id = GETPOST("id", 'int');
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm'); $confirm = GETPOST('confirm');
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
// TODO ajouter regle pour restreindre acces paiement // TODO ajouter regle pour restreindre acces paiement
//$result = restrictedArea($user, 'facture', $id,''); //$result = restrictedArea($user, 'facture', $id,'');
$payment = new PaymentLoan($db); $payment = new PaymentLoan($db);
if ($id > 0) if ($id > 0) {
{
$result = $payment->fetch($id); $result = $payment->fetch($id);
if (!$result) dol_print_error($db, 'Failed to get payment id '.$id); if (!$result) {
dol_print_error($db, 'Failed to get payment id '.$id);
}
} }
@ -50,8 +55,7 @@ if ($id > 0)
*/ */
// Delete payment // Delete payment
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->delete) if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->delete) {
{
$db->begin(); $db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".$payment->fk_bank; $sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".$payment->fk_bank;
@ -60,8 +64,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->del
$fk_loan = $payment->fk_loan; $fk_loan = $payment->fk_loan;
$result = $payment->delete($user); $result = $payment->delete($user);
if ($result > 0) if ($result > 0) {
{
$db->commit(); $db->commit();
header("Location: ".DOL_URL_ROOT."/loan/card.php?id=".$fk_loan); header("Location: ".DOL_URL_ROOT."/loan/card.php?id=".$fk_loan);
exit; exit;
@ -93,8 +96,7 @@ print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'p
/* /*
* Confirm deletion of the payment * Confirm deletion of the payment
*/ */
if ($action == 'delete') if ($action == 'delete') {
{
print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2); print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
} }
@ -127,10 +129,8 @@ print '<tr><td>'.$langs->trans('NotePrivate').'</td><td>'.nl2br($payment->note_p
print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($payment->note_public).'</td></tr>'; print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($payment->note_public).'</td></tr>';
// Bank account // Bank account
if (!empty($conf->banque->enabled)) if (!empty($conf->banque->enabled)) {
{ if ($payment->bank_account) {
if ($payment->bank_account)
{
$bankline = new AccountLine($db); $bankline = new AccountLine($db);
$bankline->fetch($payment->bank_line); $bankline->fetch($payment->bank_line);
@ -161,8 +161,7 @@ $sql .= ' AND pl.rowid = '.$payment->id;
dol_syslog("loan/payment/card.php", LOG_DEBUG); dol_syslog("loan/payment/card.php", LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
@ -176,10 +175,8 @@ if ($resql)
print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>'; print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
print "</tr>\n"; print "</tr>\n";
if ($num > 0) if ($num > 0) {
{ while ($i < $num) {
while ($i < $num)
{
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
print '<tr class="oddeven">'; print '<tr class="oddeven">';
@ -199,8 +196,7 @@ if ($resql)
print '<td class="right">'.price($amount_payed).'</td>'; print '<td class="right">'.price($amount_payed).'</td>';
print "</tr>\n"; print "</tr>\n";
if ($objp->paid == 1) // If at least one invoice is paid, disable delete if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
{
$disable_delete = 1; $disable_delete = 1;
} }
$total = $total + $objp->amount_capital; $total = $total + $objp->amount_capital;
@ -224,10 +220,8 @@ print '</div>';
print '<div class="tabsAction">'; print '<div class="tabsAction">';
if (empty($action) && !empty($user->rights->loan->delete)) if (empty($action) && !empty($user->rights->loan->delete)) {
{ if (!$disable_delete) {
if (!$disable_delete)
{
print '<a class="butActionDelete" href="card.php?id='.$id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans('Delete').'</a>'; print '<a class="butActionDelete" href="card.php?id='.$id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans('Delete').'</a>';
} else { } else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>'; print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';

View File

@ -39,10 +39,14 @@ $datepaid = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'in
// Security check // Security check
$socid = 0; $socid = 0;
if ($user->socid > 0) if ($user->socid > 0) {
$socid = $user->socid; $socid = $user->socid;
elseif (GETPOSTISSET('socid')) $socid = GETPOST('socid', 'int'); } elseif (GETPOSTISSET('socid')) {
if (empty($user->rights->loan->write)) accessforbidden(); $socid = GETPOST('socid', 'int');
}
if (empty($user->rights->loan->write)) {
accessforbidden();
}
$loan = new Loan($db); $loan = new Loan($db);
$loan->fetch($chid); $loan->fetch($chid);
@ -51,35 +55,31 @@ $echance = 0;
$ls = new LoanSchedule($db); $ls = new LoanSchedule($db);
// grab all loanschedule // grab all loanschedule
$res = $ls->fetchAll($chid); $res = $ls->fetchAll($chid);
if ($res > 0) if ($res > 0) {
{ foreach ($ls->lines as $l) {
foreach ($ls->lines as $l)
{
$echance++; // Count term pos $echance++; // Count term pos
// last unpaid term // last unpaid term
if (empty($l->fk_bank)) if (empty($l->fk_bank)) {
{
$line_id = $l->id; $line_id = $l->id;
break; break;
} } elseif ($line_id == $l->id) {
// If line_id provided, only count temp pos // If line_id provided, only count temp pos
elseif ($line_id == $l->id)
{
break; break;
} }
} }
} }
// Set current line with last unpaid line (only if shedule is used) // Set current line with last unpaid line (only if shedule is used)
if (!empty($line_id)) if (!empty($line_id)) {
{
$line = new LoanSchedule($db); $line = new LoanSchedule($db);
$res = $line->fetch($line_id); $res = $line->fetch($line_id);
if ($res > 0) { if ($res > 0) {
$amount_capital = price($line->amount_capital); $amount_capital = price($line->amount_capital);
$amount_insurance = price($line->amount_insurance); $amount_insurance = price($line->amount_insurance);
$amount_interest = price($line->amount_interest); $amount_interest = price($line->amount_interest);
if (empty($datepaid)) $ts_temppaid = $line->datep; if (empty($datepaid)) {
$ts_temppaid = $line->datep;
}
} }
} }
@ -88,66 +88,59 @@ if (!empty($line_id))
* Actions * Actions
*/ */
if ($action == 'add_payment') if ($action == 'add_payment') {
{
$error = 0; $error = 0;
if ($cancel) if ($cancel) {
{
$loc = DOL_URL_ROOT.'/loan/card.php?id='.$chid; $loc = DOL_URL_ROOT.'/loan/card.php?id='.$chid;
header("Location: ".$loc); header("Location: ".$loc);
exit; exit;
} }
if (!GETPOST('paymenttype', 'int') > 0) if (!GETPOST('paymenttype', 'int') > 0) {
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors');
$error++; $error++;
} }
if ($datepaid == '') if ($datepaid == '') {
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
$error++; $error++;
} }
if (!empty($conf->banque->enabled) && !GETPOST('accountid', 'int') > 0) if (!empty($conf->banque->enabled) && !GETPOST('accountid', 'int') > 0) {
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors');
$error++; $error++;
} }
if (!$error) if (!$error) {
{
$paymentid = 0; $paymentid = 0;
$pay_amount_capital = price2num(GETPOST('amount_capital')); $pay_amount_capital = price2num(GETPOST('amount_capital'));
$pay_amount_insurance = price2num(GETPOST('amount_insurance')); $pay_amount_insurance = price2num(GETPOST('amount_insurance'));
// User can't set interest him self if schedule is set (else value in schedule can be incoherent) // User can't set interest him self if schedule is set (else value in schedule can be incoherent)
if (!empty($line)) $pay_amount_interest = $line->amount_interest; if (!empty($line)) {
else $pay_amount_interest = price2num(GETPOST('amount_interest')); $pay_amount_interest = $line->amount_interest;
} else {
$pay_amount_interest = price2num(GETPOST('amount_interest'));
}
$remaindertopay = price2num(GETPOST('remaindertopay')); $remaindertopay = price2num(GETPOST('remaindertopay'));
$amount = $pay_amount_capital + $pay_amount_insurance + $pay_amount_interest; $amount = $pay_amount_capital + $pay_amount_insurance + $pay_amount_interest;
// This term is allready paid // This term is allready paid
if (!empty($line) && !empty($line->fk_bank)) if (!empty($line) && !empty($line->fk_bank)) {
{
setEventMessages($langs->trans('TermPaidAllreadyPaid'), null, 'errors'); setEventMessages($langs->trans('TermPaidAllreadyPaid'), null, 'errors');
$error++; $error++;
} }
if (empty($remaindertopay)) if (empty($remaindertopay)) {
{
setEventMessages('Empty sumpaid', null, 'errors'); setEventMessages('Empty sumpaid', null, 'errors');
$error++; $error++;
} }
if ($amount == 0) if ($amount == 0) {
{
setEventMessages($langs->trans('ErrorNoPaymentDefined'), null, 'errors'); setEventMessages($langs->trans('ErrorNoPaymentDefined'), null, 'errors');
$error++; $error++;
} }
if (!$error) if (!$error) {
{
$db->begin(); $db->begin();
// Create a line of payments // Create a line of payments
@ -164,38 +157,30 @@ if ($action == 'add_payment')
$payment->note_private = GETPOST('note_private', 'restricthtml'); $payment->note_private = GETPOST('note_private', 'restricthtml');
$payment->note_public = GETPOST('note_public', 'restricthtml'); $payment->note_public = GETPOST('note_public', 'restricthtml');
if (!$error) if (!$error) {
{
$paymentid = $payment->create($user); $paymentid = $payment->create($user);
if ($paymentid < 0) if ($paymentid < 0) {
{
setEventMessages($payment->error, $payment->errors, 'errors'); setEventMessages($payment->error, $payment->errors, 'errors');
$error++; $error++;
} }
} }
if (!$error) if (!$error) {
{
$result = $payment->addPaymentToBank($user, $chid, 'payment_loan', '(LoanPayment)', $payment->fk_bank, '', ''); $result = $payment->addPaymentToBank($user, $chid, 'payment_loan', '(LoanPayment)', $payment->fk_bank, '', '');
if (!$result > 0) if (!$result > 0) {
{
setEventMessages($payment->error, $payment->errors, 'errors'); setEventMessages($payment->error, $payment->errors, 'errors');
$error++; $error++;
} }
} }
// Update loan schedule with payment value // Update loan schedule with payment value
if (!$error && !empty($line)) if (!$error && !empty($line)) {
{
// If payment values are modified, recalculate schedule // If payment values are modified, recalculate schedule
if (($line->amount_capital <> $pay_amount_capital) || ($line->amount_insurance <> $pay_amount_insurance) || ($line->amount_interest <> $pay_amount_interest)) if (($line->amount_capital <> $pay_amount_capital) || ($line->amount_insurance <> $pay_amount_insurance) || ($line->amount_interest <> $pay_amount_interest)) {
{
$arr_term = loanCalcMonthlyPayment(($pay_amount_capital + $pay_amount_interest), $remaindertopay, ($loan->rate / 100), $echance, $loan->nbterm); $arr_term = loanCalcMonthlyPayment(($pay_amount_capital + $pay_amount_interest), $remaindertopay, ($loan->rate / 100), $echance, $loan->nbterm);
foreach ($arr_term as $k=>$v) foreach ($arr_term as $k => $v) {
{
// Update fk_bank for current line // Update fk_bank for current line
if ($k == $echance) if ($k == $echance) {
{
$ls->lines[$k - 1]->fk_bank = $payment->fk_bank; $ls->lines[$k - 1]->fk_bank = $payment->fk_bank;
$ls->lines[$k - 1]->fk_payment_loan = $payment->id; $ls->lines[$k - 1]->fk_payment_loan = $payment->id;
} }
@ -204,29 +189,25 @@ if ($action == 'add_payment')
$ls->lines[$k - 1]->tms = dol_now(); $ls->lines[$k - 1]->tms = dol_now();
$ls->lines[$k - 1]->fk_user_modif = $user->id; $ls->lines[$k - 1]->fk_user_modif = $user->id;
$result = $ls->lines[$k - 1]->update($user, 0); $result = $ls->lines[$k - 1]->update($user, 0);
if ($result < 1) if ($result < 1) {
{
setEventMessages(null, $ls->errors, 'errors'); setEventMessages(null, $ls->errors, 'errors');
$error++; $error++;
break; break;
} }
} }
} } else // Only add fk_bank bank to schedule line (mark as paid)
else // Only add fk_bank bank to schedule line (mark as paid)
{ {
$line->fk_bank = $payment->fk_bank; $line->fk_bank = $payment->fk_bank;
$line->fk_payment_loan = $payment->id; $line->fk_payment_loan = $payment->id;
$result = $line->update($user, 0); $result = $line->update($user, 0);
if ($result < 1) if ($result < 1) {
{
setEventMessages(null, $line->errors, 'errors'); setEventMessages(null, $line->errors, 'errors');
$error++; $error++;
} }
} }
} }
if (!$error) if (!$error) {
{
$db->commit(); $db->commit();
$loc = DOL_URL_ROOT.'/loan/card.php?id='.$chid; $loc = DOL_URL_ROOT.'/loan/card.php?id='.$chid;
header('Location: '.$loc); header('Location: '.$loc);
@ -251,8 +232,7 @@ $form = new Form($db);
// Form to create loan's payment // Form to create loan's payment
if ($action == 'create') if ($action == 'create') {
{
$total = $loan->capital; $total = $loan->capital;
print load_fiche_titre($langs->trans("DoPayment")); print load_fiche_titre($langs->trans("DoPayment"));
@ -261,8 +241,7 @@ if ($action == 'create')
$sql .= " FROM ".MAIN_DB_PREFIX."payment_loan"; $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan";
$sql .= " WHERE fk_loan = ".$chid; $sql .= " WHERE fk_loan = ".$chid;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$sumpaid = $obj->total; $sumpaid = $obj->total;
$db->free(); $db->free();
@ -282,10 +261,10 @@ if ($action == 'create')
print '<table class="border centpercent">'; print '<table class="border centpercent">';
print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td colspan="2"><a href="'.DOL_URL_ROOT.'/loan/card.php?id='.$chid.'">'.$chid.'</a></td></tr>'; print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td colspan="2"><a href="'.DOL_URL_ROOT.'/loan/card.php?id='.$chid.'">'.$chid.'</a></td></tr>';
if ($echance > 0) if ($echance > 0)
{ {
print '<tr><td>'.$langs->trans("Term").'</td><td colspan="2"><a href="'.DOL_URL_ROOT.'/loan/schedule.php?loanid='.$chid.'#n'.$echance.'">'.$echance.'</a></td></tr>'."\n"; print '<tr><td>'.$langs->trans("Term").'</td><td colspan="2"><a href="'.DOL_URL_ROOT.'/loan/schedule.php?loanid='.$chid.'#n'.$echance.'">'.$echance.'</a></td></tr>'."\n";
} }
print '<tr><td>'.$langs->trans("DateStart").'</td><td colspan="2">'.dol_print_date($loan->datestart, 'day')."</td></tr>\n"; 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("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>'; print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">'.price($loan->capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
@ -300,108 +279,106 @@ if ($action == 'create')
print '<table class="border centpercent">'; print '<table class="border centpercent">';
print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Date").'</td><td colspan="2">'; print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Date").'</td><td colspan="2">';
if (empty($datepaid)) if (empty($datepaid)) {
if (empty($ts_temppaid)) $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : dol_now(); if (empty($ts_temppaid)) {
else $datepayment = $ts_temppaid; $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : dol_now();
else $datepayment = $datepaid; } else {
print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1); $datepayment = $ts_temppaid;
print "</td>"; }
print '</tr>'; } else {
$datepayment = $datepaid;
}
print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1);
print "</td>";
print '</tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td colspan="2">'; print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td colspan="2">';
$form->select_types_paiements(GETPOSTISSET("paymenttype") ? GETPOST("paymenttype", 'alphanohtml') : $loan->fk_typepayment, "paymenttype"); $form->select_types_paiements(GETPOSTISSET("paymenttype") ? GETPOST("paymenttype", 'alphanohtml') : $loan->fk_typepayment, "paymenttype");
print "</td>\n"; print "</td>\n";
print '</tr>'; print '</tr>';
print '<tr>'; print '<tr>';
print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>'; print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>';
print '<td colspan="2">'; print '<td colspan="2">';
$form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid", 'int') : $loan->accountid, "accountid", 0, 'courant = '.Account::TYPE_CURRENT, 1); // Show opend bank account list $form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid", 'int') : $loan->accountid, "accountid", 0, 'courant = '.Account::TYPE_CURRENT, 1); // Show opend bank account list
print '</td></tr>'; print '</td></tr>';
// Number // Number
print '<tr><td>'.$langs->trans('Numero'); print '<tr><td>'.$langs->trans('Numero');
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>'; print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
print '</td>'; print '</td>';
print '<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST('num_payment', 'alphanohtml').'"></td>'."\n"; print '<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST('num_payment', 'alphanohtml').'"></td>'."\n";
print "</tr>"; print "</tr>";
print '<tr>'; print '<tr>';
print '<td class="tdtop">'.$langs->trans("NotePrivate").'</td>'; print '<td class="tdtop">'.$langs->trans("NotePrivate").'</td>';
print '<td valign="top" colspan="2"><textarea name="note_private" wrap="soft" cols="60" rows="'.ROWS_3.'"></textarea></td>'; print '<td valign="top" colspan="2"><textarea name="note_private" wrap="soft" cols="60" rows="'.ROWS_3.'"></textarea></td>';
print '</tr>'; print '</tr>';
print '<tr>'; print '<tr>';
print '<td class="tdtop">'.$langs->trans("NotePublic").'</td>'; print '<td class="tdtop">'.$langs->trans("NotePublic").'</td>';
print '<td valign="top" colspan="2"><textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_3.'"></textarea></td>'; print '<td valign="top" colspan="2"><textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_3.'"></textarea></td>';
print '</tr>'; print '</tr>';
print '</table>'; print '</table>';
print dol_get_fiche_end(); print dol_get_fiche_end();
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td class="left">'.$langs->trans("DateDue").'</td>'; print '<td class="left">'.$langs->trans("DateDue").'</td>';
print '<td class="right">'.$langs->trans("LoanCapital").'</td>'; print '<td class="right">'.$langs->trans("LoanCapital").'</td>';
print '<td class="right">'.$langs->trans("AlreadyPaid").'</td>'; print '<td class="right">'.$langs->trans("AlreadyPaid").'</td>';
print '<td class="right">'.$langs->trans("RemainderToPay").'</td>'; print '<td class="right">'.$langs->trans("RemainderToPay").'</td>';
print '<td class="right">'.$langs->trans("Amount").'</td>'; print '<td class="right">'.$langs->trans("Amount").'</td>';
print "</tr>\n"; print "</tr>\n";
print '<tr class="oddeven">'; print '<tr class="oddeven">';
if ($loan->datestart > 0) if ($loan->datestart > 0) {
{
print '<td class="left" valign="center">'.dol_print_date($loan->datestart, 'day').'</td>'; print '<td class="left" valign="center">'.dol_print_date($loan->datestart, 'day').'</td>';
} else { } else {
print '<td class="center" valign="center"><b>!!!</b></td>'; print '<td class="center" valign="center"><b>!!!</b></td>';
} }
print '<td class="right" valign="center">'.price($loan->capital)."</td>"; print '<td class="right" valign="center">'.price($loan->capital)."</td>";
print '<td class="right" valign="center">'.price($sumpaid)."</td>"; print '<td class="right" valign="center">'.price($sumpaid)."</td>";
print '<td class="right" valign="center">'.price($loan->capital - $sumpaid)."</td>"; print '<td class="right" valign="center">'.price($loan->capital - $sumpaid)."</td>";
print '<td class="right">'; print '<td class="right">';
if ($sumpaid < $loan->capital) if ($sumpaid < $loan->capital) {
{
print $langs->trans("LoanCapital").': <input type="text" size="8" name="amount_capital" value="'.(GETPOSTISSET('amount_capital') ?GETPOST('amount_capital') : $amount_capital).'">'; print $langs->trans("LoanCapital").': <input type="text" size="8" name="amount_capital" value="'.(GETPOSTISSET('amount_capital') ?GETPOST('amount_capital') : $amount_capital).'">';
} } else {
else {
print '-'; print '-';
} }
print '<br>'; print '<br>';
if ($sumpaid < $loan->capital) if ($sumpaid < $loan->capital) {
{
print $langs->trans("Insurance").': <input type="text" size="8" name="amount_insurance" value="'.(GETPOSTISSET('amount_insurance') ?GETPOST('amount_insurance') : $amount_insurance).'">'; print $langs->trans("Insurance").': <input type="text" size="8" name="amount_insurance" value="'.(GETPOSTISSET('amount_insurance') ?GETPOST('amount_insurance') : $amount_insurance).'">';
} } else {
else {
print '-'; print '-';
} }
print '<br>'; print '<br>';
if ($sumpaid < $loan->capital) if ($sumpaid < $loan->capital) {
{
print $langs->trans("Interest").': <input type="text" size="8" name="amount_interest" value="'.(GETPOSTISSET('amount_interest') ?GETPOST('amount_interest') : $amount_interest).'" '.(!empty($line) ? 'disabled title="'.$langs->trans('CantModifyInterestIfScheduleIsUsed').'"' : '').'>'; print $langs->trans("Interest").': <input type="text" size="8" name="amount_interest" value="'.(GETPOSTISSET('amount_interest') ?GETPOST('amount_interest') : $amount_interest).'" '.(!empty($line) ? 'disabled title="'.$langs->trans('CantModifyInterestIfScheduleIsUsed').'"' : '').'>';
} } else {
else {
print '-'; print '-';
} }
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
print '</table>'; print '</table>';
print '<br><div class="center">'; print '<br><div class="center">';
print '<input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">'; print '<input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">';
print '&nbsp; &nbsp;'; print '&nbsp; &nbsp;';
print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">'; print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>'; print '</div>';
print "</form>\n"; print "</form>\n";
} }
llxFooter(); llxFooter();

View File

@ -35,9 +35,15 @@ $action = GETPOST('action', 'aZ09');
// Security check // Security check
$socid = 0; $socid = 0;
if (GETPOSTISSET('socid')) $socid = GETPOST('socid', 'int'); if (GETPOSTISSET('socid')) {
if ($user->socid) $socid = $user->socid; $socid = GETPOST('socid', 'int');
if (empty($user->rights->loan->calc)) accessforbidden(); }
if ($user->socid) {
$socid = $user->socid;
}
if (empty($user->rights->loan->calc)) {
accessforbidden();
}
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("compta", "bills", "loan")); $langs->loadLangs(array("compta", "bills", "loan"));
@ -120,7 +126,9 @@ if ($action == 'updateecheancier' && empty($pay_without_schedule)) {
$echeances->lines[$i - 1] = $new_echeance; $echeances->lines[$i - 1] = $new_echeance;
$i++; $i++;
} }
if ($result > 0) $db->commit(); if ($result > 0) {
$db->commit();
}
} }
/* /*
@ -141,24 +149,23 @@ $morehtmlref = '<div class="refidno">';
$morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'string', '', 0, 1); $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'string', '', 0, 1);
$morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, 0, 'string', '', null, null, '', 1); $morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, 0, 'string', '', null, null, '', 1);
// Project // Project
if (!empty($conf->projet->enabled)) if (!empty($conf->projet->enabled)) {
{
$langs->loadLangs(array("projects")); $langs->loadLangs(array("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 class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : '; //$morehtmlref .= '<a class="editfielda" 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="'.newToken().'">'; $morehtmlref .= '<input type="hidden" name="token" value="'.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)) {
@ -212,14 +219,14 @@ $(document).ready(function() {
</script> </script>
<?php <?php
if ($pay_without_schedule == 1) if ($pay_without_schedule == 1) {
print '<div class="warning">'.$langs->trans('CantUseScheduleWithLoanStartedToPaid').'</div>'."\n"; print '<div class="warning">'.$langs->trans('CantUseScheduleWithLoanStartedToPaid').'</div>'."\n";
}
print '<form name="createecheancier" action="'.$_SERVER["PHP_SELF"].'" method="POST">'; print '<form name="createecheancier" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="loanid" value="'.$loanid.'">'; print '<input type="hidden" name="loanid" value="'.$loanid.'">';
if (count($echeances->lines) > 0) if (count($echeances->lines) > 0) {
{
print '<input type="hidden" name="action" value="updateecheancier">'; print '<input type="hidden" name="action" value="updateecheancier">';
} else { } else {
print '<input type="hidden" name="action" value="createecheancier">'; print '<input type="hidden" name="action" value="createecheancier">';
@ -229,7 +236,9 @@ print '<div class="div-table-responsive-no-min">';
print '<table class="border centpercent">'; print '<table class="border centpercent">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
$colspan = 6; $colspan = 6;
if (count($echeances->lines) > 0) $colspan++; if (count($echeances->lines) > 0) {
$colspan++;
}
print '<th class="center" colspan="'.$colspan.'">'; print '<th class="center" colspan="'.$colspan.'">';
print $langs->trans("FinancialCommitment"); print $langs->trans("FinancialCommitment");
print '</th>'; print '</th>';
@ -245,18 +254,18 @@ print '<th class="center">'.$langs->trans("CapitalRemain");
print '<br>('.price($object->capital, 0, '', 1, -1, -1, $conf->currency).')'; print '<br>('.price($object->capital, 0, '', 1, -1, -1, $conf->currency).')';
print '<input type="hidden" name="hi_capital0" id ="hi_capital0" value="'.$object->capital.'">'; print '<input type="hidden" name="hi_capital0" id ="hi_capital0" value="'.$object->capital.'">';
print '</th>'; print '</th>';
if (count($echeances->lines) > 0) print '<th class="center">'.$langs->trans('DoPayment').'</th>'; if (count($echeances->lines) > 0) {
print '<th class="center">'.$langs->trans('DoPayment').'</th>';
}
print '</tr>'."\n"; print '</tr>'."\n";
if ($object->nbterm > 0 && count($echeances->lines) == 0) if ($object->nbterm > 0 && count($echeances->lines) == 0) {
{
$i = 1; $i = 1;
$capital = $object->capital; $capital = $object->capital;
$insurance = $object->insurance_amount / $object->nbterm; $insurance = $object->insurance_amount / $object->nbterm;
$insurance = price2num($insurance, 'MT'); $insurance = price2num($insurance, 'MT');
$regulInsurance = price2num($object->insurance_amount - ($insurance * $object->nbterm)); $regulInsurance = price2num($object->insurance_amount - ($insurance * $object->nbterm));
while ($i < $object->nbterm + 1) while ($i < $object->nbterm + 1) {
{
$mens = price2num($echeances->calcMonthlyPayments($capital, $object->rate / 100, $object->nbterm - $i + 1), 'MT'); $mens = price2num($echeances->calcMonthlyPayments($capital, $object->rate / 100, $object->nbterm - $i + 1), 'MT');
$int = ($capital * ($object->rate / 12)) / 100; $int = ($capital * ($object->rate / 12)) / 100;
$int = price2num($int, 'MT'); $int = price2num($int, 'MT');
@ -273,8 +282,7 @@ if ($object->nbterm > 0 && count($echeances->lines) == 0)
$i++; $i++;
$capital = $cap_rest; $capital = $cap_rest;
} }
} elseif (count($echeances->lines) > 0) } elseif (count($echeances->lines) > 0) {
{
$i = 1; $i = 1;
$capital = $object->capital; $capital = $object->capital;
$insurance = $object->insurance_amount / $object->nbterm; $insurance = $object->insurance_amount / $object->nbterm;
@ -300,14 +308,12 @@ if ($object->nbterm > 0 && count($echeances->lines) == 0)
print '<td class="center" id="capital'.$i.'">'.price($cap_rest, 0, '', 1, -1, -1, $conf->currency).'</td><input type="hidden" name="hi_capital'.$i.'" id ="hi_capital'.$i.'" value="'.$cap_rest.'">'; print '<td class="center" id="capital'.$i.'">'.price($cap_rest, 0, '', 1, -1, -1, $conf->currency).'</td><input type="hidden" name="hi_capital'.$i.'" id ="hi_capital'.$i.'" value="'.$cap_rest.'">';
print '<td class="center">'; print '<td class="center">';
if (!empty($line->fk_bank)) if (!empty($line->fk_bank)) {
{
print $langs->trans('Paid'); print $langs->trans('Paid');
if (!empty($line->fk_payment_loan)) if (!empty($line->fk_payment_loan)) {
print '&nbsp;<a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$line->fk_payment_loan.'">('.img_object($langs->trans("Payment"), "payment").' '.$line->fk_payment_loan.')</a>'; print '&nbsp;<a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$line->fk_payment_loan.'">('.img_object($langs->trans("Payment"), "payment").' '.$line->fk_payment_loan.')</a>';
} }
elseif (!$printed) } elseif (!$printed) {
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&amp;action=create">'.$langs->trans('DoPayment').'</a>'; print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&amp;action=create">'.$langs->trans('DoPayment').'</a>';
$printed = true; $printed = true;
} }
@ -323,8 +329,11 @@ print '</div>';
print '</br>'; print '</br>';
if (count($echeances->lines) == 0) $label = $langs->trans("Create"); if (count($echeances->lines) == 0) {
else $label = $langs->trans("Save"); $label = $langs->trans("Create");
} else {
$label = $langs->trans("Save");
}
print '<div class="center"><input class="button" type="submit" value="'.$label.'" '.(($pay_without_schedule == 1) ? 'disabled title="'.$langs->trans('CantUseScheduleWithLoanStartedToPaid').'"' : '').'title=""></div>'; print '<div class="center"><input class="button" type="submit" value="'.$label.'" '.(($pay_without_schedule == 1) ? 'disabled title="'.$langs->trans('CantUseScheduleWithLoanStartedToPaid').'"' : '').'title=""></div>';
print '</form>'; print '</form>';