diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php index e4af98742ae..679e042f1ac 100644 --- a/htdocs/compta/paiement/fiche.php +++ b/htdocs/compta/paiement/fiche.php @@ -2,7 +2,7 @@ /* Copyright (C) 2004 Rodolphe Quiedeville * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * * 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 @@ -36,14 +36,17 @@ $langs->load('banks'); $langs->load('companies'); // Security check -$id=GETPOST("id"); -$action=GETPOST("action"); +$id=GETPOST('id','int'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); if ($user->societe_id) $socid=$user->societe_id; // TODO ajouter regle pour restreindre acces paiement //$result = restrictedArea($user, 'facture', $id,''); $mesg=''; +$object = new Paiement($db); + /* * Actions @@ -53,9 +56,8 @@ if ($action == 'setnote' && $user->rights->facture->paiement) { $db->begin(); - $paiement = new Paiement($db); - $paiement->fetch($id); - $result = $paiement->update_note(GETPOST('note')); + $object->fetch($id); + $result = $object->update_note(GETPOST('note')); if ($result > 0) { $db->commit(); @@ -63,18 +65,17 @@ if ($action == 'setnote' && $user->rights->facture->paiement) } else { - $mesg='
'.$paiement->error.'
'; + $mesg='
'.$object->error.'
'; $db->rollback(); } } -if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights->facture->paiement) +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->paiement) { $db->begin(); - $paiement = new Paiement($db); - $paiement->fetch($id); - $result = $paiement->delete(); + $object->fetch($id); + $result = $object->delete(); if ($result > 0) { $db->commit(); @@ -84,18 +85,17 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights- else { $langs->load("errors"); - $mesg='
'.$langs->trans($paiement->error).'
'; + $mesg='
'.$langs->trans($object->error).'
'; $db->rollback(); } } -if ($action == 'confirm_valide' && GETPOST('confirm') == 'yes' && $user->rights->facture->paiement) +if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->facture->paiement) { $db->begin(); - $paiement = new Paiement($db); - $paiement->fetch($id); - if ($paiement->valide() > 0) + $object->fetch($id); + if ($object->valide() > 0) { $db->commit(); @@ -115,22 +115,21 @@ if ($action == 'confirm_valide' && GETPOST('confirm') == 'yes' && $user->rights- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $fac, $fac->modelpdf, $outputlangs, $hookmanager); } - Header('Location: fiche.php?id='.$paiement->id); + Header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); exit; } else { $langs->load("errors"); - $mesg='
'.$langs->trans($paiement->error).'
'; + $mesg='
'.$langs->trans($object->error).'
'; $db->rollback(); } } -if ($action == 'setnum' && !empty($_POST['num'])) +if ($action == 'setnum' && ! empty($_POST['num_paiement'])) { - $paiement = new Paiement($db); - $paiement->fetch($id); - $res = $paiement->update_num($_POST['num']); + $object->fetch($id); + $res = $object->update_num($_POST['num_paiement']); if ($res === 0) { $mesg = '
'.$langs->trans('PaymentNumberUpdateSucceeded').'
'; @@ -141,12 +140,11 @@ if ($action == 'setnum' && !empty($_POST['num'])) } } -if ($action == 'setdate' && !empty($_POST['dateday'])) +if ($action == 'setdate' && ! empty($_POST['datepday'])) { - $paiement = new Paiement($db); - $paiement->fetch($id); - $datepaye = dol_mktime(12, 0, 0, $_POST['datemonth'], $_POST['dateday'], $_POST['dateyear']); - $res = $paiement->update_date($datepaye); + $object->fetch($id); + $datepaye = dol_mktime(12, 0, 0, $_POST['datepmonth'], $_POST['datepday'], $_POST['datepyear']); + $res = $object->update_date($datepaye); if ($res === 0) { $mesg = '
'.$langs->trans('PaymentDateUpdateSucceeded').'
'; @@ -166,8 +164,7 @@ llxHeader(); $thirdpartystatic=new Societe($db); -$paiement = new Paiement($db); -$result=$paiement->fetch($id); +$result=$object->fetch($id); if ($result <= 0) { dol_print_error($db,'Payement '.$id.' not found in database'); @@ -178,7 +175,7 @@ $form = new Form($db); $h=0; -$head[$h][0] = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$id; +$head[$h][0] = $_SERVER['PHP_SELF'].'?id='.$id; $head[$h][1] = $langs->trans("Card"); $hselected = $h; $h++; @@ -195,7 +192,7 @@ dol_fiche_head($head, $hselected, $langs->trans("PaymentCustomerInvoice"), 0, 'p */ if ($action == 'delete') { - $ret=$form->form_confirm('fiche.php?id='.$paiement->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); + $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); if ($ret == 'html') print '
'; } @@ -205,7 +202,7 @@ if ($action == 'delete') if ($action == 'valide') { $facid = $_GET['facid']; - $ret=$form->form_confirm('fiche.php?id='.$paiement->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); + $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); if ($ret == 'html') print '
'; } @@ -216,37 +213,37 @@ dol_htmloutput_mesg($mesg); print ''; // Ref -print ''; +print ''; // Date payment -print ''; // Payment type (VIR, LIQ, ...) -$labeltype=$langs->trans("PaymentType".$paiement->type_code)!=("PaymentType".$paiement->type_code)?$langs->trans("PaymentType".$paiement->type_code):$paiement->type_libelle; +$labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->type_libelle; print ''; // Payment numero -print ''; // Amount -print ''; +print ''; // Note -print ''; // Bank account if ($conf->banque->enabled) { - if ($paiement->bank_account) + if ($object->bank_account) { $bankline=new AccountLine($db); - $bankline->fetch($paiement->bank_line); + $bankline->fetch($object->bank_line); print ''; print ''; @@ -270,7 +267,7 @@ $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture $sql.= ' WHERE pf.fk_facture = f.rowid'; $sql.= ' AND f.fk_soc = s.rowid'; $sql.= ' AND f.entity = '.$conf->entity; -$sql.= ' AND pf.fk_paiement = '.$paiement->id; +$sql.= ' AND pf.fk_paiement = '.$object->id; $resql=$db->query($sql); if ($resql) { @@ -360,11 +357,11 @@ print '
'; if ($conf->global->BILL_ADD_PAYMENT_VALIDATION) { - if ($user->societe_id == 0 && $paiement->statut == 0 && $_GET['action'] == '') + if ($user->societe_id == 0 && $object->statut == 0 && $_GET['action'] == '') { if ($user->rights->facture->paiement) { - print ''.$langs->trans('Valid').''; + print ''.$langs->trans('Valid').''; } } } @@ -375,7 +372,7 @@ if ($user->societe_id == 0 && $action == '') { if (! $disable_delete) { - print ''.$langs->trans('Delete').''; + print ''.$langs->trans('Delete').''; } else { @@ -386,7 +383,7 @@ if ($user->societe_id == 0 && $action == '') print '
'; -$db->close(); - llxFooter(); + +$db->close(); ?> diff --git a/htdocs/core/ajax/loadinplace.php b/htdocs/core/ajax/loadinplace.php index 453fd7c8b3e..48fd654b3e4 100644 --- a/htdocs/core/ajax/loadinplace.php +++ b/htdocs/core/ajax/loadinplace.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2012 Regis Houssin * * 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 @@ -63,7 +63,8 @@ if((isset($_GET['field']) && ! empty($_GET['field'])) if ($element == 'propal') $element = 'propale'; else if ($element == 'fichinter') $element = 'ficheinter'; - if ($user->rights->$element->lire || $user->rights->$element->read + if (($element == 'payment' && $user->rights->facture->paiement) + || $user->rights->$element->lire || $user->rights->$element->read || $user->rights->$element->$subelement->lire || $user->rights->$element->$subelement->read) { if ($type == 'select') diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index 0c1434a4fd8..e88eda87e9f 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -69,7 +69,8 @@ if((isset($_POST['field']) && ! empty($_POST['field'])) if ($element == 'propal') $element = 'propale'; else if ($element == 'fichinter') $element = 'ficheinter'; - if ($user->rights->$element->creer || $user->rights->$element->write + if (($element == 'payment' && $user->rights->facture->paiement) + || $user->rights->$element->creer || $user->rights->$element->write || $user->rights->$element->$subelement->creer || $user->rights->$element->$subelement->write) { // Clean parameters diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 09f352c7ec0..2283660ba0c 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -118,9 +118,10 @@ class Form * @param string $typeofdata Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height', 'select:xxx'...) * @param string $editvalue When in edit mode, use this value as $value instead of value * @param object $extObject External object + * @param string $success Success message * @return string HTML edit field */ - function editfieldval($text,$htmlname,$value,$object,$perm,$typeofdata='string',$editvalue='',$extObject=false) + function editfieldval($text,$htmlname,$value,$object,$perm,$typeofdata='string',$editvalue='',$extObject=null,$success=null) { global $conf,$langs,$db; @@ -129,7 +130,7 @@ class Form // When option to edit inline is activated if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) { - $ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $extObject); + $ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $extObject, $success); } else { @@ -194,11 +195,12 @@ class Form * @param int $condition Condition to edit * @param string $inputType Type of input ('numeric', 'datepicker', 'textarea', 'ckeditor:dolibarr_zzz', 'select:xxx') * @param object $extObject External object + * @param string $success Success message * @return string HTML edit in place */ - private function editInPlace($object, $value, $htmlname, $condition, $inputType='textarea', $extObject=false) + private function editInPlace($object, $value, $htmlname, $condition, $inputType='textarea', $extObject=null, $success=null) { - global $conf; + global $conf, $langs; $out=''; @@ -238,7 +240,7 @@ class Form $inputType=$tmp[0]; $inputOption=$tmp[1]; if (! empty($tmp[2])) $savemethod=$tmp[2]; } - if (preg_match('/^datepicker/',$inputType)) + else if (preg_match('/^datepicker/',$inputType)) { $tmp=explode(':',$inputType); $inputType=$tmp[0]; $inputOption=$tmp[1]; @@ -276,6 +278,7 @@ class Form $out.= ''."\n"; $out.= ''."\n"; $out.= ''."\n"; + if (! empty($success)) $out.= ''."\n"; //$out.= ''."\n"; //$out.= ''."\n"; diff --git a/htdocs/core/js/editinplace.js b/htdocs/core/js/editinplace.js index ca3d3bacab8..503bb47ba26 100644 --- a/htdocs/core/js/editinplace.js +++ b/htdocs/core/js/editinplace.js @@ -1,5 +1,5 @@ -// Copyright (C) 2011 Regis Houssin -// Copyright (C) 2009 Laurent Destailleur +// Copyright (C) 2011-2012 Regis Houssin +// Copyright (C) 2011 Laurent Destailleur // // 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 @@ -45,14 +45,7 @@ $(document).ready(function() { return getParameters('textarea', htmlname); }, callback : function(result, settings) { - var obj = $.parseJSON(result); - - if (obj.error) { - $(this).html(this.revert); - $.jnotify(obj.error, "error", true); - } else { - $(this).html(obj.value); - } + getResult(this, result); } }); $('.editkey_textarea').hover( @@ -85,14 +78,7 @@ $(document).ready(function() { return getParameters('ckeditor', htmlname); }, callback : function(result, settings) { - var obj = $.parseJSON(result); - - if (obj.error) { - $(this).html(this.revert); - $.jnotify(obj.error, "error", true); - } else { - $(this).html(obj.value); - } + getResult(this, result); } }); $('.editkey_ckeditor').hover( @@ -121,14 +107,7 @@ $(document).ready(function() { return getParameters('string', htmlname); }, callback : function(result, settings) { - var obj = $.parseJSON(result); - - if (obj.error) { - $(this).html(this.revert); - $.jnotify(obj.error, "error", true); - } else { - $(this).html(obj.value); - } + getResult(this, result); } }); $('.editkey_string').hover( @@ -193,14 +172,7 @@ $(document).ready(function() { return getParameters('datepicker', htmlname); }, callback : function(result, settings) { - var obj = $.parseJSON(result); - - if (obj.error) { - $(this).html(this.revert); - $.jnotify(obj.error, "error", true); - } else { - $(this).html(obj.value); - } + getResult(this, result); } }); $('.editkey_datepicker').hover( @@ -235,14 +207,7 @@ $(document).ready(function() { return getParameters('select', htmlname); }, callback : function(result, settings) { - var obj = $.parseJSON(result); - - if (obj.error) { - $(this).html(this.revert); - $.jnotify(obj.error, "error", true); - } else { - $(this).html(obj.value); - } + getResult(this, result); } }); $('.editkey_select').hover( @@ -282,6 +247,21 @@ $(document).ready(function() { }; } + function getResult(obj, result) { + var res = $.parseJSON(result); + if (res.error) { + $(obj).html(obj.revert); + $.jnotify(res.error, "error", true); + } else { + var htmlname = $(obj).attr('id').substr(4); + var success = $( '#success_' + htmlname ).val(); + if (success != undefined) { + $.jnotify(success, "ok"); + } + $(obj).html(res.value); + } + } + $('.edit_autocomplete').editable(urlSaveInPlace, { type : 'autocomplete', id : 'field',
'.$langs->trans('Ref').''.$paiement->id.'
'.$langs->trans('Ref').''.$object->id.'
'.$form->editfieldkey("Date",'date',$paiement->date,$paiement,$user->rights->facture->paiement).''; -print $form->editfieldval("Date",'date',$paiement->date,$paiement,$user->rights->facture->paiement,'day'); +print '
'.$form->editfieldkey("Date",'datep',$object->date,$object,$user->rights->facture->paiement).''; +print $form->editfieldval("Date",'datep',$object->date,$object,$user->rights->facture->paiement,'datepicker','',null,$langs->trans('PaymentDateUpdateSucceeded')); print '
'.$langs->trans('PaymentMode').''.$labeltype.'
'.$form->editfieldkey("Numero",'num',$paiement->numero,$paiement,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).''; -print $form->editfieldval("Numero",'num',$paiement->numero,$paiement,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'string'); +print '
'.$form->editfieldkey("Numero",'num_paiement',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).''; +print $form->editfieldval("Numero",'num_paiement',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded')); print '
'.$langs->trans('Amount').''.price($paiement->montant).' '.$langs->trans('Currency'.$conf->currency).'
'.$langs->trans('Amount').''.price($object->montant).' '.$langs->trans('Currency'.$conf->currency).'
'.$form->editfieldkey("Note",'note',$paiement->note,$paiement,$user->rights->facture->paiement).''; -print $form->editfieldval("Note",'note',$paiement->note,$paiement,$user->rights->facture->paiement,'text'); +print '
'.$form->editfieldkey("Note",'note',$object->note,$object,$user->rights->facture->paiement).''; +print $form->editfieldval("Note",'note',$object->note,$object,$user->rights->facture->paiement,'textarea'); print '
'.$langs->trans('BankTransactionLine').'