/*<ControllerActionImplementation:ImportLekosCSV:1/>*/
        public ActionResult ExecuteImportLekosCSV()
        {
            ActionResult _result = null;
            string       pathCSV = zAppDev.DotNet.Framework.Utilities.Web.MapPath(System.IO.Path.Combine("~/App_Data/Uploads", @model.LekosPath));

            if ((pathCSV?.Contains("LEKOS") ?? false))
            {
                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "DeveloperTools", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "LEKOS File Import");
                int?     rowCount       = 0;
                string[] entries        = null;
                string[] productEntries = null;
                int?     test           = 0;
                DSS5_SupplyChainFinancialsOptimisation.BO.CommercialAgreement commercialAgreement = new DSS5_SupplyChainFinancialsOptimisation.BO.CommercialAgreement();
                DSS5_SupplyChainFinancialsOptimisation.BO.Order newOrder = new DSS5_SupplyChainFinancialsOptimisation.BO.Order();
                System.Collections.Generic.List <DSS5_SupplyChainFinancialsOptimisation.BO.OrderProduct> products = new System.Collections.Generic.List <DSS5_SupplyChainFinancialsOptimisation.BO.OrderProduct>();
                commercialAgreement.Supplier = new DSS5_SupplyChainFinancialsOptimisation.DAL.Repository().GetAsQueryable <DSS5_SupplyChainFinancialsOptimisation.BO.Supplier>((a) => a.UserName == "Supplier25")?.FirstOrDefault();
                System.Collections.Generic.List <string> delim = new System.Collections.Generic.List <string>();
                delim.Add("\r");
                delim.Add("\n");
                foreach (var row in System.IO.File.ReadAllText(pathCSV).SplitExtended(delim.ToArray(), true) ?? Enumerable.Empty <string>())
                {
                    if (((((row == null || row == "")) == false) && (((row == null || row.Trim() == "")) == false)))
                    {
                        entries = row?.SplitExtended(';', false);
                        if ((entries.Length > 0))
                        {
                            if (zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0).StartsWith("Α-ΔΑ"))
                            {
                                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "DeveloperTools", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Found Delivery Note");
                                newOrder.PaymentTerms = "";
                                DSS5_SupplyChainFinancialsOptimisation.BO.DeliveryNote newDeliveryNote = new DSS5_SupplyChainFinancialsOptimisation.BO.DeliveryNote();
                                newDeliveryNote.DeliveryNoteNumber = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0);
                                newDeliveryNote.Description        = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 1);
                                newDeliveryNote.DateIssued         = zAppDev.DotNet.Framework.Utilities.Common.ParseExactDate(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 2), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value);
                                newDeliveryNote.Amount             = zAppDev.DotNet.Framework.Utilities.Common.ConvertToDecimal(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 14));
                                newOrder?.AddDeliveryNotes(newDeliveryNote);
                                commercialAgreement?.AddOrders(newOrder);
                            }
                            else if (zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0).StartsWith("Α-ΠΑ"))
                            {
                                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "DeveloperTools", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Found Order");
                                newOrder.OrderNumber  = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0);
                                newOrder.DateOfOrder  = zAppDev.DotNet.Framework.Utilities.Common.ParseExactDate(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 2), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value);
                                newOrder.PaymentTerms = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 10);
                                commercialAgreement?.AddOrders(newOrder);
                            }
                            else if (zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0).StartsWith("Α-ΤΔ"))
                            {
                                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "DeveloperTools", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Found Delivery Note & Invoice");
                                newOrder.PaymentTerms = "";
                                DSS5_SupplyChainFinancialsOptimisation.BO.DeliveryNote newDeliveryNote = new DSS5_SupplyChainFinancialsOptimisation.BO.DeliveryNote();
                                newDeliveryNote.DeliveryNoteNumber = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0);
                                newDeliveryNote.Description        = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 1);
                                newDeliveryNote.DateIssued         = zAppDev.DotNet.Framework.Utilities.Common.ParseExactDate(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 2), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value);
                                newDeliveryNote.Amount             = zAppDev.DotNet.Framework.Utilities.Common.ConvertToDecimal(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 14));
                                newOrder?.AddDeliveryNotes(newDeliveryNote);
                                DSS5_SupplyChainFinancialsOptimisation.BO.Invoice newInvoice = new DSS5_SupplyChainFinancialsOptimisation.BO.Invoice();
                                newInvoice.InvoiceNumber = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0);
                                newInvoice.Description   = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 1);
                                newInvoice.DateIssued    = zAppDev.DotNet.Framework.Utilities.Common.ParseExactDate(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 2), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value);
                                newInvoice.Amount        = zAppDev.DotNet.Framework.Utilities.Common.ConvertToDecimal(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 14));
                                newOrder?.AddInvoices(newInvoice);
                                commercialAgreement?.AddOrders(newOrder);
                            }
                            else if (zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0).StartsWith("Α-ΤΠ"))
                            {
                                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "DeveloperTools", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Found Invoice");
                                newOrder.PaymentTerms = "";
                                DSS5_SupplyChainFinancialsOptimisation.BO.Invoice newInvoice = new DSS5_SupplyChainFinancialsOptimisation.BO.Invoice();
                                newInvoice.InvoiceNumber = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0);
                                newInvoice.Description   = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 1);
                                newInvoice.DateIssued    = zAppDev.DotNet.Framework.Utilities.Common.ParseExactDate(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 2), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value);
                                newInvoice.Amount        = zAppDev.DotNet.Framework.Utilities.Common.ConvertToDecimal(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 14));
                                newOrder?.AddInvoices(newInvoice);
                                commercialAgreement?.AddOrders(newOrder);
                            }
                            else if (zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0).StartsWith("Χ-Α"))
                            {
                                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "DeveloperTools", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Found Cancelled Order");
                                newOrder.PaymentTerms = "";
                                DSS5_SupplyChainFinancialsOptimisation.BO.CreditNote crNote = new DSS5_SupplyChainFinancialsOptimisation.BO.CreditNote();
                                crNote.CreditNoteNumber = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0);
                                crNote.Description      = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 1);
                                crNote.DateIssued       = zAppDev.DotNet.Framework.Utilities.Common.ParseExactDate(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 2), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value);
                                crNote.TotalPrice       = zAppDev.DotNet.Framework.Utilities.Common.ConvertToDecimal(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 14));
                                newOrder?.AddCreditNotes(crNote);
                                commercialAgreement?.AddOrders(newOrder);
                            }
                            else if (zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0).StartsWith("Ε-ΤΠ"))
                            {
                                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "DeveloperTools", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Found EU Invoice");
                                newOrder.PaymentTerms = "";
                                DSS5_SupplyChainFinancialsOptimisation.BO.Invoice newInvoice = new DSS5_SupplyChainFinancialsOptimisation.BO.Invoice();
                                newInvoice.InvoiceNumber = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 0);
                                newInvoice.Description   = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 1);
                                newInvoice.DateIssued    = zAppDev.DotNet.Framework.Utilities.Common.ParseExactDate(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 2), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value);
                                newInvoice.Amount        = zAppDev.DotNet.Framework.Utilities.Common.ConvertToDecimal(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(entries, 14));
                                newInvoice.CustomerType  = "EU Customer";
                                newOrder?.AddInvoices(newInvoice);
                                commercialAgreement?.AddOrders(newOrder);
                            }
                        }
                        else
                        {
                            zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "DeveloperTools", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Row: " + (rowCount?.ToString() ?? "") + "does not have 2 entries.");
                        }
                    }
                    else
                    {
                        zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "DeveloperTools", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Row " + (rowCount?.ToString() ?? "") + " did not have value.");
                    }
                    if (rowCount > 0)
                    {
                        zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "DeveloperTools", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "product----> " + row);
                        productEntries = row?.SplitExtended(';', false);
                        DSS5_SupplyChainFinancialsOptimisation.BO.OrderProduct product = new DSS5_SupplyChainFinancialsOptimisation.BO.OrderProduct();
                        product.Code            = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(productEntries, 0);
                        product.Description     = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(productEntries, 1);
                        product.MeasurementUnit = zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(productEntries, 2);
                        products?.Add(product);
                        product.Quantity = zAppDev.DotNet.Framework.Utilities.Common.ConvertToDecimal(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(productEntries, 3));
                    }
                    rowCount = rowCount.GetValueOrDefault(0) + 1;
                    commercialAgreement?.AddOrders(newOrder);
                    new DSS5_SupplyChainFinancialsOptimisation.DAL.Repository().Save <DSS5_SupplyChainFinancialsOptimisation.BO.CommercialAgreement>(commercialAgreement);
                }
                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "DeveloperTools", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Rowcount " + (rowCount?.ToString() ?? ""));
            }
            return(_result);
        }
