Exemple #1
0
        public void recordSale()
        {
            if (SaleProducts.Count == 0)
            {
            }
            else
            {
                PaymentModel payment_model = new PaymentModel();
                payment_model.PaymentMethodID.value = 1;
                payment_model.SubTotal.value        = Convert.ToDouble(SubTotal);
                payment_model.Discount.value        = Convert.ToDouble(Discount);
                payment_model.Total.value           = Convert.ToDouble(Total);
                payment_model.Paid.value            = Convert.ToDouble(Paid);
                payment_model.Balance.value         = Convert.ToDouble(Balance);
                payment_model.TransactionTime.value = DateTime.Now;
                int payment_id = SaleAccess.singleton.addPayment(payment_model);

                SaleModel sale_model = new SaleModel();
                sale_model.UserID.value       = this.HomeViewModel.LoggedInUser.ID.value;
                sale_model.PaymentID.value    = payment_id;
                sale_model.CartDiscount.value = CartDiscount;
                int sale_id = SaleAccess.singleton.addSale(sale_model);

                foreach (SaleProductModel sale_product in SaleProducts)
                {
                    SaleProductModel sale_product_model = new SaleProductModel();
                    sale_product_model = sale_product;
                    sale_product_model.SaleID.value = sale_id;
                    SaleAccess.singleton.addSaleProduct(sale_product_model);
                    StockModel model = StockAccess.singleton.getStockOfProduct(Convert.ToInt32(sale_product.ProductID.value));
                    if (model != null)
                    {
                        if (model.Quantity.value > sale_product.Qunatity.value)
                        {
                            model.Quantity.value -= sale_product.Qunatity.value;
                            StockAccess.singleton.updateStock(model, Convert.ToInt32(model.ID.value));
                        }
                        else
                        {
                            model.Quantity.value = 0;
                            StockAccess.singleton.updateStock(model, Convert.ToInt32(model.ID.value));
                        }
                    }
                }
                ReciptModel recipt_model = new ReciptModel();
                string      recipt_id    = string.Format("rpt-{0}", ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds());
                recipt_model.ID.value     = recipt_id;
                recipt_model.SaleID.value = sale_id;
                this.ReciptID             = recipt_id;
                SaleAccess.singleton.addRecipt(recipt_model);
            }
        }
