This commit is contained in:
Philippe 2017-12-18 15:37:46 +01:00
commit dd8ef47a25
34 changed files with 980 additions and 815 deletions

View File

@ -2,6 +2,27 @@
English Dolibarr ChangeLog English Dolibarr ChangeLog
-------------------------------------------------------------- --------------------------------------------------------------
***** ChangeLog for 6.0.4 compared to 6.0.3 *****
FIX: #7737
FIX: #7751
FIX: #7756 Add better error message
FIX: #7786
FIX: #7806
FIX: #7824
FIX: add line bad price and ref
FIX: A lot of several fix on local taxes and NPR tax
FIX: createfromorder
FIX: CSS for IE10
FIX: external user cannot be set as internal
FIX: Filter type on actioncomm with multiselect doesn't work
FIX: list of donation not filtered on multicompany
FIX: list of module not complete when module mb_strlen not available
FIX: Locatax were not propagated when cloning order or proposal
FIX: Searching translation should not be case sensitive
FIX: Search into language is ok for file into external modules two.
FIX: test for filter fk_status
FIX: too much users on holiday list
FIX: Wrong alias sql
***** ChangeLog for 6.0.3 compared to 6.0.2 ***** ***** ChangeLog for 6.0.3 compared to 6.0.2 *****
FIX: #7211 Update qty dispatched on qty change FIX: #7211 Update qty dispatched on qty change

View File

@ -131,7 +131,7 @@ $iterator1 = new RecursiveIteratorIterator($dir_iterator1);
$files = new RegexIterator($iterator1, '#^(?:[A-Z]:)?(?:/(?!(?:'.($includecustom?'':'custom\/|').'documents\/|conf\/|install\/))[^/]+)+/[^/]+\.(?:php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$#i'); $files = new RegexIterator($iterator1, '#^(?:[A-Z]:)?(?:/(?!(?:'.($includecustom?'':'custom\/|').'documents\/|conf\/|install\/))[^/]+)+/[^/]+\.(?:php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$#i');
*/ */
$regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$'; $regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$';
$regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install)$'; // Exclude dirs $regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs
$files = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude, 'fullname'); $files = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude, 'fullname');
$dir=''; $dir='';
$needtoclose=0; $needtoclose=0;

View File

@ -556,9 +556,6 @@ if ($nboftargetok) {
$ret=`rm -f $BUILDROOT/$PROJECT/.cvsignore $BUILDROOT/$PROJECT/*/.cvsignore $BUILDROOT/$PROJECT/*/*/.cvsignore $BUILDROOT/$PROJECT/*/*/*/.cvsignore $BUILDROOT/$PROJECT/*/*/*/*/.cvsignore $BUILDROOT/$PROJECT/*/*/*/*/*/.cvsignore $BUILDROOT/$PROJECT/*/*/*/*/*/*/.cvsignore`; $ret=`rm -f $BUILDROOT/$PROJECT/.cvsignore $BUILDROOT/$PROJECT/*/.cvsignore $BUILDROOT/$PROJECT/*/*/.cvsignore $BUILDROOT/$PROJECT/*/*/*/.cvsignore $BUILDROOT/$PROJECT/*/*/*/*/.cvsignore $BUILDROOT/$PROJECT/*/*/*/*/*/.cvsignore $BUILDROOT/$PROJECT/*/*/*/*/*/*/.cvsignore`;
$ret=`rm -f $BUILDROOT/$PROJECT/.gitignore $BUILDROOT/$PROJECT/*/.gitignore $BUILDROOT/$PROJECT/*/*/.gitignore $BUILDROOT/$PROJECT/*/*/*/.gitignore $BUILDROOT/$PROJECT/*/*/*/*/.gitignore $BUILDROOT/$PROJECT/*/*/*/*/*/.gitignore $BUILDROOT/$PROJECT/*/*/*/*/*/*/.gitignore`; $ret=`rm -f $BUILDROOT/$PROJECT/.gitignore $BUILDROOT/$PROJECT/*/.gitignore $BUILDROOT/$PROJECT/*/*/.gitignore $BUILDROOT/$PROJECT/*/*/*/.gitignore $BUILDROOT/$PROJECT/*/*/*/*/.gitignore $BUILDROOT/$PROJECT/*/*/*/*/*/.gitignore $BUILDROOT/$PROJECT/*/*/*/*/*/*/.gitignore`;
$ret=`rm -f $BUILDROOT/$PROJECT/htdocs/includes/geoip/sample*.*`; $ret=`rm -f $BUILDROOT/$PROJECT/htdocs/includes/geoip/sample*.*`;
$ret=`rm -f $BUILDROOT/$PROJECT/htdocs/includes/jquery/plugins/jqueryFileTree/connectors/jqueryFileTree.pl`; # Avoid errors into rpmlint
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/jquery/plugins/template`; # Package not valid for most linux distributions (errors reported into compile.js). Package should be embed by modules to avoid problems.
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/phpmailer`; # Package not valid for most linux distributions (errors reported into file LICENSE). Package should be embed by modules to avoid problems.
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/ckeditor/ckeditor/adapters`; # Keep this removal in case we embed libraries $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/ckeditor/ckeditor/adapters`; # Keep this removal in case we embed libraries
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/ckeditor/ckeditor/samples`; # Keep this removal in case we embed libraries $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/ckeditor/ckeditor/samples`; # Keep this removal in case we embed libraries
#$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/ckeditor/_source`; # _source must be kept into tarball #$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/ckeditor/_source`; # _source must be kept into tarball

View File

@ -110,4 +110,17 @@ to get
if ($className == 'Luracast\Restler\string') return; if ($className == 'Luracast\Restler\string') return;
if ($className == 'Luracast\Restler\mixed') return; if ($className == 'Luracast\Restler\mixed') return;
... ...
PARSEDOWN
---------
* Fix to avoid fatal error when mb_strlen not available:
// @CHANGE LDR Fix when mb_strlen is not available
//$shortage = 4 - mb_strlen($line, 'utf-8') % 4;
if (function_exists('mb_strlen')) $len = mb_strlen($line, 'utf-8');
else $len = strlen($line);
$shortage = 4 - $len % 4;

View File

@ -212,7 +212,7 @@ if ($xml)
// Defined qualified files (must be same than into generate_filelist_xml.php) // Defined qualified files (must be same than into generate_filelist_xml.php)
$regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$'; $regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$';
$regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install)$'; // Exclude dirs $regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs
$scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude); $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude);
// Fill file_list with files in signature, new files, modified files // Fill file_list with files in signature, new files, modified files

View File

@ -867,13 +867,33 @@ if (empty($reshook))
// Add custom code and origin country into description // Add custom code and origin country into description
if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code)))
{ {
$tmptxt = '('; // Define output language
if (! empty($prod->customcode)) if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode; $outputlangs = $langs;
if (! empty($prod->customcode) && ! empty($prod->country_code)) $newlang = '';
$tmptxt .= ' - '; if (empty($newlang) && GETPOST('lang_id','alpha'))
if (! empty($prod->country_code)) $newlang = GETPOST('lang_id','alpha');
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0); if (empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('products');
}
if (! empty($prod->customcode))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $outputlangs, 0);
} else {
if (! empty($prod->customcode))
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
}
$tmptxt .= ')'; $tmptxt .= ')';
$desc = dol_concatdesc($desc, $tmptxt); $desc = dol_concatdesc($desc, $tmptxt);
} }

View File

@ -824,12 +824,33 @@ if (empty($reshook))
// Add custom code and origin country into description // Add custom code and origin country into description
if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) { if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) {
$tmptxt = '('; $tmptxt = '(';
if (! empty($prod->customcode)) // Define output language
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode; if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
if (! empty($prod->customcode) && ! empty($prod->country_code)) $outputlangs = $langs;
$tmptxt .= ' - '; $newlang = '';
if (! empty($prod->country_code)) if (empty($newlang) && GETPOST('lang_id','alpha'))
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0); $newlang = GETPOST('lang_id','alpha');
if (empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('products');
}
if (! empty($prod->customcode))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $outputlangs, 0);
} else {
if (! empty($prod->customcode))
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
}
$tmptxt .= ')'; $tmptxt .= ')';
$desc = dol_concatdesc($desc, $tmptxt); $desc = dol_concatdesc($desc, $tmptxt);
} }

View File

