Example #1
0
 function procesar()
 {
     //$this->datasis->modulo_id($this->modulo,1);
     $this->load->library('validation');
     $fechai = $this->input->post('fechai');
     $fechaf = $this->input->post('fechaf');
     $ban = 0;
     $ban += $this->validation->chfecha($fechai);
     $ban += $this->validation->chfecha($fechaf);
     if ($ban != 2) {
         echo 'Error: Fechas erroneas';
         return false;
     }
     $c = $this->datasis->dameval("SELECT COUNT(*) FROM casise\n\t\tWHERE 1*CONCAT(ano,mes) >=EXTRACT(YEAR_MONTH FROM '" . human_to_dbdate($fechai) . "')\n\t\t\tAND \n\t\t\t1*CONCAT(ano,mes)<= EXTRACT(YEAR_MONTH FROM '" . human_to_dbdate($fechaf) . "')");
     if ($c > 0) {
         echo 'Error: El Mes ya esta cerrado';
         return false;
     }
     $qfechai = date("Ymd", timestampFromInputDate($fechai, 'd/m/Y'));
     $qfechaf = date("Ymd", timestampFromInputDate($fechaf, 'd/m/Y'));
     $generar = $this->input->post('genera');
     $salida = $this->_procesar($qfechai, $qfechaf, $generar);
     echo $salida;
     return true;
     //redirect('contabilidad/generar/index/completo');
 }
Example #2
0
 function _getNewValue()
 {
     $this->_getValue();
     if (isset($this->request[$this->name])) {
         $this->newValue = date($this->dbformat, timestampFromInputDate($this->value, $this->format));
     }
 }
Example #3
0
 function procesar()
 {
     $this->datasis->modulo_id($this->modulo, 1);
     $this->load->library('validation');
     $fechai = $this->input->post('fechai');
     $fechaf = $this->input->post('fechaf');
     $fechamin = $this->datasis->dameval('SELECT inicio FROM cemp LIMIT 1');
     if ($fechamin > substr(human_to_dbdate($fechai), 0, 10)) {
         echo 'Error: Fecha inicial menor a la permitida ' . substr(human_to_dbdate($fechai), 0, 10);
         return false;
     }
     $ban = 0;
     $ban += $this->validation->chfecha($fechai);
     $ban += $this->validation->chfecha($fechaf);
     if ($ban != 2) {
         echo 'Error: Fechas erroneas';
         return false;
     }
     session_write_close();
     $qfechai = date("Ymd", timestampFromInputDate($fechai, 'd/m/Y'));
     $qfechaf = date("Ymd", timestampFromInputDate($fechaf, 'd/m/Y'));
     $generar = $this->input->post('genera');
     $salida = $this->_procesar($qfechai, $qfechaf, $generar);
     echo $salida;
     return true;
     //redirect('contabilidad/generar/index/completo');
 }
Example #4
0
 function ejecutar()
 {
     $error = false;
     $mfinal = $this->input->post('fecha');
     //echo $mfinal;
     //$mfinal='31/12/2009';
     if ($mfinal == false) {
         redirect('contabilidad/cierre');
     }
     $mfinal = date('Ymd', timestampFromInputDate($mfinal));
     $anio = substr($mfinal, 2, 2);
     $annio = substr($mfinal, 0, 4);
     $comprob = "ZIERRE{$anio}";
     $this->db->simple_query("DELETE FROM itcasi WHERE comprob='{$comprob}'");
     $this->db->simple_query("DELETE FROM casi   WHERE comprob='{$comprob}'");
     $mSQL = "INSERT INTO casi SET comprob='{$comprob}', fecha={$mfinal}, descrip='ASIENTO DE CIERRE DEL EJERCICIO', total = 0, debe=0, haber=0, estampa=NOW(),tipo='INDETERMIN',status='A',origen='MANUAL'";
     $centinela = $this->db->simple_query($mSQL);
     if ($centinela == false) {
         memowrite($mSQL, 'casi');
         $error = true;
     }
     $mSQL = "INSERT INTO itcasi (fecha,comprob,origen,cuenta,referen,concepto,debe,haber,ccosto,sucursal)\n\t\t    SELECT {$mfinal} fecha,\n\t\t    '{$comprob}' comp, 'MANUAL' origen,\n\t\t    cuenta, 'CIERRE " . $anio . "' referen,\n\t\t    'CIERRE DE CUENTAS DE RESULTADO EJERCICIO " . $anio . "' concepto,\n\t\t    SUM(haber) debe, SUM(debe) haber, 0 ccosto, 0 sucu\n\t\t    FROM itcasi WHERE cuenta>='4' AND fecha<={$mfinal} AND fecha>={$annio}0101\n\t\t    GROUP BY cuenta";
     $centinela = $this->db->simple_query($mSQL);
     if ($centinela == false) {
         memowrite($mSQL, 'itcasi');
         $error = true;
     }
     $mSQL = "INSERT INTO itcasi (fecha,comprob,origen,cuenta,referen,concepto,debe,haber,ccosto,sucursal)\n\t\tSELECT fecha, comprob, origen,\n\t\t    (SELECT resultado FROM cemp limit 1) AS cuenta,\n\t\t    referen,concepto,\n\t\t    IF(SUM(debe-haber)>0,0,SUM(haber-debe)) AS debe,\n\t\t    IF(SUM(debe-haber)>0,SUM(debe-haber),0) AS haber, 0 AS ccosto, 0 AS sucu\n\t\t    FROM itcasi WHERE comprob='{$comprob}' GROUP BY comprob ";
     $centinela = $this->db->simple_query($mSQL);
     if ($centinela == false) {
         memowrite($mSQL, 'itcasi');
         $error = true;
     }
     $centinela = $this->db->simple_query("DELETE FROM itcasi WHERE debe=haber AND comprob='{$comprob}'");
     if ($centinela == false) {
         memowrite($mSQL, 'itcasi');
         $error = true;
     }
     $centinela = $this->db->simple_query("UPDATE casi SET\n\t\t    debe =(SELECT SUM(debe)  FROM itcasi WHERE comprob='{$comprob}'),\n\t\t    haber=(SELECT SUM(haber) FROM itcasi WHERE comprob='{$comprob}')\n\t\t    WHERE comprob='{$comprob}'");
     if ($centinela == false) {
         memowrite($mSQL, 'itcasi');
         $error = true;
     }
     if ($error) {
         echo 'Hubo algunos errores, se generaron centinelas, favor comunicarse con servicio tecnico';
     } else {
         echo "Cierre realizado {$comprob}";
         logusu('cierre', "Realizo cierre contable {$comprob}");
     }
 }
