Improved ofx upload. Started curl class to handle anah requets
authorwww-data <www-data@n3150.home>
Sat, 2 Apr 2022 23:16:01 +0000 (01:16 +0200)
committerwww-data <www-data@n3150.home>
Sat, 2 Apr 2022 23:16:01 +0000 (01:16 +0200)
class.curl.php [new file with mode: 0644]
class.http.Request.php
class.ofx.php
class.validator.php

diff --git a/class.curl.php b/class.curl.php
new file mode 100644 (file)
index 0000000..8811e79
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+
+/**
+ *
+ */
+class cURL
+{
+    public  $curl;
+    public  $url = null;
+    private $options = Array();
+
+    public function __construct($_url)
+    {
+        if ( !extension_loaded('curl'))
+        {
+            throw new \ErrorException('cURL library not loaded');
+        }
+        $this->curl = curl_init();
+    }
+
+    /**
+     * @brief core function to execute a curl request
+     *
+     */
+    private function exec()
+    {
+    }
+    /**
+     *
+     */
+    public function get($_url,$_data = [])
+    {
+    }
+
+    /**
+     * @brief setOpt of curl instance
+     * 
+     * @param $opt String Option to set
+     * @param $val Object or String or Function
+     * 
+     * @return boolean true if sucess, 0 if failure
+     */
+    public function setOpt($opt,$val)
+    {
+        $ret = curl_setopt($this->curl,$opt,$val);
+        if ($ret)
+        {
+            $this->options[$opt] = $val;
+        }
+        return $ret;
+    }
+}
+
+?>
index 4d993dbae8b4445139dc55c12d104df9b7fb76b7..060706b11053492df0a2979ed2589f25ae8d211a 100644 (file)
@@ -42,7 +42,7 @@ class Request implements ArrayAccess,IRequest
      * implement ArrayAccess method
      *
      */
-    public function offsetExists($offet)
+    public function offsetExists($offset)
     {
         return isset($this->data[$offset]);
     }
index f9a523d5d5af54f53837121f6e9e62f823a325a0..f44f5f8b736bac8929431db1088b673942f73b8e 100644 (file)
@@ -23,7 +23,7 @@ class Ofx {
         $this->texte = substr($this->texte, $fin) ; 
     } else 
     {
-      error_log("no more paragraph ".$code." début=".$debut." text:".substr($this->texte,0,20));
+      //error_log("no more paragraph ".$code." début=".$debut." text:".substr($this->texte,0,20));
       $this->para = '' ;
     } 
   } 
@@ -47,12 +47,16 @@ class Ofx {
     //$compte_id = $row_rs_compte['id'] ;
   }
   
-  public function onMouvement($type,$date,$montant,$reste,$libelle,$info)
+  public function onMouvement($type,$date,$montant,$mvmt_id,$libelle,$info)
+  {
+  }
+  
+  public function onEnd()
   {
   }
 
-public function parse($fichier)
-{
+  public function parse($fichier)
+  {
     $ofx_msg = ""; 
     //if($_size_ > 3200000) $ofx_msg = "Erreur: le fichier est trop lourd (max 3M)"; 
     if(empty($errStr))
@@ -68,7 +72,6 @@ public function parse($fichier)
                 $code_guichet = $this->valeur('BRANCHID') ; 
                 $no_compte = $this->valeur('ACCTID') ; 
                 $this->onAccount($code_banque,$code_guichet,$no_compte);
-                $compte_id   = 512000; 
                 //$totalRows_rs_compte = mysql_num_rows($rs_compte);     
                 $totalRows_rs_compte = 1;     
                 if ($totalRows_rs_compte == 1) { 
@@ -81,14 +84,13 @@ public function parse($fichier)
                         $type = $this->valeur('TRNTYPE') ; 
                         $date = $this->valeur('DTPOSTED') ; 
                         $montant = $this->valeur ('TRNAMT') ; 
-                        $reste = $montant ; 
-                        $banque_mouvement_id = $compte_id.' - '.$this->valeur('FITID') ; 
+                        $mouvement_id = $this->valeur('FITID') ; 
                         $libelle = ucwords(strtolower(str_replace($a_supprimer, ' ', $this->valeur('NAME')))) ; 
                         $info = ucwords(strtolower(str_replace($a_supprimer, ' ', $this->valeur ('MEMO')))) ; 
                         //$values .= "(".$compte_id.",'".$type."',".$date.",".$montant.",".$reste. 
                         //    ",'".$banque_mouvement_id."','".$libelle."','".$info."'), " ; 
                         $this->paragraphe('STMTTRN') ;
-                        $this->onMouvement($type,$date,$montant,$reste,$libelle,$info);
+                        $this->onMouvement($type,$date,$montant,$mouvement_id,$libelle,$info);
                     } 
                     //$values = substr($values, 0, strlen($values)-2) ;
                     //mysql_select_db($database_locations, $locations); 
@@ -96,12 +98,15 @@ public function parse($fichier)
                     //if (mysql_query($query_insert, $locations) == 1) 
                     //    $ofx_msg = "Importation réussie de $i mouvements dans le compte ".$row_rs_compte['libelle'].'<br />'.mysql_info($locations) ; 
                     //else $ofx_msg = "Erreur dans l'insertion des mouvements" ;
-
                 } else $ofx_msg = "Erreur: le compte bancaire $code_banque / $code_guichet / $no_compte n'existe pas" ; 
             } else $ofx_msg = "Erreur: le fichier ne semble pas être un fichier OFX valide" ; 
         } else $ofx_msg = "Erreur: échec lors de l'ouverture du fichier $fichier" ; 
     } else $ofx_msg = "Erreur: le fichier n'a pas été téléchargé" ; 
-    error_log("Parsing end ".$i." : ".$ofx_msg);
+    if (ofx_msg != "")
+    {
+        error_log("Parsing end ".$i." : ".$ofx_msg);
+    }
+    $this->onEnd();
  }
 }
 
index 4629005850f6a9e652e3081b3293e3a1efce2623..40fc166cfd57650d24218e5a73473e85f7000b38 100644 (file)
@@ -21,15 +21,17 @@ class Validator {
         }
       }
       if ($filter == FILTER_VALIDATE_INT) {
-       // Fix code code validate 0 as integer (add filter_var === 0)
+        // Fix code code validate 0 as integer (add filter_var === 0)
         if (! (filter_var($var,$filter) === 0 || filter_var($var,$filter) )) {
-                throw new Exception(_("Field validation not an int ").$msg);
+                throw new Exception(_("Field validation not an int").$msg);
         }
       }
       if ($filter == FILTER_VALIDATE_FLOAT) {
+        if ($var == "0.0" )
+            return; // it's ok
         if (!filter_var($var,$filter)) {
-                throw new Exception(_("Field validation not a float ").$msg);
-       }
+                throw new Exception(_("Field validation not a float").$msg);
+        }
       }
     }