Пример #1
0
        public override void create(IModelView obj)
        {
            using (var tran = Marfil.Inf.Genericos.Helper.TransactionScopeBuilder.CreateTransactionObject())
            {
                var model      = obj as PedidosModel;
                var validation = _validationService as PedidosValidation;
                validation.EjercicioId = EjercicioId;
                //Calculo ID
                var contador = ServiceHelper.GetNextId <Pedidos>(_db, Empresa, model.Fkseries);
                var identificadorsegmento = "";
                model.Referencia            = ServiceHelper.GetReference <Pedidos>(_db, model.Empresa, model.Fkseries, contador, model.Fechadocumento.Value, out identificadorsegmento);
                model.Identificadorsegmento = identificadorsegmento;

                DocumentosHelpers.GenerarCarpetaAsociada(model, TipoDocumentos.PedidosVentas, _context, _db);

                base.create(obj);

                ModificarCantidadesPedidasPresupuestos(obj as PedidosModel);

                _db.SaveChanges();
                tran.Complete();
            }
        }
        public ReservasstockModel Clonar(string id)
        {
            var appService = new ApplicationHelper(_context);

            using (var tran = Marfil.Inf.Genericos.Helper.TransactionScopeBuilder.CreateTransactionObject())
            {
                var obj = _converterModel.CreateView(id) as ReservasstockModel;

                obj.Fechadocumento = DateTime.Now;
                obj.Fechavalidez   = DateTime.Now.AddMonths(1);
                foreach (var ReservasstockLinModel in obj.Lineas)
                {
                    ReservasstockLinModel.Fkpedidos           = null;
                    ReservasstockLinModel.Fkpedidosid         = null;
                    ReservasstockLinModel.Fkpedidosreferencia = string.Empty;
                }
                foreach (var item in obj.Lineas)
                {
                    item.Cantidadpedida = 0;
                }
                obj.Fkestados = appService.GetConfiguracion().Estadoreservasinicial;
                var contador = ServiceHelper.GetNextId <Reservasstock>(_db, Empresa, obj.Fkseries);
                var identificadorsegmento = "";
                obj.Referencia            = ServiceHelper.GetReference <Reservasstock>(_db, obj.Empresa, obj.Fkseries, contador, obj.Fechadocumento.Value, out identificadorsegmento);
                obj.Identificadorsegmento = identificadorsegmento;
                var newItem = _converterModel.CreatePersitance(obj);
                if (_validationService.ValidarGrabar(newItem))
                {
                    ReservasstockModel result;
                    result = _converterModel.GetModelView(newItem) as ReservasstockModel;
                    //generar carpeta
                    DocumentosHelpers.GenerarCarpetaAsociada(result, TipoDocumentos.Reservas, _context, _db);
                    newItem.fkcarpetas = result.Fkcarpetas;
                    _db.Set <Reservasstock>().Add(newItem);
                    try
                    {
                        _db.SaveChanges();

                        tran.Complete();
                        result.Id = newItem.id;
                    }
                    catch (DbUpdateException ex)
                    {
                        if (ex.InnerException != null &&
                            ex.InnerException.InnerException != null)
                        {
                            var inner = ex.InnerException.InnerException as SqlException;
                            if (inner != null)
                            {
                                if (inner.Number == 2627 || inner.Number == 2601)
                                {
                                    throw new ValidationException(General.ErrorRegistroExistente);
                                }
                            }
                        }


                        throw;
                    }

                    return(result);
                }
            }

            throw new ValidationException(General.ErrorClonarGeneral);
        }
Пример #3
0
        public override void create(IModelView obj)
        {
            using (var tran = Marfil.Inf.Genericos.Helper.TransactionScopeBuilder.CreateTransactionObject())
            {
                var model      = obj as AlbaranesModel;
                var validation = _validationService as AlbaranesValidation;
                validation.EjercicioId = EjercicioId;

                //Calculo ID
                var contador = ServiceHelper.GetNextId <Albaranes>(_db, Empresa, model.Fkseries);
                var identificadorsegmento = "";
                model.Referencia            = ServiceHelper.GetReference <Albaranes>(_db, model.Empresa, model.Fkseries, contador, model.Fechadocumento.Value, out identificadorsegmento);
                model.Identificadorsegmento = identificadorsegmento;

                DocumentosHelpers.GenerarCarpetaAsociada(model, TipoDocumentos.AlbaranesVentas, _context, _db);

                //Actualizar precios si estos son = 0
                ApplicationHelper app = new ApplicationHelper(_context);

                if (app.GetListTiposAlbaranes().Where(f => f.EnumInterno == model.Tipoalbaran).Select(f => f.CosteAdq).SingleOrDefault())
                {
                    foreach (var l in model.Lineas)
                    {
                        if (l.Importe == null || l.Importe == 0)
                        {
                            var lotesService = new LotesService(_context);
                            l.Precio = Math.Round((double)_db.Stockhistorico.Where(f => f.empresa == _context.Empresa && f.lote == l.Lote && f.loteid == l.Tabla.ToString() && f.fkarticulos == l.Fkarticulos)
                                                  .Select(f => f.preciovaloracion + f.costeacicionalvariable / f.metrosentrada + f.costeadicionalmaterial / f.metrosentrada
                                                          + f.costeadicionalotro / f.metrosentrada + f.costeadicionalportes / f.metrosentrada).SingleOrDefault(), 2);
                            l.Importe = Math.Round((double)((decimal)l.Precio * (decimal)l.Metros), l.Decimalesmonedas ?? 2);
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(model.Fkpedidos))
                {
                    foreach (var lineaAlbaran in model.Lineas)
                    {
                        if (lineaAlbaran.Precio == 0)
                        {
                            var idPedido     = _db.Pedidos.Where(f => f.empresa == model.Empresa && f.referencia == model.Fkpedidos).Select(f => f.id).SingleOrDefault();
                            var lineasPedido = _db.PedidosLin.Where(f => f.empresa == model.Empresa && f.fkpedidos == idPedido);

                            foreach (var lineaPedido in lineasPedido)
                            {
                                if (lineaAlbaran.Fkarticulos == lineaPedido.fkarticulos)
                                {
                                    lineaAlbaran.Precio  = lineaPedido.precio;
                                    lineaAlbaran.Importe = Math.Round((double)((lineaAlbaran.Metros * lineaAlbaran.Precio) - (lineaAlbaran.Metros * lineaAlbaran.Precio *
                                                                                                                              (lineaAlbaran.Porcentajedescuento / 100))), 2);
                                }
                            }
                        }
                    }
                }
                //fin actualizar precios

                base.create(obj);

                ModificarCantidadesPedidasPedidos(obj as AlbaranesModel);
                ModificarMovimientosArticulos(obj as AlbaranesModel);

                _db.SaveChanges();
                tran.Complete();
            }
        }