Ejemplo n.º 1
0
 /** Stores/Updates currency value object in the DB */
 public function store()
 {
     global $ari;
     $flagStore = true;
     //@todo: falta validar pto y coma segun config del idioma y guardar segun acepta MySQL
     if (!OOB_numeric::isValid($this->value)) {
         $flagStore = false;
         $ari->error->addError("currency_value", "INVALID_VALUE");
     }
     $this->value = OOB_numeric::formatMySQL($this->value);
     if ($flagStore) {
         $this->value = $ari->db->qMagic($this->value);
         $this->date = $ari->db->qMagic(date('Y-m-d H:i:s'));
         $currency_id = $ari->db->qMagic($this->currency->get('id'));
         if ($this->id > ID_MINIMAL) {
             // update data
             $ari->db->StartTrans();
             $sql = "UPDATE Currency_Value\n\t\t\t\t\t   SET Currency_Value.Date = {$this->date},\n\t\t\t\t\t   \t   Currency_Value.Value = {$this->value},\n\t\t\t\t\t   \t   Currency_Value.CurrencyID = {$currency_id}\n\t\t\t\t\t   WHERE ID = '{$this->id}'";
             $ari->db->Execute($sql);
             if (!$ari->db->CompleteTrans()) {
                 throw new OOB_exception("Error en DB: {$ari->db}->ErrorMsg()", "010", "Error en la Base de Datos", false);
             } else {
                 $return = true;
             }
         } else {
             // insert new
             $sql = "INSERT INTO Currency_Value\n\t\t\t\t\t   ( `Date`, `Value`, `CurrencyID`)\n\t\t\t\t\t   VALUES ( {$this->date}, {$this->value}, {$currency_id} )\n\t\t\t\t\t\t   \t";
             $ari->db->StartTrans();
             $ari->db->Execute($sql);
             $this->id = $ari->db->Insert_ID();
             if (!$ari->db->CompleteTrans()) {
                 throw new OOB_exception("Error en DB: {$ari->db}->ErrorMsg()", "010", "Error en la Base de Datos", false);
             } else {
                 $return = true;
             }
         }
         //end if
         return $return;
     } else {
         // no validan los datos
         return false;
         //devuelve un objeto de error con los errores!
     }
     //end if
 }
Ejemplo n.º 2
0
 public function __construct($id = ID_UNDEFINED)
 {
     global $ari;
     if ($id > ID_MINIMAL && OOB_numeric::isValid($id)) {
         $this->id = $id;
         if (!$this->fill()) {
             throw new OOB_exception("Invalid " . static::getClass() . " id: " . $id, "814", "Invalid class", true);
         }
     }
 }
Ejemplo n.º 3
0
 /** Valida que sea un numero, utiliza localidad, por lo q difiere en puntos y comas segun LOCALE */
 public static function isNumeric($v)
 {
     return OOB_numeric::isValid($v);
 }
Ejemplo n.º 4
0
 /** 
  * Returns true if successful, false if not.
  */
 public function addChange($value, $date = false)
 {
     global $ari;
     $flagStore = true;
     if (!OOB_numeric::isValid($value)) {
         $flagStore = false;
         $ari->error->addError("currency_currency", "INVALID_VALUE");
     }
     if (!$date) {
         $date = new Date();
     }
     //valid and clean Date
     if (!OOB_validatetext::isValidDate($date)) {
         $flagStore = false;
         $ari->error->addError("currency_currency", "INVALID_DATE");
     } else {
         $date = $ari->db->qMagic($date->format("%Y-%m-%d %H:%M:%S"));
     }
     $value = OOB_numeric::formatMySQL(trim($value));
     if ($flagStore) {
         $value = $ari->db->qMagic($value);
         $id = $ari->db->qMagic($this->id);
         $ari->db->StartTrans();
         $sql = "INSERT INTO Currency_Change\n\t\t\t\t   ( Date, Value, CurrencyID)\n\t\t\t\t   VALUES \n\t\t\t\t   ( {$date},{$value},{$id} )\n\t\t\t\t  ";
         //echo $sql; exit;
         $ari->db->Execute($sql);
         if (!$ari->db->CompleteTrans()) {
             throw new OOB_exception("Error en DB: {$ari->db}->ErrorMsg()", "010", "Error en la Base de Datos", false);
             //return false;
         } else {
             return true;
         }
     } else {
         return false;
     }
 }