altocompta/include/class_icard.php
Dany De Bontridder b43f4c87b4 Merged revisions 2905-2938 via svnmerge from
svn+ssh://danydb@svn/svn/phpcompta/branches/rel500

........
  r2906 | danydb | 2010-01-27 15:16:08 +0100 (Wed, 27 Jan 2010) | 2 lines
  
  Cosmetic for html popup
........
  r2907 | danydb | 2010-01-27 15:28:03 +0100 (Wed, 27 Jan 2010) | 5 lines
  
  Fix typo translation
  
  Fix Bug  : cannot save extension in IE, probably because the same scripts are included several times
........
  r2908 | danydb | 2010-01-28 13:56:37 +0100 (Thu, 28 Jan 2010) | 5 lines
  
  Fix Bug In getNodeText when retrieving data for Internet Explorer, 
  it fails if the xmlNode.firstChild.nodeValue does not contains data. 
  It is directly set to undefined
........
  r2909 | danydb | 2010-01-29 12:20:24 +0100 (Fri, 29 Jan 2010) | 2 lines
  
  Generate invoice : update the comment of the entry only if there were no comment
........
  r2910 | danydb | 2010-01-29 19:39:11 +0100 (Fri, 29 Jan 2010) | 6 lines
  
  Improve User
  ============
  Status only plugin means that the user can use only the plugin and can't access to 
  anything else.
........
  r2911 | danydb | 2010-01-29 19:42:38 +0100 (Fri, 29 Jan 2010) | 1 line
  
  Bug import Dexia
........
  r2912 | danydb | 2010-01-31 16:24:22 +0100 (Sun, 31 Jan 2010) | 3 lines
  
  For insert_jrnx, the desc is now in the function, we don't need anymore to update after inserting
........
  r2913 | danydb | 2010-01-31 16:33:55 +0100 (Sun, 31 Jan 2010) | 4 lines
  
  Fix bug : cannot see operation in quick_writing 
     cause : the p_action must be set to ALL, it wasn't for quick_writing
........
  r2914 | danydb | 2010-02-02 14:52:37 +0100 (Tue, 02 Feb 2010) | 4 lines
  
  Code cleaning
  Bug : in ledger of sale, we have twice the possibility to add~ or generate document, and only for invoice (type 4)
  Solution : fix the function Acc_Ledger_Purchase::extra_info (type of document = 10), remove extra code
........
  r2915 | danydb | 2010-02-05 01:01:11 +0100 (Fri, 05 Feb 2010) | 4 lines
  
  Improve : search_card you can also find a card thanks is tva_num
  Documentation doxygen improved
........
  r2916 | danydb | 2010-02-05 11:18:36 +0100 (Fri, 05 Feb 2010) | 2 lines
  
  when inserting into ledger_sold the test to check the attach was wrong
........
  r2917 | danydb | 2010-02-05 14:45:33 +0100 (Fri, 05 Feb 2010) | 2 lines
  
  Extension : add the possibility to use ajax
........
  r2918 | danydb | 2010-02-06 14:25:22 +0100 (Sat, 06 Feb 2010) | 1 line
  
  rewrite the function encodeJSON, hide and show for doxygen
........
  r2919 | danydb | 2010-02-06 14:26:07 +0100 (Sat, 06 Feb 2010) | 1 line
  
  remove error where _SESSION is expired
........
  r2920 | danydb | 2010-02-06 14:26:49 +0100 (Sat, 06 Feb 2010) | 1 line
  
  In ITva_Select add the display
........
  r2921 | danydb | 2010-02-06 14:27:47 +0100 (Sat, 06 Feb 2010) | 1 line
  
  Cosmetic
........
  r2922 | danydb | 2010-02-06 14:27:49 +0100 (Sat, 06 Feb 2010) | 1 line
  
  IPopup add a new property drag to make the ipopup dragguable or not
........
  r2923 | danydb | 2010-02-06 14:35:28 +0100 (Sat, 06 Feb 2010) | 5 lines
  
  Middle of payment
  =================
  Feature : add or remove middle of payment
