public NvCongNoVm.Dto GetAmmountSupplierLend(string code) { var _unitCode = GetCurrentUnitCode(); NvCongNoVm.Dto result = new NvCongNoVm.Dto(); try { var supplier = UnitOfWork.Repository <MdSupplier>().DbSet.FirstOrDefault(x => x.MaNCC == code && x.UnitCode == _unitCode); if (supplier != null) { result.MaKhachHang = supplier.MaNCC; result.ThanhTienCanTra = 0; var phieuXBs = UnitOfWork.Repository <NvVatTuChungTu>().DbSet.Where(x => x.MaKhachHang == supplier.MaNCC && x.LoaiPhieu == TypeVoucher.NMUA.ToString() && x.UnitCode == _unitCode && x.TrangThai == (int)OrderState.IsComplete).ToList(); if (phieuXBs.Count > 0) { phieuXBs.ForEach(x => result.ThanhTienCanTra += (x.ThanhTienSauVat != null ? x.ThanhTienSauVat : 0)); } var phieuCNs = UnitOfWork.Repository <NvCongNo>().DbSet.Where(x => x.MaNhaCungCap == supplier.MaNCC && x.LoaiChungTu == LoaiCongNo.CNNCC.ToString() && x.UnitCode == _unitCode).ToList(); if (phieuCNs.Count > 0) { phieuCNs.ForEach(x => result.ThanhTienCanTra -= (x.ThanhTien != null ? x.ThanhTien : 0)); } } return(result); } catch (Exception e) { throw e; } }
public NvCongNo UpdatePhieu(NvCongNoVm.Dto instance) { var _ParentUnitCode = GetParentUnitCode(); var exsitItem = FindById(instance.Id); if (exsitItem.TrangThai == (int)ApprovalState.IsComplete) { return(null); } var masterData = Mapper.Map <NvCongNoVm.Dto, NvCongNo>(instance); var result = Update(masterData); return(result); }
public NvCongNo InsertPhieu(NvCongNoVm.Dto instance) { var _ParentUnitCode = GetParentUnitCode(); var item = Mapper.Map <NvCongNoVm.Dto, NvCongNo>(instance); item.ThoiGianDuyetPhieu = int.Parse(DateTime.Now.ToString("HHmmssfff")); item.Id = Guid.NewGuid().ToString(); var result = AddUnit(item); string _unitCode = GetCurrentUnitCode(); result.MaChungTu = BuildCode_PTNX(instance.LoaiChungTu, _unitCode, true); item.GenerateMaChungTuPk(); result = Insert(result); return(result); }
public NvCongNoVm.Dto GetAmmountCustomerBorrowed(string code, DateTime ngayDuyetPhieu) { var _unitCode = GetCurrentUnitCode(); NvCongNoVm.Dto result = new NvCongNoVm.Dto(); try { var customer = UnitOfWork.Repository <MdCustomer>().DbSet.FirstOrDefault(x => x.MaKH == code && x.UnitCode == _unitCode); if (customer != null) { result.MaKhachHang = customer.MaKH; result.ThanhTienCanTra = 0; result.TienThanhToan = 0; var phieuXBs = UnitOfWork.Repository <NvVatTuChungTu>().DbSet.Where(x => x.MaKhachHang == customer.MaKH && DbFunctions.TruncateTime(x.NgayDuyetPhieu) <= DbFunctions.TruncateTime(ngayDuyetPhieu) && x.TrangThai == (int)OrderState.IsComplete && x.LoaiPhieu == TypeVoucher.XBAN.ToString() && x.UnitCode == _unitCode).ToList(); if (phieuXBs.Count > 0) { phieuXBs.ForEach(x => result.ThanhTienCanTra += (x.ThanhTienSauVat != null ? x.ThanhTienSauVat : 0)); } var phieuTLs = UnitOfWork.Repository <NvVatTuChungTu>().DbSet.Where(x => DbFunctions.TruncateTime(x.NgayDuyetPhieu) > DbFunctions.TruncateTime(DATESTART_NHBANTL) && DbFunctions.TruncateTime(x.NgayDuyetPhieu) <= DbFunctions.TruncateTime(ngayDuyetPhieu) && x.MaKhachHang == customer.MaKH && x.LoaiPhieu == TypeVoucher.NHBANTL.ToString() && x.UnitCode == _unitCode && x.TrangThai == (int)OrderState.IsComplete).ToList(); if (phieuTLs.Count > 0) { phieuTLs.ForEach(x => result.ThanhTienCanTra += (x.ThanhTienSauVat != null ? x.ThanhTienSauVat : 0)); } var phieuCNs = UnitOfWork.Repository <NvCongNo>().DbSet.Where(x => x.MaKhachHang == customer.MaKH && DbFunctions.TruncateTime(x.NgayCT) <= DbFunctions.TruncateTime(ngayDuyetPhieu) && x.LoaiChungTu == LoaiCongNo.CNKH.ToString() && x.UnitCode == _unitCode).ToList(); if (phieuCNs.Count > 0) { phieuCNs.ForEach(x => result.ThanhTienCanTra -= (x.ThanhTien != null ? x.ThanhTien : 0)); } } return(result); } catch (Exception e) { throw e; } }