From c70dff89dde708b64ab4266754d5562454f75ebb Mon Sep 17 00:00:00 2001 From: atm-ph Date: Wed, 6 Dec 2017 12:13:15 +0100 Subject: [PATCH 1/6] Fix $boad instead of $board --- htdocs/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/index.php b/htdocs/index.php index ae4ec72a901..195d583046f 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -548,7 +548,7 @@ if (! empty($valid_dashboardlines)) $boxwork.=''; foreach($valid_dashboardlines as $board) { - if (empty($boad->nbtodo)) $nbworkboardempty++; + if (empty($board->nbtodo)) $nbworkboardempty++; $textlate = $langs->trans("NActionsLate",$board->nbtodolate); $textlate.= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($board->warning_delay) >= 0 ? '+' : '').ceil($board->warning_delay).' '.$langs->trans("days").')'; From eb03f8f08e35e7dfcb75be7f29cfe511ba58ed8b Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Fri, 8 Dec 2017 15:03:42 +0100 Subject: [PATCH 2/6] fix MAIN_COPY_FILE_IN_EVENT_AUTO --- htdocs/core/actions_sendmails.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index fca8ac511da..a888e4a7656 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -413,6 +413,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO $object->trackid = $trackid; $object->fk_element = $object->id; $object->elementtype = $object->element; + $object->attachedfiles = $attachedfiles; // Call of triggers if (! empty($trigger_name)) From 60fc500fa80365783becad9ffbcfee1b9736ab22 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 10 Dec 2017 07:00:46 +0100 Subject: [PATCH 3/6] FIX : Edit accountancy account and warning message on loan --- htdocs/loan/card.php | 588 ++++++++++++------------ htdocs/loan/class/loan.class.php | 744 ++++++++++++++++--------------- 2 files changed, 671 insertions(+), 661 deletions(-) diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index 4f61aa833bf..f44316ba45d 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2014-2017 Alexandre Spangaro * Copyright (C) 2015 Frederic France * Copyright (C) 2017 Laurent Destailleur * @@ -18,9 +18,9 @@ */ /** - * \file htdocs/loan/card.php - * \ingroup loan - * \brief Loan card + * \file htdocs/loan/card.php + * \ingroup loan + * \brief Loan card */ require '../main.inc.php'; @@ -61,129 +61,81 @@ $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if (empty($reshook)) { - // Classify paid - if ($action == 'confirm_paid' && $confirm == 'yes') - { - $object->fetch($id); - $result = $object->set_paid($user); - if ($result > 0) - { - setEventMessages($langs->trans('LoanPaid'), null, 'mesgs'); - } - else - { - setEventMessages($loan->error, null, 'errors'); - } - } + // Classify paid + if ($action == 'confirm_paid' && $confirm == 'yes') + { + $object->fetch($id); + $result = $object->set_paid($user); + if ($result > 0) + { + setEventMessages($langs->trans('LoanPaid'), null, 'mesgs'); + } + else + { + setEventMessages($loan->error, null, 'errors'); + } + } - // Delete loan - if ($action == 'confirm_delete' && $confirm == 'yes') - { - $object->fetch($id); - $result=$object->delete($user); - if ($result > 0) - { - setEventMessages($langs->trans('LoanDeleted'), null, 'mesgs'); - header("Location: index.php"); - exit; - } - else - { - setEventMessages($loan->error, null, 'errors'); - } - } + // Delete loan + if ($action == 'confirm_delete' && $confirm == 'yes') + { + $object->fetch($id); + $result=$object->delete($user); + if ($result > 0) + { + setEventMessages($langs->trans('LoanDeleted'), null, 'mesgs'); + header("Location: index.php"); + exit; + } + else + { + setEventMessages($loan->error, null, 'errors'); + } + } - // Add loan - if ($action == 'add' && $user->rights->loan->write) - { - if (! $cancel) - { - $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')); - $capital = price2num(GETPOST('capital')); - $rate = GETPOST('rate'); + // Add loan + if ($action == 'add' && $user->rights->loan->write) + { + if (! $cancel) + { + $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')); + $capital = price2num(GETPOST('capital')); + $rate = GETPOST('rate'); - if (! $capital) - { - $error++; $action = 'create'; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors'); - } - if (! $datestart) - { - $error++; $action = 'create'; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateStart")), null, 'errors'); - } - if (! $dateend) - { - $error++; $action = 'create'; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateEnd")), null, 'errors'); - } - if ($rate == '') - { - $error++; $action = 'create'; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rate")), null, 'errors'); - } + if (! $capital) + { + $error++; $action = 'create'; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors'); + } + if (! $datestart) + { + $error++; $action = 'create'; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateStart")), null, 'errors'); + } + if (! $dateend) + { + $error++; $action = 'create'; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateEnd")), null, 'errors'); + } + if ($rate == '') + { + $error++; $action = 'create'; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rate")), null, 'errors'); + } - if (! $error) - { - $object->label = GETPOST('label'); - $object->fk_bank = GETPOST('accountid'); - $object->capital = $capital; - $object->datestart = $datestart; - $object->dateend = $dateend; - $object->nbterm = GETPOST('nbterm'); - $object->rate = $rate; - $object->note_private = GETPOST('note_private'); - $object->note_public = GETPOST('note_public'); - $object->fk_project = GETPOST('projectid','int'); - - $accountancy_account_capital = GETPOST('accountancy_account_capital'); - $accountancy_account_insurance = GETPOST('accountancy_account_insurance'); - $accountancy_account_interest = GETPOST('accountancy_account_interest'); - - if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; } - if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; } - if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; } - - $id=$object->create($user); - if ($id <= 0) - { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - $action = 'create'; - } - } - } - else - { - header("Location: index.php"); - exit(); - } - } - - // Update record - else if ($action == 'update' && $user->rights->loan->write) - { - if (! $cancel) - { - $result = $object->fetch($id); - - $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')); - $capital = price2num(GETPOST('capital')); - - if (! $capital) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors'); - $action = 'edit'; - } - else - { - $object->datestart = $datestart; - $object->dateend = $dateend; - $object->capital = $capital; - $object->nbterm = GETPOST("nbterm"); - $object->rate = GETPOST("rate"); + if (! $error) + { + $object->label = GETPOST('label'); + $object->fk_bank = GETPOST('accountid'); + $object->capital = $capital; + $object->datestart = $datestart; + $object->dateend = $dateend; + $object->nbterm = GETPOST('nbterm'); + $object->rate = $rate; + $object->note_private = GETPOST('note_private'); + $object->note_public = GETPOST('note_public'); + $object->fk_project = GETPOST('projectid','int'); $accountancy_account_capital = GETPOST('accountancy_account_capital'); $accountancy_account_insurance = GETPOST('accountancy_account_insurance'); @@ -192,43 +144,91 @@ if (empty($reshook)) if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; } if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; } if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; } - } - $result = $object->update($user); + $id=$object->create($user); + if ($id <= 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'create'; + } + } + } + else + { + header("Location: index.php"); + exit(); + } + } - if ($result > 0) - { - header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); - exit; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - else - { - header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); - exit; - } - } + // Update record + else if ($action == 'update' && $user->rights->loan->write) + { + if (! $cancel) + { + $result = $object->fetch($id); + + $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')); + $capital = price2num(GETPOST('capital')); + + if (! $capital) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors'); + $action = 'edit'; + } + else + { + $object->datestart = $datestart; + $object->dateend = $dateend; + $object->capital = $capital; + $object->nbterm = GETPOST("nbterm"); + $object->rate = GETPOST("rate"); + + $accountancy_account_capital = GETPOST('accountancy_account_capital'); + $accountancy_account_insurance = GETPOST('accountancy_account_insurance'); + $accountancy_account_interest = GETPOST('accountancy_account_interest'); + + if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; } + if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; } + if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; } + } + + $result = $object->update($user); + + if ($result > 0) + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + else + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } + } // Link to a project if ($action == 'classin' && $user->rights->loan->write) { - $object->fetch($id); - $result = $object->setProject($projectid); + $object->fetch($id); + $result = $object->setProject($projectid); if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } - if ($action == 'setlabel' && $user->rights->loan->write) - { - $object->fetch($id); - $result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY'); - if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); - } + if ($action == 'setlabel' && $user->rights->loan->write) + { + $object->fetch($id); + $result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY'); + if ($result < 0) + setEventMessages($object->error, $object->errors, 'errors'); + } } @@ -249,19 +249,19 @@ llxHeader("",$title,$help_url); if ($action == 'create') { //WYSIWYG Editor - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - print load_fiche_titre($langs->trans("NewLoan"), '', 'title_accountancy.png'); + print load_fiche_titre($langs->trans("NewLoan"), '', 'title_accountancy.png'); - $datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int')); + $datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int')); - print '
' . "\n"; - print ''; - print ''; + print '' . "\n"; + print ''; + print ''; dol_fiche_head(); - print ''; + print '
'; // Label print ''; @@ -280,97 +280,97 @@ if ($action == 'create') print ''; } - // Capital - print ''; + // Capital + print ''; // Date Start print ""; - print ''; + print ''; // Date End print ""; - print ''; + print ''; // Number of terms print ''; // Rate - print ''; + print ''; - // Project - if (! empty($conf->projet->enabled)) - { + // Project + if (! empty($conf->projet->enabled)) + { $formproject=new FormProjets($db); // Projet associe $langs->load("projects"); - print ''; - } + print ''; + } - // Note Private - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; - // Note Public - print ''; - print ''; - print ''; + // Note Public + print ''; + print ''; + print ''; - // Accountancy + // Accountancy if (! empty($conf->accounting->enabled)) { // Accountancy_account_capital - print ''; - print ''; + print ''; + print ''; // Accountancy_account_insurance - print ''; - print ''; + print ''; + print ''; // Accountancy_account_interest - print ''; - print ''; + print ''; + print ''; } else // For external software { - // Accountancy_account_capital - print ''; - print ''; + // Accountancy_account_capital + print ''; + print ''; // Accountancy_account_insurance - print ''; - print ''; + print ''; + print ''; // Accountancy_account_interest - print ''; - print ''; + print ''; + print ''; } print '
'.$langs->trans("Label").'
'.$langs->trans("LoanCapital").'
'.$langs->trans("LoanCapital").'
'.$langs->trans("DateStart").''; - print $form->select_date($datestart?$datestart:-1,'start','','','','add',1,1,1); - print '
'.$langs->trans("DateStart").''; + print $form->select_date($datestart?$datestart:-1,'start','','','','add',1,1,1); + print '
'.$langs->trans("DateEnd").''; - print $form->select_date($dateend?$dateend:-1,'end','','','','add',1,1,1); - print '
'.$langs->trans("DateEnd").''; + print $form->select_date($dateend?$dateend:-1,'end','','','','add',1,1,1); + print '
'.$langs->trans("Nbterms").'
'.$langs->trans("Rate").' %
'.$langs->trans("Rate").' %
'.$langs->trans("Project").''; + print '
'.$langs->trans("Project").''; - $numproject=$formproject->select_projects(-1, $projectid, 'projectid', 16, 0, 1, 1); + $numproject=$formproject->select_projects(-1, $projectid, 'projectid', 16, 0, 1, 1); - print '
'.$langs->trans('NotePrivate').''; + // Note Private + print '
'.$langs->trans('NotePrivate').''; - $doleditor = new DolEditor('note_private', GETPOST('note_private', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%'); - print $doleditor->Create(1); + $doleditor = new DolEditor('note_private', GETPOST('note_private', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%'); + print $doleditor->Create(1); - print '
'.$langs->trans('NotePublic').''; - $doleditor = new DolEditor('note_public', GETPOST('note_public', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%'); - print $doleditor->Create(1); - print '
'.$langs->trans('NotePublic').''; + $doleditor = new DolEditor('note_public', GETPOST('note_public', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%'); + print $doleditor->Create(1); + print '
'.$langs->trans("LoanAccountancyCapitalCode").''; + print '
'.$langs->trans("LoanAccountancyCapitalCode").''; print $formaccounting->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1); - print '
'.$langs->trans("LoanAccountancyInsuranceCode").''; + print '
'.$langs->trans("LoanAccountancyInsuranceCode").''; print $formaccounting->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1); - print '
'.$langs->trans("LoanAccountancyInterestCode").''; + print '
'.$langs->trans("LoanAccountancyInterestCode").''; print $formaccounting->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1); - print '
'.$langs->trans("LoanAccountancyCapitalCode").''; - print '
'.$langs->trans("LoanAccountancyCapitalCode").''; + print '
'.$langs->trans("LoanAccountancyInsuranceCode").''; - print '
'.$langs->trans("LoanAccountancyInsuranceCode").''; + print '
'.$langs->trans("LoanAccountancyInterestCode").''; - print '
'.$langs->trans("LoanAccountancyInterestCode").''; + print '
'; @@ -382,14 +382,14 @@ if ($action == 'create') print ''; print ''; - print '
'; + print ''; } // View if ($id > 0) { $object = new Loan($db); - $result = $object->fetch($id); + $result = $object->fetch($id); if ($result > 0) { @@ -413,9 +413,9 @@ if ($id > 0) if ($action == 'edit') { print '
' . "\n"; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; } dol_fiche_head($head, 'card', $langs->trans("Loan"), -1, 'bill'); @@ -441,40 +441,40 @@ if ($id > 0) $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); // Project - if (! empty($conf->projet->enabled)) - { - $langs->load("projects"); - $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->loan->write) - { - if ($action != 'classify') - $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref.=''; - $morehtmlref.='
'; - } else { - $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); - } - } else { - if (! empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref.=''; - $morehtmlref.=$proj->ref; - $morehtmlref.=''; - } else { - $morehtmlref.=''; - } - } - } - $morehtmlref.=''; + if (! empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($user->rights->loan->write) + { + if ($action != 'classify') + $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.='
'; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref.=''; + $morehtmlref.='
'; + } else { + $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref.=''; + $morehtmlref.=$proj->ref; + $morehtmlref.=''; + } else { + $morehtmlref.=''; + } + } + } + $morehtmlref.=''; - $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status + $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); @@ -496,7 +496,7 @@ if ($id > 0) print ''.$langs->trans("LoanCapital").''.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).''; } - // Date start + // Date start print ''.$langs->trans("DateStart").""; print ""; if ($action == 'edit') @@ -548,15 +548,15 @@ if ($id > 0) } print ''; - // Accountancy account capital + // Accountancy account capital print ''; - print $langs->trans("LoanAccountancyCapitalCode"); - print ''; + print $langs->trans("LoanAccountancyCapitalCode"); + print ''; if ($action == 'edit') { if (! empty($conf->accounting->enabled)) { - print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 0, 1); + print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 1, 1); } else { @@ -573,15 +573,15 @@ if ($id > 0) } print ''; - // Accountancy account insurance + // Accountancy account insurance print ''; - print $langs->trans("LoanAccountancyInsuranceCode"); - print ''; + print $langs->trans("LoanAccountancyInsuranceCode"); + print ''; if ($action == 'edit') { if (! empty($conf->accounting->enabled)) { - print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 0, 1); + print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 1, 1); } else { @@ -600,13 +600,13 @@ if ($id > 0) // Accountancy account interest print ''; - print $langs->trans("LoanAccountancyInterestCode"); - print ''; + print $langs->trans("LoanAccountancyInterestCode"); + print ''; if ($action == 'edit') { if (! empty($conf->accounting->enabled)) { - print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 0, 1); + print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 1, 1); } else { @@ -650,9 +650,9 @@ if ($id > 0) { $num = $db->num_rows($resql); $i = 0; - $total_insurance = 0; - $total_interest = 0; - $total_capital = 0; + $total_insurance = 0; + $total_interest = 0; + $total_capital = 0; print ''; print ''; print ''; @@ -660,8 +660,8 @@ if ($id > 0) print ''; print ''; print ''; - print ''; - print ''; + print ''; + print ''; $var=True; while ($i < $num) @@ -672,11 +672,11 @@ if ($id > 0) print ''; print '\n"; print "\n"; - print '\n"; - print '\n"; - print '\n"; + print '\n"; + print '\n"; + print '\n"; print ""; - $total_capital += $objp->amount_capital; + $total_capital += $objp->amount_capital; $i++; } @@ -716,47 +716,47 @@ if ($id > 0) print ''; print ''; - print ''; + print ''; } /* - * Buttons actions + * Buttons actions */ if ($action != 'edit') { $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) - { - print '
'; + { + print '
'; - // Edit - if ($user->rights->loan->write) - { - print ''.$langs->trans('CreateCalcSchedule').''; + // Edit + if ($user->rights->loan->write) + { + print ''.$langs->trans('CreateCalcSchedule').''; - print ''.$langs->trans("Modify").''; - } + print ''.$langs->trans("Modify").''; + } - // Emit payment - if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write) - { - print ''.$langs->trans("DoPayment").''; - } + // Emit payment + if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write) + { + print ''.$langs->trans("DoPayment").''; + } - // Classify 'paid' - if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write) - { - print ''.$langs->trans("ClassifyPaid").''; - } + // Classify 'paid' + if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write) + { + print ''.$langs->trans("ClassifyPaid").''; + } - // Delete - if ($user->rights->loan->delete) - { - print ''.$langs->trans("Delete").''; - } + // Delete + if ($user->rights->loan->delete) + { + print ''.$langs->trans("Delete").''; + } - print "
"; - } + print "
"; + } } } else diff --git a/htdocs/loan/class/loan.class.php b/htdocs/loan/class/loan.class.php index 734c2356b3a..3d80bae8057 100644 --- a/htdocs/loan/class/loan.class.php +++ b/htdocs/loan/class/loan.class.php @@ -17,128 +17,128 @@ */ /** - * \file htdocs/loan/class/loan.class.php - * \ingroup loan - * \brief Class for loan module + * \file htdocs/loan/class/loan.class.php + * \ingroup loan + * \brief Class for loan module */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; /** - * Loan + * Loan */ class Loan extends CommonObject { - public $element='loan'; - public $table='loan'; - public $table_element='loan'; + public $element='loan'; + public $table='loan'; + public $table_element='loan'; - public $picto = 'bill'; + public $picto = 'bill'; - public $rowid; - public $datestart; - public $dateend; - public $label; - public $capital; - public $nbterm; - public $rate; - public $paid; - public $account_capital; - public $account_insurance; - public $account_interest; - public $date_creation; - public $date_modification; - public $date_validation; - public $fk_bank; - public $fk_user_creat; - public $fk_user_modif; - public $fk_project; + public $rowid; + public $datestart; + public $dateend; + public $label; + public $capital; + public $nbterm; + public $rate; + public $paid; + public $account_capital; + public $account_insurance; + public $account_interest; + public $date_creation; + public $date_modification; + public $date_validation; + public $fk_bank; + public $fk_user_creat; + public $fk_user_modif; + public $fk_project; - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - return 1; - } + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + $this->db = $db; + return 1; + } - /** - * Load object in memory from database - * - * @param int $id id object - * @return int <0 error , >=0 no error - */ - function fetch($id) - { - $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public,"; + /** + * Load object in memory from database + * + * @param int $id id object + * @return int <0 error , >=0 no error + */ + function fetch($id) + { + $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public,"; $sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest, l.fk_projet as fk_project"; - $sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; - $sql.= " WHERE l.rowid = ".$id; + $sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; + $sql.= " WHERE l.rowid = ".$id; - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - $this->datestart = $this->db->jdate($obj->datestart); - $this->dateend = $this->db->jdate($obj->dateend); - $this->label = $obj->label; - $this->capital = $obj->capital; - $this->nbterm = $obj->nbterm; - $this->rate = $obj->rate; - $this->note_private = $obj->note_private; - $this->note_public = $obj->note_public; - $this->paid = $obj->paid; + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->datestart = $this->db->jdate($obj->datestart); + $this->dateend = $this->db->jdate($obj->dateend); + $this->label = $obj->label; + $this->capital = $obj->capital; + $this->nbterm = $obj->nbterm; + $this->rate = $obj->rate; + $this->note_private = $obj->note_private; + $this->note_public = $obj->note_public; + $this->paid = $obj->paid; $this->account_capital = $obj->accountancy_account_capital; $this->account_insurance = $obj->accountancy_account_insurance; $this->account_interest = $obj->accountancy_account_interest; $this->fk_project = $obj->fk_project; - $this->db->free($resql); + $this->db->free($resql); return 1; - } - else - { - $this->db->free($resql); - return 0; - } - } - else - { - $this->error=$this->db->lasterror(); - return -1; - } - } + } + else + { + $this->db->free($resql); + return 0; + } + } + else + { + $this->error=$this->db->lasterror(); + return -1; + } + } - /** - * Create a loan into database - * - * @param User $user User making creation - * @return int <0 if KO, id if OK - */ - function create($user) - { - global $conf, $langs; + /** + * Create a loan into database + * + * @param User $user User making creation + * @return int <0 if KO, id if OK + */ + function create($user) + { + global $conf, $langs; $error=0; - $now=dol_now(); + $now=dol_now(); - // clean parameters - $newcapital=price2num($this->capital,'MT'); - if (isset($this->note_private)) $this->note_private = trim($this->note_private); - if (isset($this->note_public)) $this->note_public = trim($this->note_public); + // clean parameters + $newcapital=price2num($this->capital,'MT'); + 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->account_capital)) $this->account_capital = trim($this->account_capital); if (isset($this->account_insurance)) $this->account_insurance = trim($this->account_insurance); if (isset($this->account_interest)) $this->account_interest = trim($this->account_interest); @@ -147,322 +147,332 @@ class Loan extends CommonObject if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); if (isset($this->fk_project)) $this->fk_project=trim($this->fk_project); - // Check parameters - if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend)) - { - $this->error="ErrorBadParameter"; - return -2; - } - if (($conf->accounting->enabled) && empty($this->account_capital) && empty($this->account_insurance) && empty($this->account_interest)) + // Check parameters + if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend)) { - $this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Accounting")); - return -2; + $this->error="ErrorBadParameter"; + return -2; + } + if (($conf->accounting->enabled) && empty($this->account_capital)) + { + $this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyCapitalCode")); + return -2; + } + if (($conf->accounting->enabled) && empty($this->account_insurance)) + { + $this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInsuranceCode")); + return -2; + } + if (($conf->accounting->enabled) && empty($this->account_interest)) + { + $this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInterestCode")); + return -2; } - $this->db->begin(); + $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public,"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public,"; $sql.= " accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity,"; $sql.= " datec, fk_projet, fk_user_author)"; $sql.= " VALUES ('".$this->db->escape($this->label)."',"; $sql.= " '".$this->db->escape($this->fk_bank)."',"; - $sql.= " '".price2num($newcapital)."',"; + $sql.= " '".price2num($newcapital)."',"; $sql.= " '".$this->db->idate($this->datestart)."',"; $sql.= " '".$this->db->idate($this->dateend)."',"; - $sql.= " '".$this->db->escape($this->nbterm)."',"; + $sql.= " '".$this->db->escape($this->nbterm)."',"; $sql.= " '".$this->db->escape($this->rate)."',"; $sql.= " '".$this->db->escape($this->note_private)."',"; $sql.= " '".$this->db->escape($this->note_public)."',"; $sql.= " '".$this->db->escape($this->account_capital)."',"; $sql.= " '".$this->db->escape($this->account_insurance)."',"; $sql.= " '".$this->db->escape($this->account_interest)."',"; - $sql.= " ".$conf->entity.","; + $sql.= " ".$conf->entity.","; $sql.= " '".$this->db->idate($now)."',"; $sql.= " ".(empty($this->fk_project)?'NULL':$this->fk_project).","; $sql.= " ".$user->id; - $sql.= ")"; + $sql.= ")"; - dol_syslog(get_class($this)."::create", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."loan"); + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."loan"); - //dol_syslog("Loans::create this->id=".$this->id); - $this->db->commit(); - return $this->id; - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - return -1; - } - } + //dol_syslog("Loans::create this->id=".$this->id); + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + } - /** - * Delete a loan - * - * @param User $user Object user making delete - * @return int <0 if KO, >0 if OK - */ - function delete($user) - { - $error=0; + /** + * Delete a loan + * + * @param User $user Object user making delete + * @return int <0 if KO, >0 if OK + */ + function delete($user) + { + $error=0; - $this->db->begin(); + $this->db->begin(); - // Get bank transaction lines for this loan - include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; - $account=new Account($this->db); - $lines_url=$account->get_url('',$this->id,'loan'); + // Get bank transaction lines for this loan + include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + $account=new Account($this->db); + $lines_url=$account->get_url('',$this->id,'loan'); - // Delete bank urls - foreach ($lines_url as $line_url) - { - if (! $error) - { - $accountline=new AccountLine($this->db); - $accountline->fetch($line_url['fk_bank']); - $result=$accountline->delete_urls($user); - if ($result < 0) - { - $error++; - } - } - } + // Delete bank urls + foreach ($lines_url as $line_url) + { + if (! $error) + { + $accountline=new AccountLine($this->db); + $accountline->fetch($line_url['fk_bank']); + $result=$accountline->delete_urls($user); + if ($result < 0) + { + $error++; + } + } + } - // Delete payments - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan=".$this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) - { - $error++; - $this->error=$this->db->lasterror(); - } - } + // Delete payments + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan=".$this->id; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql=$this->db->query($sql); + if (! $resql) + { + $error++; + $this->error=$this->db->lasterror(); + } + } - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid=".$this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) - { - $error++; - $this->error=$this->db->lasterror(); - } - } + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid=".$this->id; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql=$this->db->query($sql); + if (! $resql) + { + $error++; + $this->error=$this->db->lasterror(); + } + } - if (! $error) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -1; - } + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } - } + } - /** - * Update loan - * - * @param User $user User who modified - * @return int <0 if error, >0 if ok - */ - function update($user) - { - $this->db->begin(); + /** + * Update loan + * + * @param User $user User who modified + * @return int <0 if error, >0 if ok + */ + function update($user) + { + $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."loan"; - $sql.= " SET label='".$this->db->escape($this->label)."',"; + $sql = "UPDATE ".MAIN_DB_PREFIX."loan"; + $sql.= " SET label='".$this->db->escape($this->label)."',"; $sql.= " capital='".price2num($this->db->escape($this->capital))."',"; - $sql.= " datestart='".$this->db->idate($this->datestart)."',"; - $sql.= " dateend='".$this->db->idate($this->dateend)."',"; - $sql.= " fk_projet=".(empty($this->fk_project)?'NULL':$this->fk_project).","; + $sql.= " datestart='".$this->db->idate($this->datestart)."',"; + $sql.= " dateend='".$this->db->idate($this->dateend)."',"; + $sql.= " fk_projet=".(empty($this->fk_project)?'NULL':$this->fk_project).","; $sql.= " fk_user_modif = ".$user->id; - $sql.= " WHERE rowid=".$this->id; + $sql.= " WHERE rowid=".$this->id; - dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - return -1; - } - } + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + } - /** - * Tag loan as payed completely - * - * @param User $user Object user making change - * @return int <0 if KO, >0 if OK - */ - function set_paid($user) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."loan SET"; - $sql.= " paid = 1"; - $sql.= " WHERE rowid = ".$this->id; - $return = $this->db->query($sql); + /** + * Tag loan as payed completely + * + * @param User $user Object user making change + * @return int <0 if KO, >0 if OK + */ + function set_paid($user) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."loan SET"; + $sql.= " paid = 1"; + $sql.= " WHERE rowid = ".$this->id; + $return = $this->db->query($sql); if ($return) { return 1; } else { $this->error=$this->db->lasterror(); return -1; } - } - - /** - * Return label of loan status (unpaid, paid) - * - * @param int $mode 0=label, 1=short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label - * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) - * @return string Label - */ - function getLibStatut($mode=0,$alreadypaid=-1) - { - return $this->LibStatut($this->paid,$mode,$alreadypaid); - } - - /** - * Return label for given status - * - * @param int $statut Id statut - * @param int $mode 0=Label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label, 5=Short label + Picto - * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) - * @return string Label - */ - function LibStatut($statut,$mode=0,$alreadypaid=-1) - { - global $langs; - $langs->load('customers'); - $langs->load('bills'); - - if ($mode == 0) - { - if ($statut == 0) return $langs->trans("Unpaid"); - if ($statut == 1) return $langs->trans("Paid"); - } - if ($mode == 1) - { - if ($statut == 0) return $langs->trans("Unpaid"); - if ($statut == 1) return $langs->trans("Paid"); - } - if ($mode == 2) - { - if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid"); - if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted"); - if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid"); - } - if ($mode == 3) - { - if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1'); - if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3'); - if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6'); - } - if ($mode == 4) - { - if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid"); - if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted"); - if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid"); - } - if ($mode == 5) - { - if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1'); - if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3'); - if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6'); - } - if ($mode == 6) - { - if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1'); - if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3'); - if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6'); - } - - return "Error, mode/status not found"; - } - - - /** - * Return clicable name (with eventually the picto) - * - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @param int $maxlen Label max length - * @return string Chaine with URL - */ - function getNomUrl($withpicto=0,$maxlen=0) - { - global $langs; - - $result=''; - - $tooltip = '' . $langs->trans("ShowLoan") . ''; - if (! empty($this->ref)) - $tooltip .= '
' . $langs->trans('Ref') . ': ' . $this->ref; - if (! empty($this->label)) - $tooltip .= '
' . $langs->trans('Label') . ': ' . $this->label; - $link = ''; - $linkend = ''; - - if ($withpicto) $result.=($link.$linkclose.img_object($langs->trans("ShowLoan").': '.$this->label,'bill', 'class="classfortooltip"').$linkend.' '); - if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$link.$linkclose.($maxlen?dol_trunc($this->label,$maxlen):$this->label).$linkend; - return $result; - } - - /** - * Return amount of payments already done - * - * @return int Amount of payment already done, <0 if KO - */ - function getSumPayment() - { - $table='payment_loan'; - $field='fk_loan'; - - $sql = 'SELECT sum(amount) as amount'; - $sql.= ' FROM '.MAIN_DB_PREFIX.$table; - $sql.= ' WHERE '.$field.' = '.$this->id; - - dol_syslog(get_class($this)."::getSumPayment", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $amount=0; - - $obj = $this->db->fetch_object($resql); - if ($obj) $amount=$obj->amount?$obj->amount:0; - - $this->db->free($resql); - return $amount; - } - else - { - $this->error=$this->db->lasterror(); - return -1; - } - } + } /** - * Information on record + * Return label of loan status (unpaid, paid) * - * @param int $id Id of record - * @return integer|null + * @param int $mode 0=label, 1=short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label + * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) + * @return string Label + */ + function getLibStatut($mode=0,$alreadypaid=-1) + { + return $this->LibStatut($this->paid,$mode,$alreadypaid); + } + + /** + * Return label for given status + * + * @param int $statut Id statut + * @param int $mode 0=Label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label, 5=Short label + Picto + * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) + * @return string Label + */ + function LibStatut($statut,$mode=0,$alreadypaid=-1) + { + global $langs; + $langs->load('customers'); + $langs->load('bills'); + + if ($mode == 0) + { + if ($statut == 0) return $langs->trans("Unpaid"); + if ($statut == 1) return $langs->trans("Paid"); + } + if ($mode == 1) + { + if ($statut == 0) return $langs->trans("Unpaid"); + if ($statut == 1) return $langs->trans("Paid"); + } + if ($mode == 2) + { + if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid"); + if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted"); + if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid"); + } + if ($mode == 3) + { + if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1'); + if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3'); + if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6'); + } + if ($mode == 4) + { + if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid"); + if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted"); + if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid"); + } + if ($mode == 5) + { + if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1'); + if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3'); + if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6'); + } + if ($mode == 6) + { + if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1'); + if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3'); + if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6'); + } + + return "Error, mode/status not found"; + } + + + /** + * Return clicable name (with eventually the picto) + * + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param int $maxlen Label max length + * @return string Chaine with URL + */ + function getNomUrl($withpicto=0,$maxlen=0) + { + global $langs; + + $result=''; + + $tooltip = '' . $langs->trans("ShowLoan") . ''; + if (! empty($this->ref)) + $tooltip .= '
' . $langs->trans('Ref') . ': ' . $this->ref; + if (! empty($this->label)) + $tooltip .= '
' . $langs->trans('Label') . ': ' . $this->label; + $link = ''; + $linkend = ''; + + if ($withpicto) $result.=($link.$linkclose.img_object($langs->trans("ShowLoan").': '.$this->label,'bill', 'class="classfortooltip"').$linkend.' '); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$link.$linkclose.($maxlen?dol_trunc($this->label,$maxlen):$this->label).$linkend; + return $result; + } + + /** + * Return amount of payments already done + * + * @return int Amount of payment already done, <0 if KO + */ + function getSumPayment() + { + $table='payment_loan'; + $field='fk_loan'; + + $sql = 'SELECT sum(amount) as amount'; + $sql.= ' FROM '.MAIN_DB_PREFIX.$table; + $sql.= ' WHERE '.$field.' = '.$this->id; + + dol_syslog(get_class($this)."::getSumPayment", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $amount=0; + + $obj = $this->db->fetch_object($resql); + if ($obj) $amount=$obj->amount?$obj->amount:0; + + $this->db->free($resql); + return $amount; + } + else + { + $this->error=$this->db->lasterror(); + return -1; + } + } + + /** + * Information on record + * + * @param int $id Id of record + * @return integer|null */ function info($id) { @@ -492,17 +502,17 @@ class Loan extends CommonObject $muser->fetch($obj->fk_user_modif); $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 = ""; $this->date_modification = $this->db->jdate($obj->tms); - $this->db->free($result); + $this->db->free($result); return 1; } else { - $this->db->free($result); - return 0; + $this->db->free($result); + return 0; } } else From 12d09282448bf0eb4dfaf40540e0db89c78e2859 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sun, 10 Dec 2017 19:59:56 +0100 Subject: [PATCH 4/6] Fix display error message when stock not enough on invoice validation --- htdocs/compta/facture/class/facture.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 840bb93a49f..3c35a03f218 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2197,6 +2197,7 @@ class Facture extends CommonInvoice else $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr",$num)); if ($result < 0) { $error++; + $this->error = $mouvP->error; } } } From 033016da7fd5de610089ec59ae18513c9192c66c Mon Sep 17 00:00:00 2001 From: patrick Delcroix Date: Sun, 10 Dec 2017 20:02:26 +0100 Subject: [PATCH 5/6] fix: unable to remove salaries, plus correct default rights management --- htdocs/core/lib/security.lib.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index e799579b181..c7d72e796ea 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -242,17 +242,17 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu { foreach($feature2 as $subfeature) { - if (empty($user->rights->$feature->$subfeature->creer) - && empty($user->rights->$feature->$subfeature->write) - && empty($user->rights->$feature->$subfeature->create)) { $createok=0; $nbko++; } + if (empty($user->rights->{$feature}->{$subfeature}->creer) + && empty($user->rights->{$feature}->{$subfeature}->write) + && empty($user->rights->{$feature}->{$subfeature}->create)) { $createok=0; $nbko++; } else { $createok=1; break; } // Break to bypass second test if the first is ok } } else if (! empty($feature)) // This is for old permissions ('creer' or 'write') { //print '
feature='.$feature.' creer='.$user->rights->$feature->creer.' write='.$user->rights->$feature->write; - if (empty($user->rights->$feature->creer) - && empty($user->rights->$feature->write)) { $createok=0; $nbko++; } + if (empty($user->rights->{$feature}->creer) + && empty($user->rights->{$feature}->write)) { $createok=0; $nbko++; } } } @@ -306,21 +306,24 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu else if ($feature == 'ftp') { if (! $user->rights->ftp->write) $deleteok=0; + }else if ($feature == 'salaries') + { + if (! $user->rights->salaries->delete) $deleteok=0; } else if (! empty($feature2)) // This should be used for future changes { foreach($feature2 as $subfeature) { - if (empty($user->rights->$feature->$subfeature->supprimer) && empty($user->rights->$feature->$subfeature->delete)) $deleteok=0; + if (empty($user->rights->{$feature}->{$subfeature}->supprimer) && empty($user->rights->$feature->$subfeature->delete)) $deleteok=0; else { $deleteok=1; break; } // For bypass the second test if the first is ok } } else if (! empty($feature)) // This is for old permissions { //print '
feature='.$feature.' creer='.$user->rights->$feature->supprimer.' write='.$user->rights->$feature->delete; - if (empty($user->rights->$feature->supprimer) - && empty($user->rights->$feature->delete) - && empty($user->rights->$feature->run)) $deleteok=0; + if (empty($user->rights->{$feature}->supprimer) + && empty($user->rights->{$feature}->delete) + && empty($user->rights->{$feature}->run)) $deleteok=0; } } From f18edd57879c83efee640a91464fe9d917d22eab Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 10 Dec 2017 21:08:13 +0100 Subject: [PATCH 6/6] Update security.lib.php --- htdocs/core/lib/security.lib.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index c7d72e796ea..0632f4d723f 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -242,17 +242,17 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu { foreach($feature2 as $subfeature) { - if (empty($user->rights->{$feature}->{$subfeature}->creer) - && empty($user->rights->{$feature}->{$subfeature}->write) - && empty($user->rights->{$feature}->{$subfeature}->create)) { $createok=0; $nbko++; } + if (empty($user->rights->$feature->$subfeature->creer) + && empty($user->rights->$feature->$subfeature->write) + && empty($user->rights->$feature->$subfeature->create)) { $createok=0; $nbko++; } else { $createok=1; break; } // Break to bypass second test if the first is ok } } else if (! empty($feature)) // This is for old permissions ('creer' or 'write') { //print '
feature='.$feature.' creer='.$user->rights->$feature->creer.' write='.$user->rights->$feature->write; - if (empty($user->rights->{$feature}->creer) - && empty($user->rights->{$feature}->write)) { $createok=0; $nbko++; } + if (empty($user->rights->$feature->creer) + && empty($user->rights->$feature->write)) { $createok=0; $nbko++; } } } @@ -314,16 +314,16 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu { foreach($feature2 as $subfeature) { - if (empty($user->rights->{$feature}->{$subfeature}->supprimer) && empty($user->rights->$feature->$subfeature->delete)) $deleteok=0; + if (empty($user->rights->$feature->$subfeature->supprimer) && empty($user->rights->$feature->$subfeature->delete)) $deleteok=0; else { $deleteok=1; break; } // For bypass the second test if the first is ok } } else if (! empty($feature)) // This is for old permissions { //print '
feature='.$feature.' creer='.$user->rights->$feature->supprimer.' write='.$user->rights->$feature->delete; - if (empty($user->rights->{$feature}->supprimer) - && empty($user->rights->{$feature}->delete) - && empty($user->rights->{$feature}->run)) $deleteok=0; + if (empty($user->rights->$feature->supprimer) + && empty($user->rights->$feature->delete) + && empty($user->rights->$feature->run)) $deleteok=0; } }
'.$langs->trans("RefPayment").''.$langs->trans("Type").''.$langs->trans("Insurance").''.$langs->trans("Interest").''.$langs->trans("LoanCapital").'
'.$langs->trans("LoanCapital").'
'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."".$objp->paiement_type.' '.$objp->num_payment."'.price($objp->amount_insurance, 0, $langs, 0, 0, -1, $conf->currency)."'.price($objp->amount_interest, 0, $langs, 0, 0, -1, $conf->currency)."'.price($objp->amount_capital, 0, $langs, 0, 0, -1, $conf->currency)."'.price($objp->amount_insurance, 0, $langs, 0, 0, -1, $conf->currency)."'.price($objp->amount_interest, 0, $langs, 0, 0, -1, $conf->currency)."'.price($objp->amount_capital, 0, $langs, 0, 0, -1, $conf->currency)."