using CAPI.Custom; using CAPI.Custom.Data; using CAPI.Custom.Services; using CAPI.Custom.Entities; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace CEP.ConsoleTests { public class TestQuoteProcess : IConsoleTest { public TestResult RunTest() { var methodName = MethodBase.GetCurrentMethod().DeclaringType.Name; Console.WriteLine($"Executing: {methodName} ..."); StringBuilder output = new StringBuilder($"# {methodName}") .AppendLine(); var db = new QuotesContext(); var quotesService = new QuoteService(); var processor = new QuoteProcessor(db); var quote = db.Quotes.OrderByDescending(p => p.itemID) .FirstOrDefault(); var result = processor.ProcessInMemory(quote.itemID); output.AppendLine($"**{quote.itemID}: {quote.Number}**") .AppendLine($"## Enquiry Items: *{result.EnquiryItems.Count}*") .AppendLine("| Sequence | PartNumber | Quantity |") .AppendLine("|:--------:|:---------- |:--------:|"); result.EnquiryItems.ForEach(item => output.AppendLine($"| {item.Sequence} | {item.PartNumber} | {item.Quantity} |")); output.AppendLine($"## Request Items: *{result.RequestItems.Count}*") .AppendLine("| MasterNo | PartNo | Required | Weight | Description |") .AppendLine("| -------- | ------ |:--------:|:------:| ----------- |"); result.RequestItems.ToList().ForEach(p => output.AppendLine($"|{p.MasterNumber}|{p.PartNumber}|{p.QuantityRequired}|{p.WeightKG}|{p.Description}|")); output.AppendLine($"## Part Numbers: *{result.PartNumbers.Count}*") .AppendLine("```json") .AppendLine(result.PartNumbers.ToJson()) .AppendLine("```"); output.AppendLine($"## Parts and Alternates: *{result.Parts.Count}*") .AppendLine("| CEPNo | Master | Part | Alternate | Description |") .AppendLine("| ----- | ------ | ---- | --------- | ----------- |"); result.Parts.ForEach(part => output.AppendLine($"|{part.CEPNumber}|{part.MasterNumber}|{part.PartNumber}|{part.PartNumber}|{part.Description}|")); //output.AppendLine($"## Parts and Alternates: *{result.Parts.Count}*") // .AppendLine("```json") // .AppendLine(result.Parts.ToJsonIndented()) // .AppendLine("```"); output.AppendLine($"## Inventory Items: *{result.InventoryItems.Count}*") .AppendLine("| CEPNo | Master | Part | Alternate | Description |") .AppendLine("| ----- | ------ | ---- | --------- | ----------- |"); result.InventoryItems.ForEach(part => output.AppendLine($"|{part.CEPNumber}|{part.MasterNumber}|{part.PartNumber}|{part.PartNumber}|{part.Description}|")); //output.AppendLine($"## Inventory Items: *{result.InventoryItems.Count}*") // .AppendLine("```json") // .AppendLine(result.InventoryItems.ToJsonIndented()) // .AppendLine("```"); output.AppendLine($"## Pricelist Items: *{result.PriceListParts.Count}*") .AppendLine("| Part | Alternate | Description | Supplier |") .AppendLine("| ---- | --------- | ----------- | -------- |"); result.PriceListParts.ForEach(part => output.AppendLine($"|{part.PartNumber}|{part.PartNumber}|{part.Description}|{part.SupplierName}|")); //output.AppendLine($"## Pricelist Items: *{result.PriceListParts.Count}*") // .AppendLine("```json") // .AppendLine(result.PriceListParts.ToJsonIndented()) // .AppendLine("```"); output.AppendLine($"## Buyout Suppliers: *{result.BuyoutSuppliers.Count}*"); result.BuyoutSuppliers.ToList().ForEach(buyoutSupplier => { output.AppendLine() .AppendLine($"### {buyoutSupplier.TradingName}") .AppendLine("| Supplier | Discount | LeadTime | Duty | Freight | Currency | Xrate |") .AppendLine("| -------- |:--------:|:--------:|:----:|:-------:|:--------:|:-----:|") .AppendLine($"|{buyoutSupplier.TradingName}|{buyoutSupplier.DefaultDiscount}|{buyoutSupplier.DefaultLeadtime}|{buyoutSupplier.Duty}|{buyoutSupplier.Freight}|{buyoutSupplier.Currency}|{buyoutSupplier.ExchangeRate}|") .AppendLine() .AppendLine("#### Buyout Items") .AppendLine("| Master | Part | Brand | Condition | CostForex | CostZAR | Desc | Duty | Freight | Discount | Cost | Available | Required | Weight |") .AppendLine("| ------ | ---- | ----- | --------- | --------- | ------- | ---- | ---- | ------- | -------- | ---- | --------- | -------- | ------ |"); result.BuyoutItems.Where(p => p.ParentSurfaceItemId == buyoutSupplier.itemID).ToList().ForEach(p => { output.AppendLine("|" + string.Join("|", new string[] { p.MasterPartNumber, p.PartNumber, p.Brand, p.Condition, p.CostPriceForex.ToString(), p.CostPriceZAR.ToString(), p.Description, p.DutyCost.ToString(), p.FreightCost.ToString(), p.Discount.ToString(), p.TotalCost.ToString(), p.QuantityAvailable.ToString(), p.QuantityRequired.ToString(), p.WeightKG.ToString() }) + "|"); }); }); output.AppendLine($"## Quote Items: *{result.Items.Count}*") .AppendLine() .AppendLine("| Master | Part | Brand | Condition | Supplier | LeadTime | CostPrice | SellPrice |") .AppendLine("| ------ | ---- | ----- | --------- | -------- | -------- | --------- | --------- |"); result.Items.ToList().ForEach(p => { output.AppendLine("|" + string.Join("|", new string[] { p.MasterPartNumber, p.PartNumber, p.Brand, p.Condition, p.Supplier, p.LeadTime, p.CostPrice.ToString(), p.SellingPrice.ToString() }) + "|"); }); return new TestResult { Name = methodName, Output = output.ToString() }; } } }