예제 #1
0
        private string saveInvoice(out int invoiceN)
        {
            using (ClubDBEntities club = new ClubDBEntities())
            {
                // get info
                int     clientID = Convert.ToInt32(tbFile.Text);
                decimal total    = Convert.ToDecimal(tbTotal.Text);
                int     dis      = (string.IsNullOrEmpty(tbDis.Text)) ? 0 : Convert.ToInt32(tbDis.Text);
                decimal final    = Convert.ToDecimal(tbFinal.Text);
                decimal rem      = (string.IsNullOrEmpty(tbRemain.Text)) ? 0 : Convert.ToDecimal(tbRemain.Text);
                //int dep = Convert.ToInt32(ddlDep.SelectedValue);
                InvoiceHeader inv = new InvoiceHeader();
                inv.ClientID    = clientID;
                inv.TotalAmount = total;
                inv.Discount    = dis;
                inv.FinalAmount = final;
                //inv.Dep = dep;
                inv.Notes = tbNotes.Text;
                inv.Type  = rbType.SelectedValue;
                //inv.DocID = Convert.ToInt32(ddlDoc.SelectedValue);
                string userName = User.Identity.Name;
                inv.Status = InvoiceStatus.Complete.ToString();

                inv.RecepName = userName;
                inv.Date      = Convert.ToDateTime(tbDate.Text);//DateTime.Now.Date;// TODO: chnage this

                // services

                club.InvoiceHeaders.AddObject(inv);
                club.SaveChanges();
                invoiceN = inv.InvID;
                var services = (from o in club.Services
                                where ids.Contains(o.ServiceID)
                                select o).ToList();
                foreach (var s in services)
                {
                    // create  a sub if sub
                    if (s.Sub)
                    {
                        Subscribtion sub = new Subscribtion();
                        sub.ClientID  = clientID;
                        sub.Date      = Convert.ToDateTime(tbDate.Text);
                        sub.ServiceID = s.ServiceID;
                        sub.AttDays   = 0;
                        sub.LeftDays  = s.TotalDays;
                        sub.SubDays   = s.TotalDays;
                        club.Subscribtions.AddObject(sub);
                        club.SaveChanges();
                        switch (s.DepID)
                        {
                        case 1:
                            NutSub nut = new NutSub();
                            nut.SubID = sub.SubID;
                            club.NutSubs.AddObject(nut);
                            club.SaveChanges();
                            break;

                        case 2:
                            IntSub Int = new IntSub();
                            Int.SubID = sub.SubID;
                            club.IntSubs.AddObject(Int);
                            club.SaveChanges();
                            break;
                        }
                    }
                    // create a service
                    InvoiceService ser = new InvoiceService();
                    ser.InvID     = inv.InvID;
                    ser.ServiceID = s.ServiceID;
                    if (dis == 0)
                    {
                        if (rbType.SelectedIndex == 1)
                        {
                            decimal paid = Convert.ToDecimal(string.IsNullOrEmpty(tbPaid.Text) ? "0" : tbPaid.Text);
                            ser.PaidAmount  = getPrecentage(s.Price, final, paid);
                            ser.AskedAmount = s.Price;
                            ser.Percentage  = s.Price / final;
                        }

                        else
                        {
                            ser.PaidAmount  = s.Price;
                            ser.AskedAmount = s.Price;
                            ser.Percentage  = s.Price / final;
                        }
                    }
                    else
                    {
                        if (rbType.SelectedIndex == 1)
                        {
                            decimal paid    = Convert.ToDecimal(string.IsNullOrEmpty(tbPaid.Text) ? "0" : tbPaid.Text);
                            decimal asked   = applyDis(dis, s.Price);
                            decimal serpaid = getPrecentage(s.Price, final, paid);
                            ser.AskedAmount = asked;
                            ser.PaidAmount  = serpaid;
                            ser.Percentage  = s.Price / final;
                        }
                        else
                        {
                            decimal asked = applyDis(dis, s.Price);
                            ser.AskedAmount = asked;
                            ser.PaidAmount  = asked;
                            ser.Percentage  = s.Price / final;
                            //decimal paid = getPrecentage(asked, final, final);
                        }
                    }

                    club.InvoiceServices.AddObject(ser);
                }
                Deposit deposit = new Deposit();
                deposit.InvID      = invoiceN;
                deposit.Notes      = tbNotes.Text;
                deposit.Date       = Convert.ToDateTime(tbDate.Text);//DateTime.Now.Date;// TODO: chnage this
                deposit.Employee   = club.Employees.Where(a => a.UserName == User.Identity.Name).Select(o => o.Name).First();
                deposit.FromPerson = club.Clients.Where(a => a.ClientID == inv.ClientID).First().FullName();
                switch (rbType.SelectedIndex)
                {
                case 0:
                    deposit.CheckNum = Convert.ToInt64(tbCheck.Text);
                    deposit.Bank     = tbBank.Text;
                    inv.Type         = InvoiceType.Check.ToString();
                    break;

                case 1:
                    decimal paid = Convert.ToDecimal(tbPaid.Text);
                    deposit.Amount = paid;
                    inv.Type       = InvoiceType.Credit.ToString();
                    break;

                case 2:
                    decimal amount = Convert.ToDecimal(tbFinal.Text);
                    deposit.Amount = amount;
                    inv.Type       = InvoiceType.Cash.ToString();
                    break;
                }
                club.Deposits.AddObject(deposit);
                club.SaveChanges();
                VoucherID = deposit.ID;
                return(inv.Status);
            }
        }
