Пример #1
0
        public List <PepperiImportDetailTemp> MapFileImportDetailToTemp(string businessName,
                                                                        PepperiTransactionTempModel.SalesTransactionTransactionLine[] tls,
                                                                        PepperiTransactionTempModel.SalesTransactionTransactionHeader th,
                                                                        UserModel taskUser,
                                                                        ScheduledTask task)
        {
            List <PepperiImportDetailTemp> details = new List <PepperiImportDetailTemp>();
            var lineNumber = 0;

            var company  = CompanyService.FindCompanyFriendlyNameModel(businessName);
            var customer = GetCustomer(company, th, taskUser);

            if (company != null)
            {
                if (tls.Length != 0)
                {
                    foreach (PepperiTransactionTempModel.SalesTransactionTransactionLine tl in tls)
                    {
                        var pidt = new PepperiImportDetailTemp();
                        pidt.CompanyId = company.Id;

                        var product = ProductService.FindProductModel(tl.ItemFields.ItemExternalID, null, company, false);
                        // Stop import if product is false
                        pidt.ProductId                    = product.Id;
                        pidt.BrandCategoryId              = ProductService.FindProductBrandCategoryModel(company.Id, pidt.ProductId.Value).Id;
                        pidt.ItemWrntyId                  = tl.ItemFields.ItemWrntyID;
                        pidt.ItemExternalId               = tl.ItemFields.ItemExternalID;
                        pidt.ItemMainCategory             = tl.ItemFields.ItemMainCategory;
                        pidt.ItemMainCategoryCode         = tl.ItemFields.ItemMainCategoryCode;
                        pidt.ItemName                     = tl.ItemFields.ItemName.Replace(",", "").Replace("'", "");
                        pidt.ItemPrice                    = tl.ItemFields.ItemPrice;
                        pidt.ItemInStockQuantity          = tl.ItemFields.ItemInStockQuantity;
                        pidt.TSANextAvailableDate         = (tl.ItemFields.TSANextAvailableDate == "") ? (DateTimeOffset?)null : DateTimeOffsetExtensions.ParseDate(DateTimeOffset.Parse(tl.ItemFields.TSANextAvailableDate), (TimeZoneInfo.Local.BaseUtcOffset.Hours * 60));
                        pidt.TSATotalAvailable            = (string.IsNullOrEmpty(tl.ItemFields.TSATotalAvailable)) ? 0 : Convert.ToInt32(tl.ItemFields.TSATotalAvailable);
                        pidt.TSADuePDF                    = tl.TransactionLineCustomFields.TSADuePDF as string;
                        pidt.TSALineAmount                = tl.TransactionLineCustomFields.TSALineAmount;
                        pidt.UnitsQuantity                = tl.TransactionLineFields.UnitsQuantity;
                        pidt.UnitPrice                    = tl.TransactionLineFields.UnitPrice;
                        pidt.UnitDiscountPercentage       = tl.TransactionLineFields.UnitDiscountPercentage;
                        pidt.UnitPriceAfterDiscount       = tl.TransactionLineFields.UnitPriceAfterDiscount;
                        pidt.TotalUnitsPriceAfterDiscount = tl.TransactionLineFields.TotalUnitsPriceAfterDiscount;
                        pidt.DeliveryDate                 = DateTimeOffsetExtensions.ParseDate(DateTimeOffset.Parse(tl.TransactionLineFields.DeliveryDate), (TimeZoneInfo.Local.BaseUtcOffset.Hours * 60));
                        pidt.TransactionWrntyId           = tl.TransactionLineFields.TransactionWrntyID;
                        pidt.TransactionExternalId        = (tl.TransactionLineFields.TransactionExternalID as string == null) ? (long?)null : Convert.ToInt64(tl.TransactionLineFields.TransactionExternalID);
                        pidt.LineNumber                   = lineNumber;
                        pidt.TaxCodeId                    = customer.TaxCodeId;
                        pidt.DiscountPercent              = tl.TransactionLineFields.UnitDiscountPercentage;
                        details.Add(pidt);

                        lineNumber += 100;
                    }
                }
            }
            else
            {
                TaskService.WriteTaskLog(task, $"Error: Failed to find company '{businessName}' - @MapFileImportDetailToTemp", LogSeverity.Severe);
            }

            return(details);
        }