@ -1644,12 +1644,32 @@ if (empty($reshook))
// Add custom code and origin country into description // Add custom code and origin country into description
if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) { if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) {
$tmptxt = '('; $tmptxt = '(';
if (! empty($prod->customcode)) // Define output language
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode; if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
if (! empty($prod->customcode) && ! empty($prod->country_code)) $outputlangs = $langs;
$tmptxt .= ' - '; $newlang = '';
if (! empty($prod->country_code)) if (empty($newlang) && GETPOST('lang_id','alpha'))
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0); $newlang = GETPOST('lang_id','alpha');
if (empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
if (! empty($prod->customcode))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $outputlangs, 0);
} else {
if (! empty($prod->customcode))
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
}
$tmptxt .= ')'; $tmptxt .= ')';
$desc = dol_concatdesc($desc, $tmptxt); $desc = dol_concatdesc($desc, $tmptxt);
} }
@ -2514,11 +2534,11 @@ if ($action == 'create')
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3);
print $desc; print $desc;
print '<div id="credit_note_options" class="clearboth">'; print '<div id="credit_note_options" class="clearboth">';
print '&nbsp;&nbsp;&nbsp; <input data-role="none" type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithPaymentRestAmount\').removeAttr(\'checked\'); }" '.(GETPOST('invoiceAvoirWithLines','int')>0 ? 'checked':'').' /> <label for="invoiceAvoirWithLines">'.$langs->trans('invoiceAvoirWithLines')."</label>"; print '&nbsp;&nbsp;&nbsp; <input data-role="none" type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="$(\'#credit_note_options input[type=checkbox]\').not(this).prop(\'checked\', false);" '.(GETPOST('invoiceAvoirWithLines','int')>0 ? 'checked':'').' /> <label for="invoiceAvoirWithLines">'.$langs->trans('invoiceAvoirWithLines')."</label>";
print '<br>&nbsp;&nbsp;&nbsp; <input data-role="none" type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithLines\').removeAttr(\'checked\'); }" '.(GETPOST('invoiceAvoirWithPaymentRestAmount','int')>0 ? 'checked':'').' /> <label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans('invoiceAvoirWithPaymentRestAmount')."</label>"; print '<br>&nbsp;&nbsp;&nbsp; <input data-role="none" type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="$(\'#credit_note_options input[type=checkbox]\').not(this).prop(\'checked\', false);" '.(GETPOST('invoiceAvoirWithPaymentRestAmount','int')>0 ? 'checked':'').' /> <label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans('invoiceAvoirWithPaymentRestAmount')."</label>";
print '</div>'; print '</div>';
print '</div></div>'; print '</div></div>';
} }
} }

View File

@ -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)); else $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr",$num));
if ($result < 0) { if ($result < 0) {
$error++; $error++;
$this->error = $mouvP->error;
} }
} }
} }

View File

@ -4,6 +4,7 @@
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com> * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr> * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2017 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -189,6 +190,6 @@ else
print $langs->trans("ErrorUnknown"); print $langs->trans("ErrorUnknown");
} }
$db->close();
llxFooter(); llxFooter();
$db->close();

View File

@ -552,14 +552,14 @@ if ($resql)
if ($search_societe) $param.='&search_societe=' .urlencode($search_societe); if ($search_societe) $param.='&search_societe=' .urlencode($search_societe);
if ($search_sale > 0) $param.='&search_sale=' .urlencode($search_sale); if ($search_sale > 0) $param.='&search_sale=' .urlencode($search_sale);
if ($search_user > 0) $param.='&search_user=' .urlencode($search_user); if ($search_user > 0) $param.='&search_user=' .urlencode($search_user);
if ($search_product_category > 0) $param.='$search_product_category=' .urlencode($search_product_category); if ($search_product_category > 0) $param.='&search_product_category=' .urlencode($search_product_category);
if ($search_montant_ht != '') $param.='&search_montant_ht='.urlencode($search_montant_ht); if ($search_montant_ht != '') $param.='&search_montant_ht='.urlencode($search_montant_ht);
if ($search_montant_vat != '') $param.='&search_montant_vat='.urlencode($search_montant_vat); if ($search_montant_vat != '') $param.='&search_montant_vat='.urlencode($search_montant_vat);
if ($search_montant_localtax1 != '') $param.='&search_montant_localtax1='.urlencode($search_montant_localtax1); if ($search_montant_localtax1 != '') $param.='&search_montant_localtax1='.urlencode($search_montant_localtax1);
if ($search_montant_localtax2 != '') $param.='&search_montant_localtax2='.urlencode($search_montant_localtax2); if ($search_montant_localtax2 != '') $param.='&search_montant_localtax2='.urlencode($search_montant_localtax2);
if ($search_montant_ttc != '') $param.='&search_montant_ttc='.urlencode($search_montant_ttc); if ($search_montant_ttc != '') $param.='&search_montant_ttc='.urlencode($search_montant_ttc);
if ($search_status != '') $param.='&search_status='.urlencode($search_status); if ($search_status != '') $param.='&search_status='.urlencode($search_status);
if ($search_paymentmode > 0) $param.='search_paymentmode='.urlencode($search_paymentmode); if ($search_paymentmode > 0) $param.='&search_paymentmode='.urlencode($search_paymentmode);
if ($show_files) $param.='&show_files=' .$show_files; if ($show_files) $param.='&show_files=' .$show_files;
if ($option) $param.="&option=".$option; if ($option) $param.="&option=".$option;
if ($optioncss != '') $param.='&optioncss='.$optioncss; if ($optioncss != '') $param.='&optioncss='.$optioncss;

View File

@ -46,14 +46,14 @@ $confirm=GETPOST('confirm', 'alpha');
// Security check // Security check
$fieldname = (! empty($ref)?'ref':'rowid'); $fieldname = (! empty($ref)?'ref':'rowid');
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'cheque', $id, 'bordereau_cheque','','',$fieldname); $result = restrictedArea($user, 'cheque', $id, 'bordereau_cheque','','fk_user_author',$fieldname);
$sortfield=GETPOST('sortfield', 'alpha'); $sortfield=GETPOST('sortfield', 'alpha');
$sortorder=GETPOST('sortorder', 'alpha'); $sortorder=GETPOST('sortorder', 'alpha');
$page=GETPOST('page', 'int'); $page=GETPOST('page', 'int');
if (! $sortorder) $sortorder="ASC"; if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="b.dateo,b.rowid"; if (! $sortfield) $sortfield="b.dateo,b.rowid";
if ($page < 0) { $page = 0 ; } if (empty($page) || $page == -1) { $page = 0; }
$limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
$offset = $limit * $page ; $offset = $limit * $page ;
@ -490,53 +490,55 @@ if ($action == 'new')
if (count($lines[$bid])) if (count($lines[$bid]))
{ {
foreach ($lines[$bid] as $lid => $value) foreach ($lines[$bid] as $lid => $value)
{ {
$account_id = $bid; //$account_id = $bid; FIXME not used
if (! isset($accounts[$bid]))
$accounts[$bid]=0;
$accounts[$bid] += 1;
print '<tr class="oddeven">'; // FIXME $accounts[$bid] is a label !
print '<td>'.dol_print_date($value["date"],'day').'</td>'; /*if (! isset($accounts[$bid]))
print '<td>'.$value["numero"]."</td>\n"; $accounts[$bid]=0;
print '<td>'.$value["emetteur"]."</td>\n"; $accounts[$bid] += 1;*/
print '<td>'.$value["banque"]."</td>\n";
print '<td align="right">'.price($value["amount"], 0, $langs, 1, -1, -1, $conf->currency).'</td>';
// Link to payment print '<tr class="oddeven">';
print '<td align="center">'; print '<td>'.dol_print_date($value["date"],'day').'</td>';
$paymentstatic->id=$value["paymentid"]; print '<td>'.$value["numero"]."</td>\n";
$paymentstatic->ref=$value["paymentid"]; print '<td>'.$value["emetteur"]."</td>\n";
if ($paymentstatic->id) print '<td>'.$value["banque"]."</td>\n";
{ print '<td align="right">'.price($value["amount"], 0, $langs, 1, -1, -1, $conf->currency).'</td>';
print $paymentstatic->getNomUrl(1);
}
else
{
print '&nbsp;';
}
print '</td>';
// Link to bank transaction
print '<td align="center">';
$accountlinestatic->rowid=$value["id"];
if ($accountlinestatic->rowid)
{
print $accountlinestatic->getNomUrl(1);
}
else
{
print '&nbsp;';
}
print '</td>';
print '<td align="center">'; // Link to payment
print '<input id="'.$value["id"].'" class="flat checkforremise_'.$bid.'" checked type="checkbox" name="toRemise[]" value="'.$value["id"].'">'; print '<td align="center">';
print '</td>' ; $paymentstatic->id=$value["paymentid"];
print '</tr>'; $paymentstatic->ref=$value["paymentid"];
if ($paymentstatic->id)
{
print $paymentstatic->getNomUrl(1);
}
else
{
print '&nbsp;';
}
print '</td>';
// Link to bank transaction
print '<td align="center">';
$accountlinestatic->rowid=$value["id"];
if ($accountlinestatic->rowid)
{
print $accountlinestatic->getNomUrl(1);
}
else
{
print '&nbsp;';
}
print '</td>';
$i++; print '<td align="center">';
} print '<input id="'.$value["id"].'" class="flat checkforremise_'.$bid.'" checked type="checkbox" name="toRemise[]" value="'.$value["id"].'">';
print '</td>' ;
print '</tr>';
$i++;
}
} }
print "</table>"; print "</table>";
print '</div>'; print '</div>';
@ -688,10 +690,12 @@ else
{ {
while ($objp = $db->fetch_object($resql)) while ($objp = $db->fetch_object($resql))
{ {
$account_id = $objp->bid; //$account_id = $objp->bid; FIXME not used
if (! isset($accounts[$objp->bid]))
// FIXME $accounts[$objp->bid] is a label
/*if (! isset($accounts[$objp->bid]))
$accounts[$objp->bid]=0; $accounts[$objp->bid]=0;
$accounts[$objp->bid] += 1; $accounts[$objp->bid] += 1;*/
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td align="center">'.$i.'</td>'; print '<td align="center">'.$i.'</td>';

View File

@ -413,6 +413,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$object->trackid = $trackid; $object->trackid = $trackid;
$object->fk_element = $object->id; $object->fk_element = $object->id;
$object->elementtype = $object->element; $object->elementtype = $object->element;
$object->attachedfiles = $attachedfiles;
// Call of triggers // Call of triggers
if (! empty($trigger_name)) if (! empty($trigger_name))

View File

@ -83,8 +83,8 @@ class Conf
$this->file = new stdClass(); $this->file = new stdClass();
$this->db = new stdClass(); $this->db = new stdClass();
$this->global = new stdClass(); $this->global = new stdClass();
$this->mycompany = new stdClass(); $this->mycompany = new stdClass();
$this->admin = new stdClass(); $this->admin = new stdClass();
$this->user = new stdClass(); $this->user = new stdClass();
$this->syslog = new stdClass(); $this->syslog = new stdClass();
$this->browser = new stdClass(); $this->browser = new stdClass();

View File

@ -6,7 +6,7 @@
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr> * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com> * Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
* Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es> * Copyright (C) 2016-2017 Ferran Marcet <fmarcet@2byte.es>
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -938,9 +938,9 @@ class FormFile
if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.'; if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
} }
// For backward compatiblity, we detect file is stored into an old path // For backward compatiblity, we detect file is stored into an old path
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $file['level1name'] == 'photos') if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos')
{ {
$relativepath=preg_replace('/^.*\/produit\//','',$file['path']).'/'; $relativepath=preg_replace('/^.*\/produit\//','',$filearray[0]['path']).'/';
} }
// Defined relative dir to DOL_DATA_ROOT // Defined relative dir to DOL_DATA_ROOT
$relativedir = ''; $relativedir = '';

View File

@ -1359,10 +1359,10 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint=
else $out.='-'.dol_print_date($histo[$key]['dateend'],'dayhour'); else $out.='-'.dol_print_date($histo[$key]['dateend'],'dayhour');
} }
$late=0; $late=0;
if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $db->jdate($histo[$key]['datestart']) < ($now - $delay_warning)) $late=1; if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late=1;
if ($histo[$key]['percent'] == 0 && ! $histo[$key]['datestart'] && $histo[$key]['dateend'] && $db->jdate($histo[$key]['datestart']) < ($now - $delay_warning)) $late=1; if ($histo[$key]['percent'] == 0 && ! $histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late=1;
if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $db->jdate($histo[$key]['dateend']) < ($now - $delay_warning)) $late=1; if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) $late=1;
if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && ! $histo[$key]['dateend'] && $histo[$key]['datestart'] && $db->jdate($histo[$key]['datestart']) < ($now - $delay_warning)) $late=1; if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && ! $histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late=1;
if ($late) $out.=img_warning($langs->trans("Late")).' '; if ($late) $out.=img_warning($langs->trans("Late")).' ';
$out.="</td>\n"; $out.="</td>\n";