Example #5
0
 function ejecutar()
 {
     $mfinal = $this->input->post('fecha');
     if ($mfinal == FALSE) {
         redirec('contabilidad/cierre');
     }
     $mfinal = date("Ymd", timestampFromInputDate($mfinal));
     $ano = substr($mfinal, 2, 2);
     $comprob = "ZIERRE{$ano}";
     $this->db->query("DELETE FROM itcasi WHERE comprob='{$comprob}'");
     $this->db->query("DELETE FROM casi   WHERE comprob='{$comprob}'");
     $mSQL = "INSERT INTO casi SET comprob='{$comprob}', fecha={$mfinal}, descrip='ASIENTO DE CIERRE DEL EJERCICIO', total = 0, debe=0, haber=0, estampa=now(),tipo='INDETERMIN',status='A',origen='MANUAL'";
     $this->db->query($mSQL);
     $mSQL = "INSERT INTO itcasi \r\n\t    SELECT {$mfinal} fecha, \r\n\t    '{$comprob}' comp, 'MANUAL' origen,\r\n\t    cuenta, 'CIERRE " . substr($mfinal, 0, 2) . "' referen, \r\n\t    'CIERRE DE CUENTAS DE RESULTADO EJERCICIO " . substr($mfinal, 0, 2) . "' concepto,\r\n\t    sum(haber) debe, sum(debe) haber, 0 ccosto, 0 sucu \r\n\t    FROM itcasi WHERE cuenta>='4' AND fecha<={$mfinal} \r\n\t    GROUP BY cuenta ";
     $this->db->query($mSQL);
     $mSQL = "INSERT INTO itcasi \r\n       SELECT fecha, comprob, origen, \r\n\t    (SELECT resultado FROM cemp limit 1) cuenta, \r\n\t    referen, \r\n\t    concepto, \r\n\t    if(sum(debe-haber)>0,0,sum(haber-debe)) debe, \r\n\t    if(sum(debe-haber)>0,sum(debe-haber),0) haber, 0 ccosto, 0 sucu \r\n\t    FROM itcasi WHERE comprob='{$comprob}' group by comprob ";
     $this->db->query($mSQL);
     $this->db->query("DELETE FROM itcasi WHERE debe=haber AND comprob='{$comprob}'");
     echo "Cierre realizado {$comprob}";
 }
Example #6
0
 function procesar()
 {
     $this->datasis->modulo_id($this->modulo, 1);
     $this->load->library('validation');
     $fechai = $this->input->post('fechai');
     $fechaf = $this->input->post('fechaf');
     $ban = 0;
     $ban += $this->validation->chfecha($fechai);
     $ban += $this->validation->chfecha($fechaf);
     if ($ban != 2) {
         echo 'Error: Fechas erroneas';
         return false;
     }
     $qfechai = date("Ymd", timestampFromInputDate($fechai, 'd/m/Y'));
     $qfechaf = date("Ymd", timestampFromInputDate($fechaf, 'd/m/Y'));
     $generar = $this->input->post('genera');
     $salida = $this->_procesar($qfechai, $qfechaf, $generar);
     echo $salida;
     return true;
     //redirect('contabilidad/generar/index/completo');
 }
Example #7
0
 function ejecutar()
 {
     $error = FALSE;
     $mfinal = $this->input->post('fecha');
     //echo $mfinal;
     //$mfinal='31/12/2009';
     if ($mfinal == FALSE) {
         redirect('contabilidad/cierre');
     }
     $mfinal = date("Ymd", timestampFromInputDate($mfinal));
     $ano = substr($mfinal, 2, 2);
     $comprob = "ZIERRE{$ano}";
     $this->db->simple_query("DELETE FROM itcasi WHERE comprob='{$comprob}'");
     $this->db->simple_query("DELETE FROM casi   WHERE comprob='{$comprob}'");
     $mSQL = "INSERT INTO casi SET comprob='{$comprob}', fecha={$mfinal}, descrip='ASIENTO DE CIERRE DEL EJERCICIO', total = 0, debe=0, haber=0, estampa=now(),tipo='INDETERMIN',status='A',origen='MANUAL'";
     $centinela = $this->db->simple_query($mSQL);
     if ($centinela == FALSE) {
         memowrite($mSQL, 'casi');
         $error = TRUE;
     }
     $mSQL = "INSERT INTO itcasi \n\t\t    SELECT {$mfinal} fecha, \n\t\t    '{$comprob}' comp, 'MANUAL' origen,\n\t\t    cuenta, 'CIERRE " . substr($mfinal, 0, 2) . "' referen, \n\t\t    'CIERRE DE CUENTAS DE RESULTADO EJERCICIO " . substr($mfinal, 0, 2) . "' concepto,\n\t\t    sum(haber) debe, sum(debe) haber, 0 ccosto, 0 sucu, null AS id\n\t\t    FROM itcasi WHERE cuenta>='4' AND fecha<={$mfinal} \n\t\t    GROUP BY cuenta ";
     $centinela = $this->db->simple_query($mSQL);
     if ($centinela == FALSE) {
         memowrite($mSQL, 'itcasi');
         $error = TRUE;
     }
     $mSQL = "INSERT INTO itcasi \n\t\t SELECT fecha, comprob, origen, \n\t\t    (SELECT resultado FROM cemp limit 1) cuenta, \n\t\t    referen, \n\t\t    concepto, \n\t\t    if(sum(debe-haber)>0,0,sum(haber-debe)) debe, \n\t\t    if(sum(debe-haber)>0,sum(debe-haber),0) haber, 0 ccosto, 0 sucu, null AS id\n\t\t    FROM itcasi WHERE comprob='{$comprob}' group by comprob ";
     $centinela = $this->db->simple_query($mSQL);
     if ($centinela == FALSE) {
         memowrite($mSQL, 'itcasi');
         $error = TRUE;
     }
     $this->db->simple_query("DELETE FROM itcasi WHERE debe=haber AND comprob='{$comprob}'");
     if ($error) {
         echo "Hubo algunos errores, favor comunicarse con servicio tecnico";
     } else {
         echo "Cierre realizado {$comprob}";
     }
 }
