Beispiel #1
0
        private decimal SumOfPaymentDetail_NGOAITRU(KcbThanhtoanChitiet[] objArrPaymentDetail)
        {
            decimal SumOfPaymentDetail = 0;
            var sum = (from loz in objArrPaymentDetail.AsEnumerable()
                       where loz.TuTuc == 0
                       select loz).Sum(c => c.DonGia * c.SoLuong);
            //.Sum(c=>c.SoLuong*c.DonGia))
            foreach (KcbThanhtoanChitiet paymentDetail in objArrPaymentDetail)
            {
                if (paymentDetail.TuTuc == 0)
                    SumOfPaymentDetail += (Utility.Int32Dbnull(paymentDetail.SoLuong) *
                                           Utility.DecimaltoDbnull(paymentDetail.DonGia));

            }
            return SumOfPaymentDetail;
        }
Beispiel #2
0
        /// <summary>
        /// Trả lại tiền
        /// </summary>
        /// <param name="objThanhtoan"></param>
        /// <param name="objLuotkham"></param>
        /// <param name="objArrPaymentDetail"></param>
        /// <returns></returns>
        public ActionResult HUYTHANHTOAN_NGOAITRU(KcbThanhtoan objThanhtoan, KcbLuotkham objLuotkham, KcbThanhtoanChitiet[] objArrPaymentDetail)
        {
            decimal v_DiscountRate = 0;
            ///tổng tiền hiện tại truyền vào của lần payment đang thực hiện
            decimal v_TotalOrginPrice = 0;
            ///tổng tiền đã thanh toán
            decimal v_TotalPaymentDetail = 0;
            try
            {
                using (var scope = new TransactionScope())
                {
                    using (var sh = new SharedDbConnectionScope())
                    {

                        v_TotalOrginPrice = SumOfPaymentDetail(objArrPaymentDetail);
                        KcbThanhtoanCollection paymentCollection =
                            new KcbThanhtoanController().FetchByQuery(
                                KcbThanhtoan.CreateQuery().AddWhere(KcbThanhtoan.Columns.MaLuotkham, Comparison.Equals,
                                                                objLuotkham.MaLuotkham).AND(
                                                                    KcbThanhtoan.Columns.IdBenhnhan, Comparison.Equals,
                                                                    objLuotkham.IdBenhnhan));

                        foreach (KcbThanhtoan payment in paymentCollection)
                        {
                            KcbThanhtoanChitietCollection paymentDetailCollection =
                                new KcbThanhtoanChitietController().FetchByQuery(
                                    KcbThanhtoanChitiet.CreateQuery().AddWhere(KcbThanhtoanChitiet.Columns.IdThanhtoan, Comparison.Equals, payment.IdThanhtoan));
                            foreach (KcbThanhtoanChitiet paymentDetail in paymentDetailCollection)
                            {
                                if (paymentDetail.TuTuc == 0)
                                    v_TotalPaymentDetail += Utility.DecimaltoDbnull(paymentDetail.DonGia);

                            }

                        }
                        ///lấy thông tin chiết khấu xem đã thực hiện chưa
                        LayThongtinPtramBHYT(v_TotalPaymentDetail - v_TotalOrginPrice, objLuotkham, ref v_DiscountRate);
                        objThanhtoan.TrangThai = 1;
                        objThanhtoan.IdNhanvienThanhtoan = globalVariables.gv_intIDNhanvien;
                        objThanhtoan.NgayThanhtoan = globalVariables.SysDate;
                        //objThanhtoan.IpMayTao = THU_VIEN_CHUNG.GetIP4Address();
                        //objThanhtoan.IpMacTao = THU_VIEN_CHUNG.GetMACAddress();
                        // objThanhtoan.MaThanhtoan = THU_VIEN_CHUNG.GenerateMaThanhtoan(globalVariables.SysDate, 0);
                        objThanhtoan.MaThanhtoan = THU_VIEN_CHUNG.TaoMathanhtoan(globalVariables.SysDate);
                        objThanhtoan.IsNew = true;
                        objThanhtoan.Save();
                        //StoredProcedure spPament = SPs.KcbThanhtoanThemmoi(objThanhtoan.IdThanhtoan, objThanhtoan.MaLuotkham, objThanhtoan.IdBenhnhan,
                        //                 objThanhtoan.NgayThanhtoan, objThanhtoan.StaffId, objThanhtoan.Status,
                        //                 objThanhtoan.CreatedBy, objThanhtoan.CreatedDate, objThanhtoan.NgaySua,
                        //                 objThanhtoan.NguoiSua, objThanhtoan.MaThanhtoan, objThanhtoan.KieuThanhToan,
                        //                 objThanhtoan.DaIn, objThanhtoan.NgayIn, objThanhtoan.NgayTHop, objThanhtoan.NguoiIn,
                        //                 objThanhtoan.NguoiTHop, Utility.Int32Dbnull(objThanhtoan.TrongGoi), objThanhtoan.IpMayTao, objThanhtoan.IpMacTao, globalVariables.MA_KHOA_THIEN);
                        //spPament.Execute();
                        //objThanhtoan.IdThanhtoan = Utility.Int32Dbnull(spPament.OutputValues[0], -1);
                        //  objThanhtoan.IdThanhtoan = Utility.Int32Dbnull(_queryPayment.GetMax(KcbThanhtoan.Columns.IdThanhtoan), -1);

                        foreach (KcbThanhtoanChitiet objPayDetail in objArrPaymentDetail)
                        {
                            new Update(KcbThanhtoanChitiet.Schema)
                                //.Set(KcbThanhtoanChitiet.Columns.ng).EqualTo(1)

                                .Set(KcbThanhtoanChitiet.Columns.TrangthaiHuy).EqualTo(1)
                                .Set(KcbThanhtoanChitiet.Columns.NgayHuy).EqualTo(globalVariables.SysDate)
                                .Set(KcbThanhtoanChitiet.Columns.NguoiHuy).EqualTo(globalVariables.UserName)
                                .Where(KcbThanhtoanChitiet.Columns.IdChitiet).IsEqualTo(objPayDetail.IdChitiet).
                                Execute();
                            ///thanh toán khám chữa bệnh))
                            if (objPayDetail.IdLoaithanhtoan == 1)
                            {

                                new Update(KcbDangkyKcb.Schema)
                                    .Set(KcbDangkyKcb.Columns.TrangthaiThanhtoan).EqualTo(1)
                                    .Set(KcbDangkyKcb.Columns.TrangthaiHuy).EqualTo(1)
                                    .Where(KcbDangkyKcb.Columns.IdKham).IsEqualTo(objPayDetail.IdPhieu).Execute();
                            }
                            ///thah toán phần dịch vụ cận lâm sàng
                            if (objPayDetail.IdLoaithanhtoan == 2)
                            {
                                int status =
                                    Utility.Int32Dbnull(
                                        new Select(KcbChidinhclsChitiet.Columns.TrangThai).From(KcbChidinhclsChitiet.Schema).
                                            Where(KcbChidinhclsChitiet.Columns.IdChitietchidinh).IsEqualTo(objPayDetail.IdChitietdichvu)
                                            .ExecuteScalar().ToString(), 0);
                                if (globalVariables.UserName != "ADMIN")
                                {
                                    if (status == 1)
                                    {
                                        return ActionResult.AssginIsConfirmed;
                                    }
                                }
                                new Update(KcbChidinhclsChitiet.Schema)
                                    .Set(KcbChidinhclsChitiet.Columns.TrangthaiThanhtoan).EqualTo(1)
                                    .Set(KcbChidinhclsChitiet.Columns.TrangthaiHuy).EqualTo(1)
                                    .Where(KcbChidinhclsChitiet.Columns.IdChitietchidinh).IsEqualTo(objPayDetail.IdChitietdichvu)
                                    .Execute();
                            }
                            ///thanh toán phần thuốc
                            if (objPayDetail.IdLoaithanhtoan == 3)
                            {
                                int Status =
                                    Utility.Int32Dbnull(
                                        new Select(KcbDonthuoc.Columns.TrangThai).From(KcbDonthuoc.Schema).Where(
                                            KcbDonthuoc.Columns.IdDonthuoc).IsEqualTo(objPayDetail.IdPhieu).ExecuteScalar(),
                                        -1);

                                if (globalVariables.UserName != "ADMIN")
                                {
                                    if (Status == 3)
                                    {
                                        return ActionResult.PresIsConfirmed;
                                    }
                                }
                                new Update(KcbDonthuoc.Schema)
                                    // .Set(KcbDonthuoc.Columns.TrangthaiThanhtoan).EqualTo(1)
                                    .Set(KcbDonthuoc.Columns.TrangThai).EqualTo(0)
                                    .Where(KcbDonthuoc.Columns.IdDonthuoc).IsEqualTo(objPayDetail.IdPhieu).Execute();
                                new Update(KcbDonthuocChitiet.Schema)
                                    .Set(KcbDonthuocChitiet.Columns.TrangthaiHuy).EqualTo(1)
                                    .Set(KcbDonthuocChitiet.Columns.TrangthaiThanhtoan).EqualTo(1)
                                    .Where(KcbDonthuocChitiet.Columns.IdDonthuoc).IsEqualTo(objPayDetail.IdPhieu)
                                    .And(KcbDonthuocChitiet.Columns.IdThuoc).IsEqualTo(objPayDetail.IdDichvu)
                                    .Execute();
                            }
                            new Update(KcbThanhtoanChitiet.Schema)
                               .Set(KcbThanhtoanChitiet.Columns.NgayHuy).EqualTo(globalVariables.SysDate)
                               .Set(KcbThanhtoanChitiet.Columns.NguoiHuy).EqualTo(globalVariables.UserName)
                               .Set(KcbThanhtoanChitiet.Columns.TrangthaiHuy).EqualTo(1)
                               .Where(KcbThanhtoanChitiet.Columns.IdChitiet).IsEqualTo(objPayDetail.IdChitiet).
                               Execute();
                            objPayDetail.IdPhieu = Utility.Int32Dbnull(objPayDetail.IdThanhtoan);
                            objPayDetail.IdChitietdichvu = Utility.Int32Dbnull(objPayDetail.IdChitietdichvu);
                            //objPayDetail.IpMayTao = THU_VIEN_CHUNG.GetIP4Address();
                            //objPayDetail.IpMacTao = THU_VIEN_CHUNG.GetMACAddress();
                            objPayDetail.IdThanhtoan = Utility.Int32Dbnull(objThanhtoan.IdThanhtoan, -1);
                            objPayDetail.IsNew = true;
                            objPayDetail.Save();

                        }
                        KcbPhieuthu objPhieuthu = new KcbPhieuthu();
                        objPhieuthu.IdThanhtoan = Utility.Int32Dbnull(objThanhtoan.IdThanhtoan);
                        objPhieuthu.NgayThuchien = globalVariables.SysDate;
                        //objPhieuthu.IpMayTao = THU_VIEN_CHUNG.GetIP4Address();
                        objPhieuthu.MaPhieuthu = THU_VIEN_CHUNG.GetMaPhieuThu(globalVariables.SysDate, Utility.Int32Dbnull(objPhieuthu.LoaiPhieuthu, 0));
                        objPhieuthu.LoaiPhieuthu = 1;
                        KcbDanhsachBenhnhan objPatientInfo = KcbDanhsachBenhnhan.FetchByID(objThanhtoan.IdBenhnhan);
                        if (objPatientInfo != null)
                        {
                            objPhieuthu.NguoiNop = Utility.sDbnull(objPatientInfo.TenBenhnhan);

                        }
                        var query = (from loz in objArrPaymentDetail.AsEnumerable()
                                     select loz.TenChitietdichvu).ToArray();

                        decimal SoTien = Utility.DecimaltoDbnull(objArrPaymentDetail.Sum(c => c.BnhanChitra * c.SoLuong)) +
                                        Utility.DecimaltoDbnull(objArrPaymentDetail.Sum(c => c.PhuThu * c.SoLuong));

                        objPhieuthu.LydoNop = string.Join(";", query);
                        objPhieuthu.LoaiPhieuthu = 1;
                        objPhieuthu.SoTien = SoTien;
                        objPhieuthu.MaPhieuthu = THU_VIEN_CHUNG.GetMaPhieuThu(globalVariables.SysDate, Utility.Int32Dbnull(objPhieuthu.LoaiPhieuthu));
                        objPhieuthu.IsNew = true;
                        objPhieuthu.Save();
                        //CAN XEM LAIJ PHAN THU TUC
                        //StoredProcedure sp = SPs.KcbThanhtoanThemmoiPhieuthu(objPhieuthu.MaPthu, objThanhtoan.IdThanhtoan,
                        //                                             objPhieuthu.NgayThien,
                        //                                             objPhieuthu.NguoiNop, objPhieuthu.LdoNop,
                        //                                             objPhieuthu.SoTien,
                        //                                             objPhieuthu.SluongCtuGoc, objPhieuthu.TkhoanNo,
                        //                                             objPhieuthu.TkhoanCo,
                        //                                             objPhieuthu.LoaiPhieu, globalVariables.UserName,
                        //                                             globalVariables.SysDate,
                        //                                             globalVariables.gv_intIDNhanvien,
                        //                                             globalVariables.DepartmentID,
                        //                                             globalVariables.UserName, globalVariables.SysDate);

                        //sp.Execute();

                    }
                    scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception exception)
            {
                log.Error("Loi trong qua trinh tra tien lai:{0}", exception.ToString());
                return ActionResult.Error;
            }
        }