noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 10/238: Currency : add SQL constraint + doc


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 10/238: Currency : add SQL constraint + doc
Date: Sat, 26 Oct 2019 04:40:16 -0400 (EDT)

sparkyx pushed a commit to annotated tag rel7110
in repository noalyss.

commit cff9e49910ccf8c0be1611ace94d769580463e0f
Author: Dany De Bontridder <address@hidden>
Date:   Sun Apr 22 17:05:04 2018 +0200

    Currency : add SQL constraint + doc
---
 include/class/currency_mtable.class.php        | 20 ++++++++++++++++++--
 include/lib/html_input.class.php               |  1 +
 include/template/currency_mtable_input.php     | 25 ++++++++++++++++++++-----
 include/template/currency_mtable_input_new.php | 19 ++++++++++++++++---
 sql/upgrade.sql                                |  9 +++++++++
 5 files changed, 64 insertions(+), 10 deletions(-)

diff --git a/include/class/currency_mtable.class.php 
b/include/class/currency_mtable.class.php
index b3faf9e..4010596 100644
--- a/include/class/currency_mtable.class.php
+++ b/include/class/currency_mtable.class.php
@@ -108,6 +108,8 @@ class Currency_MTable extends Manage_Table_SQL
      *      - Name cannot be empty
      *      - At least one rate 
      *      - Date of the rate 
+     *      - code iso is max 10 char
+     *      - name is max 80
      *      
      */
     function check()
@@ -184,8 +186,22 @@ class Currency_MTable extends Manage_Table_SQL
             $is_error++;
             $this->set_error("cr_code_iso", _("Code ISO existe déjà"));
         }
