public override Lfx.Types.OperationResult Guardar() { this.Cliente.Connection = this.Connection; if (this.Facturas != null) { foreach (Lbl.Comprobantes.ComprobanteImporte Comp in this.Facturas) { Comp.Comprobante.Connection = this.Connection; } } if (this.Concepto == null) { //Concepto predeterminado para recibos if (this.DePago) { //Compra de mercadería this.Concepto = new Lbl.Cajas.Concepto(this.Connection, 21000); } else { //Ingresos por facturación this.Concepto = Lbl.Cajas.Concepto.IngresosPorFacturacion; } } else { this.Concepto.Connection = this.Connection; } if (this.Tipo.NumerarAlGuardar) { new Lbl.Comprobantes.Numerador(this).Numerar(false); } // Asiento el recibo qGen.IStatement Comando; if (this.Existe == false) { Comando = new qGen.Insert(this.TablaDatos); Comando.ColumnValues.AddWithValue("fecha", new qGen.SqlExpression("NOW()")); } else { throw new Lfx.Types.DomainException("Lbl: No se puede cambiar un recibo impreso"); } if (this.Concepto != null) { Comando.ColumnValues.AddWithValue("id_concepto", this.Concepto.Id); } else { Comando.ColumnValues.AddWithValue("id_concepto", null); } Comando.ColumnValues.AddWithValue("concepto", this.ConceptoTexto); Comando.ColumnValues.AddWithValue("tipo_fac", this.Tipo.Nomenclatura); Comando.ColumnValues.AddWithValue("pv", this.PV); Comando.ColumnValues.AddWithValue("numero", this.Numero); Comando.ColumnValues.AddWithValue("nombre", this.PV.ToString("0000") + "-" + this.Numero.ToString("00000000")); Comando.ColumnValues.AddWithValue("id_vendedor", Lfx.Data.Connection.ConvertZeroToDBNull(this.Vendedor.Id)); Comando.ColumnValues.AddWithValue("id_cliente", Lfx.Data.Connection.ConvertZeroToDBNull(this.Cliente.Id)); Comando.ColumnValues.AddWithValue("id_sucursal", Lfx.Workspace.Master.CurrentConfig.Empresa.SucursalActual); Comando.ColumnValues.AddWithValue("total", this.Total); Comando.ColumnValues.AddWithValue("obs", this.Obs); this.AgregarTags(Comando); this.Connection.ExecuteNonQuery(Comando); this.ActualizarId(); string ObsPago = string.Empty; if (this.Obs != null && this.Obs.Length > 0) { ObsPago += this.Obs + " ///"; } else if (this.DePago) { ObsPago = "Pago"; } else { ObsPago = "Cobro"; } ObsPago += " s/" + this.ToString(true); if (ConceptoTexto == null || ConceptoTexto.Length == 0) { ConceptoTexto = ObsPago; } // Asiento los valores foreach (Cobro Pg in this.Cobros) { Pg.Concepto = this.Concepto; Pg.ConceptoTexto = this.ConceptoTexto; switch (Pg.FormaDePago.Tipo) { case Lbl.Pagos.TiposFormasDePago.Efectivo: Cajas.Caja CajaDiaria = new Cajas.Caja(this.Connection, Lfx.Workspace.Master.CurrentConfig.Empresa.CajaDiaria); CajaDiaria.Movimiento(true, this.Concepto, this.ConceptoTexto, Cliente, Pg.Importe, ObsPago, null, this, string.Empty); break; case Lbl.Pagos.TiposFormasDePago.ChequePropio: case Lbl.Pagos.TiposFormasDePago.ChequeTerceros: Pg.Cheque.Connection = this.Connection; Pg.Cheque.Obs = ObsPago; Pg.Cheque.Concepto = Pg.Concepto; Pg.Cheque.ConceptoTexto = Pg.ConceptoTexto; if (this.DePago) { Pg.Cheque.ReciboPago = this; } else { Pg.Cheque.ReciboCobro = this; } Pg.Cheque.Cliente = this.Cliente; Pg.Cheque.Emitido = Pg.FormaDePago.Tipo == Lbl.Pagos.TiposFormasDePago.ChequePropio; Lfx.Types.OperationResult ResultadoCheque = Pg.Cheque.Guardar(); if (ResultadoCheque.Success == false) { return(ResultadoCheque); } break; case Lbl.Pagos.TiposFormasDePago.Tarjeta: Pg.Cupon.Connection = this.Connection; Pg.Cupon.Obs = ObsPago; Pg.Cupon.ConceptoTexto = Pg.ConceptoTexto; Pg.Cupon.Recibo = this; Pg.Cupon.Cliente = this.Cliente; Lfx.Types.OperationResult ResultadoCupon = Pg.Cupon.Guardar(); if (ResultadoCupon.Success == false) { return(ResultadoCupon); } break; case Lbl.Pagos.TiposFormasDePago.Caja: Pg.CajaDestino.Connection = this.Connection; Pg.CajaDestino.Movimiento(true, Pg.Concepto, Pg.ConceptoTexto, this.Cliente, Pg.Importe, ObsPago, null, this, string.Empty); break; case Lbl.Pagos.TiposFormasDePago.OtroValor: Pg.Valor.Connection = this.Connection; Pg.Valor.Obs = ObsPago; Pg.Valor.Recibo = this; Lfx.Types.OperationResult ResultadoValor = Pg.Valor.Guardar(); if (ResultadoValor.Success == false) { return(ResultadoValor); } break; } } foreach (Pago Pg in this.Pagos) { Pg.Concepto = this.Concepto; Pg.ConceptoTexto = this.ConceptoTexto; switch (Pg.FormaDePago.Tipo) { case Lbl.Pagos.TiposFormasDePago.Efectivo: Cajas.Caja CajaDiaria = new Cajas.Caja(this.Connection, Lfx.Workspace.Master.CurrentConfig.Empresa.CajaDiaria); CajaDiaria.Movimiento(true, Pg.Concepto, Pg.ConceptoTexto, this.Cliente, -Pg.Importe, ObsPago, null, this, string.Empty); break; case Lbl.Pagos.TiposFormasDePago.ChequePropio: Pg.Cheque.Connection = this.Connection; Pg.Cheque.Concepto = Pg.Concepto; Pg.Cheque.Cliente = this.Cliente; Pg.Cheque.ConceptoTexto = Pg.ConceptoTexto; Pg.Cheque.Obs = ObsPago; Pg.Cheque.Emitido = true; Pg.Cheque.ReciboPago = this; Lfx.Types.OperationResult ResultadoCheque = Pg.Cheque.Guardar(); if (ResultadoCheque.Success == false) { return(ResultadoCheque); } break; case Lbl.Pagos.TiposFormasDePago.Caja: Pg.CajaOrigen.Connection = this.Connection; Pg.CajaOrigen.Movimiento(true, Pg.Concepto, Pg.ConceptoTexto, this.Cliente, -Pg.Importe, ObsPago, null, this, string.Empty); break; case Lbl.Pagos.TiposFormasDePago.ChequeTerceros: Pg.Cheque.Connection = this.Connection; Lfx.Types.OperationResult ResultadoChequeTerceros = Pg.Cheque.Entregar(this); if (ResultadoChequeTerceros.Success == false) { return(ResultadoChequeTerceros); } break; case Lbl.Pagos.TiposFormasDePago.OtroValor: Pg.Valor.Connection = this.Connection; Pg.Valor.Estado = 11; if (Pg.Valor.Obs.Length > 0) { Pg.Valor.Obs += " /// "; } Pg.Valor.Obs += "Entregado s/" + this.ToString(); Pg.Valor.Recibo = this; Pg.Valor.Guardar(); Lfx.Types.OperationResult ResultadoValor = Pg.Valor.Guardar(); if (ResultadoValor.Success == false) { return(ResultadoValor); } break; } } CancelarImpagos(this.Cliente, this.Facturas, this, this.DePago ? -this.Total : this.Total); this.Cliente.CuentaCorriente.Movimiento(true, this.Concepto, this.ConceptoTexto, this.DePago ? this.Total : -this.Total, this.Obs, null, this, this.ToString()); base.Guardar(); return(new Lfx.Types.SuccessOperationResult()); }
public override Lfx.Types.OperationResult Guardar() { this.Cliente.Connection = this.Connection; if (this.Facturas != null) { foreach (Lbl.Comprobantes.ComprobanteImporte Comp in this.Facturas) { Comp.Comprobante.Connection = this.Connection; } } if (this.Concepto == null) { //Concepto predeterminado para recibos if (this.DePago) //Compra de mercadería this.Concepto = new Lbl.Cajas.Concepto(this.Connection, 21000); else //Ingresos por facturación this.Concepto = Lbl.Cajas.Concepto.IngresosPorFacturacion; } else { this.Concepto.Connection = this.Connection; } if (this.Tipo.NumerarAlGuardar) this.Numerar(false); // Asiento el recibo qGen.TableCommand Comando; if (this.Existe == false) { Comando = new qGen.Insert(this.Connection, this.TablaDatos); Comando.Fields.AddWithValue("fecha", qGen.SqlFunctions.Now); } else { throw new Lfx.Types.DomainException("Lbl: No se puede cambiar un recibo impreso"); } if (this.Concepto != null) Comando.Fields.AddWithValue("id_concepto", this.Concepto.Id); else Comando.Fields.AddWithValue("id_concepto", null); Comando.Fields.AddWithValue("concepto", this.ConceptoTexto); Comando.Fields.AddWithValue("tipo_fac", this.Tipo.Nomenclatura); Comando.Fields.AddWithValue("pv", this.PV); Comando.Fields.AddWithValue("numero", this.Numero); Comando.Fields.AddWithValue("nombre", this.PV.ToString("0000") + "-" + this.Numero.ToString("00000000")); Comando.Fields.AddWithValue("id_vendedor", Lfx.Data.Connection.ConvertZeroToDBNull(this.Vendedor.Id)); Comando.Fields.AddWithValue("id_cliente", Lfx.Data.Connection.ConvertZeroToDBNull(this.Cliente.Id)); Comando.Fields.AddWithValue("id_sucursal", Lfx.Workspace.Master.CurrentConfig.Empresa.SucursalActual); Comando.Fields.AddWithValue("total", this.Total); Comando.Fields.AddWithValue("obs", this.Obs); this.AgregarTags(Comando); this.Connection.Execute(Comando); this.ActualizarId(); string ObsPago = string.Empty; if (this.Obs != null && this.Obs.Length > 0) ObsPago += this.Obs + " ///"; else if (this.DePago) ObsPago = "Pago"; else ObsPago = "Cobro"; ObsPago += " s/" + this.ToString(true); if (ConceptoTexto == null || ConceptoTexto.Length == 0) ConceptoTexto = ObsPago; // Asiento los valores foreach (Cobro Pg in this.Cobros) { Pg.Concepto = this.Concepto; Pg.ConceptoTexto = this.ConceptoTexto; switch (Pg.FormaDePago.Tipo) { case Lbl.Pagos.TiposFormasDePago.Efectivo: Cajas.Caja CajaDiaria = new Cajas.Caja(this.Connection, Lfx.Workspace.Master.CurrentConfig.Empresa.CajaDiaria); CajaDiaria.Movimiento(true, this.Concepto, this.ConceptoTexto, Cliente, Pg.Importe, ObsPago, null, this, string.Empty); break; case Lbl.Pagos.TiposFormasDePago.ChequePropio: case Lbl.Pagos.TiposFormasDePago.ChequeTerceros: Pg.Cheque.Connection = this.Connection; Pg.Cheque.Obs = ObsPago; Pg.Cheque.Concepto = Pg.Concepto; Pg.Cheque.ConceptoTexto = Pg.ConceptoTexto; if (this.DePago) Pg.Cheque.ReciboPago = this; else Pg.Cheque.ReciboCobro = this; Pg.Cheque.Cliente = this.Cliente; Pg.Cheque.Emitido = Pg.FormaDePago.Tipo == Lbl.Pagos.TiposFormasDePago.ChequePropio; Lfx.Types.OperationResult ResultadoCheque = Pg.Cheque.Guardar(); if (ResultadoCheque.Success == false) return ResultadoCheque; break; case Lbl.Pagos.TiposFormasDePago.Tarjeta: Pg.Cupon.Connection = this.Connection; Pg.Cupon.Obs = ObsPago; Pg.Cupon.ConceptoTexto = Pg.ConceptoTexto; Pg.Cupon.Recibo = this; Pg.Cupon.Cliente = this.Cliente; Lfx.Types.OperationResult ResultadoCupon = Pg.Cupon.Guardar(); if (ResultadoCupon.Success == false) return ResultadoCupon; break; case Lbl.Pagos.TiposFormasDePago.Caja: Pg.CajaDestino.Connection = this.Connection; Pg.CajaDestino.Movimiento(true, Pg.Concepto, Pg.ConceptoTexto, this.Cliente, Pg.Importe, ObsPago, null, this, string.Empty); break; case Lbl.Pagos.TiposFormasDePago.OtroValor: Pg.Valor.Connection = this.Connection; Pg.Valor.Obs = ObsPago; Pg.Valor.Recibo = this; Lfx.Types.OperationResult ResultadoValor = Pg.Valor.Guardar(); if (ResultadoValor.Success == false) return ResultadoValor; break; } } foreach (Pago Pg in this.Pagos) { Pg.Concepto = this.Concepto; Pg.ConceptoTexto = this.ConceptoTexto; switch (Pg.FormaDePago.Tipo) { case Lbl.Pagos.TiposFormasDePago.Efectivo: Cajas.Caja CajaDiaria = new Cajas.Caja(this.Connection, Lfx.Workspace.Master.CurrentConfig.Empresa.CajaDiaria); CajaDiaria.Movimiento(true, Pg.Concepto, Pg.ConceptoTexto, this.Cliente, -Pg.Importe, ObsPago, null, this, string.Empty); break; case Lbl.Pagos.TiposFormasDePago.ChequePropio: Pg.Cheque.Connection = this.Connection; Pg.Cheque.Concepto = Pg.Concepto; Pg.Cheque.Cliente = this.Cliente; Pg.Cheque.ConceptoTexto = Pg.ConceptoTexto; Pg.Cheque.Obs = ObsPago; Pg.Cheque.Emitido = true; Pg.Cheque.ReciboPago = this; Lfx.Types.OperationResult ResultadoCheque = Pg.Cheque.Guardar(); if (ResultadoCheque.Success == false) return ResultadoCheque; break; case Lbl.Pagos.TiposFormasDePago.Caja: Pg.CajaOrigen.Connection = this.Connection; Pg.CajaOrigen.Movimiento(true, Pg.Concepto, Pg.ConceptoTexto, this.Cliente, -Pg.Importe, ObsPago, null, this, string.Empty); break; case Lbl.Pagos.TiposFormasDePago.ChequeTerceros: Pg.Cheque.Connection = this.Connection; Lfx.Types.OperationResult ResultadoChequeTerceros = Pg.Cheque.Entregar(this); if (ResultadoChequeTerceros.Success == false) return ResultadoChequeTerceros; break; case Lbl.Pagos.TiposFormasDePago.OtroValor: Pg.Valor.Connection = this.Connection; Pg.Valor.Estado = 11; if (Pg.Valor.Obs.Length > 0) Pg.Valor.Obs += " /// "; Pg.Valor.Obs += "Entregado s/" + this.ToString(); Pg.Valor.Recibo = this; Pg.Valor.Guardar(); Lfx.Types.OperationResult ResultadoValor = Pg.Valor.Guardar(); if (ResultadoValor.Success == false) return ResultadoValor; break; } } CancelarImpagos(this.Cliente, this.Facturas, this, this.DePago ? -this.Total : this.Total); this.Cliente.CuentaCorriente.Movimiento(true, this.Concepto, this.ConceptoTexto, this.DePago ? this.Total : -this.Total, this.Obs, null, this, this.ToString()); base.Guardar(); return new Lfx.Types.SuccessOperationResult(); }