View File

@ -46,7 +46,7 @@ function dol_basename($pathfile)
* @param int $recursive Determines whether subdirectories are searched * @param int $recursive Determines whether subdirectories are searched
* @param string $filter Regex filter to restrict list. This regex value must be escaped for '/' by doing preg_quote($var,'/'), since this char is used for preg_match function, * @param string $filter Regex filter to restrict list. This regex value must be escaped for '/' by doing preg_quote($var,'/'), since this char is used for preg_match function,
* but must not contains the start and end '/'. Filter is checked into basename only. * but must not contains the start and end '/'. Filter is checked into basename only.
* @param array $excludefilter Array of Regex for exclude filter (example: array('(\.meta|_preview.*\.png)$','^\.')). Exclude is checked into fullpath. * @param array $excludefilter Array of Regex for exclude filter (example: array('(\.meta|_preview.*\.png)$','^\.')). Exclude is checked both into fullpath and into basename (So '^xxx' may exclude 'xxx/dirscanned/...' and dirscanned/xxx').
* @param string $sortcriteria Sort criteria ("","fullname","relativename","name","date","size") * @param string $sortcriteria Sort criteria ("","fullname","relativename","name","date","size")
* @param string $sortorder Sort order (SORT_ASC, SORT_DESC) * @param string $sortorder Sort order (SORT_ASC, SORT_DESC)
* @param int $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only * @param int $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only
@ -107,6 +107,7 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
while (false !== ($file = readdir($dir))) // $file is always a basename (into directory $newpath) while (false !== ($file = readdir($dir))) // $file is always a basename (into directory $newpath)
{ {
if (! utf8_check($file)) $file=utf8_encode($file); // To be sure data is stored in utf8 in memory if (! utf8_check($file)) $file=utf8_encode($file); // To be sure data is stored in utf8 in memory
$fullpathfile=($newpath?$newpath.'/':'').$file;
$qualified=1; $qualified=1;
@ -120,10 +121,11 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
// Check if file is qualified // Check if file is qualified
foreach($excludefilterarray as $filt) foreach($excludefilterarray as $filt)
{ {
if (preg_match('/'.$filt.'/i',$file)) { if (preg_match('/'.$filt.'/i', $file) || preg_match('/'.$filt.'/i', $fullpathfile)) {
$qualified=0; break; $qualified=0; break;
} }
} }
//print $fullpathfile.' '.$file.' '.$qualified.'<br>';
if ($qualified) if ($qualified)
{ {

View File

@ -238,6 +238,17 @@ function dol_shutdown()
} }
/**
* Return true if we are in a context of submitting a parameter
*
* @param string $paramname Name or parameter to test
* @return boolean True if we have just submit a POST or GET request with the parameter provided (even if param is empty)
*/
function GETPOSTISSET($paramname)
{
return (isset($_POST[$paramname]) || isset($_GET[$paramname]));
}
/** /**
* Return value of a param into GET or POST supervariable. * Return value of a param into GET or POST supervariable.
* Use the property $user->default_values[path]['creatform'] and/or $user->default_values[path]['filters'] and/or $user->default_values[path]['sortorder'] * Use the property $user->default_values[path]['creatform'] and/or $user->default_values[path]['filters'] and/or $user->default_values[path]['sortorder']

View File

@ -242,9 +242,9 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu
{ {
foreach($feature2 as $subfeature) foreach($feature2 as $subfeature)
{ {
if (empty($user->rights->$feature->$subfeature->creer) if (empty($user->rights->$feature->$subfeature->creer)
&& empty($user->rights->$feature->$subfeature->write) && empty($user->rights->$feature->$subfeature->write)
&& empty($user->rights->$feature->$subfeature->create)) { $createok=0; $nbko++; } && empty($user->rights->$feature->$subfeature->create)) { $createok=0; $nbko++; }
else { $createok=1; break; } // Break to bypass second test if the first is ok else { $createok=1; break; } // Break to bypass second test if the first is ok
} }
} }
@ -306,6 +306,9 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu
else if ($feature == 'ftp') else if ($feature == 'ftp')
{ {
if (! $user->rights->ftp->write) $deleteok=0; if (! $user->rights->ftp->write) $deleteok=0;
}else if ($feature == 'salaries')
{
if (! $user->rights->salaries->delete) $deleteok=0;
} }
else if (! empty($feature2)) // This should be used for future changes else if (! empty($feature2)) // This should be used for future changes
{ {

View File

@ -65,7 +65,7 @@ class mailing_fraise extends MailingTargets
*/ */
function getSqlArrayForStats() function getSqlArrayForStats()
{ {
global $langs; global $conf, $langs;
$langs->load("members"); $langs->load("members");
@ -73,7 +73,7 @@ class mailing_fraise extends MailingTargets
$statssql=array(); $statssql=array();
$statssql[0] ="SELECT '".$this->db->escape($langs->trans("FundationMembers"))."' as label, count(*) as nb"; $statssql[0] ="SELECT '".$this->db->escape($langs->trans("FundationMembers"))."' as label, count(*) as nb";
$statssql[0].=" FROM ".MAIN_DB_PREFIX."adherent where statut = 1"; $statssql[0].=" FROM ".MAIN_DB_PREFIX."adherent where statut = 1 and entity IN (".getEntity('member').")";
return $statssql; return $statssql;
} }
@ -89,9 +89,11 @@ class mailing_fraise extends MailingTargets
*/ */
function getNbOfRecipients($sql='') function getNbOfRecipients($sql='')
{ {
global $conf;
$sql = "SELECT count(distinct(a.email)) as nb"; $sql = "SELECT count(distinct(a.email)) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as a"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
$sql .= " WHERE (a.email IS NOT NULL AND a.email != '')"; $sql .= " WHERE (a.email IS NOT NULL AND a.email != '') AND a.entity IN (".getEntity('member').")";
// La requete doit retourner un champ "nb" pour etre comprise // La requete doit retourner un champ "nb" pour etre comprise
// par parent::getNbOfRecipients // par parent::getNbOfRecipients
@ -201,7 +203,7 @@ class mailing_fraise extends MailingTargets
$sql.= " a.lastname, a.firstname,"; $sql.= " a.lastname, a.firstname,";
$sql.= " a.datefin, a.civility as civility_id, a.login, a.societe"; // Other fields $sql.= " a.datefin, a.civility as civility_id, a.login, a.societe"; // Other fields
$sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta";
$sql.= " WHERE a.email <> ''"; // Note that null != '' is false $sql.= " WHERE a.entity IN (".getEntity('member').") AND a.email <> ''"; // Note that null != '' is false
$sql.= " AND a.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; $sql.= " AND a.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
if (isset($_POST["filter"]) && $_POST["filter"] == '-1') $sql.= " AND a.statut=-1"; if (isset($_POST["filter"]) && $_POST["filter"] == '-1') $sql.= " AND a.statut=-1";
if (isset($_POST["filter"]) && $_POST["filter"] == '1a') $sql.= " AND a.statut=1 AND a.datefin >= '".$this->db->idate($now)."'"; if (isset($_POST["filter"]) && $_POST["filter"] == '1a') $sql.= " AND a.statut=1 AND a.datefin >= '".$this->db->idate($now)."'";

View File

@ -54,7 +54,7 @@ $nb=array();
$somme=array(); $somme=array();
$sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut"; $sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
$sql.= " FROM ".MAIN_DB_PREFIX."don as d"; $sql.= " FROM ".MAIN_DB_PREFIX."don as d WHERE d.entity IN (".getEntity('donation').")";
$sql.= " GROUP BY d.fk_statut"; $sql.= " GROUP BY d.fk_statut";
$sql.= " ORDER BY d.fk_statut"; $sql.= " ORDER BY d.fk_statut";

View File

@ -30,9 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
$langs->load("sendings"); $langs->loadLangs(array("sendings","deliveries",'companies','bills'));
$langs->load("deliveries");
$langs->load('companies');
$socid=GETPOST('socid','int'); $socid=GETPOST('socid','int');
// Security check // Security check

View File

@ -31,7 +31,7 @@
*/ */
if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE','Dolibarr'); if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE','Dolibarr');
if (! defined('DOL_VERSION')) define('DOL_VERSION','6.0.4'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c if (! defined('DOL_VERSION')) define('DOL_VERSION','6.0.5'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c
if (! defined('EURO')) define('EURO',chr(128)); if (! defined('EURO')) define('EURO',chr(128));

View File

@ -989,7 +989,7 @@ class Holiday extends CommonObject
while ($i < $nbUser) while ($i < $nbUser)
{ {
$now_holiday = $this->getCPforUser($users[$i]['rowid'], $val['rowid']); $now_holiday = $this->getCPforUser($users[$i]['rowid'], $val['rowid']);
$new_solde = $now_holiday + $this->getConfCP('nbHolidayEveryMonth'); $new_solde = $now_holiday + $nb_holiday;
// We add a log for each user // We add a log for each user
$this->addLogCP($user->id, $users[$i]['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $new_solde, $val['rowid']); $this->addLogCP($user->id, $users[$i]['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $new_solde, $val['rowid']);
@ -1309,15 +1309,15 @@ class Holiday extends CommonObject
// List for Dolibarr users // List for Dolibarr users
if ($type) if ($type)
{ {
$sql = "SELECT u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut"; $sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
{ {
$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug"; $sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
$sql.= " WHERE (ug.fk_user = u.rowid"; $sql.= " WHERE ((ug.fk_user = u.rowid";
$sql.= " AND ug.entity = ".$conf->entity.")"; $sql.= " AND ug.entity = ".$conf->entity.")";
$sql.= " OR u.admin = 1"; $sql.= " OR u.admin = 1)";
} }
else else
$sql.= " WHERE u.entity IN (0,".$conf->entity.")"; $sql.= " WHERE u.entity IN (0,".$conf->entity.")";

View File

@ -141,7 +141,11 @@ class Parsedown
foreach ($parts as $part) foreach ($parts as $part)
{ {
$shortage = 4 - mb_strlen($line, 'utf-8') % 4; // @CHANGE LDR Fix when mb_strlen is not available
//$shortage = 4 - mb_strlen($line, 'utf-8') % 4;
if (function_exists('mb_strlen')) $len = mb_strlen($line, 'utf-8');
else $len = strlen($line);
$shortage = 4 - $len % 4;
$line .= str_repeat(' ', $shortage); $line .= str_repeat(' ', $shortage);
$line .= $part; $line .= $part;
@ -515,10 +519,10 @@ class Parsedown
), ),
); );
if($name === 'ol') if($name === 'ol')
{ {
$listStart = stristr($matches[0], '.', true); $listStart = stristr($matches[0], '.', true);
if($listStart !== '1') if($listStart !== '1')
{ {
$Block['element']['attributes'] = array('start' => $listStart); $Block['element']['attributes'] = array('start' => $listStart);

View File

@ -367,7 +367,7 @@ $showweather=empty($conf->global->MAIN_DISABLE_METEO)?1:0;
$dashboardlines=array(); $dashboardlines=array();
// Do not include sections without management permission // Do not include sections without management permission
require DOL_DOCUMENT_ROOT.'/core/class/workboardresponse.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/workboardresponse.class.php';
// Number of actions to do (late) // Number of actions to do (late)
if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->read) if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->read)
@ -548,7 +548,7 @@ if (! empty($valid_dashboardlines))
$boxwork.='<tr class="nohover"><td class="tdboxstats nohover flexcontainer centpercent">'; $boxwork.='<tr class="nohover"><td class="tdboxstats nohover flexcontainer centpercent">';
foreach($valid_dashboardlines as $board) foreach($valid_dashboardlines as $board)
{ {
if (empty($boad->nbtodo)) $nbworkboardempty++; if (empty($board->nbtodo)) $nbworkboardempty++;
$textlate = $langs->trans("NActionsLate",$board->nbtodolate); $textlate = $langs->trans("NActionsLate",$board->nbtodolate);
$textlate.= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($board->warning_delay) >= 0 ? '+' : '').ceil($board->warning_delay).' '.$langs->trans("days").')'; $textlate.= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($board->warning_delay) >= 0 ? '+' : '').ceil($board->warning_delay).' '.$langs->trans("days").')';

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2014-2017 Alexandre Spangaro <aspangaro@zendsi.com> /* Copyright (C) 2014-2017 Alexandre Spangaro <aspangaro@zendsi.com>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr> * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* *
@ -18,9 +18,9 @@
*/ */
/** /**
* \file htdocs/loan/card.php * \file htdocs/loan/card.php
* \ingroup loan * \ingroup loan
* \brief Loan card * \brief Loan card
*/ */
require '../main.inc.php'; require '../main.inc.php';
@ -61,129 +61,81 @@ $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) if (empty($reshook))
{ {
// Classify paid // Classify paid
if ($action == 'confirm_paid' && $confirm == 'yes') if ($action == 'confirm_paid' && $confirm == 'yes')
{ {
$object->fetch($id); $object->fetch($id);
$result = $object->set_paid($user); $result = $object->set_paid($user);
if ($result > 0) if ($result > 0)
{ {
setEventMessages($langs->trans('LoanPaid'), null, 'mesgs'); setEventMessages($langs->trans('LoanPaid'), null, 'mesgs');
} }
else else
{ {
setEventMessages($loan->error, null, 'errors'); setEventMessages($loan->error, null, 'errors');
} }
} }
// Delete loan // Delete loan
if ($action == 'confirm_delete' && $confirm == 'yes') if ($action == 'confirm_delete' && $confirm == 'yes')
{ {
$object->fetch($id); $object->fetch($id);
$result=$object->delete($user); $result=$object->delete($user);
if ($result > 0) if ($result > 0)
{ {
setEventMessages($langs->trans('LoanDeleted'), null, 'mesgs'); setEventMessages($langs->trans('LoanDeleted'), null, 'mesgs');
header("Location: index.php"); header("Location: index.php");
exit; exit;
} }
else else
{ {
setEventMessages($loan->error, null, 'errors'); setEventMessages($loan->error, null, 'errors');
} }
} }
// Add loan // Add loan
if ($action == 'add' && $user->rights->loan->write) if ($action == 'add' && $user->rights->loan->write)
{ {
if (! $cancel) if (! $cancel)
{ {
$datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int')); $datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
$dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int')); $dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
$capital = price2num(GETPOST('capital')); $capital = price2num(GETPOST('capital'));
$rate = GETPOST('rate'); $rate = GETPOST('rate');
if (! $capital) if (! $capital)
{ {
$error++; $action = 'create'; $error++; $action = 'create';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
} }
if (! $datestart) if (! $datestart)
{ {
$error++; $action = 'create'; $error++; $action = 'create';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateStart")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateStart")), null, 'errors');
} }
if (! $dateend) if (! $dateend)
{ {
$error++; $action = 'create'; $error++; $action = 'create';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateEnd")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateEnd")), null, 'errors');
} }
if ($rate == '') if ($rate == '')
{ {
$error++; $action = 'create'; $error++; $action = 'create';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rate")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rate")), null, 'errors');
} }
if (! $error) if (! $error)
{ {
$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'); $object->note_private = GETPOST('note_private');
$object->note_public = GETPOST('note_public'); $object->note_public = GETPOST('note_public');
$object->fk_project = GETPOST('projectid','int'); $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");
$accountancy_account_capital = GETPOST('accountancy_account_capital'); $accountancy_account_capital = GETPOST('accountancy_account_capital');
$accountancy_account_insurance = GETPOST('accountancy_account_insurance'); $accountancy_account_insurance = GETPOST('accountancy_account_insurance');
@ -192,43 +144,91 @@ if (empty($reshook))
if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; } if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; }
if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; } if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; }
if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; } if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; }
}
$result = $object->update($user); $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) // Update record
{ else if ($action == 'update' && $user->rights->loan->write)
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); {
exit; if (! $cancel)
} {
else $result = $object->fetch($id);
{
setEventMessages($object->error, $object->errors, 'errors'); $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'));
else
{ if (! $capital)
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); {
exit; 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 // Link to a project
if ($action == 'classin' && $user->rights->loan->write) if ($action == 'classin' && $user->rights->loan->write)
{ {
$object->fetch($id); $object->fetch($id);
$result = $object->setProject($projectid); $result = $object->setProject($projectid);
if ($result < 0) if ($result < 0)
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
if ($action == 'setlabel' && $user->rights->loan->write) if ($action == 'setlabel' && $user->rights->loan->write)
{ {
$object->fetch($id); $object->fetch($id);
$result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY'); $result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY');
if ($result < 0) if ($result < 0)
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
} }
@ -249,19 +249,19 @@ llxHeader("",$title,$help_url);
if ($action == 'create') if ($action == 'create')
{ {
//WYSIWYG Editor //WYSIWYG Editor
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
print load_fiche_titre($langs->trans("NewLoan"), '', 'title_accountancy.png'); print load_fiche_titre($langs->trans("NewLoan"), '', 'title_accountancy.png');
$datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int')); $datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
print '<form name="loan" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n"; print '<form name="loan" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
dol_fiche_head(); dol_fiche_head();
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Label // Label
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Label").'</td><td><input name="label" size="40" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label')).'"></td></tr>'; print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Label").'</td><td><input name="label" size="40" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label')).'"></td></tr>';
@ -280,97 +280,97 @@ if ($action == 'create')
print '</td></tr>'; print '</td></tr>';
} }
// Capital // Capital
print '<tr><td class="fieldrequired">'.$langs->trans("LoanCapital").'</td><td><input name="capital" size="10" value="' . dol_escape_htmltag(GETPOST("capital")) . '"></td></tr>'; print '<tr><td class="fieldrequired">'.$langs->trans("LoanCapital").'</td><td><input name="capital" size="10" value="' . dol_escape_htmltag(GETPOST("capital")) . '"></td></tr>';
// Date Start // Date Start
print "<tr>"; print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>'; print '<td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
print $form->select_date($datestart?$datestart:-1,'start','','','','add',1,1,1); print $form->select_date($datestart?$datestart:-1,'start','','','','add',1,1,1);
print '</td></tr>'; print '</td></tr>';
// Date End // Date End
print "<tr>"; print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>'; print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
print $form->select_date($dateend?$dateend:-1,'end','','','','add',1,1,1); print $form->select_date($dateend?$dateend:-1,'end','','','','add',1,1,1);
print '</td></tr>'; print '</td></tr>';
// Number of terms // Number of terms
print '<tr><td class="fieldrequired">'.$langs->trans("Nbterms").'</td><td><input name="nbterm" size="5" value="' . dol_escape_htmltag(GETPOST('nbterm')) . '"></td></tr>'; print '<tr><td class="fieldrequired">'.$langs->trans("Nbterms").'</td><td><input name="nbterm" size="5" value="' . dol_escape_htmltag(GETPOST('nbterm')) . '"></td></tr>';
// Rate // Rate
print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="' . dol_escape_htmltag(GETPOST("rate")) . '"> %</td></tr>'; print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="' . dol_escape_htmltag(GETPOST("rate")) . '"> %</td></tr>';
// Project // Project
if (! empty($conf->projet->enabled)) if (! empty($conf->projet->enabled))
{ {
$formproject=new FormProjets($db); $formproject=new FormProjets($db);
// Projet associe // Projet associe
$langs->load("projects"); $langs->load("projects");
print '<tr><td>'.$langs->trans("Project").'</td><td>'; print '<tr><td>'.$langs->trans("Project").'</td><td>';
$numproject=$formproject->select_projects(-1, $projectid, 'projectid', 16, 0, 1, 1); $numproject=$formproject->select_projects(-1, $projectid, 'projectid', 16, 0, 1, 1);
print '</td></tr>'; print '</td></tr>';
} }
// Note Private // Note Private
print '<tr>'; print '<tr>';
print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>'; print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
print '<td>'; print '<td>';
$doleditor = new DolEditor('note_private', GETPOST('note_private', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%'); $doleditor = new DolEditor('note_private', GETPOST('note_private', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%');
print $doleditor->Create(1); print $doleditor->Create(1);
print '</td></tr>'; print '</td></tr>';
// Note Public // Note Public
print '<tr>'; print '<tr>';
print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>'; print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
print '<td>'; print '<td>';
$doleditor = new DolEditor('note_public', GETPOST('note_public', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%'); $doleditor = new DolEditor('note_public', GETPOST('note_public', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, true, ROWS_6, '90%');
print $doleditor->Create(1); print $doleditor->Create(1);
print '</td></tr>'; print '</td></tr>';
// Accountancy // Accountancy
if (! empty($conf->accounting->enabled)) if (! empty($conf->accounting->enabled))
{ {
// Accountancy_account_capital // Accountancy_account_capital
print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>'; print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
print '<td>'; print '<td>';
print $formaccounting->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1); print $formaccounting->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1);
print '</td></tr>'; print '</td></tr>';
// Accountancy_account_insurance // Accountancy_account_insurance
print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
print '<td>'; print '<td>';
print $formaccounting->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1); print $formaccounting->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1);
print '</td></tr>'; print '</td></tr>';
// Accountancy_account_interest // Accountancy_account_interest
print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>';
print '<td>'; print '<td>';
print $formaccounting->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1); print $formaccounting->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1);
print '</td></tr>'; print '</td></tr>';
} }
else // For external software else // For external software
{ {
// Accountancy_account_capital // Accountancy_account_capital
print '<tr><td class="titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>'; print '<tr><td class="titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">'; print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
print '</td></tr>'; print '</td></tr>';
// Accountancy_account_insurance // Accountancy_account_insurance
print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>'; print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">'; print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">';
print '</td></tr>'; print '</td></tr>';
// Accountancy_account_interest // Accountancy_account_interest
print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>'; print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>';
print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">'; print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">';
print '</td></tr>'; print '</td></tr>';
} }
print '</table>'; print '</table>';
@ -382,14 +382,14 @@ if ($action == 'create')
print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">'; print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
print '</div>'; print '</div>';
print '</form>'; print '</form>';
} }
// View // View
if ($id > 0) if ($id > 0)
{ {
$object = new Loan($db); $object = new Loan($db);
$result = $object->fetch($id); $result = $object->fetch($id);
if ($result > 0) if ($result > 0)
{ {
@ -413,9 +413,9 @@ if ($id > 0)
if ($action == 'edit') if ($action == 'edit')
{ {
print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n"; print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">'; print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$id.'">'; print '<input type="hidden" name="id" value="'.$id.'">';
} }
dol_fiche_head($head, 'card', $langs->trans("Loan"), -1, 'bill'); dol_fiche_head($head, 'card', $langs->trans("Loan"), -1, 'bill');
@ -441,40 +441,40 @@ if ($id > 0)
$morehtmlref.=$form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', 0, 1); $morehtmlref.=$form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', 0, 1);
$morehtmlref.=$form->editfieldval("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', null, null, '', 1); $morehtmlref.=$form->editfieldval("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', null, null, '', 1);
// Project // Project
if (! empty($conf->projet->enabled)) if (! empty($conf->projet->enabled))
{ {
$langs->load("projects"); $langs->load("projects");
$morehtmlref.='<br>'.$langs->trans('Project') . ' '; $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
if ($user->rights->loan->write) if ($user->rights->loan->write)
{ {
if ($action != 'classify') if ($action != 'classify')
$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; $morehtmlref.='<a 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.'">';
$morehtmlref.='<input type="hidden" name="action" value="classin">'; $morehtmlref.='<input type="hidden" name="action" value="classin">';
$morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
$morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref.='</form>'; $morehtmlref.='</form>';
} else { } else {
$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
} }
} else { } else {
if (! empty($object->fk_project)) { if (! empty($object->fk_project)) {
$proj = new Project($db); $proj = new Project($db);
$proj->fetch($object->fk_project); $proj->fetch($object->fk_project);
$morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">'; $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
$morehtmlref.=$proj->ref; $morehtmlref.=$proj->ref;
$morehtmlref.='</a>'; $morehtmlref.='</a>';
} else { } else {
$morehtmlref.=''; $morehtmlref.='';
} }
} }
} }
$morehtmlref.='</div>'; $morehtmlref.='</div>';
$object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
@ -496,7 +496,7 @@ if ($id > 0)
print '<tr><td class="titlefield">'.$langs->trans("LoanCapital").'</td><td>'.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>'; print '<tr><td class="titlefield">'.$langs->trans("LoanCapital").'</td><td>'.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
} }
// Date start // Date start
print '<tr><td>'.$langs->trans("DateStart")."</td>"; print '<tr><td>'.$langs->trans("DateStart")."</td>";
print "<td>"; print "<td>";
if ($action == 'edit') if ($action == 'edit')
@ -548,15 +548,15 @@ if ($id > 0)
} }
print '</td></tr>'; print '</td></tr>';
// Accountancy account capital // Accountancy account capital
print '<tr><td class="nowrap">'; print '<tr><td class="nowrap">';
print $langs->trans("LoanAccountancyCapitalCode"); print $langs->trans("LoanAccountancyCapitalCode");
print '</td><td>'; print '</td><td>';
if ($action == 'edit') if ($action == 'edit')
{ {
if (! empty($conf->accounting->enabled)) if (! empty($conf->accounting->enabled))
{ {
print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 0, 1); print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 1, 1);
} }
else else
{ {
@ -573,15 +573,15 @@ if ($id > 0)
} }
print '</td></tr>'; print '</td></tr>';
// Accountancy account insurance // Accountancy account insurance
print '<tr><td class="nowrap">'; print '<tr><td class="nowrap">';
print $langs->trans("LoanAccountancyInsuranceCode"); print $langs->trans("LoanAccountancyInsuranceCode");
print '</td><td>'; print '</td><td>';
if ($action == 'edit') if ($action == 'edit')
{ {
if (! empty($conf->accounting->enabled)) if (! empty($conf->accounting->enabled))
{ {
print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 0, 1); print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 1, 1);
} }
else else
{ {
@ -600,13 +600,13 @@ if ($id > 0)
// Accountancy account interest // Accountancy account interest
print '<tr><td class="nowrap">'; print '<tr><td class="nowrap">';
print $langs->trans("LoanAccountancyInterestCode"); print $langs->trans("LoanAccountancyInterestCode");
print '</td><td>'; print '</td><td>';
if ($action == 'edit') if ($action == 'edit')
{ {
if (! empty($conf->accounting->enabled)) if (! empty($conf->accounting->enabled))
{ {
print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 0, 1); print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 1, 1);
} }
else else
{ {
@ -650,9 +650,9 @@ if ($id > 0)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
$total_insurance = 0; $total_insurance = 0;
$total_interest = 0; $total_interest = 0;
$total_capital = 0; $total_capital = 0;
print '<table class="noborder paymenttable">'; print '<table class="noborder paymenttable">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("RefPayment").'</td>'; print '<td>'.$langs->trans("RefPayment").'</td>';
@ -660,8 +660,8 @@ if ($id > 0)
print '<td>'.$langs->trans("Type").'</td>'; print '<td>'.$langs->trans("Type").'</td>';
print '<td align="right">'.$langs->trans("Insurance").'</td>'; print '<td align="right">'.$langs->trans("Insurance").'</td>';
print '<td align="right">'.$langs->trans("Interest").'</td>'; print '<td align="right">'.$langs->trans("Interest").'</td>';
print '<td align="right">'.$langs->trans("LoanCapital").'</td>'; print '<td align="right">'.$langs->trans("LoanCapital").'</td>';
print '</tr>'; print '</tr>';
$var=True; $var=True;
while ($i < $num) while ($i < $num)
@ -672,11 +672,11 @@ if ($id > 0)
print '<td><a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>'; print '<td><a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n"; print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
print "<td>".$objp->paiement_type.' '.$objp->num_payment."</td>\n"; print "<td>".$objp->paiement_type.' '.$objp->num_payment."</td>\n";
print '<td align="right">'.price($objp->amount_insurance, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n"; print '<td align="right">'.price($objp->amount_insurance, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n";
print '<td align="right">'.price($objp->amount_interest, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n"; print '<td align="right">'.price($objp->amount_interest, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n";
print '<td align="right">'.price($objp->amount_capital, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n"; print '<td align="right">'.price($objp->amount_capital, 0, $langs, 0, 0, -1, $conf->currency)."</td>\n";
print "</tr>"; print "</tr>";
$total_capital += $objp->amount_capital; $total_capital += $objp->amount_capital;
$i++; $i++;
} }
@ -716,47 +716,47 @@ if ($id > 0)
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">'; print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>'; print '</div>';
print '</form>'; print '</form>';
} }
/* /*
* Buttons actions * Buttons actions
*/ */
if ($action != 'edit') if ($action != 'edit')
{ {
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if (empty($reshook)) if (empty($reshook))
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
// Edit // Edit
if ($user->rights->loan->write) if ($user->rights->loan->write)
{ {
print '<a href="javascript:popEcheancier()" class="butAction">'.$langs->trans('CreateCalcSchedule').'</a>'; print '<a href="javascript:popEcheancier()" class="butAction">'.$langs->trans('CreateCalcSchedule').'</a>';
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>'; print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
} }
// Emit payment // Emit payment
if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write) if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write)
{ {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&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>';
} }
// Classify 'paid' // Classify 'paid'
if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write) if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write)
{ {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=paid">'.$langs->trans("ClassifyPaid").'</a>'; print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=paid">'.$langs->trans("ClassifyPaid").'</a>';
} }
// Delete // Delete
if ($user->rights->loan->delete) if ($user->rights->loan->delete)
{ {
print '<a class="butActionDelete" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>'; print '<a class="butActionDelete" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
} }
print "</div>"; print "</div>";
} }
} }
} }
else else

View File

@ -17,128 +17,128 @@
*/ */
/** /**
* \file htdocs/loan/class/loan.class.php * \file htdocs/loan/class/loan.class.php
* \ingroup loan * \ingroup loan
* \brief Class for loan module * \brief Class for loan module
*/ */
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
/** /**
* Loan * Loan
*/ */
class Loan extends CommonObject class Loan extends CommonObject
{ {
public $element='loan'; public $element='loan';
public $table='loan'; public $table='loan';
public $table_element='loan'; public $table_element='loan';
public $picto = 'bill'; public $picto = 'bill';
public $rowid; public $rowid;
public $datestart; public $datestart;
public $dateend; public $dateend;
public $label; public $label;
public $capital; public $capital;
public $nbterm; public $nbterm;
public $rate; public $rate;
public $paid; public $paid;
public $account_capital; public $account_capital;
public $account_insurance; public $account_insurance;
public $account_interest; public $account_interest;
public $date_creation; public $date_creation;
public $date_modification; public $date_modification;
public $date_validation; public $date_validation;
public $fk_bank; public $fk_bank;
public $fk_user_creat; public $fk_user_creat;
public $fk_user_modif; public $fk_user_modif;
public $fk_project; public $fk_project;
/** /**
* Constructor * Constructor
* *
* @param DoliDB $db Database handler * @param DoliDB $db Database handler
*/ */
function __construct($db) function __construct($db)
{ {
$this->db = $db; $this->db = $db;
return 1; return 1;
} }
/** /**
* Load object in memory from database * Load object in memory from database
* *
* @param int $id id object * @param int $id id object
* @return int <0 error , >=0 no error * @return int <0 error , >=0 no error
*/ */
function fetch($id) function fetch($id)
{ {
$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public,"; $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public,";
$sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest, l.fk_projet as fk_project"; $sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest, l.fk_projet as fk_project";
$sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; $sql.= " FROM ".MAIN_DB_PREFIX."loan as l";
$sql.= " WHERE l.rowid = ".$id; $sql.= " WHERE l.rowid = ".$id;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
if ($this->db->num_rows($resql)) if ($this->db->num_rows($resql))
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->ref = $obj->rowid; $this->ref = $obj->rowid;
$this->datestart = $this->db->jdate($obj->datestart); $this->datestart = $this->db->jdate($obj->datestart);
$this->dateend = $this->db->jdate($obj->dateend); $this->dateend = $this->db->jdate($obj->dateend);
$this->label = $obj->label; $this->label = $obj->label;
$this->capital = $obj->capital; $this->capital = $obj->capital;
$this->nbterm = $obj->nbterm; $this->nbterm = $obj->nbterm;
$this->rate = $obj->rate; $this->rate = $obj->rate;
$this->note_private = $obj->note_private; $this->note_private = $obj->note_private;
$this->note_public = $obj->note_public; $this->note_public = $obj->note_public;
$this->paid = $obj->paid; $this->paid = $obj->paid;
$this->account_capital = $obj->accountancy_account_capital; $this->account_capital = $obj->accountancy_account_capital;
$this->account_insurance = $obj->accountancy_account_insurance; $this->account_insurance = $obj->accountancy_account_insurance;
$this->account_interest = $obj->accountancy_account_interest; $this->account_interest = $obj->accountancy_account_interest;
$this->fk_project = $obj->fk_project; $this->fk_project = $obj->fk_project;
$this->db->free($resql); $this->db->free($resql);
return 1; return 1;
} }
else else
{ {
$this->db->free($resql); $this->db->free($resql);
return 0; return 0;
} }
} }
else else
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
return -1; return -1;
} }
} }
/** /**
* Create a loan into database * Create a loan into database
* *
* @param User $user User making creation * @param User $user User making creation
* @return int <0 if KO, id if OK * @return int <0 if KO, id if OK
*/ */
function create($user) function create($user)
{ {
global $conf, $langs; global $conf, $langs;
$error=0; $error=0;
$now=dol_now(); $now=dol_now();
// clean parameters // clean parameters
$newcapital=price2num($this->capital,'MT'); $newcapital=price2num($this->capital,'MT');
if (isset($this->note_private)) $this->note_private = trim($this->note_private); if (isset($this->note_private)) $this->note_private = trim($this->note_private);
if (isset($this->note_public)) $this->note_public = trim($this->note_public); if (isset($this->note_public)) $this->note_public = trim($this->note_public);
if (isset($this->account_capital)) $this->account_capital = trim($this->account_capital); if (isset($this->account_capital)) $this->account_capital = trim($this->account_capital);
if (isset($this->account_insurance)) $this->account_insurance = trim($this->account_insurance); if (isset($this->account_insurance)) $this->account_insurance = trim($this->account_insurance);
if (isset($this->account_interest)) $this->account_interest = trim($this->account_interest); if (isset($this->account_interest)) $this->account_interest = trim($this->account_interest);
@ -147,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_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif);
if (isset($this->fk_project)) $this->fk_project=trim($this->fk_project); if (isset($this->fk_project)) $this->fk_project=trim($this->fk_project);
// Check parameters // Check parameters
if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend)) if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend))
{
$this->error="ErrorBadParameter";
return -2;
}
if (($conf->accounting->enabled) && empty($this->account_capital) && empty($this->account_insurance) && empty($this->account_interest))
{ {
$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Accounting")); $this->error="ErrorBadParameter";
return -2; return -2;
}
if (($conf->accounting->enabled) && empty($this->account_capital))
{
$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyCapitalCode"));
return -2;
}
if (($conf->accounting->enabled) && empty($this->account_insurance))
{
$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInsuranceCode"));
return -2;
}
if (($conf->accounting->enabled) && empty($this->account_interest))
{
$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInterestCode"));
return -2;
} }
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public,"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public,";
$sql.= " accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity,"; $sql.= " accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity,";
$sql.= " datec, fk_projet, fk_user_author)"; $sql.= " datec, fk_projet, fk_user_author)";
$sql.= " VALUES ('".$this->db->escape($this->label)."',"; $sql.= " VALUES ('".$this->db->escape($this->label)."',";
$sql.= " '".$this->db->escape($this->fk_bank)."',"; $sql.= " '".$this->db->escape($this->fk_bank)."',";
$sql.= " '".price2num($newcapital)."',"; $sql.= " '".price2num($newcapital)."',";
$sql.= " '".$this->db->idate($this->datestart)."',"; $sql.= " '".$this->db->idate($this->datestart)."',";
$sql.= " '".$this->db->idate($this->dateend)."',"; $sql.= " '".$this->db->idate($this->dateend)."',";
$sql.= " '".$this->db->escape($this->nbterm)."',"; $sql.= " '".$this->db->escape($this->nbterm)."',";
$sql.= " '".$this->db->escape($this->rate)."',"; $sql.= " '".$this->db->escape($this->rate)."',";
$sql.= " '".$this->db->escape($this->note_private)."',"; $sql.= " '".$this->db->escape($this->note_private)."',";
$sql.= " '".$this->db->escape($this->note_public)."',"; $sql.= " '".$this->db->escape($this->note_public)."',";
$sql.= " '".$this->db->escape($this->account_capital)."',"; $sql.= " '".$this->db->escape($this->account_capital)."',";
$sql.= " '".$this->db->escape($this->account_insurance)."',"; $sql.= " '".$this->db->escape($this->account_insurance)."',";
$sql.= " '".$this->db->escape($this->account_interest)."',"; $sql.= " '".$this->db->escape($this->account_interest)."',";
$sql.= " ".$conf->entity.","; $sql.= " ".$conf->entity.",";
$sql.= " '".$this->db->idate($now)."',"; $sql.= " '".$this->db->idate($now)."',";
$sql.= " ".(empty($this->fk_project)?'NULL':$this->fk_project).","; $sql.= " ".(empty($this->fk_project)?'NULL':$this->fk_project).",";
$sql.= " ".$user->id; $sql.= " ".$user->id;
$sql.= ")"; $sql.= ")";
dol_syslog(get_class($this)."::create", LOG_DEBUG); dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."loan"); $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."loan");
//dol_syslog("Loans::create this->id=".$this->id); //dol_syslog("Loans::create this->id=".$this->id);
$this->db->commit(); $this->db->commit();
return $this->id; return $this->id;
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
} }
/** /**
* Delete a loan * Delete a loan
* *
* @param User $user Object user making delete * @param User $user Object user making delete
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function delete($user) function delete($user)
{ {
$error=0; $error=0;
$this->db->begin(); $this->db->begin();
// Get bank transaction lines for this loan // Get bank transaction lines for this loan
include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$account=new Account($this->db); $account=new Account($this->db);
$lines_url=$account->get_url('',$this->id,'loan'); $lines_url=$account->get_url('',$this->id,'loan');
// Delete bank urls // Delete bank urls
foreach ($lines_url as $line_url) foreach ($lines_url as $line_url)
{ {
if (! $error) if (! $error)
{ {
$accountline=new AccountLine($this->db); $accountline=new AccountLine($this->db);
$accountline->fetch($line_url['fk_bank']); $accountline->fetch($line_url['fk_bank']);
$result=$accountline->delete_urls($user); $result=$accountline->delete_urls($user);
if ($result < 0) if ($result < 0)
{ {
$error++; $error++;
} }
} }
} }
// Delete payments // Delete payments
if (! $error) if (! $error)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan=".$this->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan=".$this->id;
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) if (! $resql)
{ {
$error++; $error++;
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
} }
} }
if (! $error) if (! $error)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid=".$this->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid=".$this->id;
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) if (! $resql)
{ {
$error++; $error++;
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
} }
} }
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
} }
/** /**
* Update loan * Update loan
* *
* @param User $user User who modified * @param User $user User who modified
* @return int <0 if error, >0 if ok * @return int <0 if error, >0 if ok
*/ */
function update($user) function update($user)
{ {
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."loan"; $sql = "UPDATE ".MAIN_DB_PREFIX."loan";
$sql.= " SET label='".$this->db->escape($this->label)."',"; $sql.= " SET label='".$this->db->escape($this->label)."',";
$sql.= " capital='".price2num($this->db->escape($this->capital))."',"; $sql.= " capital='".price2num($this->db->escape($this->capital))."',";
$sql.= " datestart='".$this->db->idate($this->datestart)."',"; $sql.= " datestart='".$this->db->idate($this->datestart)."',";
$sql.= " dateend='".$this->db->idate($this->dateend)."',"; $sql.= " dateend='".$this->db->idate($this->dateend)."',";
$sql.= " fk_projet=".(empty($this->fk_project)?'NULL':$this->fk_project).","; $sql.= " fk_projet=".(empty($this->fk_project)?'NULL':$this->fk_project).",";
$sql.= " fk_user_modif = ".$user->id; $sql.= " fk_user_modif = ".$user->id;
$sql.= " WHERE rowid=".$this->id; $sql.= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::update", LOG_DEBUG); dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
} }
/** /**
* Tag loan as payed completely * Tag loan as payed completely
* *
* @param User $user Object user making change * @param User $user Object user making change
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function set_paid($user) function set_paid($user)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."loan SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."loan SET";
$sql.= " paid = 1"; $sql.= " paid = 1";
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
$return = $this->db->query($sql); $return = $this->db->query($sql);
if ($return) { if ($return) {
return 1; return 1;
} else { } else {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
return -1; 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 = '<u>' . $langs->trans("ShowLoan") . '</u>';
if (! empty($this->ref))
$tooltip .= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
if (! empty($this->label))
$tooltip .= '<br><b>' . $langs->trans('Label') . ':</b> ' . $this->label;
$link = '<a href="'.DOL_URL_ROOT.'/loan/card.php?id='.$this->id.'"';
$linkclose = '" title="'.str_replace('\n', '', dol_escape_htmltag($tooltip, 1)).'" class="classfortooltip">';
$linkend = '</a>';
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 * @param int $mode 0=label, 1=short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label
* @return integer|null * @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 = '<u>' . $langs->trans("ShowLoan") . '</u>';
if (! empty($this->ref))
$tooltip .= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
if (! empty($this->label))
$tooltip .= '<br><b>' . $langs->trans('Label') . ':</b> ' . $this->label;
$link = '<a href="'.DOL_URL_ROOT.'/loan/card.php?id='.$this->id.'"';
$linkclose = '" title="'.str_replace('\n', '', dol_escape_htmltag($tooltip, 1)).'" class="classfortooltip">';
$linkend = '</a>';
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) function info($id)
{ {
@ -492,17 +502,17 @@ class Loan extends CommonObject
$muser->fetch($obj->fk_user_modif); $muser->fetch($obj->fk_user_modif);
$this->user_modification = $muser; $this->user_modification = $muser;
} }
$this->date_creation = $this->db->jdate($obj->datec); $this->date_creation = $this->db->jdate($obj->datec);
if (empty($obj->fk_user_modif)) $obj->tms = ""; if (empty($obj->fk_user_modif)) $obj->tms = "";
$this->date_modification = $this->db->jdate($obj->tms); $this->date_modification = $this->db->jdate($obj->tms);
$this->db->free($result); $this->db->free($result);
return 1; return 1;
} }
else else
{ {
$this->db->free($result); $this->db->free($result);
return 0; return 0;
} }
} }
else else

View File

@ -1538,6 +1538,7 @@ class Product extends CommonObject
$this->fourn_pu = $obj->price / $obj->quantity; // Unit price of product of supplier $this->fourn_pu = $obj->price / $obj->quantity; // Unit price of product of supplier
$this->fourn_price_base_type = 'HT'; // Price base type $this->fourn_price_base_type = 'HT'; // Price base type
$this->ref_fourn = $obj->ref_fourn; // deprecated $this->ref_fourn = $obj->ref_fourn; // deprecated
$this->product_fourn_price_id = $obj->rowid; // supplier price id
$this->ref_supplier = $obj->ref_fourn; // Ref supplier $this->ref_supplier = $obj->ref_fourn; // Ref supplier
$this->remise_percent = $obj->remise_percent; // remise percent if present and not typed $this->remise_percent = $obj->remise_percent; // remise percent if present and not typed
$this->vatrate_supplier = $obj->tva_tx; // Vat ref supplier $this->vatrate_supplier = $obj->tva_tx; // Vat ref supplier
@ -1586,6 +1587,7 @@ class Product extends CommonObject
$this->fourn_qty = $obj->quantity; // min quantity for price for a virtual supplier $this->fourn_qty = $obj->quantity; // min quantity for price for a virtual supplier
$this->fourn_pu = $obj->price / $obj->quantity; // Unit price of product for a virtual supplier $this->fourn_pu = $obj->price / $obj->quantity; // Unit price of product for a virtual supplier
$this->fourn_price_base_type = 'HT'; // Price base type for a virtual supplier $this->fourn_price_base_type = 'HT'; // Price base type for a virtual supplier
$this->product_fourn_price_id = $obj->rowid; // supplier price id
$this->ref_fourn = $obj->ref_supplier; // deprecated $this->ref_fourn = $obj->ref_supplier; // deprecated
$this->ref_supplier = $obj->ref_supplier; // Ref supplier $this->ref_supplier = $obj->ref_supplier; // Ref supplier
$this->remise_percent = $obj->remise_percent; // remise percent if present and not typed $this->remise_percent = $obj->remise_percent; // remise percent if present and not typed
@ -4001,8 +4003,8 @@ class Product extends CommonObject
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
{ {
$dirold .= get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/"; $dir = $sdir . '/'. get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/";
$pdirold .= get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/"; $pdir = '/' . get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/";
} }
// Defined relative dir to DOL_DATA_ROOT // Defined relative dir to DOL_DATA_ROOT
@ -4022,11 +4024,11 @@ class Product extends CommonObject
$filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); $filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs /*if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs
{ {
$filearrayold=dol_dir_list($dirold,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); $filearrayold=dol_dir_list($dirold,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
$filearray=array_merge($filearray, $filearrayold); $filearray=array_merge($filearray, $filearrayold);
} }*/
$filearrayindatabase = dol_dir_list_in_database($relativedir, '', null, 'name', SORT_ASC); $filearrayindatabase = dol_dir_list_in_database($relativedir, '', null, 'name', SORT_ASC);

