public static function make_delta($app_id) { // 获取包信息 $app = Model_App::instance()->get_info_by_id($app_id); if (empty($app)) { Rest_Log::error("{$app_id}对应的记录不存在,无法生成增量包"); throw new Rest_Exception(Rest_Response::HTTP_SERVER_ERROR, "{$app_id}对应的记录不存在,无法生成增量包"); } // 判断当前包是否为强制升级 if (Model_App::instance()->is_force_update($app['force_update'])) { Rest_Log::trace("{$app_id}对应的记录不存在,无法生成增量包"); return; } // 获取当前包之前的X个包 $app_delta_config = Rest_Config::get('appdelta'); $condition = ['client_id' => $app['client_id'], 'platform' => $app['platform'], 'channel' => $app['channel'], 'inner_version < ' => $app['inner_version']]; $src_app_list = Model_App::instance()->get_list($condition, ['inner_version' => 'desc'], 0, $app_delta_config['limit']); if (empty($src_app_list)) { Rest_Log::trace("{$app_id}对应的包列表不存在,就不生成增量包了"); return; } foreach ($src_app_list as $src_app) { self::do_make_delta($src_app, $app); } }
/** * 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(); }
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)); } } }
/** * Constructor del tipo de dte * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) * @version 2015-09-21 */ public function __construct($codigo = null) { parent::__construct($codigo); $this->dte_tipo =& $this->tipo; }
/** * 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(); }
/** * 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(); } }
?> , <?php } ?> <?php } elseif (Arr::get($belongs_to, $name)) { ?> <?php $column_name = NULL; $is_model = method_exists($row->{$name}, 'list_columns'); $belongs_to_model = $row->{$name}; if (!$is_model) { $belongs_to_model = Model_App::factory(ORM::get_model_name($row->object_name()), $row->{$name}); } $name = $belongs_to_model->object_name(); foreach ($belongs_to_model->list_columns() as $column => $values) { if (Arr::get($values, 'type') === 'string' and $column_name === NULL) { $column_name = $column; } } ?> <a href="<?php echo URL::site('manager/' . $name . '/edit/' . $belongs_to_model->id); ?> "><?php echo $belongs_to_model->{$column_name}; ?> </a>
<?php echo Form::select($select_name, $belongs_to_values, $model->{$select_name}, array('class' => 'form-control')); ?> <?php } elseif (!empty($has_many) and Arr::get($has_many, $name) and Arr::path($has_many, $name . '.through')) { ?> <?php $column_name = NULL; $model_name = ORM::get_model_name($name); $far_primary_key = Arr::path($has_many, $name . '.far_primary_key', 'id'); if (!class_exists($model_name)) { $model_name = Arr::path($has_many, $name . '.model'); } $parent_has_many = Model_App::factory($model_name); foreach ($parent_has_many->list_columns() as $column => $values) { if (Arr::get($values, 'type') === 'string' and $column_name === NULL) { $column_name = $column; } } $selects = $parent_has_many->find_all()->as_array('id', $column_name); $selected = $model->{$name}->find_all()->as_array(NULL, $far_primary_key); echo '<div style="max-height: 400px; overflow-x: auto; border: 1px solid #ddd; border-radius: 3px; padding: 0 10px;">'; foreach ($selects as $select_id => $select_name) { echo '<div class="checkbox">'; echo '<label class="checkbox-inline">'; echo Form::checkbox($name . '[]', $select_id, in_array($select_id, $selected)) . ' ' . $select_name . ' '; echo '</label>'; echo '</div>'; }
/** * Constructor del contribuyente * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) * @version 2015-12-31 */ public function __construct($rut = null) { if (!is_numeric($rut)) { $rut = explode('-', str_replace('.', '', $rut))[0]; } if (is_numeric($rut)) { parent::__construct($rut); if (!$this->exists()) { $this->dv = \sowerphp\app\Utility_Rut::dv($this->rut); $response = \sowerphp\core\Network_Http_Socket::get('https://sasco.cl/api/servicios/enlinea/sii/actividad_economica/' . $this->rut . '/' . $this->dv); if ($response['status']['code'] == 200) { $info = json_decode($response['body'], true); $this->razon_social = substr($info['razon_social'], 0, 100); if (!empty($info['actividades'][0]['codigo'])) { $this->actividad_economica = $info['actividades'][0]['codigo']; } if (!empty($info['actividades'][0]['glosa'])) { $this->giro = substr($info['actividades'][0]['glosa'], 0, 80); } try { $this->save(); } catch (\sowerphp\core\Exception_Model_Datasource_Database $e) { } } } $this->contribuyente =& $this->razon_social; } }