From d39368fd369bd23ea5ffad6703ebbcd85ac5c1b6 Mon Sep 17 00:00:00 2001 From: fhenry Date: Sat, 12 Jan 2013 14:02:39 +0100 Subject: [PATCH] Add boolean (checkbox) standard extrafield feature --- htdocs/core/class/extrafields.class.php | 42 +++++++++++++++++-- htdocs/core/tpl/admin_extrafields.tpl.php | 1 + htdocs/core/tpl/admin_extrafields_add.tpl.php | 1 + .../core/tpl/admin_extrafields_edit.tpl.php | 1 + htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/fr_FR/admin.lang | 1 + 6 files changed, 43 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 87e3eb5dce7..b387537165b 100755 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -52,7 +52,8 @@ class ExtraFields 'int'=>'Int', 'double'=>'Float', 'date'=>'Date', - 'datetime'=>'DateAndTime' + 'datetime'=>'DateAndTime', + 'boolean'=>'Boolean' ); /** @@ -135,7 +136,14 @@ class ExtraFields if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { - $field_desc = array('type'=>$type, 'value'=>$length, 'null'=>($required?'NOT NULL':'NULL')); + if ($type=='boolean') { + $typedb='int'; + $lengthdb='1'; + } else { + $typedb=$type; + $lengthdb=$length; + } + $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL')); $result=$this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); if ($result > 0) { @@ -304,7 +312,14 @@ class ExtraFields if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { - $field_desc = array('type'=>$type, 'value'=>$length, 'null'=>($required?'NOT NULL':'NULL')); + if ($type=='boolean') { + $typedb='int'; + $lengthdb='1'; + } else { + $typedb=$type; + $lengthdb=$length; + } + $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL')); $result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); if ($result > 0) { @@ -487,7 +502,7 @@ class ExtraFields function showInputField($key,$value,$moreparam='') { global $conf; - + $label=$this->attribute_label[$key]; $type =$this->attribute_type[$key]; $size =$this->attribute_size[$key]; @@ -534,6 +549,16 @@ class ExtraFields $doleditor=new DolEditor('options_'.$key,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,5,100); $out=$doleditor->Create(1); } + else if ($type == 'boolean') + { + $checked=''; + if (!empty($value)) { + $checked=' checked="checked" value="1" '; + } else { + $checked=' value="1" '; + } + $out=''; + } // Add comments if ($type == 'date') $out.=' (YYYY-MM-DD)'; elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; @@ -550,6 +575,7 @@ class ExtraFields */ function showOutputField($key,$value,$moreparam='') { + $label=$this->attribute_label[$key]; $type=$this->attribute_type[$key]; $size=$this->attribute_size[$key]; @@ -568,6 +594,14 @@ class ExtraFields { $showsize=10; } + elseif ($type == 'boolean') + { + $checked=''; + if (!empty($value)) { + $checked=' checked="checked" '; + } + $value=''; + } else { $showsize=round($size); diff --git a/htdocs/core/tpl/admin_extrafields.tpl.php b/htdocs/core/tpl/admin_extrafields.tpl.php index d8f23a4c183..f2ce0efa59b 100644 --- a/htdocs/core/tpl/admin_extrafields.tpl.php +++ b/htdocs/core/tpl/admin_extrafields.tpl.php @@ -29,6 +29,7 @@ else if (type == 'int') { size.val('10').removeAttr('disabled'); } else if (type == 'text') { size.val('2000').removeAttr('disabled'); } else if (type == 'varchar') { size.val('255').removeAttr('disabled'); } + else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled');} else size.val('').attr('disabled','disabled'); } init_typeoffields(); diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index d28fe1c33b2..3215c235281 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -31,6 +31,7 @@ else if (type == 'int') { size.val('10').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } else if (type == 'text') { size.val('2000').removeAttr('disabled'); unique.attr('disabled','disabled').removeAttr('checked'); } else if (type == 'varchar') { size.val('255').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } + else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled');} else size.val('').attr('disabled','disabled'); } init_typeoffields(''); diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index d681d7cf82c..4df48df6702 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -31,6 +31,7 @@ else if (type == 'int') { size.removeAttr('disabled'); } else if (type == 'text') { size.removeAttr('disabled'); unique.attr('disabled','disabled').removeAttr('checked'); } else if (type == 'varchar') { size.removeAttr('disabled'); } + else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled');} else size.val('').attr('disabled','disabled'); } init_typeoffields(jQuery("#type").val()); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 6007be581fc..9ecda1dbcef 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -351,6 +351,7 @@ Int=Integer Float=Float DateAndTime=Date and hour Unique=Unique +Boolean=Boolean (Checkbox) LibraryToBuildPDF=Library used to build PDF WarningUsingFPDF=Warning: Your conf.php contains directive dolibarr_pdf_force_fpdf=1. This means you use the FPDF library to generate PDF files. This library is old and does not support a lot of features (Unicode, image transparency, cyrillic, arab and asiatic languages, ...), so you may experience errors during PDF generation.
To solve this and have a full support of PDF generation, please download TCPDF library, then comment or remove the line $dolibarr_pdf_force_fpdf=1, and add instead $dolibarr_lib_TCPDF_PATH='path_to_TCPDF_dir' LocalTaxDesc=Some countries apply 2 or 3 taxes on each invoice line. If this is the case, choose type for second and third tax and its rate. Possible type are:
1 : local tax apply on products and services without vat (vat is not applied on local tax)
2 : local tax apply on products and services before vat (vat is calculated on amount + localtax)
3 : local tax apply on products without vat (vat is not applied on local tax)
4 : local tax apply on products before vat (vat is calculated on amount + localtax)
5 : local tax apply on services without vat (vat is not applied on local tax)
6 : local tax apply on services before vat (vat is calculated on amount + localtax) diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index d077ffedb4e..0effda388ec 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -346,6 +346,7 @@ TextLong=Texte long Int=Numérique entier Float=Décimal DateAndTime=Date et heure +Boolean=Booleen (Checkbox) LibraryToBuildPDF=Bibliothèque utilisée pour la génération des PDF WarningUsingFPDF=Attention: Votre fichier conf.php contient la directive dolibarr_pdf_force_fpdf=1. Cela signifie que vous utilisez la librairie FPDF pour générer vos fichiers PDF. Cette librairie est ancienne et ne couvre pas de nombreuses fonctionnalitée (Unicode, transparence des images, langues cyrillic, arabes ou asiatiques...), aussi vous pouvez rencontrez des problèmes durant la génération des PDF.
Pour résoudre cela et avoir un support complet de PDF, vous pouvez télécharger la librairie TCPDF puis commenter ou supprimer la ligne $dolibarr_pdf_force_fpdf=1, et ajouter à la place $dolibarr_lib_TCPDF_PATH='chemin_vers_TCPDF' LocalTaxDesc=Certains pays appliquent 2 voir 3 taux sur chaque ligne de facture. Si c'est le cas, choisissez le type du deuxième et troisième taux et sa valeur. Les types possibles sont:
1 : taxe locale sur les produits et services hors tva (la tva n'est pas appliquée sur la taxe locale)
2 : taxe locale sur les produits et services avant tva (la tva est appliquée sur le montant + la taxe locale)
3 : taxe locale uniquement sur les produits hors tva (la tva n'est pas appliquée sur la taxe locale)
4 : taxe locale uniquement sur les produits avant tva (la tva est appliquée sur le montant + la taxe locale)
5 : taxe locale uniquement sur les services hors tva (la tva n'est pas appliquée sur la taxe locale)
6 : taxe locale uniquement sur les service avant tva (la tva est appliquée sur le montant + la taxe locale)