Пример #2
0
        public List <NuOrderImportTemp> MapFileToTemp(string businessName, List <Dictionary <string, string> > orderLines, UserModel taskUser)
        {
            List <NuOrderImportTemp> nuOrderImportTempList = new List <NuOrderImportTemp>();

            CompanyModel company = CompanyService.FindCompanyFriendlyNameModel(businessName);

            if (orderLines == null)
            {
                return(null);
            }
            else
            {
                foreach (var line in orderLines)
                {
                    CustomerModel customer = GetCustomer(company, line, taskUser);

                    NuOrderImportTemp noit = new NuOrderImportTemp();
                    noit.CompanyId        = company.Id;
                    noit.SourceId         = LookupService.FindLOVItemModel(LOVName.OrderSource, "Nuorder").Id;
                    noit.CustomerId       = customer.Id;
                    noit.OrderNumber      = null;
                    noit.CustomerPO       = line["Order Number"];
                    noit.RequiredDate     = DateTimeOffset.Parse(line["Order Date"]);
                    noit.CompanyName      = line["Customer Code"];
                    noit.EndUserName      = line["Buyer"];
                    noit.ShipAddress1     = line["Shipping Line 1"];
                    noit.ShipAddress2     = line["Shipping Line 2"];
                    noit.Filespec         = null;
                    noit.Telephone        = null;
                    noit.ShipAddress3     = line["Shipping Line 3"];
                    noit.ShipAddress4     = line["Shipping Line 4"];
                    noit.ShipSuburb       = line["Shipping City"];
                    noit.ShipState        = line["Shipping State"];
                    noit.ShipPostcode     = line["Shipping Zip"];
                    noit.ShipCountryId    = LookupService.FindCountryModel(line["Shipping Country"]).Id;
                    noit.SOStatus         = (int)SalesOrderHeaderStatus.ConfirmedOrder;
                    noit.SOSubstatus      = (int)SalesOrderHeaderSubStatus.Unpicked;
                    noit.SalesPersonId    = MembershipManagementService.FindUserByAliasName(line["Sales Rep"].Replace(" ", ".")).Id;
                    noit.OrderComment     = line["Order Notes"];
                    noit.LocationId       = company.DefaultLocationID.Value;
                    noit.TermsId          = customer.PaymentTermId;
                    noit.ShippingMethodId = customer.ShippingMethodId;
                    noit.TaxPercent       = LookupService.FindTaxCodeModel(customer.TaxCodeId).TaxPercentageRate / 100;
                    noit.TaxCodeId        = customer.TaxCodeId;
                    noit.WebsiteOrderNo   = line["Order Number"];
                    noit.EmailAddress     = null;
                    noit.Comments         = line["Order Notes"];
                    noit.IsError          = false;

                    // Date Fields are in US format, so need to Parse them accordingly
                    string dateFormat = "MM/dd/yyyy";
                    var    orderDate  = line["Order Date"];
                    noit.OrderDate = DateTimeOffsetExtensions.ParseDate(DateTimeOffset.ParseExact(orderDate, dateFormat, CultureInfo.InvariantCulture), TimeZoneInfo.Local.BaseUtcOffset.Hours, OffsetType.Hours);
                    var startDate = line["Ship Date Start"];
                    noit.DeliveryWindowOpen = (startDate == null || string.IsNullOrWhiteSpace(startDate)) ? noit.OrderDate : DateTimeOffsetExtensions.ParseDate(DateTimeOffset.ParseExact(startDate, dateFormat, CultureInfo.InvariantCulture), TimeZoneInfo.Local.BaseUtcOffset.Hours, OffsetType.Hours);
                    var endDate = line["Ship Date End"];
                    noit.DeliveryWindowClose = (endDate == null || string.IsNullOrWhiteSpace(endDate) ? LookupService.GetDeliveryWindow(noit.DeliveryWindowOpen.Value) : DateTimeOffsetExtensions.ParseDate(DateTimeOffset.ParseExact(endDate, dateFormat, CultureInfo.InvariantCulture), TimeZoneInfo.Local.BaseUtcOffset.Hours, OffsetType.Hours));

                    noit.ManualDWO             = false;
                    noit.ManualDWC             = true;
                    noit.ShippingMethodAccount = null;
                    noit.NextActionId          = LookupService.FindSaleNextActionId(Enumerations.SaleNextAction.None);
                    noit.IsConfirmedAddress    = true;
                    noit.IsManualFreight       = false;
                    noit.FreightRate           = customer.FreightRate;
                    noit.MinFreightPerOrder    = customer.MinFreightPerOrder;
                    noit.FreightCarrierId      = customer.FreightCarrierId;
                    noit.WarehouseInstructions = null;
                    noit.DeliveryInstructions  = null;
                    noit.DeliveryContact       = null;
                    noit.FreightTermId         = null;
                    noit.OrderTypeId           = null;
                    noit.SignedBy       = "Customer";
                    noit.DateSigned     = noit.OrderDate;
                    noit.MethodSignedId = LookupService.FindMethodSignedModel("NuOrder").Id;
                    //noit.PrintedForm = null;
                    noit.IsMSQProblem         = false;
                    noit.IsOverrideMSQ        = false;
                    noit.SiteName             = "NuOrder";
                    noit.IsProcessed          = false;
                    noit.IsRetailSale         = false;
                    noit.IsRetailHoldingOrder = false;

                    noit.LineNumber = null;
                    var product = ProductService.FindProductModel(line["Style Number"], null, company, false);
                    noit.ItemId          = product.Id;
                    noit.ItemNumber      = line["Style Number"];
                    noit.ItemDescription = product.ItemDescription;
                    noit.BrandCategoryId = ProductService.FindProductBrandCategoryModel(company.Id, product.Id).Id;
                    noit.UnitPriceExTax  = Convert.ToDecimal(line["Price Per"]);
                    noit.UnitPriceTax    = Convert.ToDecimal(line["Price Per"]) * noit.TaxPercent;
                    var volumeDiscountPercent = customer.VolumeDiscount / 100;
                    noit.Discount        = Convert.ToDecimal(line["Price Per"]) * volumeDiscountPercent;
                    noit.DiscountPercent = customer.VolumeDiscount;
                    noit.OrderQty        = Convert.ToInt32(line["Quantity"]);
                    noit.AllocQty        = 0;
                    noit.PickQty         = 0;
                    noit.InvQty          = 0;
                    noit.LineStatusId    = (int)SalesOrderLineStatus.Unpicked;
                    noit.DateCreated     = DateTimeOffset.Now;
                    noit.DateModified    = DateTimeOffset.Now;

                    nuOrderImportTempList.Add(noit);
                }
            }


            if (SaveDataToTempTables(nuOrderImportTempList))
            {
                return(nuOrderImportTempList);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        public PepperiImportHeaderTemp MapFileImportHeaderToTemp(string businessName,
                                                                 PepperiTransactionTempModel.SalesTransactionTransactionHeader th,
                                                                 UserModel taskUser,
                                                                 ScheduledTask task)
        {
            PepperiImportHeaderTemp piht = new PepperiImportHeaderTemp();

            var company  = CompanyService.FindCompanyFriendlyNameModel(businessName);
            var customer = GetCustomer(company, th, taskUser);

            if (company != null)
            {
                piht.CompanyId                  = company.Id;
                piht.WrntyId                    = Convert.ToInt32(th.TransactionHeaderFields.WrntyID);
                piht.OrderType                  = th.TransactionHeaderFields.Type;
                piht.Status                     = th.TransactionHeaderFields.Status;
                piht.CreationDateTime           = DateTimeOffset.Parse(th.TransactionHeaderFields.CreationDateTime);
                piht.ModificationDateTime       = DateTimeOffset.Parse(th.TransactionHeaderFields.ModificationDateTime);
                piht.ActionDateTime             = DateTimeOffset.Parse(th.TransactionHeaderFields.ActionDateTime);
                piht.DeliveryDate               = DateTimeOffsetExtensions.ParseDate(DateTimeOffset.Parse(th.TransactionHeaderFields.DeliveryDate), (TimeZoneInfo.Local.BaseUtcOffset.Hours * 60));
                piht.Remark                     = th.TransactionHeaderFields.Remark as string;
                piht.CatalogId                  = th.CatalogFields.CatalogID;
                piht.CatalogDescription         = th.CatalogFields.CatalogDescription as string;
                piht.CatalogPriceFactor         = th.CatalogFields.CatalogPriceFactor;
                piht.CatalogExpirationDate      = DateTimeOffsetExtensions.ParseDate(DateTimeOffset.Parse(th.CatalogFields.CatalogExpirationDate), (TimeZoneInfo.Local.BaseUtcOffset.Hours * 60));
                piht.AgentName                  = th.SalesRepFields.AgentName;
                piht.AgentExternalId            = (th.SalesRepFields.AgentExternalID as string == null) ? 0 : Convert.ToInt64(th.SalesRepFields.AgentExternalID);
                piht.AgentEmail                 = th.SalesRepFields.AgentEmail;
                piht.AccountWrntyId             = th.AccountFields.AccountWrntyID;
                piht.AccountExternalId          = th.AccountFields.AccountExternalID;
                piht.AccountCreationDate        = DateTimeOffset.Parse(th.AccountFields.AccountCreationDate);
                piht.AccountName                = th.AccountFields.AccountName;
                piht.AccountPhone               = th.AccountFields.AccountPhone;
                piht.AccountMobile              = th.AccountFields.AccountMobile as string;
                piht.AccountFax                 = th.AccountFields.AccountFax as string;
                piht.AccountEmail               = th.AccountFields.AccountEmail;
                piht.CustomerId                 = customer.Id;
                piht.AccountStreet              = th.AccountFields.AccountStreet;
                piht.AccountCity                = th.AccountFields.AccountCity;
                piht.AccountState               = th.AccountFields.AccountState;
                piht.AccountCountryId           = LookupService.FindCountryModel(th.AccountFields.AccountCountry).Id;
                piht.AccountCountry             = th.AccountFields.AccountCountry;
                piht.AccountZipCode             = th.AccountFields.AccountZipCode;
                piht.AccountPriceLevelName      = th.AccountFields.AccountPriceLevelName as string;
                piht.BillToName                 = th.BillingFields.BillToName;
                piht.BillToStreet               = th.BillingFields.BillToStreet;
                piht.BillToCity                 = th.BillingFields.BillToCity;
                piht.BillToState                = th.BillingFields.BillToState;
                piht.BillToCountryId            = LookupService.FindCountryModel(th.BillingFields.BillToCountry).Id;
                piht.BillToCountry              = th.BillingFields.BillToCountry;
                piht.BillToZipCode              = th.BillingFields.BillToZipCode;
                piht.BillToPhone                = th.BillingFields.BillToPhone;
                piht.ShipToExternalId           = th.ShippingFields.ShipToExternalID;
                piht.ShipToName                 = th.ShippingFields.ShipToName;
                piht.ShipToStreet               = th.ShippingFields.ShipToStreet;
                piht.ShipToCity                 = th.ShippingFields.ShipToCity;
                piht.ShipToState                = th.ShippingFields.ShipToState;
                piht.ShipToCountryId            = LookupService.FindCountryModel(th.ShippingFields.ShipToCountry).Id;
                piht.ShipToCountry              = th.ShippingFields.ShipToCountry;
                piht.ShipToZipCode              = th.ShippingFields.ShipToZipCode;
                piht.ShipToPhone                = th.ShippingFields.ShipToPhone;
                piht.Currency                   = th.Totals.Currency;
                piht.TotalItemsCount            = th.Totals.TotalItemsCount;
                piht.SubTotal                   = th.Totals.SubTotal;
                piht.SubTotalAfterItemsDiscount = th.Totals.SubTotalAfterItemsDiscount;
                piht.GrandTotal                 = th.Totals.GrandTotal;
                piht.DiscountPercentage         = th.Totals.DiscountPercentage;
                piht.TaxPercentage              = th.Totals.TaxPercentage;
                piht.TSAGST                     = th.TransactionCustomFields.TSAGST;
                piht.TSADeliveryWindowOpen      = (th.TransactionCustomFields.TSADeliveryWindowOpen == "") ? DateTimeOffset.Parse(th.TransactionHeaderFields.CreationDateTime) : DateTimeOffsetExtensions.ParseDate(DateTimeOffset.Parse(th.TransactionCustomFields.TSADeliveryWindowOpen), (TimeZoneInfo.Local.BaseUtcOffset.Hours * 60));
                piht.TSADeliveryWindowClose     = (th.TransactionCustomFields.TSADeliveryWindowClose == "") ? LookupService.GetDeliveryWindow(piht.TSADeliveryWindowOpen.Value) : DateTimeOffsetExtensions.ParseDate(DateTimeOffset.Parse(th.TransactionCustomFields.TSADeliveryWindowClose), (TimeZoneInfo.Local.BaseUtcOffset.Hours * 60));
                piht.TSAOrderTakenBy            = (th.TransactionCustomFields.TSAOrderTakenBy as string == null) ? th.TransactionCustomFields.TSAOrderTakenBy as string : th.TransactionCustomFields.TSAOrderTakenBy.ToString();
                piht.TSATaxRate                 = th.TransactionCustomFields.TSATaxRate;
                piht.TSASubTotalBeforeTax       = th.TransactionCustomFields.TSASubTotalBeforeTax;
                piht.TSAGrandTotal              = th.TransactionCustomFields.TSAGrandTotal;
                piht.SalespersonId              = GetSalespersonId(th.SalesRepFields.AgentEmail);
                piht.Filespec                   = th.TransactionCustomFields.Filespec;
                piht.IsNewCustomer              = th.TransactionCustomFields.IsNewCustomer;
                piht.OrderNumber                = (int)LookupService.GetNextSequenceNumber(company, SequenceNumberType.SalesOrderNumber);
                piht.SOStatus                   = (int)SalesOrderHeaderStatus.ConfirmedOrder;
                piht.SOSubStatus                = (int)SalesOrderHeaderSubStatus.Unpicked;
                piht.LocationId                 = company.DefaultLocationID.Value;
                piht.IsConfirmedAddress         = (th.TransactionCustomFields.IsNewCustomer == true) ? false : true;
                piht.SignedBy                   = "Customer";
                piht.MethodSignedId             = LookupService.FindMethodSignedModel("Pepperi").Id;
                piht.IsMSQProblem               = false;
                piht.IsOverrideMSQ              = false;
                piht.SourceId                   = LookupService.FindLOVItemModel(LOVName.OrderSource, "Pepperi").Id;
                piht.NextActionId               = LookupService.FindSaleNextActionId(Enumerations.SaleNextAction.None);
            }
            else
            {
                TaskService.WriteTaskLog(task, $"Error: Failed to find company '{businessName}' - @MapFileImportHeaderToTemp", LogSeverity.Severe);
            }
            return(piht);
        }