public int?GetPreviousInvoiceId(int invoiceId, InvoiceTypeEnum type) { var currentInvc = Get(invoiceId); if (currentInvc == null) { return(null); } return(GetInvoices(type).Where(w => w.Id < invoiceId)?.OrderBy(o => o.Id).LastOrDefault()?.Id); }
public IEnumerable <Invoice> GetInvoices(InvoiceTypeEnum type, string searchTerm = "") { IQueryable <Invoice> items = _db.Invoice; switch (type) { case InvoiceTypeEnum.Open: items = items.Where( w => w.IsDonated == false && !w.IsQuote && !w.Voided && w.IsPaid == false); break; case InvoiceTypeEnum.Paid: items = items.Where(w => w.IsPaid == true && !w.Voided); break; case InvoiceTypeEnum.Quote: items = items.Where(w => w.IsQuote && !w.Voided); break; case InvoiceTypeEnum.Voided: items = items.Where(w => w.Voided); break; case InvoiceTypeEnum.Donated: items = items.Where(w => w.IsDonated == true && !w.Voided); break; case InvoiceTypeEnum.PastDue: items = items.Where( w => w.IsDonated == false && !w.IsQuote && !w.Voided && w.IsPaid == false && DateTime.Now >= w.OrderDate.AddMonths(1)); break; case InvoiceTypeEnum.All: default: break; } items = SearchItems(items, searchTerm); return(items .Include(i => i.Customer) .Include(i => i.Employee) .Include(i => i.LineItem) .ThenInclude(t => t.Item) .OrderBy(o => o.IsPaidToEmployees).ThenByDescending(t => t.OrderDate)); }
public IActionResult SetInvoiceStatus(int invoiceId = 0, InvoiceTypeEnum status = InvoiceTypeEnum.Open) { try { _invoiceService.SetInvoiceStatus(invoiceId, status); } catch (Exception) { return(StatusCode((int)HttpStatusCode.UnprocessableEntity)); } return(StatusCode((int)HttpStatusCode.OK)); }
public IActionResult EditInvoice(int invoiceId = 0, InvoiceTypeEnum invoiceType = InvoiceTypeEnum.Open) { var invoice = _invoiceService.Get(invoiceId); if (invoice == null) { return(RedirectToAction("Index")); } var vm = new EditInvoiceViewModel { Invoice = invoice, Customers = _customerService.GetAllCustomers().ToList(), Employees = _employeeService.GetEmployees().ToList() }; if (invoiceId == 0) { vm.InvoiceType = invoiceType; } else { if (invoice.Voided) { vm.InvoiceType = InvoiceTypeEnum.Voided; } else if (invoice.IsQuote) { vm.InvoiceType = InvoiceTypeEnum.Quote; } else if (invoice.IsDonated == true) { vm.InvoiceType = InvoiceTypeEnum.Donated; } else if (invoice.IsPaid == true) { vm.InvoiceType = InvoiceTypeEnum.Paid; } else { vm.InvoiceType = InvoiceTypeEnum.Open; } } vm.PreviousInvoiceId = _invoiceService.GetPreviousInvoiceId(invoiceId, vm.InvoiceType); vm.NextInvoiceId = _invoiceService.GetNextInvoiceId(invoiceId, vm.InvoiceType); return(View(vm)); }
public void SetInvoiceStatus(int invoiceId, InvoiceTypeEnum status, string stripeChargeId = null) { var invoice = Get(invoiceId); if (invoice?.Id == 0) { throw new InvalidDataException(); } invoice.StripeChargeId = stripeChargeId; invoice.IsPaid = false; invoice.Voided = false; invoice.IsQuote = false; invoice.IsDonated = false; invoice.PaidDate = null; switch (status) { case InvoiceTypeEnum.Paid: invoice.IsPaid = true; invoice.PaidDate = DateTime.Now; break; case InvoiceTypeEnum.Quote: invoice.IsQuote = true; break; case InvoiceTypeEnum.Voided: invoice.Voided = true; break; case InvoiceTypeEnum.Donated: invoice.IsDonated = true; break; default: break; } _db.SaveChanges(); }
/// <summary> /// POST api/CashVouchers/Pair/{invoiceType}/{invoiceId} /// Add new cash voucher. /// </summary> public async Task <CashVoucher> CreateAsync(CashVoucherCreate model, InvoiceTypeEnum invoiceType, int invoiceId) { return(await PostAsync <CashVoucher, CashVoucherCreate>(ResourceUrl + "/Pair" + "/" + (int)invoiceType + "/" + invoiceId, model)); }
/// <summary> /// GET api/IssuedInvoices/Default/{movementType}/{invoiceType}/{invoiceId} /// Method returns empty cash voucher with default values. Returned resource is suitable for creation of a new cash voucher. /// </summary> public async Task <CashVoucherCreate> DefaultAsync(MovementTypeEnum movementType, InvoiceTypeEnum invoiceType, int invoiceId) { return(await GetAsync <CashVoucherCreate>(ResourceUrl + "/Default/" + (int)movementType + "/" + (int)invoiceType + "/" + invoiceId)); }
public void Load(InvoiceItemDto invoiceItem, DivisionMethodEnum divisionMethod, decimal currencyToMainCurrencyRate, InvoiceTypeEnum invoiceType) { Entity = invoiceItem; EnableDivisionPrice = divisionMethod == DivisionMethodEnum.Direct; EnableQuantity =invoiceType!= InvoiceTypeEnum.Attach; Entity.CurrencyToMainCurrencyRate = currencyToMainCurrencyRate; }
public void Load(CompanyDto selectedCompany, InvoiceDto invoice) { CurrentCompany = selectedCompany; OrderListVM.Load(); var uid = Guid.NewGuid(); UpperDate = invoice.InvoiceDate; UpdatePartnerCompany(invoice.SupplierId, invoice.TransporterId); ToDateFilter = invoice.InvoiceDate; FromDateFilter = invoice.InvoiceDate.AddMonths(-3); invoiceType = invoice.InvoiceType; if (invoice.OrderRefrences == null) invoice.OrderRefrences = new ObservableCollection<OrderDto>(); else { foreach (var order in invoice.OrderRefrences) SelectedOrders.Add(order); LoadOrdersByFilters2(); } changed = false; }
public void EditItem(InvoiceItemDto invoiceItem, DivisionMethodEnum divistionMethod, decimal currencyToMainCurrencyRate, InvoiceTypeEnum invoiceType) { var view = ViewManager.ShowInDialog<IInvoiceItemView>(); (view.ViewModel as InvoiceItemVM).Load(invoiceItem, divistionMethod, currencyToMainCurrencyRate,invoiceType); }
public IActionResult Index(InvoiceTypeEnum type = InvoiceTypeEnum.Open, int page = 1, int take = 20, string searchTerm = "") { ViewBag.ActiveAction = ControllerContext.RouteData.Values["controller"]; var skip = take * (page - 1); var vm = new InvoiceViewModel { InvoiceType = type, SearchTerm = searchTerm }; var pagination = new PaginationViewModel { InvoiceType = type, Take = take, CurrentPage = skip / take + 1 }; var items = _invoiceService.GetInvoices(type, searchTerm).ToList(); string viewTitle; switch (type) { case InvoiceTypeEnum.Open: viewTitle = "Open Invoices"; break; case InvoiceTypeEnum.Paid: viewTitle = "Paid Invoices"; break; case InvoiceTypeEnum.Donated: viewTitle = "Donated Items"; break; case InvoiceTypeEnum.Voided: viewTitle = "Voided Items"; break; case InvoiceTypeEnum.Quote: viewTitle = "Open Quotes"; break; case InvoiceTypeEnum.PastDue: viewTitle = "Past Due Invoices"; break; case InvoiceTypeEnum.All: viewTitle = "All Invoices"; break; default: throw new NotImplementedException(); } pagination.NumberOfPages = items.Count <= take ? 1 : (int)Math.Ceiling(items.Count / (decimal)take); vm.Invoices = items.Skip(skip).Take(take).ToList(); vm.ViewTitle = viewTitle; vm.PaginationParameters = pagination; vm.InvoiceEmailCounts = _invoiceService.GetEmailCountsForInvoices(vm.Invoices.Select(s => s.Id).ToList()); return(View(vm)); }
/// <summary> /// GET api/IssuedInvoices/Default/{movementType}/{invoiceType}/{invoiceId} /// Method returns empty cash voucher with default values. Returned resource is suitable for creation of a new cash voucher. /// </summary> public CashVoucherCreate Default(MovementTypeEnum movementType, InvoiceTypeEnum invoiceType, int invoiceId) { return(Get <CashVoucherCreate>(ResourceUrl + "/Default/" + (int)movementType + "/" + (int)invoiceType + "/" + invoiceId)); }
/// <summary> /// POST api/CashVouchers/Pair/{cashVoucherId}/{invoiceType}/{invoiceId} /// Add new cash voucher. /// </summary> public CashVoucher Create(CashVoucherCreate model, int cashVoucherId, InvoiceTypeEnum invoiceType, int invoiceId) { return(Post <CashVoucher, CashVoucherCreate>(ResourceUrl + "/Pair" + "/" + cashVoucherId + "/" + (int)invoiceType + "/" + invoiceId, model)); }
public SelectModel GetBusinessInvoiceContractStockListSelect(int pageIndex, int pageSize, string orderStr, int subId, InvoiceTypeEnum invoiceType, int businessInvoiceId = 0, bool isDetail = false, bool isInvoice = false) { SelectModel select = new SelectModel(); select.PageIndex = pageIndex; select.PageSize = pageSize; if (string.IsNullOrEmpty(orderStr)) select.OrderStr = "sl.StockLogId desc"; else select.OrderStr = orderStr; int readyStatus = (int)StatusEnum.已生效; int entryStatus = (int)StatusEnum.已录入; int stockStatusType = (int)StatusTypeEnum.库存状态; int invType = (int)invoiceType; int proInvoiceType = (int)InvoiceTypeEnum.ProvisionalInvoice; int dirInvoiceType = (int)InvoiceTypeEnum.DirectFinalInvoice; StringBuilder sb = new StringBuilder(); sb.Append("sl.StockLogId,sto.StockId,sn.StockNameId"); sb.Append(",sto.StockDate,sn.RefNo,sto.UintId,mu.MUName"); sb.Append(",sto.CorpId,cor.CorpName"); sb.Append(",sto.AssetId,ass.AssetName,sto.BrandId,bra.BrandName,sto.StockStatus"); sb.Append(",ss.StatusName as StockStatusName"); sb.Append(",sl.NetAmount - isnull(abi.SumNet,0) as LastAmount"); sb.Append(",sl.GrossAmount - isnull(abi.SumGross,0) as LastGross"); sb.Append(",sl.NetAmount - isnull(abi.SumNet,0) as NetAmount"); sb.Append(",sl.GrossAmount - isnull(abi.SumGross,0) as IntegerAmount"); sb.Append(",isnull(cbi.SumBala,0) as Bala"); sb.Append(",sto.CardNo,dp.DPName "); select.ColumnName = sb.ToString(); sb.Clear(); sb.Append(" dbo.St_StockLog sl "); sb.AppendFormat(" inner join dbo.St_Stock sto on sl.StockId = sto.StockId "); sb.Append(" inner join dbo.St_StockName sn on sto.StockNameId = sn.StockNameId "); sb.Append(" left join NFMT_Basic.dbo.MeasureUnit mu on mu.MUId = sto.UintId "); sb.Append(" left join NFMT_User.dbo.Corporation cor on cor.CorpId = sto.CorpId "); sb.Append(" left join NFMT_Basic.dbo.Asset ass on ass.AssetId = sto.AssetId "); sb.Append(" left join NFMT_Basic.dbo.Brand bra on bra.BrandId = sto.BrandId "); sb.Append(" left join NFMT_Basic.dbo.DeliverPlace dp on dp.DPId = sto.DeliverPlaceId "); sb.AppendFormat(" left join NFMT_Basic.dbo.BDStatusDetail ss on ss.DetailId = sto.StockStatus and ss.StatusId ={0} ", stockStatusType); sb.Append(" left join (select SUM(isnull(bid.NetAmount,0)) as SumNet,SUM(isnull(bid.Bala,0)) as SumBala ,bid.StockLogId "); sb.Append(" from dbo.Inv_BusinessInvoiceDetail bid "); sb.AppendFormat(" inner join dbo.Inv_BusinessInvoice bi on bid.BusinessInvoiceId = bi.BusinessInvoiceId and bi.SubContractId={0} ", subId); sb.AppendFormat(" inner join dbo.Invoice inv on inv.InvoiceId = bi.InvoiceId and inv.InvoiceStatus>={0} ", entryStatus); sb.AppendFormat(" where bid.BusinessInvoiceId = {0} and bid.DetailStatus>={1} and inv.InvoiceType in ({2},{3}) ", businessInvoiceId, readyStatus, proInvoiceType, dirInvoiceType); sb.Append(" group by bid.StockLogId) as cbi on cbi.StockLogId = sl.StockLogId "); sb.Append(" left join (select SUM(isnull(bid.NetAmount,0)) as SumNet,SUM(isnull(bid.IntegerAmount,0)) as SumGross,bid.StockLogId "); sb.Append(" from dbo.Inv_BusinessInvoiceDetail bid "); sb.AppendFormat(" inner join dbo.Inv_BusinessInvoice bi on bid.BusinessInvoiceId = bi.BusinessInvoiceId and bi.SubContractId={0} ", subId); sb.AppendFormat(" inner join dbo.Invoice inv on inv.InvoiceId = bi.InvoiceId and inv.InvoiceStatus>={0} ", entryStatus); sb.AppendFormat(" where bid.BusinessInvoiceId != {0} and bid.DetailStatus>={1} and inv.InvoiceType in ({2},{3}) ", businessInvoiceId, readyStatus, proInvoiceType, dirInvoiceType); sb.Append(" group by bid.StockLogId) as abi on abi.StockLogId = sl.StockLogId "); select.TableName = sb.ToString(); sb.Clear(); sb.AppendFormat(" sl.LogStatus >= {0} and sl.SubContractId = {1} ", readyStatus, subId); sb.Append(" and sl.NetAmount - isnull(abi.SumNet,0)>0 "); if (isDetail) sb.Append(" and isnull(cbi.SumBala,0)>0 "); if (isInvoice) sb.Append(" and cbi.StockLogId is not null "); else sb.Append(" and cbi.StockLogId is null "); select.WhereStr = sb.ToString(); return select; }
public ResultModel CreateBusinessInvoice(UserModel user, Operate.Model.Invoice invoice, BusinessInvoice invoiceBusiness, List<BusinessInvoiceDetail> details, InvoiceTypeEnum invoiceType) { ResultModel result = new ResultModel(); try { BusinessInvoiceDAL businessInvoiceDAL = new BusinessInvoiceDAL(); InvoiceDAL invoiceDAL = new InvoiceDAL(); BusinessInvoiceDetailDAL detailDAL = new BusinessInvoiceDetailDAL(); ContractSubDAL subDAL = new ContractSubDAL(); StockReceiptDetailDAL stockReceiptDetailDAL = new StockReceiptDetailDAL(); SubDetailDAL subDetailDAL = new SubDetailDAL(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证子合约 result = subDAL.Get(user, invoiceBusiness.SubContractId); if (result.ResultStatus != 0) return result; ContractSub sub = result.ReturnValue as ContractSub; if (sub == null || sub.SubId <= 0) { result.ResultStatus = -1; result.Message = "子合约不存在"; return result; } if (sub.SubStatus != StatusEnum.已生效) { result.ResultStatus = -1; result.Message = "子合约非已生效状态,不能新增临票"; return result; } //获取子合约明细 result = subDetailDAL.GetDetailBySubId(user, sub.SubId); if (result.ResultStatus != 0) return result; SubDetail subDetail = result.ReturnValue as SubDetail; if (subDetail == null || subDetail.SubDetailId <= 0) { result.ResultStatus = -1; result.Message = "子合约明细获取失败"; return result; } //获取子合约下所有 result = this.businessinvoiceDAL.LoadBySubId(user, invoiceBusiness.SubContractId, invoiceType); if (result.ResultStatus != 0) return result; List<BusinessInvoice> bis = result.ReturnValue as List<BusinessInvoice>; decimal sumNetAmount = bis.Sum(temp => temp.NetAmount); decimal maxNetAmount = sub.SignAmount * (1 + subDetail.MoreOrLess); //if (maxNetAmount < sumNetAmount + invoiceBusiness.NetAmount) //{ // result.ResultStatus = -1; // result.Message = "开票重量超额"; // return result; //} //新增发票主表 int invoiceId = 0; invoice.InvoiceType = (int)invoiceType; invoice.InvoiceStatus = StatusEnum.已录入; Corporation outCorp = UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == invoice.OutCorpId); if (outCorp == null || outCorp.CorpId <= 0) { result.ResultStatus = -1; result.Message = "开票公司信息错误"; return result; } invoice.OutCorpName = outCorp.CorpName; Corporation inCorp = UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == invoice.InCorpId); if (inCorp == null || inCorp.CorpId <= 0) { result.ResultStatus = -1; result.Message = "收票公司信息错误"; return result; } invoice.InCorpName = inCorp.CorpName; result = invoiceDAL.Insert(user, invoice); if (result.ResultStatus != 0) return result; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out invoiceId)) { result.ResultStatus = -1; result.Message = "发票添加失败"; return result; } //新增业务发票表 int businessInvoiceId = 0; invoiceBusiness.InvoiceId = invoiceId; result = businessInvoiceDAL.Insert(user, invoiceBusiness); if (result.ResultStatus != 0) return result; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out businessInvoiceId)) { result.ResultStatus = -1; result.Message = "新增发票失败"; return result; } //新增业务发票明细 StockLogDAL stockLogDAL = new StockLogDAL(); StockDAL stockDAL = new StockDAL(); foreach (BusinessInvoiceDetail detail in details) { if (detail.NetAmount != 0 && detail.StockId > 0) { //验证库存 result = stockDAL.Get(user, detail.StockId); if (result.ResultStatus != 0) return result; Stock stock = result.ReturnValue as Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "发票库存获取失败"; return result; } //验证库存流水 result = stockLogDAL.Get(user, detail.StockLogId); if (result.ResultStatus != 0) return result; StockLog stockLog = result.ReturnValue as StockLog; if (stockLog == null || stockLog.StockLogId <= 0) { result.ResultStatus = -1; result.Message = "新增发票流水获取失败"; return result; } //基本验证 if (stockLog.StockId != stock.StockId) { result.ResultStatus = -1; result.Message = "库存与库存流水不匹配"; return result; } //验证流水合约与发票合约是否相同 if (stockLog.SubContractId != invoiceBusiness.SubContractId) { result.ResultStatus = -1; result.Message = "合约与库存流水不匹配"; return result; } detail.DetailStatus = StatusEnum.已生效; detail.InvoiceId = invoiceId; detail.BusinessInvoiceId = businessInvoiceId; detail.StockId = stockLog.StockId; detail.StockLogId = stockLog.StockLogId; if (invoice.InvoiceType == (int)InvoiceTypeEnum.SuppleFinalInvoice) { //获取当前流水回执信息 result = stockReceiptDetailDAL.LoadByStockLogId(user, stockLog.StockLogId); List<StockReceiptDetail> stockReceiptDetails = result.ReturnValue as List<StockReceiptDetail>; if (stockReceiptDetails == null) { result.ResultStatus = -1; result.Message = "当前流水未回执,不能补零"; return result; } decimal sumQtyMiss = stockReceiptDetails.Sum(temp => temp.QtyMiss); detail.IntegerAmount = sumQtyMiss; detail.NetAmount = sumQtyMiss; } //else //{ // detail.IntegerAmount = stockLog.GrossAmount; // detail.NetAmount = stockLog.NetAmount; //} result = detailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } } invoice.InvoiceId = invoiceId; if (result.ResultStatus == 0) result.ReturnValue = invoice; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public SelectModel GetSelectModel(int pageIndex, int pageSize, string orderStr, DateTime invoiceDateBegin, DateTime invoiceDateEnd, int status, int inCorpId, int outCorpId, InvoiceTypeEnum invoiceType) { SelectModel select = new SelectModel(); select.PageIndex = pageIndex; select.PageSize = pageSize; if (string.IsNullOrEmpty(orderStr)) select.OrderStr = "bi.BusinessInvoiceId desc"; else select.OrderStr = orderStr; int commonStatusType = (int)StatusTypeEnum.通用状态; int InvoiceDirection = (int)StyleEnum.InvoiceDirection; StringBuilder sb = new StringBuilder(); sb.Append("bi.BusinessInvoiceId,inv.InvoiceId,inv.InvoiceDate,inv.InvoiceNo,inv.InvoiceName,inv.InvoiceBala,inv.CurrencyId,cur.CurrencyName,inv.OutBlocId,outBloc.BlocName as OutBlocName,inv.OutCorpId,OutCorpName,inv.InBlocId,inBloc.BlocName as InBlocName,inv.InCorpId,InCorpName,inv.InvoiceStatus,sd.StatusName,bi.VATRatio,bi.VATBala,inv.InvoiceDirection,invDir.DetailName as DirectionName"); select.ColumnName = sb.ToString(); sb.Clear(); sb.Append(" dbo.Inv_BusinessInvoice bi "); sb.Append(" inner join dbo.Invoice inv on bi.InvoiceId = inv.InvoiceId "); sb.Append(" left join NFMT_Basic.dbo.Currency cur on cur.CurrencyId = inv.CurrencyId "); sb.Append(" left join NFMT_User.dbo.Bloc outBloc on outBloc.BlocId = inv.OutBlocId "); sb.Append(" left join NFMT_User.dbo.Bloc inBloc on inBloc.BlocId = inv.InBlocId "); sb.AppendFormat(" left join NFMT_Basic.dbo.BDStatusDetail sd on sd.DetailId = inv.InvoiceStatus and sd.StatusId ={0} ", commonStatusType); sb.AppendFormat(" left join NFMT_Basic.dbo.BDStyleDetail invDir on inv.InvoiceDirection = invDir.StyleDetailId and invDir.BDStyleId ={0} ", InvoiceDirection); select.TableName = sb.ToString(); sb.Clear(); sb.AppendFormat(" inv.InvoiceType = {0} ", (int)invoiceType); if (status > 0) sb.AppendFormat(" and inv.InvoiceStatus = {0} ", status); if (inCorpId > 0) sb.AppendFormat(" and inv.InCorpId = {0} ", inCorpId); if (outCorpId > 0) sb.AppendFormat(" and inv.OutCorpId = {0} ", outCorpId); if (invoiceDateBegin > DefaultValue.DefaultTime && invoiceDateEnd > invoiceDateBegin) sb.AppendFormat(" and inv.InvoiceDate between '{0}' and '{1}' ", invoiceDateBegin.ToString(), invoiceDateEnd.AddDays (1).ToString()); select.WhereStr = sb.ToString(); return select; }