/// <summary>
/// Copies the current object to a new instance
/// </summary>
/// <param name="deep">Copy members that refer to objects external to this class (not dependent)</param>
/// <param name="copiedObjects">Objects that should be reused</param>
/// <param name="asNew">Copy the current object as a new one, ready to be persisted, along all its members.</param>
/// <param name="reuseNestedObjects">If asNew is true, this flag if set, forces the reuse of all external objects.</param>
/// <param name="copy">Optional - An existing [CommercialAgreement] instance to use as the destination.</param>
/// <returns>A copy of the object</returns>
        public virtual CommercialAgreement Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, CommercialAgreement copy = null)
        {
            if (copiedObjects == null)
            {
                copiedObjects = new Hashtable();
            }
            if (copy == null && copiedObjects.Contains(this))
            {
                return((CommercialAgreement)copiedObjects[this]);
            }
            copy = copy ?? new CommercialAgreement();
            if (!asNew)
            {
                copy.TransientId = this.TransientId;
                copy.Id          = this.Id;
            }
            copy.ProductCategory = this.ProductCategory;
            copy.PaymentTerms    = this.PaymentTerms;
            if (!copiedObjects.Contains(this))
            {
                copiedObjects.Add(this, copy);
            }
            if (deep && this.supplier != null)
            {
                if (!copiedObjects.Contains(this.supplier))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.Supplier = this.Supplier;
                    }
                    else if (asNew)
                    {
                        copy.Supplier = this.Supplier.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.supplier = this.supplier.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.Supplier = (Supplier)copiedObjects[this.Supplier];
                    }
                    else
                    {
                        copy.supplier = (Supplier)copiedObjects[this.Supplier];
                    }
                }
            }
            if (deep && this.buyer != null)
            {
                if (!copiedObjects.Contains(this.buyer))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.Buyer = this.Buyer;
                    }
                    else if (asNew)
                    {
                        copy.Buyer = this.Buyer.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.buyer = this.buyer.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.Buyer = (Buyer)copiedObjects[this.Buyer];
                    }
                    else
                    {
                        copy.buyer = (Buyer)copiedObjects[this.Buyer];
                    }
                }
            }
            copy.orders = new List <Order>();
            if (deep && this.orders != null)
            {
                foreach (var __item in this.orders)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddOrders(__item);
                        }
                        else
                        {
                            copy.AddOrders(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddOrders((Order)copiedObjects[__item]);
                    }
                }
            }
            if (deep && this.importedBuyer != null)
            {
                if (!copiedObjects.Contains(this.importedBuyer))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.ImportedBuyer = this.ImportedBuyer;
                    }
                    else if (asNew)
                    {
                        copy.ImportedBuyer = this.ImportedBuyer.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.importedBuyer = this.importedBuyer.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.ImportedBuyer = (ImportedBuyer)copiedObjects[this.ImportedBuyer];
                    }
                    else
                    {
                        copy.importedBuyer = (ImportedBuyer)copiedObjects[this.ImportedBuyer];
                    }
                }
            }
            copy.transactions = new List <Transaction>();
            if (deep && this.transactions != null)
            {
                foreach (var __item in this.transactions)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddTransactions(__item);
                        }
                        else
                        {
                            copy.AddTransactions(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddTransactions((Transaction)copiedObjects[__item]);
                    }
                }
            }
            if (deep && this.agreement != null)
            {
                if (!copiedObjects.Contains(this.agreement))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.Agreement = this.Agreement;
                    }
                    else if (asNew)
                    {
                        copy.Agreement = this.Agreement.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.agreement = this.agreement.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.Agreement = (Agreement)copiedObjects[this.Agreement];
                    }
                    else
                    {
                        copy.agreement = (Agreement)copiedObjects[this.Agreement];
                    }
                }
            }
            return(copy);
        }