public static List <ChangeRecord> FromDTO(this Payment payment, IEnumerable <NoteDTO> nlist, string userName) { var changes = new List <ChangeRecord>(); if ((nlist != null && nlist.Count() > 0)) { Debug.Assert(nlist.Count() >= payment.PaymentNotes.Count()); //var startAt = payment.PaymentNotes.Select(x => x.Note).Select(x => x.CreatedOn).Max(); //foreach (var n in nlist.Where(x => x.CreatedOn > startAt).OrderBy(x => x.CreatedOn)) foreach (var n in nlist.Where(x => x.Id == 0)) { var newNote = new Note { CreatedOn = n.CreatedOn.StripTimeAndZone(), UserName = userName }; var pn = new PaymentNote { Payment = payment, Note = newNote }; payment.PaymentNotes.Add(pn); foreach (var nl in n.NoteLines.OrderBy(x => x.Index)) { newNote.NoteLines.Add(new NoteLine { Note = newNote, Index = nl.Index, Line = nl.Line }); } changes.Add(new ChangeRecord { Time = DateTimeOffset.Now, By = userName, Description = $"new payment note added" }); } } return(changes); }
public void Save(PaymentNote documentEntity) { tblDocument docToSave = SaveDocument(documentEntity); PaymentNote payement = documentEntity as PaymentNote; docToSave.OrderOrderTypeId = (int)payement.PaymentNoteType; foreach (PaymentNoteLineItem LossItem in payement.LineItems) { tblLineItems ll = null; if (docToSave.tblLineItems.Any(n => n.id == LossItem.Id)) ll = docToSave.tblLineItems.First(p => p.id == LossItem.Id); else { ll = new tblLineItems(); ll.id = LossItem.Id; ll.DocumentID = documentEntity.Id; docToSave.tblLineItems.Add(ll); } ll.LineItemSequenceNo = LossItem.LineItemSequenceNo; ll.Value = LossItem.Amount; ll.LineItemSequenceNo = LossItem.LineItemSequenceNo; ll.OrderLineItemType = (int)LossItem.PaymentMode; _log.DebugFormat("DocumentRepository:ll.Reason"); } _ctx.SaveChanges(); }
public void SubmitChanges(PaymentNote document, BasicConfig config) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute(); var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault(); if (createCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); _auditLogWFManager.AuditLogEntry("PaymentNote", string.Format("Created PaymentNote: {0}; From: {1}; To: {2}", document.Id, document.DocumentIssuerCostCentre.Name, document.DocumentRecipientCostCentre.Name)); var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>(); foreach (var _item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item)); } var co = commandsToExecute.OfType<ConfirmCommand>().FirstOrDefault(); if (co != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co)); _commandEnvelopeRouter.RouteCommandEnvelope(envelope); _auditLogWFManager.AuditLogEntry("PaymentNote", string.Format("Confirmed PaymentNote: {0}; From: {1}; To: {2}", document.Id, document.DocumentIssuerCostCentre.Name, document.DocumentRecipientCostCentre.Name)); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj == this) { return(true); } return(obj is V1Tender other && ((Id == null && other.Id == null) || (Id?.Equals(other.Id) == true)) && ((Type == null && other.Type == null) || (Type?.Equals(other.Type) == true)) && ((Name == null && other.Name == null) || (Name?.Equals(other.Name) == true)) && ((EmployeeId == null && other.EmployeeId == null) || (EmployeeId?.Equals(other.EmployeeId) == true)) && ((ReceiptUrl == null && other.ReceiptUrl == null) || (ReceiptUrl?.Equals(other.ReceiptUrl) == true)) && ((CardBrand == null && other.CardBrand == null) || (CardBrand?.Equals(other.CardBrand) == true)) && ((PanSuffix == null && other.PanSuffix == null) || (PanSuffix?.Equals(other.PanSuffix) == true)) && ((EntryMethod == null && other.EntryMethod == null) || (EntryMethod?.Equals(other.EntryMethod) == true)) && ((PaymentNote == null && other.PaymentNote == null) || (PaymentNote?.Equals(other.PaymentNote) == true)) && ((TotalMoney == null && other.TotalMoney == null) || (TotalMoney?.Equals(other.TotalMoney) == true)) && ((TenderedMoney == null && other.TenderedMoney == null) || (TenderedMoney?.Equals(other.TenderedMoney) == true)) && ((TenderedAt == null && other.TenderedAt == null) || (TenderedAt?.Equals(other.TenderedAt) == true)) && ((SettledAt == null && other.SettledAt == null) || (SettledAt?.Equals(other.SettledAt) == true)) && ((ChangeBackMoney == null && other.ChangeBackMoney == null) || (ChangeBackMoney?.Equals(other.ChangeBackMoney) == true)) && ((RefundedMoney == null && other.RefundedMoney == null) || (RefundedMoney?.Equals(other.RefundedMoney) == true)) && ((IsExchange == null && other.IsExchange == null) || (IsExchange?.Equals(other.IsExchange) == true))); }
private PaymentNote Map(tblDocument tblDoc) { var pn = new PaymentNote(tblDoc.Id); _Map(tblDoc, pn); pn.PaymentNoteType = (PaymentNoteType)tblDoc.OrderOrderTypeId; pn._SetLineItems(tblDoc.tblLineItems.Select(n => MapPayementLineItem(n)).ToList()); return pn; }
private PaymentNote Map(tblDocument tblDoc) { var doc = new PaymentNote(tblDoc.Id); _Map(tblDoc, doc); doc.PaymentNoteType = (PaymentNoteType)tblDoc.OrderOrderTypeId; doc._SetLineItems(tblDoc.tblLineItems.Select(n => MapPayementLineItem(n)).ToList()); return doc; }
private void PaymentNoteCreate(PaymentNote note) { var status = DefaultStorage.PaymentNoteCreate(note) > 0; if (!status) { Logger.LogError(1, "生成PaymentNote失败 支付单({0})", note.PayId); } }
///<summary> /// 支付Note创建 ///</summary> ///<param name="o">支付Note</param> ///<returns></returns> public int PaymentNoteCreate(PaymentNote o) { return(Try(nameof(PaymentNoteCreate), () => { var cmd = SqlBuilder.Insert("PaymentNote") .Column("PayId", o.PayId) .Column("PayNo", o.PayNo) .Column("UserId", o.UserId) .Column("Subject", o.Subject) .Column("Message", o.Message) .Column("RawData", o.RawData) .Column("Extra", o.Extra) .Column("CreatedBy", o.CreatedBy) .Column("CreatedOn", o.CreatedOn) .ToCommand(true); return WalletConn.ExecuteScalar <int>(cmd); })); }
public Document CreateDocument(Guid id, DocumentType documentType, CostCentre documentIssuerCC, CostCentre documentRecipientCC, User documentIssuerUser, string DocumentReference, double? longitude=null, double? latitude=null) { Document doc = null; switch (documentType) { case DocumentType.Order: doc = new Order(id); doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, /*null, */documentIssuerUser, DocumentReference, longitude, latitude); break; case DocumentType.DispatchNote:// doc = new DispatchNote(id); doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, /*null, */documentIssuerUser, DocumentReference, longitude, latitude); break; case DocumentType.Receipt: doc = new Receipt(id); doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, documentIssuerUser, DocumentReference, longitude, latitude); break; case DocumentType.DisbursementNote: doc = new DisbursementNote(id); doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, documentIssuerUser, DocumentReference, longitude, latitude); break; case DocumentType.CreditNote: doc = new CreditNote(id); doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, documentIssuerUser, DocumentReference, longitude, latitude); break; case DocumentType.ReturnsNote: doc = new ReturnsNote(id); doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, documentIssuerUser, DocumentReference, longitude, latitude); break; case DocumentType.PaymentNote: doc = new PaymentNote(id); doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, documentIssuerUser, DocumentReference, longitude, latitude); break; } return doc; }
public void SubmitToWF(PaymentNote paymentNote) { _confirmPaymentNoteWfManager.SubmitChanges(paymentNote,null); }
/// <summary> /// 处理订单 支持多次支付/合并支付 /// </summary> /// <param name="payment"></param> private void Async(Payment payment) { var now = DateTime.Now; if (payment.Status && payment.Type == 0) { var fail = 0m; //更新失败 var remain = payment.Amount; //单独或合并支付总金额 var oids = payment.RelatedId.Split(','); //可能为多个订单号 foreach (var oid in oids) { if (remain <= 0) { break; } var order = DefaultStorage.OrderMiniGet(oid, payment.UserId); //获取订单 if (order != null) { //订单为在线支付 状态为待付款 if (order.PaymentType.IsOnlinePay() && order.Status == OrderStatus.WaitBuyerPay) { var status = false; //更新订单结果 var amount = order.Unpaid; //待支付金额 if (remain - amount >= 0) { //付清(付清后如果是在线支付订单则会更新订单状态为已付款待发货并更新订单有效期) status = DefaultStorage.OrderPaid(oid, amount, true); //更新订单已付金额及状态 if (status) { remain -= amount; } else { fail += amount; } } else { //剩余金额不足 需多次支付 status = DefaultStorage.OrderPaid(oid, remain, false); if (status) { remain = 0; } else { fail += remain; } } if (!status) { Logger.LogWarning(2, "更新订单({orderId})已付金额及状态失败", oid); var note = new OrderNote(); note.Type = 1; note.UserId = payment.UserId; note.OrderId = oid; note.Subject = "更新订单已付金额/状态失败"; note.Message = string.Format("支付单({0})更新订单({1})已付金额/状态失败", payment.Id, oid); note.Extra = (remain - amount >= 0 ? amount : remain).ToString("F2"); note.CreatedBy = "sys"; note.CreatedOn = now; if (DefaultStorage.OrderNoteCreate(note) == 0) { Logger.LogError(2, "生成OrderNote失败 支付单({paymentId}) 订单({orderId}", payment.Id, oid); } } } } else { Logger.LogWarning(1, "支付单({paymentId})未匹配到订单({orderId})", payment.Id, oid); var note = new PaymentNote(); note.PayId = payment.Id; note.PayNo = payment.No; note.UserId = payment.UserId; note.Subject = "支付单未匹配到订单"; note.Message = string.Format("支付单({0})未匹配到订单({1})", payment.Id, oid); note.RawData = string.Empty; note.Extra = oid; note.CreatedBy = "sys"; note.CreatedOn = now; if (DefaultStorage.PaymentNoteCreate(note) == 0) { Logger.LogError(1, "生成PaymentNote失败 支付单({paymentId}) 订单({orderId})", payment.Id, oid); } } } if (remain - fail > 0) { //用户在支付平台支付成功 但未能及时收到通知或成功处理 造成用户多次支付 需把用户多支付的金额 退到用户钱包 } } }
/// <summary> /// 支付平台通知验证成功后触发 /// 更新付款单及订单状态等 /// </summary> /// <param name="notification">支付平台通知</param> /// <returns></returns> private bool Notified(Notification notification) { try { var now = DateTime.Now; var payment = DefaultStorage.PaymentGet(notification.PayId); if (payment == null) { Task.Factory.StartNew(() => { Logger.LogWarning(1, "支付单({0})未找到", notification.PayId); var note = new PaymentNote(); note.PayId = notification.PayId; note.PayNo = notification.PayNo; note.UserId = 0; note.Subject = "支付单未找到"; note.Message = string.Empty; note.RawData = notification.Input; note.Extra = string.Empty; note.CreatedBy = "sys"; note.CreatedOn = now; PaymentNoteCreate(note); }); return(false); } if (payment.Status) { return(true);//付款单已支付成功 直接返回true (支付平台可能会多次通知) } var status = DefaultStorage.PaymentStatusUpdate(notification.PayId, notification.PayNo, true);//更新支付单状态 if (status) { //异步处理支付成功后的相关逻辑 Task.Factory.StartNew(() => Async(payment)); } else { Task.Factory.StartNew(() => { Logger.LogWarning(1, "更新支付单({0})状态失败", notification.PayId); var note = new PaymentNote(); note.PayId = notification.PayId; note.PayNo = notification.PayNo; note.UserId = payment.UserId; note.Subject = "更新支付单状态失败"; note.Message = string.Empty; note.RawData = notification.Input; note.Extra = string.Empty; note.CreatedBy = "sys"; note.CreatedOn = now; PaymentNoteCreate(note); }); } return(status); } catch (Exception e) { Logger.LogError(1, e, "处理支付平台通知发生异常"); return(false); } }
public static List <ChangeRecord> FromDTO(this Member member, IEnumerable <PaymentDTO> list, string userName) { var changes = new List <ChangeRecord>(); if (list != null && list.Count() > 0) { var existingPayments = member.Payments.Where(x => list.Select(l => l.Id).Contains(x.Id)); var deletedPayments = member.Payments.Where(x => !list.Select(l => l.Id).Contains(x.Id)); var newPayments = list.Where(x => !member.Payments.Select(p => p.Id).Contains(x.Id)); foreach (var item in deletedPayments) { member.Payments.Remove(item); changes.Add(new ChangeRecord { Time = DateTimeOffset.Now, By = userName, Description = $"payment received on {item.ReceivedDate.Format()}, amount {item.AmountReceived.Format()} deleted" }); } foreach (var item in newPayments) { var np = new Payment { Member = member, //DueDate = item.DueDate, //AmountDue = item.AmountDue, SubscriptionYear = item.SubscriptionYear, ReceivedDate = item.ReceivedDate, AmountReceived = item.AmountReceived, Type = item.Type, IsPaid = item.IsPaid, }; foreach (var n in item.Notes) { var pn = new PaymentNote { Note = new Note { CreatedOn = n.CreatedOn.StripTimeAndZone() } }; n.NoteLines.ToList().ForEach(x => pn.Note.NoteLines.Add(new NoteLine { Index = x.Index, Line = x.Line })); np.PaymentNotes.Add(pn); } member.Payments.Add(np); changes.Add(new ChangeRecord { Time = DateTimeOffset.Now, By = userName, RecordForNewMember = true, Description = $"new payment added: Amount Received £{item.AmountReceived.Format()} for {item.SubscriptionYear}, received on {item.ReceivedDate.Format()}" }); } foreach (var item in existingPayments) { var dto = list.Single(x => x.Id == item.Id); changes.AddRange(item.FromDTO(dto, userName)); } } return(changes); }
void GeneratePaymentNote() { Distributor dist = _costCentreService.GetAll().OfType<Distributor>().FirstOrDefault(); DistributorSalesman salesman = _costCentreService.GetAll().OfType<DistributorSalesman>().FirstOrDefault(); Config con = _configService.Load(); User user = _userService.GetByCostCentre(salesman.Id).First(); PaymentNote doc = new PaymentNote(Guid.NewGuid()) { DocumentDateIssued = DateTime.Now, DocumentIssuerCostCentre = salesman, DocumentIssuerCostCentreApplicationId = con.CostCentreApplicationId, DocumentIssuerUser = user, DocumentRecipientCostCentre = dist, DocumentReference = Guid.NewGuid().ToString(), DocumentType = DocumentType.PaymentNote, EndDate = DateTime.Now, StartDate = DateTime.Now, Status = DocumentStatus.New, PaymentNoteType = PaymentNoteType.Availabe, }; doc.LineItems.Add(new PaymentNoteLineItem(Guid.NewGuid()) { Amount = 150, Description = "Payment note Test", IsNew = true, LineItemSequenceNo = 2, PaymentMode=PaymentMode.Cash, }); doc.LineItems.Add(new PaymentNoteLineItem(Guid.NewGuid()) { Amount = 100, Description = "Payment note Test", IsNew = true, LineItemSequenceNo = 1, PaymentMode = PaymentMode.MMoney, }); _confirmPaymentNoteWFManager.SubmitChanges(doc, _configService.Load()); MessageBox.Show("Close Payment note Done"); }
public override int GetHashCode() { int hashCode = 1002014939; if (Id != null) { hashCode += Id.GetHashCode(); } if (Type != null) { hashCode += Type.GetHashCode(); } if (Name != null) { hashCode += Name.GetHashCode(); } if (EmployeeId != null) { hashCode += EmployeeId.GetHashCode(); } if (ReceiptUrl != null) { hashCode += ReceiptUrl.GetHashCode(); } if (CardBrand != null) { hashCode += CardBrand.GetHashCode(); } if (PanSuffix != null) { hashCode += PanSuffix.GetHashCode(); } if (EntryMethod != null) { hashCode += EntryMethod.GetHashCode(); } if (PaymentNote != null) { hashCode += PaymentNote.GetHashCode(); } if (TotalMoney != null) { hashCode += TotalMoney.GetHashCode(); } if (TenderedMoney != null) { hashCode += TenderedMoney.GetHashCode(); } if (TenderedAt != null) { hashCode += TenderedAt.GetHashCode(); } if (SettledAt != null) { hashCode += SettledAt.GetHashCode(); } if (ChangeBackMoney != null) { hashCode += ChangeBackMoney.GetHashCode(); } if (RefundedMoney != null) { hashCode += RefundedMoney.GetHashCode(); } if (IsExchange != null) { hashCode += IsExchange.GetHashCode(); } return(hashCode); }
public void Save(PaymentNote documentEntity) { tblDocument docToSave = SaveDocument(documentEntity); _ctx.SaveChanges(); }
public PaymentNote CreatePaymentReturnDocument(ReturnsNote returnnote) { using (var container = NestedContainer) { IConfigService _configService = Using<IConfigService>(container); PaymentNote note = new PaymentNote(Guid.NewGuid()); note.DocumentDateIssued = DateTime.Now; note.DocumentIssuerCostCentre = returnnote.DocumentIssuerCostCentre; note.DocumentIssuerCostCentreApplicationId = _configService.Load().CostCentreApplicationId; note.DocumentIssuerUser = returnnote.DocumentIssuerUser; note.DocumentRecipientCostCentre = returnnote.DocumentRecipientCostCentre; note.DocumentReference = ""; note.DocumentType = DocumentType.PaymentNote; note.PaymentNoteType = PaymentNoteType.Returns; foreach (var item in returnnote._lineItems) { if (item.ReturnType == ReturnsType.Inventory && item.Product == null) continue; PaymentNoteLineItem ianLineitem = new PaymentNoteLineItem(Guid.NewGuid()) { Amount = item.Value, Description = item.Reason, LineItemSequenceNo = 0, PaymentMode = (PaymentMode) (int) item.ReturnType, }; note.AddLineItem(ianLineitem); } return note; } }