View File

@ -6,6 +6,7 @@
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com> * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr> * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View File

@ -1052,7 +1052,7 @@ while ($i < min($num, $limit))
if (! empty($arrayfields['typent.code']['checked'])) if (! empty($arrayfields['typent.code']['checked']))
{ {
print '<td align="center">'; print '<td align="center">';
if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1); if (! is_array($typenArray) || count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
print $typenArray[$obj->typent_code]; print $typenArray[$obj->typent_code];
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;

View File

@ -9,7 +9,7 @@
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr> * Copyright (C) 2015-2017 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com> * Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
* Copyright (C) 2015 Charlie Benke <charlie@patas-monkey.com> * Copyright (C) 2015 Charlie Benke <charlie@patas-monkey.com>
* Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr> * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
@ -415,8 +415,8 @@ if (empty($reshook)) {
} }
} }
if (!$error && GETPOST('contactid', 'int')) { if (!$error && GETPOSTISSET('contactid')) {
$contactid = GETPOST('contactid', 'int'); $contactid = GETPOST('contactid', 'int');
if ($contactid > 0) { if ($contactid > 0) {
$contact = new Contact($db); $contact = new Contact($db);

View File

@ -22,14 +22,14 @@ use Luracast\Restler\RestException;
/** /**
* API class for users * API class for users
* *
* @access protected * @access protected
* @class DolibarrApiAccess {@requires user,external} * @class DolibarrApiAccess {@requires user,external}
*/ */
class Users extends DolibarrApi class Users extends DolibarrApi
{ {
/** /**
* *
* @var array $FIELDS Mandatory fields, checked when create and update object * @var array $FIELDS Mandatory fields, checked when create and update object
*/ */
static $FIELDS = array( static $FIELDS = array(
'login' 'login'
@ -49,7 +49,7 @@ class Users extends DolibarrApi
$this->useraccount = new User($this->db); $this->useraccount = new User($this->db);
} }
/** /**
* List Users * List Users
* *
@ -65,22 +65,22 @@ class Users extends DolibarrApi
*/ */
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $user_ids = 0, $sqlfilters = '') { function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $user_ids = 0, $sqlfilters = '') {
global $db, $conf; global $db, $conf;
$obj_ret = array(); $obj_ret = array();
if(! DolibarrApiAccess::$user->rights->user->user->lire) { if(! DolibarrApiAccess::$user->rights->user->user->lire) {
throw new RestException(401, "You are not allowed to read list of users"); throw new RestException(401, "You are not allowed to read list of users");
} }
// case of external user, $societe param is ignored and replaced by user's socid // case of external user, $societe param is ignored and replaced by user's socid
//$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe; //$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe;
$sql = "SELECT t.rowid"; $sql = "SELECT t.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."user as t"; $sql.= " FROM ".MAIN_DB_PREFIX."user as t";
$sql.= ' WHERE t.entity IN ('.getEntity('user').')'; $sql.= ' WHERE t.entity IN ('.getEntity('user').')';
if ($user_ids) $sql.=" AND t.rowid IN (".$user_ids.")"; if ($user_ids) $sql.=" AND t.rowid IN (".$user_ids.")";
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters)
{ {
if (! DolibarrApi::_checkFilters($sqlfilters)) if (! DolibarrApi::_checkFilters($sqlfilters))
{ {
@ -89,7 +89,7 @@ class Users extends DolibarrApi
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
} }
$sql.= $db->order($sortfield, $sortorder); $sql.= $db->order($sortfield, $sortorder);
if ($limit) { if ($limit) {
if ($page < 0) if ($page < 0)
@ -97,12 +97,12 @@ class Users extends DolibarrApi
$page = 0; $page = 0;
} }
$offset = $limit * $page; $offset = $limit * $page;
$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);
@ -125,7 +125,7 @@ class Users extends DolibarrApi
} }
return $obj_ret; return $obj_ret;
} }
/** /**
* Get properties of an user object * Get properties of an user object
* *
@ -133,7 +133,7 @@ class Users extends DolibarrApi
* *
* @param int $id ID of user * @param int $id ID of user
* @return array|mixed data without useless information * @return array|mixed data without useless information
* *
* @throws RestException * @throws RestException
*/ */
function get($id) { function get($id) {
@ -154,8 +154,8 @@ class Users extends DolibarrApi
return $this->_cleanObjectDatas($this->useraccount); return $this->_cleanObjectDatas($this->useraccount);
} }
/** /**
* Create user account * Create user account
* *
@ -185,14 +185,14 @@ class Users extends DolibarrApi
} }
return $this->useraccount->id; return $this->useraccount->id;
} }
/** /**
* Update account * Update account
* *
* @param int $id Id of account to update * @param int $id Id of account to update
* @param array $request_data Datas * @param array $request_data Datas
* @return int * @return int
*/ */
function put($id, $request_data = NULL) { function put($id, $request_data = NULL) {
//if (!DolibarrApiAccess::$user->rights->user->user->creer) { //if (!DolibarrApiAccess::$user->rights->user->user->creer) {
@ -228,7 +228,7 @@ class Users extends DolibarrApi
* @param int $id User ID * @param int $id User ID
* @param int $group Group ID * @param int $group Group ID
* @return int 1 if success * @return int 1 if success
* *
* @url GET {id}/setGroup/{group} * @url GET {id}/setGroup/{group}
*/ */
function setGroup($id, $group) { function setGroup($id, $group) {
@ -240,18 +240,18 @@ class Users extends DolibarrApi
{ {
throw new RestException(404, 'User not found'); throw new RestException(404, 'User not found');
} }
if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
{ {
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
} }
$result = $this->useraccount->SetInGroup($group,1); $result = $this->useraccount->SetInGroup($group,1);
if (! ($result > 0)) if (! ($result > 0))
{ {
throw new RestException(500, $this->useraccount->error); throw new RestException(500, $this->useraccount->error);
} }
return 1; return 1;
} }
@ -286,25 +286,57 @@ class Users extends DolibarrApi
* @return array Array of cleaned object properties * @return array Array of cleaned object properties
*/ */
function _cleanObjectDatas($object) { function _cleanObjectDatas($object) {
global $conf;
$object = parent::_cleanObjectDatas($object); $object = parent::_cleanObjectDatas($object);
unset($object->default_values); unset($object->default_values);
unset($object->lastsearch_values); unset($object->lastsearch_values);
unset($object->lastsearch_values_tmp); unset($object->lastsearch_values_tmp);
unset($object->total_ht); unset($object->total_ht);
unset($object->total_tva); unset($object->total_tva);
unset($object->total_localtax1); unset($object->total_localtax1);
unset($object->total_localtax2); unset($object->total_localtax2);
unset($object->total_ttc); unset($object->total_ttc);
unset($object->libelle_incoterms);
unset($object->location_incoterms);
unset($object->fk_delivery_address);
unset($object->fk_incoterms);
unset($object->all_permissions_are_loaded);
unset($object->shipping_method_id);
unset($object->nb_rights);
unset($object->search_sid);
unset($object->ldap_sid);
// List of properties never returned by API, whatever are permissions
unset($object->pass);
unset($object->pass_indatabase);
unset($object->pass_indatabase_crypted);
unset($object->pass_temp);
unset($object->api_key);
unset($object->clicktodial_password);
unset($object->openid);
$canreadsalary = ((! empty($conf->salaries->enabled) && ! empty(DolibarrApiAccess::$user->rights->salaries->read))
|| (! empty($conf->hrm->enabled) && ! empty(DolibarrApiAccess::$user->rights->hrm->employee->read)));
if (! $canreadsalary)
{
unset($object->salary);
unset($object->salaryextra);
unset($object->thm);
unset($object->tjm);
}
return $object; return $object;
} }
/** /**
* Validate fields before create or update object * Validate fields before create or update object
* *
* @param array|null $data Data to validate * @param array|null $data Data to validate
* @return array * @return array
* @throws RestException * @throws RestException

View File

@ -139,7 +139,8 @@ $server->wsdl->addComplexType(
'date_modification' => array('name'=>'date_modification','type'=>'xsd:dateTime'), 'date_modification' => array('name'=>'date_modification','type'=>'xsd:dateTime'),
'date_invoice' => array('name'=>'date_invoice','type'=>'xsd:date'), 'date_invoice' => array('name'=>'date_invoice','type'=>'xsd:date'),
'date_term' => array('name'=>'date_modification','type'=>'xsd:date'), 'date_term' => array('name'=>'date_modification','type'=>'xsd:date'),
'type' => array('name'=>'type','type'=>'xsd:int'), 'label' => array('name'=>'label','type'=>'xsd:date'),
'type' => array('name'=>'type','type'=>'xsd:int'),
'total_net' => array('name'=>'type','type'=>'xsd:double'), 'total_net' => array('name'=>'type','type'=>'xsd:double'),
'total_vat' => array('name'=>'type','type'=>'xsd:double'), 'total_vat' => array('name'=>'type','type'=>'xsd:double'),
'total' => array('name'=>'type','type'=>'xsd:double'), 'total' => array('name'=>'type','type'=>'xsd:double'),