Conjunto 546c863 en sipes


Ignorar:
Fecha y hora:
29/07/2019 13:16:04 (hace 5 años)
Autor:
Miguel Angel Narvaez Montilva <miguelnarvaez31@…>
Branches:
stable
Children:
bce0d38
Parents:
f9d3d85
Mensaje:

Se modifica modulo ente planificador_importar para ingresar montor de reconversión monetaria

Fichero:
1 editado

Leyenda

No modificado
Añadido
Eliminado
  • 0.3-modules/ente_planificador_importar/ente_planificador_importar.module

    rf9d3d85 r546c863  
    22
    33  /**
    4   * Modulo para importar entes y terminos 
     4  * Modulo para importar entes y terminos
    55  * Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana
    66  * @file ente_planificador_importar.module
     
    1212  * the Free Software Foundation; either version 2 of the License, or
    1313  * (at your option) any later version.
    14   * 
     14  *
    1515  * This program is distributed in the hope that it will be useful,
    1616  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1717  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1818  * GNU General Public License for more details.
    19   * 
     19  *
    2020  * You should have received a copy of the GNU General Public License
    2121  * along with this program; if not, write to the Free Software
     
    5959    'type' => MENU_CALLBACK,
    6060  );
     61  $items['ente_planificador_importar/updb_proyectos'] = array(
     62    'title' => 'Importar Entes Planificadores',
     63    'page callback' => 'drupal_get_form',
     64    'page arguments' => array('ente_planificador_importar_updb_proyectos_form'),
     65    'access arguments' => array('import entes planificadores'),
     66    'type' => MENU_CALLBACK,
     67  );
    6168  $items['ente_planificador_importar/terminos'] = array(
    6269    'title' => 'Importar Terminos',
     
    120127    $links['entes'] = array(
    121128      'data' => l(t('Importar Entes Planificadores'), 'ente_planificador_importar/entes'),
    122       'class' => 'ente-planificador-importar-entes', 
     129      'class' => 'ente-planificador-importar-entes',
    123130    );
    124131  }
     
    126133    $links['term1'] = array(
    127134      'data' => l(t('Importar terminos'), 'ente_planificador_importar/terminos'),
    128       'class' => 'ente-planificador-importar-term', 
     135      'class' => 'ente-planificador-importar-term',
    129136    );
    130137    $links['term2'] = array(
    131138      'data' => l(t('Importar Campos de terminos'), 'ente_planificador_importar/terminos/fields'),
    132       'class' => 'ente-planificador-importar-term-fields', 
     139      'class' => 'ente-planificador-importar-term-fields',
    133140    );
    134141    $links['term_parent'] = array(
    135142      'data' => l(t('Relacionar taxonomias y guardar valores en un campo del termino'), 'ente_planificador_importar/terminos/relations_fields'),
    136       'class' => 'ente-planificador-importar-term-parents-fields', 
     143      'class' => 'ente-planificador-importar-term-parents-fields',
    137144    );
    138145  }
     
    140147    $links['estadoproyecto'] = array(
    141148      'data' => l(t('Actualizar estado de proyectos'), 'ente_planificador_importar/estadoproyecto'),
    142       'class' => 'ente-planificador-importar-estado-proyecto', 
     149      'class' => 'ente-planificador-importar-estado-proyecto',
    143150    );
    144151  }
     
    147154/**
    148155 * Implementation of ente_planificador_importar_terminos_form().
    149  * Form to load cvs file in term import 
     156 * Form to load cvs file in term import
    150157 */
    151158function ente_planificador_importar_terminos_relations_fields_form(&$form_state) {
     
    193200/**
    194201 * Implementation of ente_planificador_importar_terminos_form_submit().
    195  * Submit cvs file in term import 
     202 * Submit cvs file in term import
    196203 */
    197204function ente_planificador_importar_terminos_relations_fields_form_submit($form, &$form_state) {
     
    279286
    280287function ente_planificador_importar_terminos_relations_fields_name($vid) {
    281   $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent
    282     FROM {term_data} t
    283     INNER JOIN {term_hierarchy} h
    284     ON t.tid = h.tid
    285     WHERE t.vid = %d
    286     ORDER BY weight, name', 't', 'tid'), $vid);
    287  
     288  $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid);
    288289  while ($term = db_fetch_object($result)) {
    289290    $terms[trim($term->name)] = $term;
     
    422423  $output = drupal_render($new_form);
    423424  print drupal_to_js(array('data' => $output, 'status' => true));
    424   exit(); 
     425  exit();
    425426  print '';
    426427  exit();
     
    431432 * Implementation of _batch_ente_planificador_importar_term_fields().
    432433 * display term saved (used in _ente_planificador_importar_terminos_execute)
    433  * Batch run callback 
     434 * Batch run callback
    434435 */
    435436function _batch_ente_planificador_importar_term_relations_fields($term, &$context) {
     
    460461
    461462/**
     463 * Update values of field to type content
     464 */
     465function ente_planificador_importar_updb_proyectos_form(&$form_state) {
     466  $form = array();
     467  // If this #attribute is not present, upload will fail on submit
     468  $form['#attributes']['enctype'] = 'multipart/form-data';
     469  $form['file_import_entes'] = array(
     470    '#title' => t('Archivo a importar'),
     471    '#type'  => 'file',
     472    '#description' => t('Archivo cvs con el contenido de los terminos a importar'),
     473    '#weight' => -1,
     474  );
     475
     476  $options = array();
     477  for ($i = 0;$i < 30; $i++) {
     478    if (!$i) {
     479      $options[$i] = t('N/A');
     480    }
     481    else {
     482      $options[$i] = t('Fila') . ' ' . $i;
     483    }
     484  }
     485
     486  $delimiter_option = array(",",";");
     487  $form['delimiter']= array(
     488    '#type' => 'select',
     489    '#title' => t('Tipo de Delimitador'),
     490    '#options' => $delimiter_option,
     491    '#description' => t("Delimitador del archivo csv."),
     492    '#required' => TRUE,
     493    '#weight' => -1,
     494    '#default_value' => ",",
     495  );
     496
     497  $form['field_name'] = array(
     498    '#type' => 'select',
     499    '#title' => t('Nombre del campo'),
     500    '#options' => $options,
     501    '#description' => t("La fila donde se encuentra el nombre del Campo a modificar."),
     502    '#required' => TRUE,
     503    '#weight' => 0,
     504    '#default_value' => 1,
     505  );
     506
     507  $form['field_nid'] = array(
     508    '#type' => 'select',
     509    '#title' => t('Nid del nodo'),
     510    '#options' => $options,
     511    '#description' => t("La fila donde se encuentra el nid del nodo a modificar."),
     512    '#required' => TRUE,
     513    '#weight' => 1,
     514    '#default_value' => 2,
     515  );
     516
     517  $form['field_vid'] = array(
     518    '#type' => 'select',
     519    '#title' => t('Vid del campo'),
     520    '#options' => $options,
     521    '#description' => t("La fila donde se encuentra el vid del nodo a modificar."),
     522    '#required' => TRUE,
     523    '#weight' => 2,
     524    '#default_value' => 3,
     525  );
     526
     527  $form['type_content'] = array(
     528    '#type' => 'select',
     529    '#title' => t('tipo de contenido del campo'),
     530    '#options' => $options,
     531    '#description' => t("seleccione la columna donde se encuentre el tipo de contenido del campo."),
     532    '#required' => TRUE,
     533    '#weight' => 3,
     534    '#default_value' => 4,
     535  );
     536
     537  $form['field_delta'] = array(
     538    '#type' => 'select',
     539    '#title' => t('Delta del campo'),
     540    '#options' => $options,
     541    '#description' => t("si el campo es multiple seleccione la columna donde se encuentre el delta."),
     542    '#required' => TRUE,
     543    '#weight' => 4,
     544  );
     545
     546  $form['field_tid'] = array(
     547    '#type' => 'select',
     548    '#title' => t('tid del campo'),
     549    '#options' => $options,
     550    '#description' => t("si el campo es multiple seleccione la columna donde se encuentre el tid."),
     551    '#required' => TRUE,
     552    '#weight' => 5,
     553  );
     554
     555  $form['fields'] = array(
     556    '#type' => 'fieldset',
     557    '#title' => t('Campos'),
     558    '#weight' => 6,
     559  );
     560  for ($i=0; $i<12; $i++) {
     561    $form['fields']['field_value_' . $i] = array(
     562      '#type' => 'select',
     563      '#title' => t('Valor del campo ' . $i),
     564      '#options' => $options,
     565      '#description' => t("La fila donde se encuentra el valor del nodo a modificar."),
     566      '#required' => TRUE,
     567      '#weight' => $i,
     568      '#default_value' => ($i==0) ? 7 : 0 ,
     569    );
     570  }
     571
     572  $form['encabezado'] = array(
     573    '#title' => 'Primera columna como encabezado',
     574    '#type' => 'checkbox',
     575    '#return_value' => '1',
     576    '#weight' => 7,
     577    '#default_value' => TRUE,
     578  );
     579
     580  $form['submit'] = array(
     581    '#type' => 'submit',
     582    '#value' => 'Submit',
     583    '#weight' => 35,
     584  );
     585  return $form;
     586}
     587
     588/**
     589 * Implementation of function ente_planificador_importar_updb_proyectos_form().
     590 * Update values of field to type content
     591 */
     592function ente_planificador_importar_updb_proyectos_form_submit($form, &$form_state) {
     593  global $user;
     594  $validators = array('file_validate_extensions' => array('csv'));
     595  // Check for a new uploaded file.
     596  $file = file_save_upload('file_import_entes', $validators);
     597  if (isset($file)) {
     598    include_once('./'. drupal_get_path('module', 'content') .'/content.install');
     599    drupal_load('module', 'content');
     600    // $types = content_types_install();
     601    // if (empty($types)) {
     602    //   return $ret;
     603    // }
     604
     605    // File upload was attempted.
     606    if ($file) {
     607
     608      // Put the temporary file in form_values so we can save it on submit.
     609      $csv = $file->filepath;
     610      $file = fopen($csv, 'r');
     611      $time = time();
     612      $i = 1;
     613      $batch = array(
     614        'title' => t('Update value proyects and acciones ...', array('@format' => $format)),
     615        'operations' => array(),
     616        'init_message' => t('Commencing'),
     617        'progress_message' => t('Processed @current out of @total.'),
     618        'error_message' => t('An error occurred during processing'),
     619        'finished' => '_batch_ente_planificador_importar_finished',
     620      );
     621
     622      //read the csv archive
     623      $data_all =  fread($file, filesize($csv));
     624      $fgetslines = explode("\n",$data_all);
     625      $process = count($fgetslines);
     626      $process = $form_state['values']['encabezado'] && $i == 1 ? $process-1 : $process ;
     627      $encabezado = $form_state['values']['encabezado'] && $i == 1 ? 1 : 0 ;
     628
     629      for ($k=$encabezado; $k < $process; $k++) {
     630        $data_line = explode("\n",$data_all);
     631        $data_line_all = $data_line[$k];
     632        $delimet = $form_state['values']['delimiter'] ? ";" : "," ;
     633        $data = explode($delimet,$data_line_all);
     634
     635        $batch['operations'][] = array('_ente_planificador_importar_updb_proyectos_importar', array( $data, $form_state['values']));
     636      }
     637
     638      batch_set($batch);
     639      batch_process('ente_planificador_importar/updb_proyectos');
     640    }
     641    else {
     642
     643      // File upload failed.
     644      form_set_error('file_import_entes', t('The entes file could not be uploaded.'));
     645    }
     646  }
     647}
     648
     649/**
     650 * Update values of field to type content
     651 * Batch run callback
     652 */
     653 function _ente_planificador_importar_updb_proyectos_importar( $data, $formstate_values, &$context) {
     654
     655   $fields_update = trim($data[$formstate_values['field_name']-1]);
     656   $field = content_fields($fields_update, $data[$formstate_values['type_content']-1]);
     657   $values[] = $field;
     658   $index = array();
     659   for ($i=0; $i<12; $i++) {
     660     $index[] = $i === 0? 'value' : 'value_' . $i;
     661   }
     662
     663   $rate = 100000;
     664   $sql = '';
     665   foreach ($values as $field) {
     666     if ($field['multiple']) {
     667       $sql.=' and delta = '. $data[$formstate_values['field_delta']-1];
     668     }
     669     $db_info = content_database_info($field);
     670     if (array_key_exists('tid', $db_info['columns'])) {
     671       $sql.= ' and ' . $db_info['columns']['tid']['column'] . ' = ' . $data[$formstate_values['field_tid']-1] ;
     672
     673     }
     674     $table = $db_info['table'];
     675     $columns = array();
     676
     677     foreach($index as $key => $id) {
     678       if (isset($db_info['columns'][$id])) {
     679         $value = trim($data[$formstate_values['field_value_' . $key]-1]);
     680         $attributes = $db_info['columns'][$id];
     681         $column = $attributes['column'];
     682
     683         $decimals = ($field['scale']) && is_numeric($field['scale']) ? $field['scale'] : 0;
     684         if(!$value==0) {
     685
     686           //$columns[] = $column  . ' = round(' . $value . '/' . $rate . ', ' . 8 . ')';
     687
     688           // Divide monto
     689           // $value_table = round($value/$rate,8);
     690
     691           //Directamente sin dividir montos
     692           $columns[] = $column .'='.$value;
     693
     694         } else {
     695           $columns[] = $column  . ' = 0 ';
     696         }
     697       }
     698     }
     699
     700     //sql que se va a pasar visto en Entradas recientes del registro
     701     // $sql1 =('UPDATE {'. $db_info['table'] . '} AS tab SET '. implode(', ', $columns) . ' FROM {node} AS n WHERE n.nid = tab.nid AND n.vid = tab.vid AND n.vid = ' . $data[$formstate_values['field_vid']-1] . ' AND n.nid =' . $data[$formstate_values['field_nid']-1] . $sql );
     702     // watchdog('Test Sipes', '$decimals @filename.', array('@filename' => print_r($sql1,1)), WATCHDOG_ERROR);
     703    //endsql que se va a pasar visto en Entradas recientes del registro
     704
     705     update_sql('UPDATE {'. $db_info['table'] . '} AS tab SET '. implode(', ', $columns) . ' FROM {node} AS n WHERE n.nid = tab.nid AND n.vid = tab.vid AND n.vid = ' . $data[$formstate_values['field_vid']-1] . ' AND n.nid =' . $data[$formstate_values['field_nid']-1] . $sql );
     706   }
     707
     708   $context['message'] = t('Now processing nid of node: %submission', array('%submission' => trim($data[$formstate_values['field_nid']-1])));
     709   $context['results'][] = 'Node update: ' . trim($data[$formstate_values['field_nid']-1]) . '</pre>';
     710
     711   if ($context['sandbox']['progress'] >= $context['sandbox']['max']) {
     712     $context['finished'] = 1;
     713   } else {
     714     $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
     715   }
     716 }
     717
     718
     719
     720/**
    462721 * Implementation of ente_planificador_importar_terminos_form().
    463  * Form to load cvs file in term import 
     722 * Form to load cvs file in term import
    464723 */
    465724function ente_planificador_importar_terminos_fields_form(&$form_state) {
     
    499758/**
    500759 * Implementation of ente_planificador_importar_terminos_form_submit().
    501  * Submit cvs file in term import 
     760 * Submit cvs file in term import
    502761 */
    503762function ente_planificador_importar_terminos_fields_form_submit($form, &$form_state) {
     
    530789
    531790      while (($data = fgetcsv($file)) !== FALSE) {
    532          $taxonomy = taxonomy_vocabulary_load($form_state['values']['vid']); 
     791         $taxonomy = taxonomy_vocabulary_load($form_state['values']['vid']);
    533792         $terms = taxonomy_get_tree($taxonomy->vid);
    534793         $name_field = check_plain($data[$form_state['values']['nombre'] - 1]);
     
    567826 * Implementation of _batch_ente_planificador_importar_term_fields().
    568827 * display term saved (used in _ente_planificador_importar_terminos_execute)
    569  * Batch run callback 
     828 * Batch run callback
    570829 */
    571830function _batch_ente_planificador_importar_term_fields($term, &$context) {
     
    697956  $output = drupal_render($new_form);
    698957  print drupal_to_js(array('data' => $output, 'status' => true));
    699   exit(); 
     958  exit();
    700959  print '';
    701960  exit();
     
    704963/**
    705964 * Implementation of ente_planificador_importar_terminos_form().
    706  * Form to load cvs file in term import 
     965 * Form to load cvs file in term import
    707966 */
    708967function ente_planificador_importar_terminos_form() {
     
    7871046/**
    7881047 * Implementation of ente_planificador_importar_terminos_form_submit().
    789  * Submit cvs file in term import 
     1048 * Submit cvs file in term import
    7901049 */
    7911050function ente_planificador_importar_terminos_form_submit($form, &$form_state) {
     
    8501109/**
    8511110 * Implementation of _ente_planificador_importar_terminos_execute().
    852  * Batch 'execute' callback 
     1111 * Batch 'execute' callback
    8531112 */
    8541113function _ente_planificador_importar_terminos_execute($execute_id){
     
    8821141/**
    8831142 * Implementation of _batch_ente_planificador_importar_term_finished().
    884  * Batch 'finished' callback 
     1143 * Batch 'finished' callback
    8851144 */
    8861145function _batch_ente_planificador_importar_term_finished($success, $results, $operations) {
     
    9011160 * Implementation of _batch_ente_planificador_importar_term().
    9021161 * display term saved (used in _ente_planificador_importar_terminos_execute)
    903  * Batch run callback 
     1162 * Batch run callback
    9041163 */
    9051164function _batch_ente_planificador_importar_term($term, &$context) {
     
    9141173          if ($parent->name == trim($term['search_parent']) && $parents_all[count($parents_all) - 1]->name == trim($term['term_parent'])) {
    9151174            $parents = array('name' => $parent->name, 'tid_parent' => $row['tid']);
    916                
     1175
    9171176            $db_query2 = db_query(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t inner join {term_hierarchy} as h on h.tid=t.tid WHERE LOWER(t.name) = LOWER('%s') AND t.vid = %d AND h.parent = %d", 't', 'tid'), trim($term['name']), $term['vid'], $row['tid']);
    9181177            $rows_query = db_fetch_array($db_query2);
     
    9411200/**
    9421201 * Implementation of ente_planificador_importar_form().
    943  * Form to load cvs file in entes import 
     1202 * Form to load cvs file in entes import
    9441203 */
    9451204function ente_planificador_importar_form() {
     
    10031262    );
    10041263    foreach($fields as $field_id => $field) {
    1005       $campos[$field_id] =  $field; 
     1264      $campos[$field_id] =  $field;
    10061265      $form['campos'][$field_id] = array(
    10071266        '#type' => 'select',
     
    10271286/**
    10281287 * Implementation of ente_planificador_importar_form_submit().
    1029  * Submit cvs file in entes import 
     1288 * Submit cvs file in entes import
    10301289 */
    10311290function ente_planificador_importar_form_submit($form, &$form_state) {
     
    11141373/**
    11151374 * Implementation of _ente_planificador_importar_execute().
    1116  * Batch 'execute' callback 
     1375 * Batch 'execute' callback
    11171376 */
    11181377function _ente_planificador_importar_execute($execute_id){
     
    11451404/**
    11461405 * Implementation of _ente_planificador_importar_usuarios().
    1147  * Obtiene la cantidad de usuarios por tipo de ente 
     1406 * Obtiene la cantidad de usuarios por tipo de ente
    11481407 */
    11491408function _ente_planificador_importar_usuarios($tipo = 0) {
     
    11751434 * Implementation of _batch_ente_planificador_importar().
    11761435 * Save entes (used in _ente_planificador_importar_execute)
    1177  * Batch run callback 
     1436 * Batch run callback
    11781437 */
    11791438function _batch_ente_planificador_importar($ente, &$context) {
     
    12181477      }
    12191478      else {
    1220         $acronimo = 'ente_' . $acronimo; 
     1479        $acronimo = 'ente_' . $acronimo;
    12211480      }
    12221481      //se crean los usuarios segun el tipo
     
    12481507/**
    12491508 * Implementation of _batch_ente_planificador_importar_finished().
    1250  * Batch 'finished' callback 
     1509 * Batch 'finished' callback
    12511510 */
    12521511function _batch_ente_planificador_importar_finished($success, $results, $operations) {
     
    12981557/**
    12991558 * Implementation of ente_planificador_importar_aprobar_proyectos_form().
    1300  * Form to load cvs file and setting in proyectos estate update 
     1559 * Form to load cvs file and setting in proyectos estate update
    13011560 */
    13021561function ente_planificador_importar_aprobar_proyectos_form() {
     
    14011660 * Implementation of _batch_proyecto_operativo_cambiar_estado_importar().
    14021661 * Update state proyectos (used in ente_planificador_importar_aprobar_proyectos_form_submit)
    1403  * Batch run callback 
     1662 * Batch run callback
    14041663 */
    14051664function _batch_proyecto_operativo_cambiar_estado_importar($proyecto, &$context) {
     
    14341693/**
    14351694 * Implementation of _batch_ente_planificador_importar_finished().
    1436  * Batch 'finished' callback 
     1695 * Batch 'finished' callback
    14371696 */
    14381697function _batch_proyecto_operativo_cambiar_estado_importar_finished($success, $results, $operations) {
     
    14491708  drupal_set_message($message);
    14501709}
    1451 
Nota: Vea TracChangeset para ayuda en el uso del visor de conjuntos de cambios.