public ActionResult SaveProforma(ProformaDTO Proforma) { UsuarioDTO currentUser = getCurrentUser(); //ProformaDTO Proforma = new ProformaDTO(); //TryUpdateModel(Proforma); Proforma.IdEmpresa = currentUser.IdEmpresa; if (Proforma.FechaRegistro == null) { Proforma.FechaRegistro = DateTime.Now; } var lista = new ProformaBL().SaveProforma(Proforma); return Json(lista, JsonRequestBehavior.AllowGet); }
public ActionResult NuevaProforma(Int32? id) { if (!this.currentUser()) { return RedirectToAction("Ingresar", "Admin"); } UsuarioDTO currentUser = getCurrentUser(); ProformaDTO pro = new ProformaDTO(); if (id.HasValue) { pro = new ProformaBL().getProformaId(id.Value); } ViewBag.Title += " - Editar Proforma"; MenuNavBarSelected(10); return View(pro); }
public ActionResult AddProforma(ProformaDTO dto) { if (!this.currentUser()) { return RedirectToAction("Ingresar", "Admin", new { Area = string.Empty }); } if (getCurrentUser().IdRol == 4) { return RedirectToAction("Index", "Proformas"); } try { if(dto != null) { dto.DetalleProforma = (List<DetalleProformaDTO>)TempData["lstDetalleProforma"] ?? new List<DetalleProformaDTO>(); } ProformaBL objBL = new ProformaBL(); if (dto.IdProforma == 0) { if (objBL.SaveProforma(dto)) { createResponseMessage(CONSTANTES.SUCCESS); return RedirectToAction("Index", "Proformas"); } else { createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE); } } else if (dto.IdProforma > 0) { if (objBL.SaveProforma(dto)) { createResponseMessage(CONSTANTES.SUCCESS); return RedirectToAction("Index", "Proformas"); } else { createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE); } } } catch(Exception e) { if (dto.IdProforma != 0) createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE); else createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE); } TempData["Proforma"] = dto; return RedirectToAction("Proforma", "Proformas", new { id = dto.IdProforma }); }
public bool SaveProforma(ProformaDTO proforma) { bool result = false; using (var context = getContext()) { try { Proforma nuevo = new Proforma(); if (proforma.IdProforma != 0) { nuevo = context.Proforma.Where(c => c.IdProforma == proforma.IdProforma).SingleOrDefault(); } else { nuevo.FechaRegistro = DateTime.Now; } nuevo.IdProforma = proforma.IdProforma; if (proforma.CodigoProforma == null || proforma.CodigoProforma == "") { nuevo.CodigoProforma = CodigoProforma(proforma.IdEmpresa); } //else { nuevo.CodigoProforma = proforma.CodigoProforma; } nuevo.IdEmpresa = proforma.IdEmpresa; nuevo.IdContacto = proforma.IdContacto; nuevo.IdEntidadResponsable = proforma.IdEntidadResponsable; nuevo.IdMoneda = proforma.IdMoneda; nuevo.IdCuentaBancaria = proforma.IdCuentaBancaria; nuevo.ValidezOferta = proforma.ValidezOferta; nuevo.MetodoPago = proforma.MetodoPago; nuevo.FechaEntrega = proforma.FechaEntrega; DateTime Hora = DateTime.Now; nuevo.FechaProforma = proforma.FechaProforma + new TimeSpan(Hora.Hour, Hora.Minute, Hora.Second); ; nuevo.LugarEntrega = proforma.LugarEntrega; nuevo.FechaFacturacion = proforma.FechaFacturacion; nuevo.FechaCobranza = proforma.FechaCobranza; nuevo.ComentarioAdiccional = proforma.ComentarioAdiccional; nuevo.ComentarioProforma = proforma.ComentarioProforma; nuevo.OrdenCompra = proforma.OrdenCompra; nuevo.Estado = proforma.Estado; if (nuevo.IdProforma == 0) { context.Proforma.Add(nuevo); } context.SaveChanges(); Int32 IdProforma = nuevo.IdProforma; DeleteDetalleItem(IdProforma); foreach (var detalle in proforma.DetalleProforma) { DetalleProforma deta = new DetalleProforma(); deta.IdProforma = IdProforma; deta.IdItem = detalle.IdItem; deta.Cantidad = detalle.Cantidad; deta.PrecioUnidad = detalle.PrecioUnidad; deta.UnidadMedida = detalle.UnidadMedida; deta.Descuento = detalle.Descuento; deta.MontoTotal = detalle.MontoTotal; deta.TipoCambio = detalle.TipoCambio; deta.PorcentajeIgv = detalle.PorcentajeIgv; deta.Igv = detalle.Igv; context.DetalleProforma.Add(deta); } context.SaveChanges(); result = true; } catch (Exception e) { throw new ArgumentException(e.Message); } } return result; }
public ActionResult Proforma(int? id) { if (!this.currentUser()) { return RedirectToAction("Ingresar", "Admin", new { Area = string.Empty }); } ViewBag.Title += "Proforma"; MenuNavBarSelected(12); UsuarioDTO user = getCurrentUser(); EntidadResponsableBL entBL = new EntidadResponsableBL(); ViewBag.lstClientes = entBL.getEntidadesResponsablesActivasPorTipoEnEmpresa(user.IdEmpresa, 1); EmpresaBL empBL = new EmpresaBL(); ViewBag.lstMonedas = empBL.getListaMonedasAll(); MovimientoInvBL movItmBL = new MovimientoInvBL(); ViewBag.lstItems = movItmBL.getItemsEnEmpresa_PorTipoMov(user.IdEmpresa, 1); CuentaBancariaBL cbBL = new CuentaBancariaBL(); ViewBag.lstCuentasBancarias = cbBL.getCuentasBancariasActivasPorTipoEnEmpresa(user.IdEmpresa, 1); ViewBag.lstContactos = new List<ContactoDTO>(); var objSent = TempData["Proforma"]; if (objSent != null) { TempData["Proforma"] = null; return View(objSent); } ProformaDTO obj; if(id != null && id > 0) { obj = new ProformaBL().getProformaId((int)id); return View(obj); } obj = new ProformaDTO(); obj.IdEmpresa = user.IdEmpresa; obj.FechaProforma = DateTime.Now; obj.DetalleProforma = new List<DetalleProformaDTO>(); return View(obj); }