........
  r2924 | danydb | 2010-02-06 18:17:15 +0100 (Sat, 06 Feb 2010) | 7 lines
  
  Card
  ----
  A same card can now have 2 different sides (debit or credit)
  usefull to have only one card for a customer and a supplier
........
  r2925 | danydb | 2010-02-06 18:23:03 +0100 (Sat, 06 Feb 2010) | 1 line
  
  Add the sql script for the double accounting
........
  r2926 | danydb | 2010-02-06 19:29:29 +0100 (Sat, 06 Feb 2010) | 2 lines
  
  Update documentation
........
  r2927 | danydb | 2010-02-06 20:37:12 +0100 (Sat, 06 Feb 2010) | 4 lines
  
  Fiche_def
  ========
  Permit to have 2 accouting as class_base
........
  r2928 | danydb | 2010-02-06 20:56:00 +0100 (Sat, 06 Feb 2010) | 1 line
  
  Bug : FK from stock prevent the removal of a card
........
  r2929 | danydb | 2010-02-06 21:14:10 +0100 (Sat, 06 Feb 2010) | 1 line
  
  removeless useless test
........
  r2930 | danydb | 2010-02-07 00:55:03 +0100 (Sun, 07 Feb 2010) | 1 line
  
  Improve appearance extension
........
  r2931 | danydb | 2010-02-07 00:56:28 +0100 (Sun, 07 Feb 2010) | 2 lines
  
  remove debug
........
  r2932 | danydb | 2010-02-07 01:16:51 +0100 (Sun, 07 Feb 2010) | 1 line
  
  Improve appearance extension
........
  r2933 | danydb | 2010-02-07 01:19:08 +0100 (Sun, 07 Feb 2010) | 1 line
  
  Improve appearance extension
........
  r2934 | danydb | 2010-02-07 01:30:31 +0100 (Sun, 07 Feb 2010) | 1 line
  
  Improve appearance extension
........
  r2935 | danydb | 2010-02-07 02:36:25 +0100 (Sun, 07 Feb 2010) | 1 line
  
  Version PHP5.3 : split is obsolete and replace by explode
........
  r2936 | danydb | 2010-02-07 04:56:17 +0100 (Sun, 07 Feb 2010) | 1 line
  
  remove owner
........
  r2937 | danydb | 2010-02-08 22:34:07 +0100 (Mon, 08 Feb 2010) | 1 line
  
  typo
........
  r2938 | danydb | 2010-02-08 22:34:28 +0100 (Mon, 08 Feb 2010) | 1 line
  
  Start translation for Dutch
........
2010-02-10 18:38:16 +00:00

328 lines
10 KiB
PHP

