public static Result InsertHoaDonHopDong(HoaDonHopDong hdt, List <ChiTietHoaDonHopDong> addedDetails) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); string desc = string.Empty; using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew)) { hdt.HoaDonHopDongGUID = Guid.NewGuid(); db.HoaDonHopDongs.InsertOnSubmit(hdt); db.SubmitChanges(); string htttStr = Utility.ParseHinhThucThanhToanToStr((PaymentType)hdt.HinhThucThanhToan); desc += string.Format("- Hóa đơn hợp đồng: GUID: '{0}', Mã hóa đơn: '{1}', Ngày xuất HĐ: '{2}', Người mua hàng: '{3}', Tên đơn vị: '{4}', Địa chỉ: '{5}', STK: '{6}', Hình thức thanh toán: '{7}', Ghi chú: '{8}', Đã thu tiền: '{9}'\n", hdt.HoaDonHopDongGUID.ToString(), hdt.SoHoaDon, hdt.NgayXuatHoaDon.Value.ToString("dd/MM/yyyy HH:mm:ss"), hdt.TenNguoiMuaHang, hdt.TenDonVi, hdt.DiaChi, hdt.SoTaiKhoan, htttStr, hdt.Notes, !hdt.ChuaThuTien); if (addedDetails != null && addedDetails.Count > 0) { desc += "- Chi tiết hóa đơn:\n"; foreach (ChiTietHoaDonHopDong detail in addedDetails) { detail.ChiTietHoaDonHopDongGUID = Guid.NewGuid(); detail.HoaDonHopDongGUID = hdt.HoaDonHopDongGUID; db.ChiTietHoaDonHopDongs.InsertOnSubmit(detail); desc += string.Format(" + GUID: '{0}', Dịch vụ: '{1}', ĐVT: '{2}', Số lượng: '{3}', Đơn giá: '{4}', Thành tiền: '{5}'\n", detail.ChiTietHoaDonHopDongGUID.ToString(), detail.TenMatHang, detail.DonViTinh, detail.SoLuong, detail.DonGia, detail.ThanhTien); } db.SubmitChanges(); } //Update Exported Invoice if (hdt.PhieuThuHopDongGUIDList != null && hdt.PhieuThuHopDongGUIDList.Trim() != string.Empty) { string[] pttkeys = hdt.PhieuThuHopDongGUIDList.Split(','); foreach (string pttKey in pttkeys) { PhieuThuHopDong ptt = db.PhieuThuHopDongs.SingleOrDefault <PhieuThuHopDong>(r => r.PhieuThuHopDongGUID.ToString() == pttKey); if (ptt != null) { ptt.IsExported = true; } } } int soHoaDon = Convert.ToInt32(hdt.SoHoaDon); QuanLySoHoaDon qlshd = db.QuanLySoHoaDons.SingleOrDefault <QuanLySoHoaDon>(q => q.SoHoaDon == soHoaDon && q.NgayBatDau.Value >= Global.NgayThayDoiSoHoaDonSauCung); if (qlshd != null) { qlshd.DaXuat = true; } else { qlshd = new QuanLySoHoaDon(); qlshd.QuanLySoHoaDonGUID = Guid.NewGuid(); qlshd.SoHoaDon = soHoaDon; qlshd.DaXuat = true; qlshd.XuatTruoc = false; qlshd.NgayBatDau = Global.NgayThayDoiSoHoaDonSauCung; db.QuanLySoHoaDons.InsertOnSubmit(qlshd); } //Tracking desc = desc.Substring(0, desc.Length - 1); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Add; tk.Action = "Thêm thông tin hóa đơn hợp đồng"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.Price; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); t.Complete(); } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }
public static Result InsertGhiNhanTraNo(GhiNhanTraNo ghiNhanTraNo, bool isDataTraDu, string phieuThuGUID, LoaiPT loaiPT) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); string desc = string.Empty; using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew)) { //Insert if (ghiNhanTraNo.GhiNhanTraNoGUID == null || ghiNhanTraNo.GhiNhanTraNoGUID == Guid.Empty) { ghiNhanTraNo.GhiNhanTraNoGUID = Guid.NewGuid(); db.GhiNhanTraNos.InsertOnSubmit(ghiNhanTraNo); db.SubmitChanges(); //Tracking desc += string.Format("- GUID: '{0}', Phiếu thu GUID: '{1}', Ngày trả: '{2}', Số tiền: '{3}', Ghi chú: '{4}'", ghiNhanTraNo.GhiNhanTraNoGUID.ToString(), ghiNhanTraNo.MaPhieuThuGUID.ToString(), ghiNhanTraNo.NgayTra.ToString("dd/MM/yyyy HH:mm:ss"), ghiNhanTraNo.SoTien, ghiNhanTraNo.GhiChu); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Add; tk.Action = "Thêm thông tin ghi nhận trả nợ"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.None; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); } else //Update { GhiNhanTraNo tn = db.GhiNhanTraNos.SingleOrDefault <GhiNhanTraNo>(s => s.GhiNhanTraNoGUID.ToString() == ghiNhanTraNo.GhiNhanTraNoGUID.ToString()); if (tn != null) { tn.MaPhieuThuGUID = ghiNhanTraNo.MaPhieuThuGUID; tn.NgayTra = ghiNhanTraNo.NgayTra; tn.SoTien = ghiNhanTraNo.SoTien; tn.GhiChu = ghiNhanTraNo.GhiChu; tn.LoaiPT = ghiNhanTraNo.LoaiPT; tn.CreatedDate = ghiNhanTraNo.CreatedDate; tn.CreatedBy = ghiNhanTraNo.CreatedBy; tn.UpdatedDate = ghiNhanTraNo.UpdatedDate; tn.UpdatedBy = ghiNhanTraNo.UpdatedBy; tn.DeletedDate = ghiNhanTraNo.DeletedDate; tn.DeletedBy = ghiNhanTraNo.DeletedBy; tn.Status = ghiNhanTraNo.Status; //Tracking desc += string.Format("- GUID: '{0}', Phiếu thu GUID: '{1}', Ngày trả: '{2}', Số tiền: '{3}', Ghi chú: '{4}'", tn.GhiNhanTraNoGUID.ToString(), tn.MaPhieuThuGUID.ToString(), tn.NgayTra.ToString("dd/MM/yyyy HH:mm:ss"), tn.SoTien, tn.GhiChu); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Edit; tk.Action = "Sửa thông tin ghi nhận trả nợ"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.None; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); } } switch (loaiPT) { case LoaiPT.DichVu: Receipt ptdv = db.Receipts.Where(p => p.ReceiptGUID.ToString() == phieuThuGUID).FirstOrDefault(); ptdv.ChuaThuTien = !isDataTraDu; break; case LoaiPT.Thuoc: PhieuThuThuoc ptt = db.PhieuThuThuocs.Where(p => p.PhieuThuThuocGUID.ToString() == phieuThuGUID).FirstOrDefault(); ptt.ChuaThuTien = !isDataTraDu; break; case LoaiPT.HopDong: PhieuThuHopDong pthd = db.PhieuThuHopDongs.Where(p => p.PhieuThuHopDongGUID.ToString() == phieuThuGUID).FirstOrDefault(); pthd.ChuaThuTien = !isDataTraDu; break; case LoaiPT.CapCuu: PhieuThuCapCuu ptcc = db.PhieuThuCapCuus.Where(p => p.PhieuThuCapCuuGUID.ToString() == phieuThuGUID).FirstOrDefault(); ptcc.ChuaThuTien = !isDataTraDu; break; } db.SubmitChanges(); t.Complete(); } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }
public static Result DeleteHoaDonHopDong(List <string> keys, List <string> noteList) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew)) { string desc = string.Empty; int index = 0; foreach (string key in keys) { HoaDonHopDong hdt = db.HoaDonHopDongs.SingleOrDefault <HoaDonHopDong>(i => i.HoaDonHopDongGUID.ToString() == key); if (hdt != null) { hdt.DeletedDate = DateTime.Now; hdt.DeletedBy = Guid.Parse(Global.UserGUID); hdt.Status = (byte)Status.Deactived; if (hdt.Notes == null || hdt.Notes.Trim() == string.Empty) { hdt.Notes = noteList[index]; } else { hdt.Notes += string.Format(" - {0}", noteList[index]); } //Update Exported Invoice if (hdt.PhieuThuHopDongGUIDList != null && hdt.PhieuThuHopDongGUIDList.Trim() != string.Empty) { string[] pttkeys = hdt.PhieuThuHopDongGUIDList.Split(','); foreach (string pttKey in pttkeys) { PhieuThuHopDong ptt = db.PhieuThuHopDongs.SingleOrDefault <PhieuThuHopDong>(r => r.PhieuThuHopDongGUID.ToString() == pttKey); if (ptt != null) { ptt.IsExported = false; } } } int soHoaDon = Convert.ToInt32(hdt.SoHoaDon); DateTime fromDate = Global.MinDateTime; DateTime toDate = Global.MaxDateTime; var ngayThayDoi = (from n in db.NgayBatDauLamMoiSoHoaDons where n.KiHieu.ToLower() == hdt.KiHieu && n.MauSo.ToLower() == hdt.MauSo.ToLower() select n).FirstOrDefault(); if (ngayThayDoi != null) { fromDate = ngayThayDoi.NgayBatDau; var nextThayDoi = (from n in db.NgayBatDauLamMoiSoHoaDons where n.NgayBatDau > ngayThayDoi.NgayBatDau orderby n.NgayBatDau ascending select n).FirstOrDefault(); if (nextThayDoi != null) { toDate = nextThayDoi.NgayBatDau; } QuanLySoHoaDon qlshd = db.QuanLySoHoaDons.SingleOrDefault <QuanLySoHoaDon>(q => q.SoHoaDon == soHoaDon && q.NgayBatDau.Value >= fromDate && q.NgayBatDau < toDate); if (qlshd != null) { qlshd.DaXuat = false; } else { qlshd = new QuanLySoHoaDon(); qlshd.QuanLySoHoaDonGUID = Guid.NewGuid(); qlshd.SoHoaDon = soHoaDon; qlshd.DaXuat = false; qlshd.XuatTruoc = false; qlshd.NgayBatDau = fromDate; db.QuanLySoHoaDons.InsertOnSubmit(qlshd); } } string htttStr = Utility.ParseHinhThucThanhToanToStr((PaymentType)hdt.HinhThucThanhToan); desc += string.Format("- GUID: '{0}', Mã hóa đơn: '{1}', Ngày xuất HĐ: '{2}', Người mua hàng: '{3}', Tên đơn vị: '{4}', Địa chỉ: '{5}', STK: '{6}', Hình thức thanh toán: '{7}', Ghi chú: '{8}', Đã thu tiền: '{9}'\n", hdt.HoaDonHopDongGUID.ToString(), hdt.SoHoaDon, hdt.NgayXuatHoaDon.Value.ToString("dd/MM/yyyy HH:mm:ss"), hdt.TenNguoiMuaHang, hdt.TenDonVi, hdt.DiaChi, hdt.SoTaiKhoan, htttStr, noteList[index], !hdt.ChuaThuTien); } index++; } //Tracking desc = desc.Substring(0, desc.Length - 1); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Delete; tk.Action = "Xóa thông tin hóa đơn hợp đồng"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.Price; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); t.Complete(); } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }
public static Result DeleteGhiNhanTraNo(List <string> keys, string phieuThuGUID, LoaiPT loaiPT) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew)) { bool isDelete = false; string desc = string.Empty; foreach (string key in keys) { GhiNhanTraNo tn = db.GhiNhanTraNos.SingleOrDefault <GhiNhanTraNo>(ss => ss.GhiNhanTraNoGUID.ToString() == key); if (tn != null) { tn.DeletedDate = DateTime.Now; tn.DeletedBy = Guid.Parse(Global.UserGUID); if (tn.Status == (byte)Status.Actived) { isDelete = true; } tn.Status = (byte)Status.Deactived; desc += string.Format("- GUID: '{0}', Phiếu thu GUID: '{1}', Ngày trả: '{2}', Số tiền: '{3}', Ghi chú: '{4}'\n", tn.GhiNhanTraNoGUID.ToString(), tn.MaPhieuThuGUID.ToString(), tn.NgayTra.ToString("dd/MM/yyyy HH:mm:ss"), tn.SoTien, tn.GhiChu); } } //Update trạng thái phiếu thu if (isDelete) { switch (loaiPT) { case LoaiPT.DichVu: Receipt ptdv = db.Receipts.Where(p => p.ReceiptGUID.ToString() == phieuThuGUID).FirstOrDefault(); ptdv.ChuaThuTien = true; break; case LoaiPT.Thuoc: PhieuThuThuoc ptt = db.PhieuThuThuocs.Where(p => p.PhieuThuThuocGUID.ToString() == phieuThuGUID).FirstOrDefault(); ptt.ChuaThuTien = true; break; case LoaiPT.HopDong: PhieuThuHopDong pthd = db.PhieuThuHopDongs.Where(p => p.PhieuThuHopDongGUID.ToString() == phieuThuGUID).FirstOrDefault(); pthd.ChuaThuTien = true; break; case LoaiPT.CapCuu: PhieuThuCapCuu ptcc = db.PhieuThuCapCuus.Where(p => p.PhieuThuCapCuuGUID.ToString() == phieuThuGUID).FirstOrDefault(); ptcc.ChuaThuTien = true; break; } } //Tracking desc = desc.Substring(0, desc.Length - 1); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Delete; tk.Action = "Xóa thông tin ghi nhận trả nợ"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.None; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); t.Complete(); } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }