/** * Método para guardar el mantenedor del folio usando una transacción * serializable * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) * @version 2015-09-22 */ public function save($exitOnFailTransaction = true) { if (!$this->db->beginTransaction(true) and $exitOnFailTransaction) { return false; } parent::save(); return $this->db->commit(); }
/** * Método para guardar el documento recibido, creará el emisor si no existe * antes de ser guardado el documento * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) * @version 2015-12-29 */ public function save() { $this->getEmisor(); // si el emisor no existe con esto se creará return parent::save(); }
protected function save() { $this->model->values($this->request->post()); // clean null values foreach ($this->model->table_columns() as $field => $values) { $is_boolean = Arr::get($values, 'data_type') === 'tinyint' and Arr::get($values, 'display') == 1; $is_nullable = Arr::get($values, 'is_nullable'); $has_value = (bool) $this->model->{$field} and $this->model->{$field} !== NULL; if ($is_nullable and !$is_boolean and !$has_value) { $this->model->{$field} = NULL; } } try { if (isset($_FILES)) { foreach ($_FILES as $name => $file) { if (Upload::not_empty($file)) { $filename = uniqid() . '_' . $file['name']; $filename = preg_replace('/\\s+/u', '_', $filename); $dir = DOCROOT . 'public' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . strtolower($this->model_name); create_dir($dir); Upload::save($file, $filename, $dir); $this->model->{$name} = $filename; } } } if ($this->parent_id) { $this->model->{$this->parent . '_id'} = $this->parent_id; } $this->has_many = Arr::merge($this->has_many, $this->model->has_many()); $this->save_before(); $this->model->save(); $this->save_after(); // ignore external relations $has_many_through = array_filter($this->has_many, function ($item) { return strpos(Arr::get($item, 'through'), $this->model->table_name() . '_') === 0; }); // add has many foreach ($has_many_through as $name => $values) { $ids = $this->request->post($name); $this->model->remove($name); if (!$ids) { continue; } $this->model->add($name, $ids); } $this->flush(); if ($this->request->is_ajax()) { $this->response->json($this->model->all_as_array()); return; } Session::instance()->set('success', 'Registro salvo com sucesso!'); if ($this->redirect === NULL) { HTTP::redirect($this->url()); } else { HTTP::redirect($this->redirect); } } catch (ORM_Validation_Exception $e) { $errors = $e->errors('models'); if (!$errors) { $errors = array($e->getMessage()); } View::set_global('errors', $errors); if ($this->request->is_ajax()) { $this->response->json(array('errors' => $errors)); } } }
/** * Método que guarda el enviodte que se ha recibido desde otro contribuyente * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) * @version 2015-09-28 */ public function save() { $this->certificacion = (int) $this->certificacion; if (!isset($this->codigo)) { // ver si existe una entrada igual $existe = (bool) $this->db->getValue(' SELECT COUNT(*) FROM dte_intercambio WHERE receptor = :receptor AND certificacion = :certificacion AND fecha_hora_firma = :fecha_hora_firma AND archivo_md5 = :archivo_md5 ', ['receptor' => $this->receptor, 'certificacion' => $this->certificacion, 'fecha_hora_firma' => $this->fecha_hora_firma, 'archivo_md5' => $this->archivo_md5]); if ($existe) { return false; } // guardar entrada $this->db->beginTransaction(true); $this->codigo = (int) $this->db->getValue(' SELECT MAX(codigo) FROM dte_intercambio WHERE receptor = :receptor AND certificacion = :certificacion ', [':receptor' => $this->receptor, 'certificacion' => $this->certificacion]) + 1; $status = parent::save(); $this->db->commit(); return $status; } else { return parent::save(); } }