Example #8
0
 function _traedine($fecha = NULL, $sucu = NULL)
 {
     if (empty($sucu) and empty($fecha)) {
         echo 'Error de parametros DINE ';
         return 0;
     }
     $sucux = $this->load->database('sucu' . $sucu, TRUE);
     $timestamp = timestampFromInputDate($fecha);
     $fecha = inputDateFromTimestamp($timestamp, 'Ymd');
     $url = $this->datasis->dameval("SELECT CONCAT_WS('',url,proteo) FROM sucu WHERE prefijo='{$sucu}'");
     if (strlen($url) < 3) {
         echo 'Sucursal sin direccion';
         return 0;
     }
     $sucu = intval($sucu);
     $ch = curl_init("http://{$url}/supermercado/traer/dine/{$fecha}/dine.zip");
     $fp = fopen("./uploads/dine.zip", "w");
     curl_setopt($ch, CURLOPT_FILE, $fp);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_exec($ch);
     curl_close($ch);
     fclose($fp);
     $zip = new ZipArchive();
     $res = $zip->open('./uploads/dine.zip');
     if ($res === TRUE) {
         $zip->extractTo('./uploads/');
         $zip->close();
         $mSQL = "DELETE itdine FROM itdine JOIN dine ON dine.numero=itdine.numero WHERE dine.fecha='{$fecha}'";
         $sucux->simple_query($mSQL);
         $mSQL = "DELETE FROM dine WHERE fecha='{$fecha}'";
         $sucux->simple_query($mSQL);
         $lines = file('./uploads/dine.sql');
         foreach ($lines as $line_num => $line) {
             if (substr($line, 0, 6) == 'INSERT') {
                 $mSQL = str_replace('TEMPdine', 'dine', $line);
                 $mSQL = str_replace('TEMPitdine', 'itdine', $mSQL);
                 $sucux->simple_query($mSQL);
             }
         }
         unlink('./uploads/dine.zip');
         unlink('./uploads/dine.sql');
     } else {
         echo 'Error con el zip';
     }
 }
Example #9
0
 function ejecutar()
 {
     $this->rapyd->load('datagrid2', 'fields');
     function dif($a, $b)
     {
         return number_format($a - $b, 2, ',', '.');
     }
     function escasql($text)
     {
         $text = preg_replace("/\r\n+|\r+|\n+|\t+/i", ' ', $text);
         $text = htmlspecialchars($text);
         $text = str_replace(array("'", '"'), array('&#39;', '&quot;'), $text);
         return $text;
     }
     $modulo = $_POST['modulo'];
     $dbmodulo = $this->db->escape($modulo);
     $mFECHA = date('Ymd', timestampFromInputDate($_POST['fecha'], 'd/m/Y'));
     $mTABLA = $this->datasis->dameval("SELECT origen  FROM reglascont WHERE modulo={$dbmodulo} AND regla=1 ");
     $mCONTROL = $this->datasis->dameval("SELECT control FROM reglascont WHERE modulo={$dbmodulo} AND regla=1 ");
     $action = "javascript:window.location='" . site_url("contabilidad/reglas/index/{$mFECHA}") . "'";
     $data['content'] = '';
     $query = $this->db->query("SELECT a.{$mCONTROL} FROM {$mTABLA} WHERE a.fecha={$mFECHA} GROUP BY {$mCONTROL} ");
     foreach ($query->result_array() as $fila) {
         $aregla = $this->_hace_regla($modulo, $mCONTROL, $fila[$mCONTROL]);
         //echo '<pre>';print_r($aregla);'</pre>';
         $encab = $encab_titu = $pivote = array();
         //Construye los encabezados
         foreach ($aregla['casi'] as $mSQL) {
             $casi_query = $this->db->query($mSQL);
             if ($casi_query->num_rows() > 0) {
                 $row = $casi_query->row();
                 $encab[$row->comprob] = array();
                 $encab_titu[$row->comprob] = '<b>Comprobante:</b> ' . $row->comprob . ' <b>Fecha:</b> ' . date('d/m/Y', timestampFromInputDate($row->fecha, 'Y-m-d')) . ' <b>Concepto:</b> ' . $row->concepto;
             }
         }
         //echo $query;
         //Construye la data de los encabezados
         foreach ($aregla['itcasi'] as $mSQL) {
             //echo $mSQL;
             $itcasi_query = $this->db->query($mSQL);
             $acumulador = array(0, 0);
             if ($itcasi_query->num_rows() > 0) {
                 foreach ($itcasi_query->result() as $row) {
                     $pivote['origen'] = $row->clave;
                     $pivote['cuenta'] = $row->cuenta;
                     $pivote['referen'] = $row->referen;
                     $pivote['concepto'] = $row->concepto;
                     $pivote['debe'] = $row->debe;
                     $pivote['haber'] = $row->haber;
                     $pivote['sucursal'] = $row->sucursal;
                     $pivote['ccosto'] = $row->ccosto;
                     $pivote['msql'] = $mSQL;
                     $encab[$row->comprob][] = $pivote;
                     //$acumulador[0]+=$row->debe;
                     //$acumulador[1]+=$row->haber;
                 }
                 $pivote['origen'] = $pivote['cuenta'] = $pivote['referen'] = $pivote['concepto'] = $pivote['sucursal'] = '';
                 $pivote['debe'] = nformat($acumulador[0]);
                 $pivote['haber'] = nformat($acumulador[1]);
                 $pivote['diferencia'] = nformat($acumulador[0] - $acumulador[1]);
                 //$encab[$row->comprob][]=$pivote;
             }
         }
         foreach ($encab as $comprob => $tabla) {
             if (array_key_exists($comprob, $encab_titu)) {
                 $titulo = $encab_titu[$comprob];
             } else {
                 $titulo = 'HUERFANO';
             }
             $grid = new DataGrid2($titulo, $tabla);
             $grid->per_page = count($tabla);
             $grid->use_function('dif', 'escasql');
             //$grid->column('Or&iacute;gen', 'msql');
             $grid->column('Or&iacute;gen', '<span title="<escasql><#msql#></escasql>" onclick="prompt(\'Consulta\',this.title)"><#origen#></span>');
             $grid->column('Cuenta', 'cuenta');
             $grid->column('Referencia', 'referen');
             $grid->column('Concepto', 'concepto');
             $grid->column('Debe', '<nformat><#debe#></nformat>', 'align=\'right\'');
             $grid->column('Haber', '<nformat><#haber#></nformat>', 'align=\'right\'');
             //$grid->column("Diferencia" , "<dif><#debe#>|<#haber#></dif>",'align=right');
             $grid->column('Sucursal', 'sucursal', 'align=\'right\'');
             $grid->column('C. Costo', 'ccosto', 'align=\'right\'');
             $grid->totalizar('debe', 'haber');
             $grid->build();
             //echo $grid->db->last_query();
             $data['content'] .= $grid->output;
         }
     }
     $data['content'] .= HTML::button('regresa', RAPYD_BUTTON_BACK, $action, 'button', 'button');
     $data['head'] = $this->rapyd->get_head();
     $data['title'] = "<h1>Ejecuci&oacute;n de la regla {$modulo}</h1>";
     $this->load->view('view_ventanas', $data);
 }
