PumpTransaction.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using Edge.Core.IndustryStandardInterface.Pump;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel.DataAnnotations;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Edge.Core.Database.Models
  9. {
  10. public enum FuelSaleTransactionState
  11. {
  12. Undefined = 0,
  13. Payable = 1,
  14. Locked = 2,
  15. Paid = 3,
  16. Cleared = 4,
  17. }
  18. public class FuelSaleTransaction
  19. {
  20. // FDC defined:
  21. //SALE_TRX_UNDEFINED = 0,
  22. //SALE_TRX_PAYABLE = 1,
  23. //SALE_TRX_LOCKED = 2,
  24. //SALE_TRX_PAID = 3,
  25. //SALE_TRX_CLEARED = 4,
  26. /// <summary>
  27. /// Gets or sets the release token for this trx, release token is an database unique
  28. /// id for a trx, unlike `TransactionSeqNumberFromPhysicalPump`, it's a
  29. /// device dependent and will be re-cyclely used by device, so there're may have multiple
  30. /// trx in database with same `TransactionSeqNumberFromPhysicalPump`, but release token is
  31. /// guranteed to be unique for a trx.
  32. /// </summary>
  33. [Key]
  34. public int ReleaseToken { get; set; }
  35. public int PumpId { get; set; }
  36. public int LogicalNozzleId { get; set; }
  37. public string TransactionSeqNumberFromPhysicalPump { get; set; }
  38. public FuelSaleTransactionState State { get; set; }
  39. public string ProductBarcode { get; set; }
  40. /// <summary>
  41. /// without decimal points
  42. /// </summary>
  43. public int UnitPrice { get; set; }
  44. /// <summary>
  45. /// without decimal points
  46. /// </summary>
  47. public int Amount { get; set; }
  48. /// <summary>
  49. /// without decimal points
  50. /// </summary>
  51. public int Volumn { get; set; }
  52. /// <summary>
  53. /// Gets or sets the Fdc Client WorkStationId which reserved this fuel point.
  54. /// the Pos id is the workstation id parameter used in Fdc client connect to Fdc server, each client
  55. /// should have an unique this id to distinguish from each other.
  56. /// until 2017 Dec, the pos id is config in COS (web), model: SiteDevice , column: PosDeviceFdcClientId, once the android POS
  57. /// downloaded this value via AccessToken web service, it will be deducted with 100, and then plus 110, like you config the id in
  58. /// COS is 109, then in fdc client connection, the final value will be 119.
  59. /// </summary>
  60. public string LockedByFdcClientId { get; set; }
  61. public DateTime? LockedTime { get; set; }
  62. public string AuthorizedByFdcClientId { get; set; }
  63. public DateTime? AuthorizedTime { get; set; }
  64. public string PaidByFdcClientId { get; set; }
  65. public DateTime? PaidTime { get; set; }
  66. public DateTime? SaleStartTime { get; set; }
  67. public DateTime? SaleEndTime { get; set; }
  68. /// <summary>
  69. /// the money amount totalizer value after this new trx done, without decimal points
  70. /// </summary>
  71. public int AmountTotalizer { get; set; }
  72. /// <summary>
  73. /// the volume amount totalizer value after this new trx done, without decimal points
  74. /// </summary>
  75. public int VolumeTotalizer { get; set; }
  76. public override string ToString()
  77. {
  78. return $"ReleaseToken: {ReleaseToken }, PumpId: {PumpId }, logicalNozzleId: {LogicalNozzleId }, " +
  79. $"seqNo: { (TransactionSeqNumberFromPhysicalPump ?? "")}, state: {State }, amount: {Amount }, " +
  80. $"LockedByFdcClientId: { (LockedByFdcClientId ?? "")}, LockedTime: {(LockedTime?.ToShortTimeString() ?? "") }, " +
  81. $"AuthorizedByFdcClientId: { (AuthorizedByFdcClientId ?? "")}, PaidByFdcClientId: { (PaidByFdcClientId ?? "")}, " +
  82. $"SaleEndTime: {SaleEndTime?.ToString("yyyy-MM-dd HH:mm:ss fff") ?? ""}";
  83. }
  84. }
  85. public class FuelSaleTransactionResponse
  86. {
  87. // FDC defined:
  88. //SALE_TRX_UNDEFINED = 0,
  89. //SALE_TRX_PAYABLE = 1,
  90. //SALE_TRX_LOCKED = 2,
  91. //SALE_TRX_PAID = 3,
  92. //SALE_TRX_CLEARED = 4,
  93. private FuelSaleTransactionResponse(FuelSaleTransaction fuelSaleTransaction,
  94. IFdcPumpController fdcPumpController)
  95. {
  96. ReleaseToken = fuelSaleTransaction.ReleaseToken;
  97. PumpId = fuelSaleTransaction.PumpId;
  98. LogicalNozzleId = fuelSaleTransaction.LogicalNozzleId;
  99. TransactionSeqNumberFromPhysicalPump = fuelSaleTransaction.TransactionSeqNumberFromPhysicalPump;
  100. State = fuelSaleTransaction.State;
  101. ProductBarcode = fuelSaleTransaction.ProductBarcode;
  102. UnitPrice = (decimal)(fuelSaleTransaction.UnitPrice / Math.Pow(10, fdcPumpController.PriceDecimalDigits));
  103. Amount = (decimal)(fuelSaleTransaction.Amount / Math.Pow(10, fdcPumpController.AmountDecimalDigits));
  104. Volumn = (decimal)(fuelSaleTransaction.Volumn / Math.Pow(10, fdcPumpController.VolumeDecimalDigits));
  105. LockedByFdcClientId = fuelSaleTransaction.LockedByFdcClientId;
  106. LockedTime = fuelSaleTransaction.LockedTime;
  107. AuthorizedByFdcClientId = fuelSaleTransaction.AuthorizedByFdcClientId;
  108. AuthorizedTime = fuelSaleTransaction.AuthorizedTime;
  109. PaidTime = fuelSaleTransaction.PaidTime;
  110. SaleStartTime = fuelSaleTransaction.SaleStartTime;
  111. SaleEndTime = fuelSaleTransaction.SaleEndTime;
  112. AmountTotalizer = (decimal)(fuelSaleTransaction.AmountTotalizer / Math.Pow(10, fdcPumpController.AmountDecimalDigits));
  113. VolumeTotalizer = (decimal)(fuelSaleTransaction.VolumeTotalizer / Math.Pow(10, fdcPumpController.VolumeTotalizerDecimalDigits));
  114. }
  115. public static FuelSaleTransactionResponse CreateInstance(FuelSaleTransaction fuelSaleTransaction,
  116. IFdcPumpController fdcPumpController)
  117. {
  118. return new FuelSaleTransactionResponse(fuelSaleTransaction, fdcPumpController);
  119. }
  120. /// <summary>
  121. /// Gets or sets the release token for this trx, release token is an database unique
  122. /// id for a trx, unlike `TransactionSeqNumberFromPhysicalPump`, it's a
  123. /// device dependent and will be re-cyclely used by device, so there're may have multiple
  124. /// trx in database with same `TransactionSeqNumberFromPhysicalPump`, but release token is
  125. /// guranteed to be unique for a trx.
  126. /// </summary>
  127. [Key]
  128. public int ReleaseToken { get; set; }
  129. public int PumpId { get; set; }
  130. public int LogicalNozzleId { get; set; }
  131. public string TransactionSeqNumberFromPhysicalPump { get; set; }
  132. public FuelSaleTransactionState State { get; set; }
  133. public string ProductBarcode { get; set; }
  134. /// <summary>
  135. /// without decimal points
  136. /// </summary>
  137. public decimal UnitPrice { get; set; }
  138. /// <summary>
  139. /// without decimal points
  140. /// </summary>
  141. public decimal Amount { get; set; }
  142. /// <summary>
  143. /// without decimal points
  144. /// </summary>
  145. public decimal Volumn { get; set; }
  146. /// <summary>
  147. /// Gets or sets the Fdc Client WorkStationId which reserved this fuel point.
  148. /// the Pos id is the workstation id parameter used in Fdc client connect to Fdc server, each client
  149. /// should have an unique this id to distinguish from each other.
  150. /// until 2017 Dec, the pos id is config in COS (web), model: SiteDevice , column: PosDeviceFdcClientId, once the android POS
  151. /// downloaded this value via AccessToken web service, it will be deducted with 100, and then plus 110, like you config the id in
  152. /// COS is 109, then in fdc client connection, the final value will be 119.
  153. /// </summary>
  154. public string LockedByFdcClientId { get; set; }
  155. public DateTime? LockedTime { get; set; }
  156. public string AuthorizedByFdcClientId { get; set; }
  157. public DateTime? AuthorizedTime { get; set; }
  158. public string PaidByFdcClientId { get; set; }
  159. public DateTime? PaidTime { get; set; }
  160. public DateTime? SaleStartTime { get; set; }
  161. public DateTime? SaleEndTime { get; set; }
  162. /// <summary>
  163. /// the money amount totalizer value after this new trx done, without decimal points
  164. /// </summary>
  165. public decimal AmountTotalizer { get; set; }
  166. /// <summary>
  167. /// the volume amount totalizer value after this new trx done, without decimal points
  168. /// </summary>
  169. public decimal VolumeTotalizer { get; set; }
  170. public override string ToString()
  171. {
  172. return "ReleaseToken: " + ReleaseToken + ", PumpId: " + PumpId + ", logicalNozzleId: " + LogicalNozzleId + ", seqNo: " + (TransactionSeqNumberFromPhysicalPump ?? "")
  173. + ", state: " + State + ", amount: " + Amount + ", LockedByFdcClientId: " + (LockedByFdcClientId ?? "")
  174. + "LockedTime: " + (LockedTime?.ToShortTimeString() ?? "") + ", AuthorizedByFdcClientId: " + (AuthorizedByFdcClientId ?? "")
  175. + ", PaidByFdcClientId: " + (PaidByFdcClientId ?? "");
  176. }
  177. }
  178. }