protected void Page_Load(object sender, EventArgs e) { // First control the type of parent page if (Request.QueryString["AmendmentInvoiceId"] != null) { aInvoiceId = Int32.Parse(Request.QueryString["AmendmentInvoiceId"]); aInv = CntAriCli.GetAmendementInvoice(aInvoiceId, ctx); caller = "amendmentinvoice"; // Called by Insurance } }
protected void Page_Init(object sender, EventArgs e) { ctx = new AriClinicContext("AriClinicContext"); // security control, it must be a user logged if (Session["User"] == null) Response.Redirect("Default.aspx"); else { user = CntAriCli.GetUser((Session["User"] as User).UserId, ctx); Process proc = (from p in ctx.Processes where p.Code == "amendmentinvoice" select p).FirstOrDefault<Process>(); per = CntAriCli.GetPermission(user.UserGroup, proc, ctx); btnAccept.Visible = per.Modify; } hc = CntAriCli.GetHealthCompany(ctx); // if (Request.QueryString["AmendmentInvoiceId"] != null) { amendmentInvoiceId = Int32.Parse(Request.QueryString["AmendmentInvoiceId"]); aInv = CntAriCli.GetAmendementInvoice(amendmentInvoiceId, ctx); LoadData(aInv); } else { // deafault values rddpInvoiceDate.SelectedDate = DateTime.Now; txtYear.Text = DateTime.Now.Year.ToString(); txtInvoiceSerial.Text = hc.InvoiceSerial; } // if (Request.QueryString["Caller"] != null) caller = Request.QueryString["Caller"]; if (Session["Clinic"] != null) cl = (Clinic)Session["Clinic"]; // always read Healt care company }
protected void Page_Init(object sender, EventArgs e) { ctx = new AriClinicContext("AriClinicContext"); // security control, it must be a user logged if (Session["User"] == null) Response.Redirect("Default.aspx"); else { user = CntAriCli.GetUser((Session["User"] as User).UserId, ctx); Process proc = (from p in ctx.Processes where p.Code == "rtickets" select p).FirstOrDefault<Process>(); per = CntAriCli.GetPermission(user.UserGroup, proc, ctx); } // cheks if is call from another form if (Request.QueryString["Report"] != null) report = Request.QueryString["Report"]; if (Request.QueryString["FDate"] != null) fDate = CntWeb.ParseUrlDate(Request.QueryString["FDate"]); if (Request.QueryString["TDate"] != null) tDate = CntWeb.ParseUrlDate(Request.QueryString["TDate"]); if (Request.QueryString["Diary"] != null) diary = CntAriCli.GetDiary(int.Parse(Request.QueryString["Diary"]),ctx); if (Request.QueryString["Visit"] != null) visit = CntAriCli.GetVisit(int.Parse(Request.QueryString["Visit"]), ctx); if (Request.QueryString["Treatment"] != null) treatment = CntAriCli.GetTreatment(int.Parse(Request.QueryString["Treatment"]), ctx); if (Request.QueryString["Invoice"] != null) invoice = CntAriCli.GetInvoice(int.Parse(Request.QueryString["Invoice"]), ctx); if (Request.QueryString["AmendmentInvoice"] != null) aInvoice = CntAriCli.GetAmendementInvoice(int.Parse(Request.QueryString["AmendmentInvoice"]), ctx); if (Request.QueryString["PrescriptionGlasses"] != null) prescriptionGlasses = CntAriCli.GetPrescriptionGlasses(int.Parse(Request.QueryString["PrescriptionGlasses"]), ctx); if (Request.QueryString["Estimate"] != null) estimate = CntAriCli.GetEstimate(int.Parse(Request.QueryString["Estimate"]), ctx); }
protected void UnloadData(AmendmentInvoice aInv) { aInv.Serial = txtInvoiceSerial.Text; aInv.Year = Int32.Parse(txtYear.Text); if (aInv.InvoiceNumber == 0) aInv.InvoiceNumber = CntAriCli.GetNextInvoiceNumber(aInv.Serial, aInv.Year, ctx); aInv.InvoiceDate = (DateTime)rddpInvoiceDate.SelectedDate; customerId = Int32.Parse(txtCustomerId.Text); aInv.Customer = CntAriCli.GetCustomer(customerId, ctx); aInv.Reason = txtReason.Text; aInv.Total = CntAriCli.GetAmendmentInvoiceTotal(aInv); txtInvoiceTotal.Text = String.Format("{0:####,#0.00}", aInv.Total); aInv.InvoiceKey = String.Format("{0}-{1:000000}-{2}", aInv.Year, aInv.InvoiceNumber, aInv.Serial); }
protected void LoadData(AmendmentInvoice aInv) { lblOriginalInvoice.Text = String.Format("Factura original:{0}-{1}-{2} Fecha:{3:dd/MM/yyyy}", aInv.OriginalInvoice.Serial, aInv.OriginalInvoice.Year, aInv.OriginalInvoice.InvoiceNumber, aInv.OriginalInvoice.InvoiceDate); txtInvoiceId.Text = aInv.AmendmentInvoiceId.ToString(); txtInvoiceSerial.Text = aInv.Serial; txtYear.Text = aInv.Year.ToString(); txtInvoiceNumber.Text = String.Format("{0:000000}", aInv.InvoiceNumber); rddpInvoiceDate.SelectedDate = aInv.InvoiceDate; txtCustomerId.Text = aInv.Customer.PersonId.ToString(); txtCustomerName.Text = aInv.Customer.ComercialName; txtReason.Text = aInv.Reason; txtInvoiceTotal.Text = String.Format("{0:####,#0.00}", aInv.Total); }
protected bool CreateChange() { if (!DataOk()) return false; if (aInv == null) { aInv = new AmendmentInvoice(); UnloadData(aInv); ctx.Add(aInv); } else { aInv = CntAriCli.GetAmendementInvoice(amendmentInvoiceId, ctx); UnloadData(aInv); } ctx.SaveChanges(); return true; }
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { // weonly process commands with a datasource (our image buttons) if (e.CommandSource == null) return; string typeOfControl = e.CommandSource.GetType().ToString(); if (typeOfControl.Equals("System.Web.UI.WebControls.ImageButton")) { int id = 0; ImageButton imgb = (ImageButton)e.CommandSource; if (imgb.ID != "New" && imgb.ID != "Exit") id = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][e.Item.OwnerTableView.DataKeyNames[0]]; switch (imgb.ID) { case "Select": break; case "Edit": break; case "Delete": aInv = (from i in ctx.AmendmentInvoices where i.AmendmentInvoiceId == id select i).FirstOrDefault<AmendmentInvoice>(); if (!CntAriCli.DeleteAmendmentInvoice(aInv,ctx)) { lblMessage.Text = Resources.GeneralResource.DeleteInvoiceFailed; return; } lblMessage.Text = ""; ctx.SaveChanges(); RefreshGrid(true); break; } } }
protected bool CreateChange() { if (!DataOk()) return false; // DateTime myDate = (DateTime)rddpInvoiceDate.SelectedDate; string reason = txtReason.Text; // create amendment invoice aInv = CntAriCli.CreateAmendmentInvoice(inv, myDate, reason, ctx); if (aInv == null) { lblMessage.Text = "No se ha podido crear la factura rectificativa, seguramente ya se ha generado otra contra esta factura"; return false; } return true; }
public static Decimal GetAmendmentInvoiceTotal(AmendmentInvoice inv) { Decimal total = 0; foreach (AmendmentInvoiceLine invl in inv.AmendmentInvoiceLines) { total += invl.Amount; } return total; }
public static AmendmentInvoice CreateAmendmentInvoice(Invoice invoice, DateTime vdate, string reason, AriClinicContext ctx) { // first of all check if there's another amendment invoice // linked to this invoice. AmendmentInvoice aInv = (from a in ctx.AmendmentInvoices where a.OriginalInvoice.InvoiceId == invoice.InvoiceId select a).FirstOrDefault<AmendmentInvoice>(); if (aInv != null) { return null; } // collecting some stuff we'll need. HealthcareCompany hc = CntAriCli.GetHealthCompany(ctx); // now let's go to create it aInv = new AmendmentInvoice(); aInv.Customer = invoice.Customer; aInv.InvoiceDate = vdate; aInv.Serial = hc.AmendmentInvoiceSerial; aInv.Year = aInv.InvoiceDate.Year; aInv.InvoiceNumber = CntAriCli.GetNextAmendmentInvoiceNumber(aInv.Serial, aInv.Year, ctx); aInv.OriginalInvoice = invoice; aInv.Reason = reason; ctx.Add(aInv); ctx.SaveChanges(); // related lines decimal total = 0; foreach (InvoiceLine il in invoice.InvoiceLines) { AmendmentInvoiceLine ail = new AmendmentInvoiceLine(); ail.AmendmentInvoice = aInv; ail.TaxType = il.TaxType; ail.TaxPercentage = il.TaxPercentage; ail.Description = il.Description; ail.Amount = -il.Amount; total += ail.Amount; ctx.Add(ail); ctx.SaveChanges(); } aInv.Total = total; ctx.SaveChanges(); return aInv; }
public static bool DeleteAmendmentInvoice(AmendmentInvoice aInv, AriClinicContext ctx) { // Last invoice number? int n = GetNextAmendmentInvoiceNumber(aInv.Serial, aInv.Year, ctx) - 1; // only the last invoice can be deleted if (aInv.InvoiceNumber != n) return false; // delete lines ctx.Delete(aInv.AmendmentInvoiceLines); // delete invoice ctx.Delete(aInv); return true; }