Example #10
0
function human_to_dbdate($date, $format = RAPYD_DATE_FORMAT)
{
    //adodb have DBDate()
    return dbDateFromTimestamp(timestampFromInputDate($date, $format));
}
Example #11
0
 function chfuturo($fecha)
 {
     $fdoc = timestampFromInputDate($fecha);
     $fact = mktime();
     if ($fdoc > $fact) {
         $this->validation->set_message('chfuturo', 'No puede meter un efecto a futuro');
         return false;
     }
     return true;
 }
Example #12
0
 function ejecutar()
 {
     $this->rapyd->load("datagrid2", "fields");
     function dif($a, $b)
     {
         return number_format($a - $b, 2, ',', '.');
     }
     $modulo = $_POST['modulo'];
     $mFECHA = date("Ymd", timestampFromInputDate($_POST['fecha'], 'd/m/Y'));
     $mTABLA = $this->datasis->dameval("SELECT origen  FROM reglascont WHERE modulo='{$modulo}' AND regla=1 ");
     $mCONTROL = $this->datasis->dameval("SELECT control FROM reglascont WHERE modulo='{$modulo}' AND regla=1 ");
     $action = "javascript:window.location='" . site_url("contabilidad/reglas/index/{$mFECHA}") . "'";
     $data['content'] = '';
     $pos = stripos($mCONTROL, 'YEAR_MONTH');
     if ($pos !== FALSE) {
         $mFECHA = 'extract(year_month from ' . $mFECHA . ')';
     } else {
         $pos = 0;
         $pos = stripos($mCONTROL, 'MONTH');
         if ($pos !== FALSE) {
             $mFECHA = 'MONTH(' . $mFECHA . ')';
         }
     }
     $query = $this->db->query("SELECT {$mCONTROL} FROM {$mTABLA} WHERE {$mCONTROL}={$mFECHA} GROUP BY {$mCONTROL} ");
     foreach ($query->result_array() as $fila) {
         $aregla = $this->_hace_regla($modulo, $mCONTROL, $fila[$mCONTROL]);
         //echo '<pre>';print_r($aregla);'</pre>';
         $encab = $encab_titu = $pivote = array();
         //Construye los encabezados
         print_r($aregla);
         foreach ($aregla['casi'] as $mSQL) {
             $casi_query = $this->db->query($mSQL);
             if ($casi_query->num_rows() > 0) {
                 $row = $casi_query->row();
                 $encab[$row->comprob] = array();
                 $encab_titu[$row->comprob] = '<b>Comprobante:</b> ' . $row->comprob . ' <b>Fecha:</b> ' . date("d/m/Y", timestampFromInputDate($row->fecha, 'Y-m-d')) . ' <b>Concepto:</b> ' . $row->concepto;
             }
         }
         //echo $query;
         //Construye la data de los encabezados
         foreach ($aregla['itcasi'] as $mSQL) {
             $itcasi_query = $this->db->query($mSQL);
             $acumulador = array(0, 0);
             if ($itcasi_query->num_rows() > 0) {
                 foreach ($itcasi_query->result() as $row) {
                     $pivote['origen'] = $row->clave;
                     $pivote['cuenta'] = $row->cuenta;
                     $pivote['referen'] = $row->referen;
                     $pivote['concepto'] = $row->concepto;
                     $pivote['debe'] = $row->debe;
                     $pivote['haber'] = $row->haber;
                     $pivote['sucursal'] = $row->sucursal;
                     $pivote['ccosto'] = $row->ccosto;
                     $encab[$row->comprob][] = $pivote;
                     //$acumulador[0]+=$row->debe;
                     //$acumulador[1]+=$row->haber;
                 }
                 $pivote['origen'] = $pivote['cuenta'] = $pivote['referen'] = $pivote['concepto'] = $pivote['sucursal'] = '';
                 $pivote['debe'] = number_format($acumulador[0], 2, ',', '.');
                 $pivote['haber'] = number_format($acumulador[1], 2, ',', '.');
                 $pivote['diferencia'] = number_format($acumulador[0] - $acumulador[1], 2, ',', '.');
                 //$encab[$row->comprob][]=$pivote;
             }
         }
         foreach ($encab as $comprob => $tabla) {
             if (array_key_exists($comprob, $encab_titu)) {
                 $titulo = $encab_titu[$comprob];
             } else {
                 $titulo = 'HUERFANO';
             }
             $grid = new DataGrid2($titulo, $tabla);
             $grid->per_page = count($tabla);
             $grid->use_function('dif');
             $grid->column('Or&iacute;gen', 'origen');
             $grid->column('Cuenta', 'cuenta');
             $grid->column('Referencia', 'referen');
             $grid->column('Concepto', 'concepto');
             $grid->column("Debe", "<nformat><#debe#></nformat>", "align=right");
             $grid->column("Haber", "<nformat><#haber#></nformat>", "align=right");
             //$grid->column("Diferencia" , "<dif><#debe#>|<#haber#></dif>",'align=right');
             $grid->column('Sucursal', 'sucursal', 'align=right');
             $grid->column('C. Costo', 'ccosto', 'align=right');
             $grid->totalizar('debe', 'haber');
             $grid->build();
             //echo $grid->db->last_query();
             $data['content'] .= $grid->output;
         }
     }
     $data['content'] .= $this->html->button('regresa', RAPYD_BUTTON_BACK, $action, "button", "button");
     $data["head"] = $this->rapyd->get_head();
     $data['title'] = "Ejecuci&oacute;n de la regla {$modulo}";
     $this->load->view('view_ventanas', $data);
 }