예제 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (edit)
            {
                using (ClubDBEntities club = new ClubDBEntities())
                {
                    var result = (from o in club.Subscribtions
                                  where o.SubID == sub.SubID
                                  select o).First();
                    result.Measurements = tbMeasurements.Text;
                    result.Diagnosis    = tbDiagnosis.Text;
                    switch (sub.Service.DepID)
                    {
                    case 1:
                        var nut = (from o in club.NutSubs
                                   where o.SubID == sub.SubID
                                   select o).First();
                        nut.Weight = tbWeight.Text;
                        nut.Hight  = tbHieght.Text;
                        nut.Fat    = tbFat.Text;
                        club.SaveChanges();
                        break;

                    case 2:
                        var iint = (from o in club.IntSubs
                                    where o.SubID == sub.SubID
                                    select o).First();
                        iint.BloodSugar    = tbBSugar.Text;
                        iint.BloodPressure = tbBPressure.Text;
                        club.SaveChanges();
                        break;

                    case 5:
                        club.SaveChanges();
                        break;
                    }
                }
                string Message = "تم حفظ التعديلات";
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", string.Format("alert('{0}');", Message), true);
            }
            else
            {
                lblError.Visible = false;
                int id      = Convert.ToInt32(tbFile.Text);
                int empID   = Convert.ToInt32(ddlDoc.SelectedValue);
                int service = Convert.ToInt32(ddlServices.SelectedValue);
                if (ddlDep.SelectedIndex != 0)
                {
                    int subId;
                    using (ClubDBEntities club = new ClubDBEntities())
                    {
                        var serviceDays = (from o in club.Services
                                           where o.ServiceID == service
                                           select o.TotalDays).First();
                        Subscribtion sub = new Subscribtion();
                        sub.ClientID  = id;
                        sub.Date      = DateTime.Now;
                        sub.LeftDays  = serviceDays;
                        sub.ServiceID = service;
                        sub.AttDays   = 0;
                        sub.SubDays   = serviceDays;
                        club.Subscribtions.AddObject(sub);
                        club.SaveChanges();
                        subId = sub.SubID;
                        switch (ddlDep.SelectedValue)
                        {
                        case "1":
                            sub.Diagnosis    = tbDiagnosis.Text;
                            sub.Measurements = tbMeasurements.Text;
                            NutSub nut = new NutSub();
                            nut.Fat    = tbFat.Text;
                            nut.Weight = tbWeight.Text;
                            nut.Hight  = tbHieght.Text;
                            nut.SubID  = subId;
                            club.NutSubs.AddObject(nut);
                            club.SaveChanges();
                            break;

                        case "2":
                            sub.Diagnosis    = tbDiagnosis.Text;
                            sub.Measurements = tbMeasurements.Text;
                            IntSub Int = new IntSub();
                            Int.BloodPressure = tbBPressure.Text;
                            Int.BloodSugar    = tbBSugar.Text;
                            club.IntSubs.AddObject(Int);
                            club.SaveChanges();
                            break;

                        case "5":
                            sub.Diagnosis    = tbDiagnosis.Text;
                            sub.Measurements = tbMeasurements.Text;
                            club.SaveChanges();
                            break;
                        }
                    }
                    // redirect to the invoice
                    Response.Redirect("Invoice.aspx?subID=" + subId + "&empID=" + empID);
                }
                else
                {
                    lblError.Text    = "الرجاء اختيار القسم";
                    lblError.Visible = true;
                }
            }
        }