Example #1
0
        public static void UpdateAccount(Account account, bool isCancelled)
        {
            if (isCancelled)
            {
                CloseAccount(account.DocId);
                return;
            }

            string           connectionString = ConfigurationManager.ConnectionStrings[Config.Common.MONFOLL].ConnectionString;
            NpgsqlConnection conn;

            conn = new NpgsqlConnection(connectionString);
            conn.Open();

            string sqlString = "UPDATE ctrl_cuenta " +
                               "SET F_DOCUMENTO = @f_documento, " +
                               "F_VENCIMIENTO = @f_vencimiento, " +
                               "ID_CLIENTE = @id_cliente, " +
                               "SERIE_DOCO = @serie_doco, " +
                               "FOLIO_DOCO = @folio_doco, " +
                               "TIPO_DOCUMENTO = @tipo_documento, " +
                               "FACTURADO = @facturado, " +
                               "SALDO = @saldo, " +
                               "MONEDA = @moneda, " +
                               "F_COBRO = @collect_date, " +
                               "TIPO_COBRO = @collect_type, " +
                               "OBSERVACIONES = @obs_note, " +
                               "TS_DESCARGADO = CURRENT_TIMESTAMP " +
                               "WHERE ap_id = @id AND enterprise_id = @enterprise";

            NpgsqlCommand cmd = new NpgsqlCommand(sqlString, conn);

            cmd.Parameters.Add("@f_documento", NpgsqlTypes.NpgsqlDbType.Date);
            cmd.Parameters.Add("@f_vencimiento", NpgsqlTypes.NpgsqlDbType.Date);
            cmd.Parameters.Add("@id_cliente", NpgsqlTypes.NpgsqlDbType.Integer);
            cmd.Parameters.Add("@serie_doco", NpgsqlTypes.NpgsqlDbType.Varchar, 4);
            cmd.Parameters.Add("@folio_doco", NpgsqlTypes.NpgsqlDbType.Integer);
            cmd.Parameters.Add("@tipo_documento", NpgsqlTypes.NpgsqlDbType.Varchar, 150);
            cmd.Parameters.Add("@facturado", NpgsqlTypes.NpgsqlDbType.Money);
            cmd.Parameters.Add("@saldo", NpgsqlTypes.NpgsqlDbType.Money);
            cmd.Parameters.Add("@moneda", NpgsqlTypes.NpgsqlDbType.Varchar, 50);
            cmd.Parameters.Add("@id", NpgsqlTypes.NpgsqlDbType.Integer);
            cmd.Parameters.Add("@enterprise", NpgsqlTypes.NpgsqlDbType.Integer);

            cmd.Parameters.Add("@collect_date", NpgsqlTypes.NpgsqlDbType.Date);
            cmd.Parameters.Add("@collect_type", NpgsqlTypes.NpgsqlDbType.Varchar, 100);
            cmd.Parameters.Add("@obs_note", NpgsqlTypes.NpgsqlDbType.Varchar, 250);

            cmd.Parameters["@f_documento"].Value   = account.DocDate;
            cmd.Parameters["@f_vencimiento"].Value = account.DueDate;

            int coId = CompanyId(conn, account.Company.ApId, account.Company.EnterpriseId);

            if (coId == 0)
            {
                Company company = AdminPaqImpl.GetCompany(account.Company.ApId, account.Company.EnterprisePath, account.Company.EnterpriseId);
                if (company != null)
                {
                    AddCompany(conn, company);
                }
                else
                {
                    conn.Close();
                    return;
                }

                coId = CompanyId(conn, account.Company.ApId, account.Company.EnterpriseId);
                if (coId == 0)
                {
                    conn.Close();
                    return;
                }
            }

            cmd.Parameters["@id_cliente"].Value     = coId;
            cmd.Parameters["@serie_doco"].Value     = account.Serie;
            cmd.Parameters["@folio_doco"].Value     = account.Folio;
            cmd.Parameters["@tipo_documento"].Value = account.DocType;
            cmd.Parameters["@facturado"].Value      = account.Amount;
            cmd.Parameters["@saldo"].Value          = account.Balance;
            cmd.Parameters["@moneda"].Value         = account.Currency;
            cmd.Parameters["@id"].Value             = account.ApId;
            cmd.Parameters["@enterprise"].Value     = account.Company.EnterpriseId;

            cmd.Parameters["@collect_date"].Value = account.CollectDate;
            cmd.Parameters["@collect_type"].Value = account.CollectType;
            cmd.Parameters["@obs_note"].Value     = account.Note;


            cmd.ExecuteNonQuery();
            conn.Close();
        }
Example #2
0
        public static void AddAccount(Account account, EventLog log)
        {
            string           connectionString = ConfigurationManager.ConnectionStrings[Config.Common.MONFOLL].ConnectionString;
            NpgsqlConnection conn;

            conn = new NpgsqlConnection(connectionString);
            conn.Open();

            string sqlString = "INSERT INTO ctrl_cuenta (ap_id, enterprise_id, F_DOCUMENTO, F_VENCIMIENTO, F_COBRO, ID_CLIENTE, SERIE_DOCO, FOLIO_DOCO, TIPO_DOCUMENTO, TIPO_COBRO, FACTURADO, " +
                               "SALDO, MONEDA, OBSERVACIONES) " +
                               "VALUES( @id, @enterprise, @f_documento, @f_vencimiento, @f_cobro, @id_cliente, @serie_doco, @folio_doco, @tipo_documento, @tipo_cobro, @facturado, @saldo, " +
                               "@moneda, @observaciones);";

            NpgsqlCommand cmd = new NpgsqlCommand(sqlString, conn);

            cmd.Parameters.Add("@id", NpgsqlTypes.NpgsqlDbType.Integer);
            cmd.Parameters.Add("@enterprise", NpgsqlTypes.NpgsqlDbType.Integer);
            cmd.Parameters.Add("@f_documento", NpgsqlTypes.NpgsqlDbType.Date);
            cmd.Parameters.Add("@f_vencimiento", NpgsqlTypes.NpgsqlDbType.Date);
            cmd.Parameters.Add("@f_cobro", NpgsqlTypes.NpgsqlDbType.Date);
            cmd.Parameters.Add("@id_cliente", NpgsqlTypes.NpgsqlDbType.Integer);
            cmd.Parameters.Add("@serie_doco", NpgsqlTypes.NpgsqlDbType.Varchar, 4);
            cmd.Parameters.Add("@folio_doco", NpgsqlTypes.NpgsqlDbType.Integer);
            cmd.Parameters.Add("@tipo_documento", NpgsqlTypes.NpgsqlDbType.Varchar, 150);
            cmd.Parameters.Add("@tipo_cobro", NpgsqlTypes.NpgsqlDbType.Varchar, 100);
            cmd.Parameters.Add("@facturado", NpgsqlTypes.NpgsqlDbType.Money);
            cmd.Parameters.Add("@saldo", NpgsqlTypes.NpgsqlDbType.Money);
            cmd.Parameters.Add("@moneda", NpgsqlTypes.NpgsqlDbType.Varchar, 50);
            cmd.Parameters.Add("@observaciones", NpgsqlTypes.NpgsqlDbType.Varchar, 250);

            cmd.Parameters["@id"].Value            = account.ApId;
            cmd.Parameters["@enterprise"].Value    = account.Company.EnterpriseId;
            cmd.Parameters["@f_documento"].Value   = account.DocDate;
            cmd.Parameters["@f_vencimiento"].Value = account.DueDate;
            cmd.Parameters["@f_cobro"].Value       = account.CollectDate;

            int coId = CompanyId(conn, account.Company.ApId, account.Company.EnterpriseId);

            if (coId == 0)
            {
                log.WriteEntry("Unable to find client apId: " + account.Company.ApId + "; enterprise: " + account.Company.EnterpriseId, EventLogEntryType.Warning);
                Company company = AdminPaqImpl.GetCompany(account.Company.ApId, account.Company.EnterprisePath, account.Company.EnterpriseId);
                if (company != null)
                {
                    AddCompany(conn, company);
                }
                else
                {
                    log.WriteEntry("Unable to find client in adminPaq", EventLogEntryType.Warning);
                    conn.Close();
                    return;
                }

                coId = CompanyId(conn, account.Company.ApId, account.Company.EnterpriseId);
                if (coId == 0)
                {
                    conn.Close();
                    return;
                }
            }

            cmd.Parameters["@id_cliente"].Value     = coId;
            cmd.Parameters["@serie_doco"].Value     = account.Serie;
            cmd.Parameters["@folio_doco"].Value     = account.Folio;
            cmd.Parameters["@tipo_documento"].Value = account.DocType;
            cmd.Parameters["@tipo_cobro"].Value     = account.CollectType;
            cmd.Parameters["@facturado"].Value      = account.Amount;
            cmd.Parameters["@saldo"].Value          = account.Balance;
            cmd.Parameters["@moneda"].Value         = account.Currency;
            cmd.Parameters["@observaciones"].Value  = account.Note;

            cmd.ExecuteNonQuery();
            conn.Close();
        }