Exemple #1
0
        private DataTable crear_cobro_(DataTable dt)
        {
            string condicion = " where 1=1 ";

            if (lb_bodegas2.Text != "")
            {
                condicion += " and siteid in (" + agregra_comillas(lb_bodegas2.Text) + ") ";
            }
            string clase = "";

            if (rd_humano.Checked)
            {
                condicion += " and  glclassid in ('ABAR', 'MANI') and invtid > '1000' and invtid <> '9918' ";
            }
            else
            {
                condicion += " and  glclassid <> 'ABAR' and glclassid <>  'MANI'  and invtid <> '9905'  and invtid <> '9999'  and invtid <> '9907'   ";
            }

            double v_me       = 0;
            int    an         = 0;
            int    me         = 0;
            double daymon     = 0;
            double valor_dia  = 0;
            int    dias_hasta = 0;


            try
            {
                v_me       = Convert.ToDouble(tx_valor_mensual.Text);
                an         = Convert.ToInt32(TX_AÑO.Text);
                me         = Convert.ToInt32(CB_TIPO_DOC_GRILLA.SelectedValue.ToString());
                daymon     = System.DateTime.DaysInMonth(an, me);
                valor_dia  = v_me / daymon;
                dias_hasta = Convert.ToInt32(txt_hasta.Text.Substring(0, 2));
            }
            catch (Exception ex)

            {
                foreach (DataRow r in dt.Rows)
                {
                    string invtid = r[0].ToString().Split('-')[0].Trim();

                    DataTable arrastre_noventa_y_salidas = ReporteRNegocio.arrastre_noventa(condicion + " and invtid = '" + invtid + "' ", CB_TIPO_DOC_GRILLA.SelectedValue, TX_AÑO.Text, tx_dias_sobre.Text);

                    string fecha_inicial = "";

                    fecha_inicial = arrastre_noventa_y_salidas.Rows[0][0].ToString();

                    r[4] = fecha_inicial;
                }
                return(dt);
            }

            double SUMA_TOTAL_COBRO = 0;
            double SUMA_TOTAL_KILOS = 0;

            //double SUMA_TOTAL_
            foreach (DataRow r in dt.Rows)
            {
                //double aux_var = 0;
                //try
                //{
                //    aux_var = Convert.ToDouble(r[3]);
                //}
                //catch { }

                //if (aux_var > 0)
                //{

                //DataTable dias_cobro = new DataTable();

                //dias_cobro.Columns.Add("Dia");
                //dias_cobro.Columns.Add("Entrada");
                //dias_cobro.Columns.Add("Salida");
                //dias_cobro.Columns.Add("Arrastre");
                //dias_cobro.Columns.Add("Cobro");

                string invtid = r[0].ToString().Split('-')[0].Trim();

                try
                {
                    DataTable arrastre_noventa_y_salidas = ReporteRNegocio.arrastre_noventa(condicion + " and invtid = '" + invtid + "' ", CB_TIPO_DOC_GRILLA.SelectedValue, TX_AÑO.Text, tx_dias_sobre.Text);

                    double arrastre_noven = 0;
                    string fecha_inicial  = "";

                    arrastre_noven = Convert.ToDouble(arrastre_noventa_y_salidas.Rows[0][1]);
                    fecha_inicial  = arrastre_noventa_y_salidas.Rows[0][0].ToString();

                    if (Convert.ToDouble(r[3].ToString().Replace(".", ",")) < 0)
                    {
                        r[1] = "0";
                        r[3] = "0";
                    }
                    else
                    {
                        SUMA_TOTAL_KILOS += Convert.ToDouble(r[3].ToString().Replace(".", ","));
                    }
                    double arrastre      = 0;
                    double SUMA_A_COBRAR = 0;
                    for (int i = 1; i <= dias_hasta; i++)
                    {
                        //row = dias_cobro.NewRow();
                        //row[0] = i;
                        DataTable estrada_y_salida = ReporteRNegocio.dia_entrada_noven(condicion + " and invtid = '" + invtid + "' ", CB_TIPO_DOC_GRILLA.SelectedValue, TX_AÑO.Text, i, tx_dias_sobre.Text);
                        double    entrada          = Convert.ToDouble(estrada_y_salida.Rows[0][0]);
                        double    salida           = Convert.ToDouble(estrada_y_salida.Rows[0][1]);

                        //if (arrastre_noven < 0)
                        //{


                        //}


                        //row[1] = entrada.ToString("N0");
                        //row[2] = salida.ToString("N0");

                        arrastre = (arrastre_noven + entrada + salida);
                        //row[3] = arrastre.ToString("N0");
                        arrastre_noven = arrastre;


                        double kilos = arrastre;


                        double valor_for = (kilos * (valor_dia * Convert.ToDouble(tx_dolar.Text)) / 1000);

                        if (valor_for > 0)
                        {
                            SUMA_A_COBRAR += valor_for;
                        }

                        //row[4] = (kilos * (valor_dia * Convert.ToDouble(tx_dolar.Text)) / 1000).ToString("N0");
                        //dias_cobro.Rows.Add(row);
                    }


                    r[4]              = fecha_inicial;
                    r[5]              = SUMA_A_COBRAR.ToString("N0");
                    SUMA_TOTAL_COBRO += SUMA_A_COBRAR;
                }



                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }

            DataView dv2 = dt.DefaultView;

            dv2.Sort = "producto ASC";
            dt       = dv2.ToTable();


            DataRow row = dt.NewRow();


            row[0] = "";
            row[1] = 0;
            row[2] = "TONELADAS   :   ";;
            row[3] = Base.monto_format2(SUMA_TOTAL_KILOS / 1000);
            row[4] = "TOTAL PESO CL :   ";
            row[5] = SUMA_TOTAL_COBRO.ToString("N0");
            dt.Rows.Add(row);

            DataRow row2 = dt.NewRow();

            row2[0] = "";
            row2[1] = 0;
            row2[2] = "";;
            row2[3] = "";
            row2[4] = "TOTAL USD:   ";
            row2[5] = (SUMA_TOTAL_COBRO / Convert.ToDouble(tx_dolar.Text)).ToString("N0");
            dt.Rows.Add(row2);

            return(dt);
        }