From 410d5984d1c5eb8ac07ba3463bbe85fe89979db5 Mon Sep 17 00:00:00 2001 From: www-data Date: Sun, 3 Apr 2022 01:16:01 +0200 Subject: [PATCH] Improved ofx upload. Started curl class to handle anah requets --- class.curl.php | 55 ++++++++++++++++++++++++++++++++++++++++++ class.http.Request.php | 2 +- class.ofx.php | 25 +++++++++++-------- class.validator.php | 10 +++++--- 4 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 class.curl.php diff --git a/class.curl.php b/class.curl.php new file mode 100644 index 0000000..8811e79 --- /dev/null +++ b/class.curl.php @@ -0,0 +1,55 @@ +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; + } +} + +?> diff --git a/class.http.Request.php b/class.http.Request.php index 4d993db..060706b 100644 --- a/class.http.Request.php +++ b/class.http.Request.php @@ -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]); } diff --git a/class.ofx.php b/class.ofx.php index f9a523d..f44f5f8 100644 --- a/class.ofx.php +++ b/class.ofx.php @@ -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'].'
'.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(); } } diff --git a/class.validator.php b/class.validator.php index 4629005..40fc166 100644 --- a/class.validator.php +++ b/class.validator.php @@ -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); + } } } -- 2.30.2