<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision: 1615 $ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*!\file
* \brief Input HTML for the card show buttons, in the file, you have to add JS_CARD
*
*/
/*!
* \brief Input HTML for the card show buttons, in the file, you have to add JS_CARD
* How to use :
* - label is the label in the button
* - extra contents the type (all, deb or cred, a list of FD_ID between parent. or a SQL clause
* - attribute are the attribute to set (via ajax). The ledger is either a attribute (jrn) or a
* hidden field in the document, if none are set, there is no filter on the ledger
*\note you must in a hidden field PHPSESSID and the gDossier (dossier::hidden)
*\see ajaxFid
*\see card.js
*\see fid.php
*
* Set the hidden field or input field to be set by javascript with the function set_attribute
* call the input method. After selecting a value the update_value function is called. If you need
* to modify the queryString before the request is sent, you'll use the set_callback; the first
* parameter is the INPUT field and the second the queryString, the function must returns a
* queryString
*\code
// insert all the javascript files
echo js_include('prototype.js');
echo js_include('scriptaculous.js');
echo js_include('effects.js');
echo js_include('controls.js');
//
$W1=new ICard();
$W1->label="Client ".HtmlInput::infobulle(0) ;
$W1->name="e_client";
$W1->tabindex=3;
$W1->value=$e_client;
$W1->table=0;
// If double click call the javascript fill_ipopcard
$W1->set_dblclick("fill_ipopcard(this);");
// This attribute is mandatory, it is the name of the IPopup
$W1->set_attribute('ipopup','ipopcard');
// name of the field to update with the name of the card
$W1->set_attribute('label','e_client_label');
// Type of card : deb, cred,
$W1->set_attribute('typecard','deb');
$W1->extra='deb';
// Add the callback function to filter the card on the jrn
$W1->set_callback('filter_card');
// when value selected in the autcomplete
$W1->set_function('fill_data');
// when the data change
$W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
$W1->name);
$f_client_qcode=$W1->input();
$client_label=new ISpan();
$client_label->table=0;
$f_client=$client_label->input("e_client_label",$e_client_label);
// Search button for card
$f_client_bt=$W1->search();
* \endcode
*/
require_once('class_html_input.php');
require_once('function_javascript.php');
class ICard extends HtmlInput
{
function __construct($name="",$value="") {
parent::__construct($name,$value);
$this->fct='update_value';
$this->dblclick='';
$this->callback='null';
$this->javascript='';
}
/*!\brief set the javascript callback function
* by default it is update_value called BEFORE the querystring is send
*
*\param $p_name callback function name
*/
function set_callback($p_name) {
$this->callback=$p_name;
}
/*!\brief set the javascript callback function
* by default it is update_value called AFTER an item has been selected
*\param $p_name callback function name
*/
function set_function($p_name) {
$this->fct=$p_name;
}
/*!\brief return the html string for creating the ipopup, this ipopup
* can be used for adding, modifying or display a card
*\param $p_name name of the ipopup, must be set after with set_attribute
\code
$f_add_button=new IButton('add_card');
$f_add_button->label='Créer une nouvelle fiche';
$f_add_button->set_attribute('ipopup','ipop_newcard');
$f_add_button->set_attribute('filter',$this->get_all_fiche_def ());
$f_add_button->javascript=" select_card_type(this);";
$str_add_button=$f_add_button->input();
\endcode
*\return html string
*\note must be one of first instruction on a new page, to avoid problem
* of position with IE
*/
static function ipopup($p_name) {
$ip_card=new IPopup ($p_name);
$ip_card->set_width('30%');
$ip_card->title='Fiche ';
$ip_card->value='';
return $ip_card->input();
}
/*!\brief set the extra javascript property for a double click on
* INPUT field
*\param $p_action action when a double click happens
*\note the $p_action cannot contain a double quote
*/
function set_dblclick($p_action) {
$this->dblclick=$p_action;
}
/*!\brief show the html input of the widget*/
public function input($p_name=null,$p_value=null)
{
if ( $p_name == null && $this->name == "")
throw (new Exception('Le nom d une icard doit être donne'));
$this->value=($p_value==null)?$this->value:$p_value;
if ( $this->readOnly==true) return $this->display();
$l_sessid=$_REQUEST['PHPSESSID'];
$attr=$this->get_js_attr();
$label='';
if ( $this->dblclick != '') {
$e=sprintf(' ondblclick="%s" ',
$this->dblclick);
$this->dblclick=$e;
}
$input=sprintf('<INPUT TYPE="Text" class="input_text" '.
' NAME="%s" ID="%s" VALUE="%s" SIZE="%d" %s %s>',
$this->name,
$this->name,
$this->value,
$this->size,
$this->dblclick,
$this->javascript
);
$ind=sprintf('<span id="%s_ind" style="display:none"> <img src="image/loading.gif" alt="Chargement..."/>'.
'</span>',
$this->name);
$div=sprintf('<div id="%s_choices" class="autocomplete"></div>',
$this->name);
$query=dossier::get().'&PHPSESSID='.$l_sessid.'&e='.urlencode($this->extra);
$javascript=sprintf('try { new Ajax.Autocompleter("%s","%s_choices","fid_card.php?%s",'.
'{paramName:"FID",minChars:1,indicator:null,'.
'callback:%s, '.
' afterUpdateElement:%s});} catch (e){alert(e.message);};',
$this->name,$this->name,$query,
$this->callback,
$this->fct);
$javascript=create_script($javascript.$this->dblclick);
$r=$label.$input.$attr.$ind.$div.$javascript;
if ( $this->table == 1 )
$r=td($r);
return $r;
}
/*!\brief print in html the readonly value of the widget*/
public function display()
{
$r=sprintf(' <INPUT TYPE="hidden" NAME="%s" VALUE="%s" SIZE="8">',
$this->name,
$this->value
);
$r.='<span>'.$this->value.'</span>';
return $r;
}
static function javascript() {
$str='';
echo js_include('prototype.js');
echo js_include('scriptaculous.js');
echo js_include('effects.js');
echo js_include('controls.js');
return $str;
}
/**
*@brief return a string containing the button for displaying
* a search form. When clicking on the result, update the input text file
* the common used attribute as
* - jrn the ledger
* - label the field to update
* - name name of the input text
* - price amount
* - tvaid
* - typecard (deb, cred, filter or list of value)
* will be set
* if ICard is in readOnly, the button disappears, so the return string is empty
\code
// search ipopup
$search_card=new IPopup('ipop_card');
$search_card->title=_('Recherche de fiche');
$search_card->value='';
echo $search_card->input();
$a=new ICard('test');
$a->search();
\endcode
*\see ajax_card.php
*\note the ipopup id is hard coded : ipop_card
*@return HTML string with the button
*/
function search() {
if ( $this->readOnly==true) return '';
$button=new IButton($this->name.'_bt');
$a="";
foreach (array('typecard','jrn','label','price','tvaid') as $att) {
if (isset($this->$att) )
$a.="this.".$att."='".$this->$att."';";
}
if (isset($this->name))
$a.="this.inp='".$this->name."';";
$a.="this.popup='ipop_card';";
$button->javascript=$a.' search_card(this)';
return $button->input();
}
static public function test_me()
{
require_once('class_itext.php');
$_SESSION['isValid']=1;
$a=new ICard('testme');
$a->extra="all";
$a->set_attribute('label','ctl_label');
$a->set_attribute('tvaid','ctl_tvaid');
$a->set_attribute('price','ctl_price');
$a->set_attribute('purchase','ctl_purchase');
$a->set_attribute('type','all');
echo <<<EOF
<div id="debug" style="border:solid 1px black;overflow:auto"></div>
<script type="text/javascript" language="javascript" src="js/prototype.js">
</script>
<script type="text/javascript" language="javascript" src="js/scriptaculous.js">
</script>
<script type="text/javascript" language="javascript" src="js/effects.js">
</script>
<script type="text/javascript" language="javascript" src="js/controls.js">
</script>
<script type="text/javascript" language="javascript" src="js/ajax_fid.js">
</script>
<script type="text/javascript" language="javascript" >
function test_value(text,li) {
alert("premier"+li.id);
str="";
str=text.id+'<hr>';
if ( text.js_attr1) { str+=text.js_attr1;str+='<hr>';}
if ( text.js_attr2) { str+=text.js_attr2;str+='<hr>';}
if ( text.js_attr3) { str+=text.js_attr3;str+='<hr>';}
for (var i in text) { str+=i+'<br>';
}
// $('debug').innerHTML=str;
ajaxFid(text);
}
</script>
EOF;
echo "<form>";
$l=new IText('ctl_label');
$t=new IText('ctl_tvaid');
$p=new IText('ctl_price');
$b=new IText('ctl_purchase');
echo "Label ".$l->input().'<br>';
echo "Tva id ".$t->input().'<br>';
echo "Price ".$p->input().'<br>';
echo "Purchase ".$b->input().'<br>';
if ( isset($_REQUEST['test_select']) )
echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
$a->set_function('test_value');
$a->javascript=' onchange="alert(\'onchange\');" onblur="alert(\'onblur\');" ';
echo $a->input();
echo dossier::hidden();
echo HtmlInput::submit('Entree','entree');
echo '</form>';
echo <<<EOF
EOF;
}
}