Example #13
0
 function resument()
 {
     $fecha = $this->input->post('fecha');
     if (!$fecha) {
         redirec('contabilidad/lresument');
     }
     $titulo = $this->datasis->traevalor('TITULO1');
     $rif = $this->datasis->traevalor('RIF');
     $qfecha = date("Ymd", timestampFromInputDate($fecha));
     $this->load->library('fpdf');
     $esta =& $this->fpdf;
     $esta->AddPage();
     $esta->SetFillColor(52, 186, 114);
     $esta->image($_SERVER['DOCUMENT_ROOT'] . base_url() . 'images/logotipo.jpg', 10, 8, 40);
     $esta->ln(5);
     $esta->SetFont('Arial', 'B', 16);
     $esta->cell(0, 10, "TOTAL SUCURSALES AL DIA {$fecha}", 0, 2, 'C');
     $esta->ln(1);
     $esta->SetFont('Arial', '', 10);
     $esta->cell(0, 5, "    RIF: " . $rif, 0, 2, 'L');
     $esta->ln(1);
     $esta->SetFont('Arial', 'I', 14);
     $esta->cell(0, 7, "CIERRE DE SUCURSAL", 1, 2, 'L');
     $esta->ln(1);
     $esta->SetFont('Arial', 'B', 10);
     $esta->SetTextColor(255, 255, 255);
     $esta->cell(14, 5, "Caja", 0, 0, 'C', 1);
     $esta->cell(32, 5, "Cajero", 0, 0, 'C', 1);
     $esta->cell(40, 5, "Arqueo", 0, 0, 'C', 1);
     $esta->cell(40, 5, "Sistema", 0, 0, 'C', 1);
     $esta->cell(32, 5, "Faltantes", 0, 0, 'C', 1);
     $esta->cell(32, 5, "Sobrantes", 0, 0, 'C', 1);
     $esta->ln(5);
     $esta->SetTextColor(0);
     $mSQL = "SELECT MID(a.caja,1,1) caja, CONCAT('.Sucursal ',MID(a.caja,1,1)) nombre, SUM(a.trecibe) trecibe, SUM(a.computa) computa,\n\t\t               SUM(if(a.trecibe-a.computa<0,a.trecibe-a.computa,0)) faltante,\n\t\t               SUM(if(a.trecibe-a.computa>0,a.trecibe-a.computa,0)) sobrante \n\t\t        FROM dine AS a LEFT JOIN scaj AS b ON a.cajero=b.cajero \n\t\t        WHERE a.fecha={$qfecha} GROUP BY MID(a.caja,1,1) ";
     $query = $this->db->query($mSQL);
     if ($query->num_rows() > 0) {
         foreach ($query->result() as $row) {
             $esta->SetFont('Arial', '', 9);
             $esta->cell(14, 5, $row->caja, 0, 0, 'L');
             $esta->cell(32, 5, substr($row->nombre, 1, 25), 0, 0, 'L');
             $esta->cell(40, 5, number_format($row->trecibe, 2), 0, 0, 'R');
             $esta->cell(40, 5, number_format($row->computa, 2), 0, 0, 'R');
             $esta->cell(32, 5, number_format($row->faltante, 2), 0, 0, 'R');
             $esta->cell(32, 5, number_format($row->sobrante, 2), 0, 0, 'R');
             $esta->ln(5);
         }
     }
     $query->free_result();
     $mSQL = "SELECT caja, cajero, sum(trecibe) tr, sum(computa) tc, sum(if(trecibe-computa<0,trecibe-computa,0))tf , sum(if(trecibe-computa>0,trecibe-computa,0)) ts FROM dine WHERE fecha={$qfecha} GROUP BY fecha ";
     $query = $this->db->query($mSQL);
     $esta->SetTextColor(255, 255, 255);
     if ($query->num_rows() > 0) {
         foreach ($query->result() as $row) {
             $esta->SetFont('Arial', 'B', 9);
             $esta->cell(46, 5, "Totales..", 0, 0, 'R', 1);
             $esta->cell(40, 5, number_format($row->tr, 2), 0, 0, 'R', 1);
             $esta->cell(40, 5, number_format($row->tc, 2), 0, 0, 'R', 1);
             $esta->cell(32, 5, number_format($row->tf, 2), 0, 0, 'R', 1);
             $esta->cell(32, 5, number_format($row->ts, 2), 0, 0, 'R', 1);
             $esta->ln(4);
         }
     }
     $query->free_result();
     $esta->SetTextColor(0);
     $esta->ln(2);
     $esta->SetFont('Arial', 'I', 14);
     $esta->cell(0, 7, "RECAUDACION POR TIPO DE PAGO", 1, 2, 'L');
     $esta->ln(1);
     $esta->SetFont('Arial', 'B', 10);
     $esta->SetTextColor(255, 255, 255);
     $esta->cell(100, 5, "FORMA DE PAGO", 0, 0, 'C', 1);
     $esta->cell(50, 5, "MONTO", 0, 0, 'C', 1);
     $esta->cell(20, 5, "#TRANS", 0, 0, 'C', 1);
     $esta->cell(20, 5, "%", 0, 0, 'C', 1);
     $esta->SetTextColor(0);
     $esta->ln(5);
     $venta = $this->datasis->dameval("SELECT sum(a.total) FROM itdine AS a, dine AS b WHERE b.fecha={$qfecha} AND a.numero=b.numero ");
     $mSQL = "SELECT a.tipo, b.nombre, sum(a.total) tot,count(*) tra\n        \tFROM itdine AS a \n        \tLEFT JOIN tarjeta AS b ON a.tipo=b.tipo\n        \tJOIN dine AS c ON a.numero=c.numero\n        \tWHERE c.fecha={$qfecha} \n        \tGROUP BY a.tipo ";
     $query = $this->db->query($mSQL);
     if ($query->num_rows() > 0) {
         foreach ($query->result() as $row) {
             $esta->SetFont('Arial', '', 9);
             $esta->cell(20, 5, $row->tipo, 0, 0, 'C');
             $esta->cell(80, 5, $row->nombre, 0, 0, 'L');
             $esta->cell(50, 5, number_format($row->tot, 2), 0, 0, 'R');
             $esta->cell(20, 5, number_format($row->tra, 0), 0, 0, 'R');
             $esta->cell(20, 5, number_format($row->tot * 100 / $venta, 2), 0, 0, 'R');
             $esta->ln(4);
         }
     }
     $query->free_result();
     $esta->SetFont('Arial', 'B', 10);
     $esta->SetTextColor(255, 255, 255);
     $esta->cell(100, 5, "Total Bs...", 0, 0, 'R', 1);
     $esta->cell(50, 5, number_format($venta, 2), 0, 0, 'R', 1);
     $esta->cell(40, 5, '', 0, 0, 'R', 1);
     $esta->SetTextColor(0);
     $esta->ln(15);
     $esta->SetFont('Arial', 'B', 18);
     $esta->SetFillColor(0, 102, 204);
     $esta->SetTextColor(255, 255, 255);
     $esta->cell(190, 10, "RESUMEN DEL MES HASTA LA FECHA", 0, 0, "C", 1);
     $esta->ln(10);
     $esta->SetTextColor(0);
     $esta->SetFont('Arial', 'I', 14);
     $esta->cell(0, 7, "TOTALES DEL MES", 1, 2, 'L');
     $esta->ln(1);
     $esta->SetFont('Arial', 'B', 10);
     $esta->SetTextColor(255, 255, 255);
     $esta->cell(14, 5, "Caja", 0, 0, 'C', 1);
     $esta->cell(32, 5, "Cajero", 0, 0, 'C', 1);
     $esta->cell(40, 5, "Arqueo", 0, 0, 'C', 1);
     $esta->cell(40, 5, "Sistema", 0, 0, 'C', 1);
     $esta->cell(32, 5, "Faltantes", 0, 0, 'C', 1);
     $esta->cell(32, 5, "Sobrantes", 0, 0, 'C', 1);
     $esta->ln(5);
     $esta->SetTextColor(0);
     $mSQL = "SELECT MID(a.caja,1,1) caja, CONCAT('.Sucursal ',MID(a.caja,1,1)) nombre, SUM(a.trecibe) trecibe, SUM(a.computa) computa,\n\t\t               SUM(if(a.trecibe-a.computa<0,a.trecibe-a.computa,0)) faltante,\n\t\t               SUM(if(a.trecibe-a.computa>0,a.trecibe-a.computa,0)) sobrante \n\t\t        FROM dine AS a LEFT JOIN scaj AS b ON a.cajero=b.cajero \n\t\t        WHERE a.fecha<={$qfecha} AND EXTRACT(YEAR_MONTH FROM a.fecha)=" . substr($qfecha, 0, 6) . " GROUP BY MID(a.caja,1,1) ";
     $query = $this->db->query($mSQL);
     if ($query->num_rows() > 0) {
         foreach ($query->result() as $row) {
             $esta->SetFont('Arial', '', 9);
             $esta->cell(14, 5, $row->caja, 0, 0, 'L');
             $esta->cell(32, 5, substr($row->nombre, 1, 25), 0, 0, 'L');
             $esta->cell(40, 5, number_format($row->trecibe, 2), 0, 0, 'R');
             $esta->cell(40, 5, number_format($row->computa, 2), 0, 0, 'R');
             $esta->cell(32, 5, number_format($row->faltante, 2), 0, 0, 'R');
             $esta->cell(32, 5, number_format($row->sobrante, 2), 0, 0, 'R');
             $esta->ln(5);
         }
     }
     $query->free_result();
     $mSQL = "SELECT sum(trecibe) tr, sum(computa) tc, sum(if(trecibe-computa<0,trecibe-computa,0))tf , sum(if(trecibe-computa>0,trecibe-computa,0)) ts FROM dine WHERE fecha<={$qfecha} AND EXTRACT(YEAR_MONTH FROM fecha)=" . substr($qfecha, 0, 6) . "  ";
     $query = $this->db->query($mSQL);
     $esta->SetTextColor(255, 255, 255);
     if ($query->num_rows() > 0) {
         foreach ($query->result() as $row) {
             $esta->SetFont('Arial', 'B', 9);
             $esta->cell(46, 5, "Totales.." . substr($qfecha, 0, 6), 0, 0, 'R', 1);
             $esta->cell(40, 5, number_format($row->tr, 2), 0, 0, 'R', 1);
             $esta->cell(40, 5, number_format($row->tc, 2), 0, 0, 'R', 1);
             $esta->cell(32, 5, number_format($row->tf, 2), 0, 0, 'R', 1);
             $esta->cell(32, 5, number_format($row->ts, 2), 0, 0, 'R', 1);
             $esta->ln(4);
         }
     }
     $query->free_result();
     $esta->SetTextColor(0);
     $esta->ln(2);
     $esta->SetFont('Arial', 'I', 14);
     $esta->cell(0, 7, "RECAUDACION POR TIPO DE PAGO DEL MES", 1, 2, 'L');
     $esta->ln(1);
     $esta->SetFont('Arial', 'B', 10);
     $esta->SetTextColor(255, 255, 255);
     $esta->cell(100, 5, "FORMA DE PAGO", 0, 0, 'C', 1);
     $esta->cell(50, 5, "MONTO", 0, 0, 'C', 1);
     $esta->cell(20, 5, "#TRANS", 0, 0, 'C', 1);
     $esta->cell(20, 5, "%", 0, 0, 'C', 1);
     $esta->SetTextColor(0);
     $esta->ln(5);
     $venta = $this->datasis->dameval("SELECT sum(a.total) FROM itdine AS a, dine AS b WHERE b.fecha<={$qfecha} AND a.numero=b.numero AND EXTRACT(YEAR_MONTH FROM b.fecha)=" . substr($qfecha, 0, 6) . "");
     $mSQL = "SELECT a.tipo, b.nombre, sum(a.total) tot,count(*) tra\n        \tFROM itdine AS a \n        \tLEFT JOIN tarjeta AS b ON a.tipo=b.tipo\n        \tJOIN dine AS c ON a.numero=c.numero\n        \tWHERE c.fecha<={$qfecha} AND EXTRACT(YEAR_MONTH FROM c.fecha)=" . substr($qfecha, 0, 6) . "\n        \tGROUP BY a.tipo ";
     $query = $this->db->query($mSQL);
     if ($query->num_rows() > 0) {
         foreach ($query->result() as $row) {
             $esta->SetFont('Arial', '', 9);
             $esta->cell(20, 5, $row->tipo, 0, 0, 'C');
             $esta->cell(80, 5, $row->nombre, 0, 0, 'L');
             $esta->cell(50, 5, number_format($row->tot, 2), 0, 0, 'R');
             $esta->cell(20, 5, number_format($row->tra, 0), 0, 0, 'R');
             $esta->cell(20, 5, number_format($row->tot * 100 / $venta, 2), 0, 0, 'R');
             $esta->ln(4);
         }
     }
     $query->free_result();
     $esta->SetFont('Arial', 'B', 10);
     $esta->SetTextColor(255, 255, 255);
     $esta->cell(100, 5, "Total Ventas por POS Bs...", 0, 0, 'R', 1);
     $esta->cell(50, 5, number_format($venta, 2), 0, 0, 'R', 1);
     $esta->cell(40, 5, '', 0, 0, 'R', 1);
     $esta->SetTextColor(0);
     $esta->ln(6);
     $dech = $this->datasis->dameval("SELECT sum(gtotal*IF(tipo='D',-1,1)) FROM fmay WHERE fecha<={$qfecha} AND EXTRACT(YEAR_MONTH FROM fecha)=" . substr($qfecha, 0, 6) . " AND tipo<>'A' ");
     $esta->SetFont('Arial', 'B', 10);
     $esta->SetFillColor(0, 0, 120);
     $esta->SetTextColor(255, 255, 255);
     $esta->cell(100, 5, "Total Ventas al Mayor Bs...", 0, 0, 'R', 1);
     $esta->cell(50, 5, number_format($dech, 2), 0, 0, 'R', 1);
     $esta->cell(40, 5, '', 0, 0, 'R', 1);
     $esta->SetTextColor(0);
     $esta->ln(10);
     $esta->SetFillColor(0, 130, 0);
     $esta->SetFont('Arial', 'B', 14);
     $esta->SetTextColor(255, 255, 255);
     $esta->cell(100, 7, "Total Ventas al Mayor y POS Bs...", 0, 0, 'R', 1);
     $esta->cell(50, 7, number_format($dech + $venta, 2), 0, 0, 'R', 1);
     $esta->cell(40, 7, '', 0, 0, 'R', 1);
     $esta->SetTextColor(0);
     $esta->ln(5);
     //		$esta->cell(140,5,"VENTAS TOTALES AL MAYOR",0,0,"L");
     //		$esta->cell(50,5,number_format($dech,2),0,0,"R");
     //		$esta->ln(5);
     /*
     
     		$esta->SetFont('Arial','',10);
     		$cajapos=$this->datasis->dameval("SELECT valor FROM valores WHERE nombre='CAJAPOS'");
     		$defe=$this->datasis->dameval("SELECT sum(efectivo) FROM bcaj WHERE estampa=$qqfecha AND envia='$cajapos' ");
     		$esta->cell(140,5,"DEPOSITOS EN EFECTIVO EN TRANSITO",0,0,"L");
     		$esta->cell(50,5,number_format($defe,2),0,0,"R");
     		$esta->ln(5);
     		
     		$dech=$this->datasis->dameval("SELECT sum(cheques) FROM bcaj WHERE estampa=$qqfecha AND envia='$cajapos' ");
     		$esta->cell(140,5,"DEPOSITOS EN CHEQUE EN TRANSITO",0,0,"L");
     		$esta->cell(50,5,number_format($dech,2),0,0,"R");
     		$esta->ln(5);
     		
     		$detc=$this->datasis->dameval("SELECT sum(tarjeta) FROM bcaj WHERE estampa=$qqfecha AND envia='$cajapos' ");
     		$esta->cell(140,5,"DEPOSITOS EN TARJETA DE CREDITO",0,0,"L");
     		$esta->cell(50,5,number_format($detc,2),0,0,"R");
     		$esta->ln(5);
     		
     		$detd=$this->datasis->dameval("SELECT sum(tdebito) FROM bcaj WHERE estampa=$qqfecha AND envia='$cajapos' ");
     		$esta->cell(140,5,"DEPOSITOS EN TARJETA DE DEBITO",0,0,"L");
     		$esta->cell(50,5,number_format($detd,2),0,0,"R");
     		$esta->ln(5);
     		
     		$pago=$this->datasis->dameval("SELECT sum(monto) FROM bcaj WHERE estampa=$qqfecha AND envia='$cajapos' AND tipo='TR' ");
     		$esta->cell(140,5,"TRASFERIDO A ADMINISTRACION",0,0,"L");
     		$esta->cell( 50,5,number_format($pago,2),0,0,"R");
     		$esta->ln(5);
     		
     		$cesta=$this->datasis->dameval("SELECT sum(monto) FROM bcaj WHERE estampa=$qqfecha AND envia='$cajapos' AND tipo='RM' ");
     		$esta->cell(140,5,"CESTA TICKET Y VALORES AL COBRO",0,0,"L");
     		$esta->cell( 50,5,number_format($cesta,2),0,0,"R");
     		$esta->ln(5);
     		
     		$esta->SetTextColor(255,255,255);
     		$esta->cell(140,5, "RESUMEN DISTRIBUCION POS",0,0,"L",1);
     		$esta->cell(50,5,number_format($defe+$dech+$detc+$detd+$pago+$cesta,2),0,0,"R",1);
     		$esta->ln(8);
     		$esta->SetTextColor(0);
     		$pago=$this->datasis->dameval("SELECT saldo FROM banc WHERE codbanc='$cajapos' ");
     
     		$esta->SetFont('Arial','B',18);
     		$esta->SetFillColor(0,102,204);
     		$esta->SetTextColor(255,255,255);
     		$esta->cell(190,10,"SALDO CAJA POS: ".number_format($pago,2),0,0,"C",1);
     		$esta->ln(12);
     		
     		$esta->SetFillColor(52,186,114);
     		$esta->SetTextColor(0);
     		
     		$esta->ln(2);
     		$esta->SetFont('Arial','I',14);
     		$esta->cell(0,7,"VALORES EN CUSTODIA", 1, 2, 'L');
     		$esta->ln(1);
     
     		$esta->SetFont('Arial','B',10);
     		$esta->SetTextColor(255,255,255);
     		$esta->cell(50,5,"Descripcion", 0, 0, 'C',1);
     		$esta->cell(35,5,"Anterior", 0, 0, 'C',1);
     		$esta->cell(35,5,"Ingresos", 0, 0, 'C',1);
     		$esta->cell(35,5,"Egresos", 0, 0, 'C',1);
     		$esta->cell(35,5,"Saldo", 0, 0, 'C',1);
     		$esta->SetTextColor(0);
     		$esta->ln(5);
     		
     		$mSQL = "SELECT tarjeta, concepto, enlace, saldo, descrip FROM tardet WHERE enlace IS NOT NULL AND enlace!='' GROUP BY enlace";
     		$manterior = $mingresos = $megresos  = $msaldos   = 0;
     		
     		$menlaces = $this->db->query($mSQL);
     		$esta->SetFont('Arial','',10);
     		
     		if ($menlaces->num_rows() > 0){
     			foreach ($menlaces->result() as $row){
     				$mSQL = "SELECT sum(a.total) FROM itdine AS a, dine AS b WHERE a.tipo='".$row->tarjeta."' AND a.concepto='".$row->concepto."' AND a.numero=b.numero AND b.fecha=$qfecha GROUP BY fecha ";
     				$ingreso = $this->datasis->dameval($mSQL);
     				$mSQL = "SELECT sum(a.monto) FROM itbcaj AS a, bcaj AS b WHERE a.tipo='".$row->tarjeta."' AND a.concep='".$row->concepto."' AND a.numero=b.numero AND b.estampa=$qqfecha GROUP BY fecha ";
     				$egreso = $this->datasis->dameval($mSQL);
     				$esta->cell(50,5,$row->descrip, 0, 0, 'L');
     				$esta->cell(35,5,number_format($row->saldo-$ingreso+$egreso,2), 0, 0, 'R');
     				$manterior += $row->saldo-$ingreso+$egreso ;
     				$esta->cell(35,5,number_format($ingreso,2), 0, 0, 'R');
     				$mingresos += $ingreso ;
     				$esta->cell(35,5,number_format($egreso,2), 0, 0, 'R');
     				$megresos += $egreso ;
     				$esta->cell(35,5,number_format($row->saldo,2), 0, 0, 'R');
     				$msaldos += $row->saldo;
     				$esta->ln(5);
     			}
     		}
     		$esta->SetFont('Arial','B',10);
     		$esta->SetTextColor(255,255,255);
     		$esta->cell(50,5, "Totales...",0,0,'R',1);
     		$esta->cell(35,5,number_format($manterior,2),0,0,'R',1);
     		$esta->cell(35,5,number_format($mingresos,2),0,0,'R',1);
     		$esta->cell(35,5,number_format($megresos,2), 0,0,'R',1);
     		$esta->cell(35,5,number_format($msaldos,2),  0,0,'R',1);
     		$esta->SetTextColor(0);
     */
     $esta->Output();
 }