//---------------------- //Agregar Item Recibo //---------------------- public bool Ins_AgregarItemRecibo(string cPerJurCodigo, string cPerCodigo, string NroRecibo, long nCtaCteSerCodigo, DateTime dFechaSys, long nCantidad, double nPrecioUnit, double nImporte) { bool exito = false; long nLinea = 0; //para Tipo de cambio double nTC = 0; BL_Sistema daTC = new BL_Sistema(); //para CtaCteIteLIne BL_CtaCteIteLine blCCItemLine = new BL_CtaCteIteLine(); //para Obtener Serv. BE_ReqCtaCteServBusca ReqServ = new BE_ReqCtaCteServBusca(); BL_CtaCtaServicio daServ = new BL_CtaCtaServicio(); BL_ImpuestoServicio blImpServ = new BL_ImpuestoServicio(); BL_CtaCteIteLinRetencion blCCRetencion = new BL_CtaCteIteLinRetencion(); //Update CtaCteItem BL_CtaCteItem daCCItem = new BL_CtaCteItem(); try { using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required)) { ReqServ.cPerJurCodigo = cPerJurCodigo; ReqServ.nCtaCteSerCodigo = nCtaCteSerCodigo; ReqServ.nFlag = "SERV"; // if (daServ.Get_CtaCteServicio(ReqServ).Rows.Count > 0) { DataRow row = daServ.Get_CtaCteServicio(ReqServ).Rows[0]; //-------------- //Tipo de cambio //-------------- if (Convert.ToInt32(row["nMonCodigo"]) == 2) //Dolar { if (daTC.Get_TipodeCambio(Convert.ToInt32(row["nMonCodigo"]), "TCD", String.Format("{0:dd/MM/yyyy}", dFechaSys), 0, 0).Rows.Count > 0) { //DataRow row = daTC.Get_TipodeCambio(ReqTC).Rows[0]; nTC = Convert.ToDouble(daTC.Get_TipodeCambio(Convert.ToInt32(row["nMonCodigo"]), "TCD", String.Format("{0:dd/MM/yyyy}", dFechaSys), 0, 0).Rows[0]["nCompra"]); } else throw new ApplicationException("No se ha registrado el Tipo de Cambio del dia: " + String.Format("{0:ddd, MMM d, yyyy}", dFechaSys)); } else nTC = 1.0; //-------------- //CtaCteIteLine //-------------- nLinea = blCCItemLine.Ins_CtaCteIteLine(cPerJurCodigo, cPerCodigo, NroRecibo, Convert.ToInt32(row["nCtaCteSerCodigo"]), Convert.ToInt32(row["nMonCodigo"]), nCantidad, nPrecioUnit, nImporte, nTC, 1); if (nLinea != 0) { //--------------------- //CtaCteIteLinRetencion //--------------------- foreach (DataRow posicion in blImpServ.Get_ImpuestoServicio(cPerJurCodigo, cPerCodigo, NroRecibo, Convert.ToInt32(row["nCtaCteSerCodigo"]), 9256).Rows) //9256.- Perú { if (!blCCRetencion.Ins_CtaCteIteLinRetencion(cPerJurCodigo, cPerCodigo, NroRecibo, nLinea, Convert.ToInt32(posicion["nSysTasCodigo"]), Convert.ToDouble(row["nCtaCteSerImpDef"]), Convert.ToInt32(posicion["fSysTasValor"]), dFechaSys)) { throw new ApplicationException("Se encontraron errores en la transaccion: Ins_CtaCteIteLinRetencion.!"); } } } else throw new ApplicationException("Se encontraron errores en la transaccion: Ins_CtaCteIteLine.!"); //----------------------------------- // Actulizar campo "nCtaCteImporte" //----------------------------------- if (!daCCItem.Upd_CtaCteItem_nCtaCteImpAplicado(cPerJurCodigo, NroRecibo, nImporte, "ADDITEM")) { throw new ApplicationException("Se encontraron errores en la transaccion: [Upd_CtaCteItem_nCtaCteImpAplicado].!"); } exito = true; tx.Complete(); } else throw new ApplicationException("Configuracion de parametros no establecida.!"); } } catch (Exception) { throw; } return exito; }