/// <inheritdoc /> public string PresentAsset(Asset asset) { if (asset == null) { return("null"); } var sb = new StringBuilder(); sb.Append("new Asset {"); sb.AppendLine($" StringID = {ProcessString(asset.StringID)},"); sb.AppendLine($" User = {ProcessString(asset.User)}, "); sb.AppendLine($" Name = {ProcessString(asset.Name)},"); sb.AppendLine(asset.Date.HasValue ? $" Date = D(\"{asset.Date:yyyy-MM-dd}\")," : " Date = null,"); sb.AppendLine($" Currency = {ProcessString(asset.Currency)},"); sb.AppendLine($" Value = {asset.Value}, Salvage = {asset.Salvage}, Life = {asset.Life},"); sb.AppendLine($" Title = {asset.Title}, Method = DepreciationMethod.{asset.Method},"); sb.AppendLine( $" DepreciationTitle = {asset.DepreciationTitle}, DepreciationExpenseTitle = {asset.DepreciationExpenseTitle}, DepreciationExpenseSubTitle = {asset.DepreciationExpenseSubTitle},"); sb.AppendLine( $" DevaluationTitle = {asset.DevaluationTitle}, DevaluationExpenseTitle = {asset.DevaluationExpenseTitle}, DevaluationExpenseSubTitle = {asset.DevaluationExpenseSubTitle},"); if (asset.Remark != null) { sb.AppendLine($" Remark = {ProcessString(asset.Remark)},"); } sb.AppendLine(" Schedule = new List<AssetItem> {"); if (asset.Schedule != null) { void Present(AssetItem item, string str) { sb.Append($" new {item.GetType().Name.CPadRight(16)} {{ "); sb.Append(item.Date.HasValue ? $"Date = D(\"{item.Date:yyyy-MM-dd}\"), " : "Date = null, "); sb.Append($"VoucherID = {(ProcessString(item.VoucherID) + ",").CPadRight(28)}"); sb.Append(str.CPadRight(30)); sb.Append($"Value = {item.Value.ToString(CultureInfo.InvariantCulture).CPadRight(16)} "); if (item.Remark != null) { sb.Append("".CPadLeft(30)); sb.Append($", Remark = {ProcessString(item.Remark)} "); } sb.AppendLine("},"); } foreach (var item in asset.Schedule) { Present(item, item switch { AcquisitionItem acq => $"OrigValue = {acq.OrigValue},", DepreciateItem dep => $"Amount = {dep.Amount},", DevalueItem dev => $"FairValue = {dev.FairValue}, Amount = {dev.Amount},", DispositionItem _ => "", _ => throw new InvalidOperationException(), });
public static AcquisitionItemModel From(AcquisitionItem value) { return(new AcquisitionItemModel { Id = value.Id, ProductName = value.Product.Name, Quantity = value.Quantity.Formatted(), Price = value.Price.Formatted(), Value = (value.Quantity * value.Price).Formatted(), }); }
public override AssetItem Deserialize(IBsonReader bsonReader) { string read = null; bsonReader.ReadStartDocument(); var vid = bsonReader.ReadObjectId("voucher", ref read); var dt = bsonReader.ReadDateTime("date", ref read); var rmk = bsonReader.ReadString("remark", ref read); AssetItem item; double? val; if ((val = bsonReader.ReadDouble("acq", ref read)).HasValue) { item = new AcquisitionItem { VoucherID = vid, Date = dt, Remark = rmk, OrigValue = val.Value } } ; else if ((val = bsonReader.ReadDouble("dep", ref read)).HasValue) { item = new DepreciateItem { VoucherID = vid, Date = dt, Remark = rmk, Amount = val.Value } } ; else if ((val = bsonReader.ReadDouble("devto", ref read)).HasValue) { item = new DevalueItem { VoucherID = vid, Date = dt, Remark = rmk, FairValue = val.Value } } ; else if (bsonReader.ReadNull("dispo", ref read)) { item = new DispositionItem { VoucherID = vid, Date = dt, Remark = rmk } } ; else { item = null; } bsonReader.ReadEndDocument(); return(item); }
private static void UpdateStock(Repository repository, IEnumerable <Stock> stocks, AcquisitionItem acquisitionItem) { var newQuantity = acquisitionItem.Quantity; var product = acquisitionItem.Product; var productId = product.Id; var stock = stocks.FirstOrDefault(it => it.ProductId == productId); if (stock != null) { stock.Quantity += newQuantity; } else { stock = new Stock { ProductId = productId, Name = product.Name, SalePrice = product.SalePrice, Quantity = newQuantity, PurchaseValue = Math.Round(newQuantity * acquisitionItem.Price, 2), SaleValue = Math.Round(newQuantity * product.SalePrice.GetValueOrDefault(), 2), }; repository.Stocks.Add(stock); } repository.SaveChanges(); }