-
-
+        // - check size
+        if ( trim(mb_strlen($table->cr_code_iso))>10)
+        {
+            $is_error++;
+            $this->set_error("cr_code_iso", _("Code ISO trop long max = 10"));
+        }
+        // - check size
+        if ( trim(mb_strlen($table->cr_name))>80)
+        {
+            $is_error++;
+            $this->set_error("cr_name", _("Nom trop long max=80"));
+        }
+        if ( $table->ch_value < 0 || $table->ch_value == 0) {
+            $is_error++;
+            $this->set_error("ch_value", _("Valeur incorrecte"));
+        }
         if ($is_error==0)
         {
             return TRUE;
diff --git a/include/lib/html_input.class.php b/include/lib/html_input.class.php
index ba6d1c4..cfabb49 100755
--- a/include/lib/html_input.class.php
+++ b/include/lib/html_input.class.php
@@ -261,6 +261,7 @@ class HtmlInput
     static function errorbulle($p_comment)
     {
         global $g_failed;
+        if ( $p_comment == "") return "";
         $r=sprintf('<A HREF="#" tabindex="-1" 
style="display:inline;color:red;background-color:transparent;padding-left:4px;padding-right:4px;text-decoration:none;"
 onmouseover="displayBulle(\'%s\')"  onclick="displayBulle(\'%s\')" 
onmouseout="hideBulle(0)"> %s </A>',
                 $p_comment, $p_comment, $g_failed);
         return $r;
diff --git a/include/template/currency_mtable_input.php 
b/include/template/currency_mtable_input.php
index e48c6ee..59f6957 100644
--- a/include/template/currency_mtable_input.php
+++ b/include/template/currency_mtable_input.php
@@ -31,6 +31,9 @@ if (!defined('ALLOWED'))     die('Appel direct ne sont pas 
permis');
     <tr>
         <td>
             ISO
+            <?php   $error=$this->get_error("cr_code_iso");
+                echo HtmlInput::errorbulle($error);
+            ?>
         </td>
         <td>
             <?php echo $cr_code_iso->input(); ?>
@@ -38,7 +41,10 @@ if (!defined('ALLOWED'))     die('Appel direct ne sont pas 
permis');
     </tr>
     <tr>
         <td>
-            <?php echo _("Nom")?>
+            <?php echo _("Nom");
+            $error=$this->get_error("cr_name");
+            echo HtmlInput::errorbulle($error);
+            ?>
         </td>
         <td>
             <?php echo $cr_name->input(); ?>
@@ -53,10 +59,14 @@ if (!defined('ALLOWED'))     die('Appel direct ne sont pas 
permis');
 <table class="result" id="currency_rate_table">
     <tr>
     <th>
-        <?php echo _("Date");?>
+        <?php echo _("Date");
+        
+        ?>
     </th>
     <th>
-        <?php echo _("Valeur")?>
+        <?php echo _("Valeur");
+        
+            ?>
     </th>
     <th>
         
@@ -85,7 +95,10 @@ if (!defined('ALLOWED'))     die('Appel direct ne sont pas 
permis');
     <?php    endfor; ?>
   <tr>
         <td>
-            <?php echo _("Date"); ?>
+            <?php echo _("Date"); 
+             $error=$this->get_error("str_from");
+            echo HtmlInput::errorbulle($error);
+            ?>
         </td>
         <td>
             <?php echo $new_rate_date->input();?>
@@ -93,7 +106,9 @@ if (!defined('ALLOWED'))     die('Appel direct ne sont pas 
permis');
     </tr>
     <tr>
       <td>
-            <?php echo _("Valeur"); ?>
+            <?php echo _("Valeur");  
+            $error=$this->get_error("ch_value");
+            echo HtmlInput::errorbulle($error);?>
         </td>
         <td>
             <?php echo $new_rate_value->input();?>
diff --git a/include/template/currency_mtable_input_new.php 
b/include/template/currency_mtable_input_new.php
index 88639b8..8a988b1 100644
--- a/include/template/currency_mtable_input_new.php
+++ b/include/template/currency_mtable_input_new.php
@@ -31,6 +31,9 @@ if (!defined('ALLOWED'))     die('Appel direct ne sont pas 
permis');
     <tr>
         <td>
             ISO
+              <?php   $error=$this->get_error("cr_code_iso");
+                echo HtmlInput::errorbulle($error);
+            ?>
         </td>
         <td>
             <?php echo $cr_code_iso->input(); ?>
@@ -38,7 +41,11 @@ if (!defined('ALLOWED'))     die('Appel direct ne sont pas 
permis');
     </tr>
     <tr>
         <td>
-            <?php echo _("Nom")?>
+            <?php echo _("Nom");
+             $error=$this->get_error("cr_name");
+            echo HtmlInput::errorbulle($error);
+            ?>
+            
         </td>
         <td>
             <?php echo $cr_name->input(); ?>
@@ -46,7 +53,10 @@ if (!defined('ALLOWED'))     die('Appel direct ne sont pas 
permis');
     </tr>
     <tr>
         <td>
-            <?php echo _("Date"); ?>
+            <?php echo _("Date"); 
+              $error=$this->get_error("str_from");
+            echo HtmlInput::errorbulle($error);
+            ?>
         </td>
         <td>
             <?php echo $new_rate_date->input();?>
@@ -54,7 +64,10 @@ if (!defined('ALLOWED'))     die('Appel direct ne sont pas 
permis');
     </tr>
     <tr>
       <td>
-            <?php echo _("Valeur"); ?>
+            <?php echo _("Valeur"); 
+             $error=$this->get_error("ch_value");
+            echo HtmlInput::errorbulle($error);
+            ?>
         </td>
         <td>
             <?php echo $new_rate_value->input();?>
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index b5d6ba8..14ccf36 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -36,6 +36,8 @@ CREATE TABLE public.currency_history (
 
 ALTER TABLE public.currency ADD cr_name varchar(80) NULL;
 
+ALTER TABLE public.currency_history ADD CONSTRAINT currency_history_check 
CHECK (ch_value > 0) ;
+
 -- Create view to manage the table
 create view v_currency_last_value as 
 with recent_rate as 
@@ -57,5 +59,12 @@ currency as cr1
 join recent_rate on (currency_id=cr1.id)
 join currency_history as ch1 on (recent_rate.currency_id=ch1.currency_id and 
rc_from=ch1.ch_from);
 
+COMMENT ON COLUMN public.currency_history.id IS 'pk' ;
+COMMENT ON COLUMN public.currency_history.ch_value IS 'rate of currency 
depending of currency of the folder' ;
+COMMENT ON COLUMN public.currency_history.ch_from IS 'Date when the rate is 
available' ;
+COMMENT ON COLUMN public.currency_history.currency_id IS 'FK to currency' ;
+COMMENT ON COLUMN public.currency.cr_code_iso IS 'Code ISO' ;
+COMMENT ON COLUMN public.currency.cr_name IS 'Name of the currency' ;
+
 
 insert into "parameter" values ('MY_CURRENCY','N');
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]