Exemple #2
0
        public ActionResult Recipt(int Id)
        {
            var patient       = PatientServices.GetByPatientId(Id);
            var gender        = GenderServices.GetById(patient.GenderId);
            var branch        = BranchServices.GetById(patient.BranchId);
            var branchContact = BranchServices.GetBranchContact(patient.BranchId);
            var refer         = ReferDoctorsServices.GetPatientReferById(patient.Id);
            var SubTestList   = PatientTestService.GetSubCategoryByPatientId(patient.Id);
            var payment       = PaymentServices.GetPaymentByPatientId(patient.Id);
            var testList      = new List <TestSubCategoryModel>();

            foreach (var item in SubTestList)
            {
                testList.Add(new TestSubCategoryModel
                {
                    TestSubcategoryName = item.TestSubcategoryName,
                    Unit = item.Unit,
                    Rate = item.Rate
                });
            }

            var branchModel = new BranchModel()
            {
                Name    = branch.BranchName,
                Address = branch.BranchAddress,
                Contact = branchContact.BranchContactNo
            };
            var model = new PatientModel
            {
                Id          = patient.Id,
                Name        = patient.PatientName,
                Date        = patient.DateTime,
                Age         = patient.Age,
                Email       = patient.Email,
                Discount    = payment.Discount,
                PaidAmount  = payment.PaidAmount,
                PhoneNumber = patient.PatientNumber,
                GenderDesc  = gender.GenderDescription
            };
            ReciptModel recipt = new ReciptModel();

            recipt.PatientDetails = model;
            recipt.Branch         = branchModel;
            recipt.PatientTests   = testList;
            recipt.LogedInUser    = Session["loginusername"].ToString();

            //var pdfDocModel = GeneratePatientRecipt(model, gender, SubTestList, branch, branchContact);

            return(Json(recipt, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
 public void addRecipt(ReciptModel model)
 {
     using (SqlConnection connection = new SqlConnection(Constants.CONNECTION_STRING)) {
         string command_text = "INSERT INTO dbo.Recipt (ID, Sale_ID) VALUES (@ID, @Sale_ID)";
         using (SqlCommand command = new SqlCommand(command_text)) {
             command.Connection = connection;
             command.Parameters.Add("@ID", System.Data.SqlDbType.VarChar, 20).Value = model.ID.value;
             command.Parameters.Add("@Sale_ID", System.Data.SqlDbType.Int).Value    = model.SaleID.value;
             try {
                 connection.Open();
                 command.ExecuteNonQuery();
                 CoreApp.logger.log("Successfully recipt added to database");
             }
             catch (Exception ex) { throw new Exception(ex.Message); }
             finally {
                 try { connection.Close(); CoreApp.logger.log("Successfully connection closed"); }
                 catch (Exception ex) { throw new Exception(ex.Message); }
             }
         }
     }
 }
Exemple #4
0
        public ActionResult AddPatient(PatientModel model)
        {
            #region temp code this must be removed
            //PatientPaymentServices.AddPayType(new PayType
            //{
            //    Description = "Card"
            //});
            //PatientPaymentServices.AddPayType(new PayType
            //{
            //    Description = "Cash"
            //});
            #endregion
            #region testing code should be delete
            //var model=new PatientModel(){
            //    BranchId=1,
            //    Name="firstTestPatient",
            //    Email="*****@*****.**",
            //    GenderId=1,
            //    DateofBirth=DateTime.Now,
            //    PhoneNumber="987987697",
            //    ReferredId=-1
            //};
            #endregion

            try
            {
                if (model.PatientTestIds.Count > 0)
                {
                    int UserId = Convert.ToInt32(Session["loginuser"].ToString());
                    var branch = UserServices.GetUserBranch(UserId);
                    model.BranchId = branch.Id;
                    model.Age      = (DateTime.Now.Year - model.DateofBirth.Year).ToString();

                    PatientServices.Add(model);
                    List <TestSubCategoryModel> selectedTests = new List <TestSubCategoryModel>();
                    double netAmount = 0;
                    foreach (var TestId in model.PatientTestIds)
                    {
                        PatientTestService.Add(new PatientTest
                        {
                            PatientId         = model.Id,
                            TestSubcategoryId = TestId
                        });
                        var test = TestSubCategoryServices.getById(TestId);
                        selectedTests.Add(new TestSubCategoryModel {
                            Rate = test.Rate,
                            TestSubcategoryName = test.TestSubcategoryName,
                            Unit = test.Unit
                        });

                        netAmount = netAmount + test.Rate;
                    }

                    if (model.Discount > 0)
                    {
                        netAmount = netAmount - model.Discount;
                    }

                    PatientPaymentServices.Add(new Payment
                    {
                        PatientId   = model.Id,
                        PatientName = model.Name,
                        PaidAmount  = model.PaidAmount,
                        Discount    = model.Discount,
                        NetAmount   = netAmount,
                        Balance     = netAmount - model.PaidAmount,
                        PayTypeId   = model.PayId
                    });

                    var gender = GenderServices.GetById(model.GenderId);

                    model.Genders.Add(new SelectListItem
                    {
                        Text = gender.GenderDescription
                    });

                    var referdoctor = ReferDoctorsServices.GetReferDoctorById(model.ReferredId);

                    model.ReferredDoctors.Add(new SelectListItem
                    {
                        Text = referdoctor.ReferredDoctorName
                    });
                    var branchContact = BranchServices.GetBranchContact(branch.Id);

                    SmsServices.SendSms(model.PhoneNumber, model.Id);
                    model.GenderDesc = gender.GenderDescription;
                    var ReciptModels = new ReciptModel()
                    {
                        Branch = new BranchModel
                        {
                            Address = branch.BranchAddress,
                            Contact = branchContact.BranchContactNo,
                            Name    = branch.BranchName
                        },
                        PatientDetails = model,
                        PatientTests   = selectedTests
                    };
                    ReciptModels.LogedInUser = Session["loginusername"].ToString();
                    // var pdfDocModel = GeneratePatientRecipt(model, gender, selectedTests, branch, branchContact);

                    return(Json(ReciptModels, JsonRequestBehavior.AllowGet));
                }
                return(Json("Please assign tests to patients", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }