public AccountAddresses SaveAccountAddress(AccountAddresses customeraddresses, int currentUserId)
        {
            if (customeraddresses.AddressID < 1)
            {
                customeraddresses.Name = customeraddresses.Name.Trim();

                customeraddresses.DateCreated = DateTime.UtcNow;
                customeraddresses.DateUpdated = DateTime.UtcNow;
                customeraddresses.CreatedBy   = currentUserId;
                customeraddresses.UpdatedBy   = currentUserId;
                customeraddresses.IsDeleted   = false;

                _currentDbContext.AccountAddresses.Add(customeraddresses);
                var customer = _currentDbContext.Account.First(m => m.AccountID == customeraddresses.AccountID);
                customer.DateUpdated = DateTime.UtcNow;
                customer.UpdatedBy   = currentUserId;
                _currentDbContext.Account.Attach(customer);
                var entry1 = _currentDbContext.Entry(customer);
                entry1.Property(e => e.DateUpdated).IsModified = true;
                entry1.Property(e => e.UpdatedBy).IsModified   = true;
            }
            else
            {
                if (!String.IsNullOrEmpty(customeraddresses.Name))
                {
                    customeraddresses.Name = customeraddresses.Name.Trim();
                }

                customeraddresses.DateUpdated = DateTime.UtcNow;
                customeraddresses.UpdatedBy   = currentUserId;

                _currentDbContext.AccountAddresses.Attach(customeraddresses);
                var entry = _currentDbContext.Entry(customeraddresses);
                entry.Property(e => e.Name).IsModified             = true;
                entry.Property(e => e.AddressLine1).IsModified     = true;
                entry.Property(e => e.AddressLine2).IsModified     = true;
                entry.Property(e => e.AddressLine3).IsModified     = true;
                entry.Property(e => e.Telephone).IsModified        = true;
                entry.Property(e => e.Town).IsModified             = true;
                entry.Property(e => e.County).IsModified           = true;
                entry.Property(e => e.PostCode).IsModified         = true;
                entry.Property(e => e.CountryID).IsModified        = true;
                entry.Property(e => e.AccountID).IsModified        = true;
                entry.Property(e => e.DateUpdated).IsModified      = true;
                entry.Property(e => e.UpdatedBy).IsModified        = true;
                entry.Property(e => e.AddTypeDefault).IsModified   = true;
                entry.Property(e => e.AddTypeMarketing).IsModified = true;
                entry.Property(e => e.AddTypeShipping).IsModified  = true;
            }
            _currentDbContext.SaveChanges();

            return(customeraddresses);
        }
示例#2
0
        public ActionResult SaveAccountAddress(AccountAddresses model)
        {
            caUser user = caCurrent.CurrentUser();

            if (model.AccountID == 0)
            {
                model.AccountID = int.Parse(Session["account"].ToString());
            }

            AccountServices.SaveAccountAddress(model, CurrentUserId);

            return(Redirect(Url.Action("Edit", new { id = Session["account"] }) + "#addresses"));
        }
        public ActionResult Edit([Bind(Include = "AddRecNo,Name,ContactName,AddressLine1,AddressLine2,AddressLine3,Telephone,Town,County,PostCode,CountryID,CustomerID")] AccountAddresses customeraddresses)
        {
            if (ModelState.IsValid)
            {
                AccountServices.SaveAccountAddress(customeraddresses, CurrentUserId);

                return(RedirectToAction("Create", new { id = customeraddresses.AccountID }));
            }

            ViewBag.CountryID  = new SelectList(LookupServices.GetAllGlobalCountries(), "CountryID", "CountryName", customeraddresses.CountryID);
            ViewBag.CustomerID = customeraddresses.AccountID;

            ViewBag.Addresses = AccountServices.GetAllValidAccountAddressesByAccountId(customeraddresses.AccountID).ToList();

            return(View(customeraddresses));
        }
示例#4
0
        public Order CreateSalesOrder(Order order, OrderRecipientInfo shipmentAndRecipientInfo, int tenantId, int warehouseId,
                                      int userId, List <OrderDetail> orderDetails = null, List <OrderNotes> orderNotes = null)
        {
            order.OrderNumber = order.OrderNumber.Trim();
            var duplicateOrder = _currentDbContext.Order.FirstOrDefault(m => m.OrderNumber.Equals(order.OrderNumber, StringComparison.CurrentCultureIgnoreCase));

            if (duplicateOrder != null)
            {
                throw new Exception($"Order Number {order.OrderNumber} already associated with another Order. Please regenerate order number.", new Exception("Duplicate Order Number"));
            }

            order.IssueDate     = DateTime.UtcNow;
            order.OrderStatusID = (int)OrderStatusEnum.Active;
            order.DateCreated   = DateTime.UtcNow;
            order.DateUpdated   = DateTime.UtcNow;
            order.TenentId      = tenantId;
            order.CreatedBy     = userId;
            order.UpdatedBy     = userId;
            order.WarehouseId   = warehouseId;
            if (order.AccountID > 0)
            {
                var account = _currentDbContext.Account.Find(order.AccountID);
                if (account != null)
                {
                    order.AccountCurrencyID = account.CurrencyID;
                }
            }
            if (!caCurrent.CurrentWarehouse().AutoAllowProcess)
            {
                order.OrderStatusID = _currentDbContext.OrderStatus.First(a => a.OrderStatusID == (int)OrderStatusEnum.Hold).OrderStatusID;
            }
            else
            {
                order.OrderStatusID = _currentDbContext.OrderStatus.First(a => a.OrderStatusID == (int)OrderStatusEnum.Active).OrderStatusID;
            }
            _currentDbContext.Order.Add(order);


            if (orderDetails != null)
            {
                if (orderDetails.Any(m => m.OrderDetailStatusId == (int)OrderStatusEnum.AwaitingAuthorisation))
                {
                    order.OrderStatusID = (int)OrderStatusEnum.AwaitingAuthorisation;
                }

                decimal?ordTotal = 0;
                foreach (var item in orderDetails)
                {
                    item.DateCreated   = DateTime.UtcNow;
                    item.CreatedBy     = userId;
                    item.OrderID       = order.OrderID;
                    item.TenentId      = tenantId;
                    item.SortOrder     = item.ProductMaster?.ProductGroup?.SortOrder ?? 0;
                    item.ProductMaster = null;
                    item.TaxName       = null;
                    item.Warranty      = null;
                    item.WarehouseId   = warehouseId;
                    order.OrderDetails.Add(item);
                    ordTotal = ordTotal + ((item.Price * item.Qty) + item.TaxAmount);
                }

                order.OrderTotal = (decimal)ordTotal;
            }
            if (orderNotes != null)
            {
                foreach (var item in orderNotes)
                {
                    item.DateCreated = DateTime.UtcNow;
                    item.CreatedBy   = userId;
                    item.OrderID     = order.OrderID;
                    item.TenantId    = tenantId;
                    order.OrderNotes.Add(item);
                }
            }
            if (shipmentAndRecipientInfo.AddAddressToAccount == true && order.AccountID > 0 && (!order.ShipmentAccountAddressId.HasValue || order.ShipmentAccountAddressId < 1))
            {
                var account        = _accountServices.GetAccountsById(order.AccountID.Value);
                var accountAddress = new AccountAddresses()
                {
                    AccountID       = order.AccountID.Value,
                    AddressLine1    = shipmentAndRecipientInfo.ShipmentAddressLine1,
                    AddressLine2    = shipmentAndRecipientInfo.ShipmentAddressLine2,
                    AddressLine3    = shipmentAndRecipientInfo.ShipmentAddressLine3,
                    Town            = shipmentAndRecipientInfo.ShipmentAddressLine4,
                    PostCode        = shipmentAndRecipientInfo.ShipmentAddressPostcode,
                    AddTypeShipping = true,
                    CountryID       = account.CountryID,
                    CreatedBy       = userId,
                    DateCreated     = DateTime.UtcNow,
                    IsActive        = true,
                    Name            = account.CompanyName
                };
                _currentDbContext.AccountAddresses.Add(accountAddress);
            }
            if (order.ShipmentAccountAddressId < 1)
            {
                order.ShipmentAccountAddressId = (int?)null;
            }

            if (order.ConsignmentTypeId == 4)
            {
                order.ShipmentAddressLine1     = _currentDbContext.ConsignmentTypes.FirstOrDefault(u => u.ConsignmentTypeId == 4)?.ConsignmentType;
                order.ShipmentAddressLine2     = null;
                order.ShipmentAddressLine3     = null;
                order.ShipmentAddressLine4     = null;
                order.ShipmentAddressPostcode  = null;
                order.ShipmentAccountAddressId = (int?)null;
            }


            #region SendEmailWithAttachment
            if (shipmentAndRecipientInfo.SendEmailWithAttachment)
            {
                if (shipmentAndRecipientInfo.AccountEmailContacts != null && shipmentAndRecipientInfo.AccountEmailContacts.Length > 0)
                {
                    foreach (var item in shipmentAndRecipientInfo.AccountEmailContacts)
                    {
                        string email = "";

                        var secondryAddress = _currentDbContext.AccountContacts.Where(u => u.AccountContactId == item).AsNoTracking().FirstOrDefault();
                        if (secondryAddress != null)
                        {
                            email = secondryAddress.ContactEmail;
                        }

                        var recipient = new OrderPTenantEmailRecipient()
                        {
                            OrderId          = order.OrderID,
                            EmailAddress     = email,
                            AccountContactId = item,
                            UpdatedBy        = userId,
                            DateUpdated      = DateTime.UtcNow,
                        };

                        _currentDbContext.OrderPTenantEmailRecipients.Add(recipient);
                    }
                }
            }
            #endregion

            _currentDbContext.SaveChanges();
            Inventory.StockRecalculateByOrderId(order.OrderID, warehouseId, tenantId, caCurrent.CurrentUser().UserId);

            return(order);
        }
示例#5
0
        public Order SaveSalesOrder(Order order, OrderRecipientInfo shipmentAndRecipientInfo, int tenantId, int warehouseId,
                                    int userId, List <OrderDetail> orderDetails = null, List <OrderNotes> orderNotes = null)
        {
            decimal total = 0;

            if (orderDetails != null)
            {
                var toAdd  = orderDetails.Where(a => a.OrderDetailID < 0).ToList();
                var cItems = orderDetails.Where(a => a.OrderDetailID > 0).ToList();

                var toDelete = _currentDbContext.OrderDetail.Where(a => a.OrderID == order.OrderID && a.IsDeleted != true).Select(a => a.OrderDetailID).Except(cItems.Select(a => a.OrderDetailID).ToList());
                foreach (var item in toDelete)
                {
                    var dItem = _currentDbContext.OrderDetail.FirstOrDefault(a => a.OrderDetailID == item);
                    dItem.IsDeleted = true;
                }

                foreach (var item in toAdd)
                {
                    int?taxId      = item.TaxID;
                    int?warrantyId = item.WarrantyID;
                    int productId  = item.ProductId;
                    item.DateCreated = DateTime.UtcNow;
                    item.CreatedBy   = userId;
                    item.TenentId    = tenantId;
                    item.OrderID     = order.OrderID;
                    total            = total + item.TotalAmount;
                    item.TenentId    = tenantId;
                    item.WarehouseId = warehouseId;
                    item.IsDeleted   = null;

                    if (item.WarrantyID > 0)
                    {
                        bool warrantyTypePercent = false;
                        var  warranty            = _currentDbContext.TenantWarranty.AsNoTracking().FirstOrDefault(x => x.WarrantyID == item.WarrantyID);
                        if (warranty != null)
                        {
                            warrantyTypePercent = warranty.IsPercent;
                        }
                        if (warrantyTypePercent)
                        {
                            item.WarrantyAmount = (item.TotalAmount / 100) * item.Warranty.PercentageOfPrice;
                        }
                        else
                        {
                            item.WarrantyAmount = item.Warranty.FixedPrice;
                        }
                    }

                    // fix navigation issue
                    item.ProductMaster = null;
                    item.TaxName       = null;
                    item.Warranty      = null;

                    item.ProductId  = productId;
                    item.TaxID      = taxId;
                    item.WarrantyID = warrantyId;

                    if (item.OrderDetailID > 0)
                    {
                        _currentDbContext.Entry(item).State = EntityState.Modified;
                    }
                    else
                    {
                        _currentDbContext.OrderDetail.Add(item);
                    }

                    _currentDbContext.SaveChanges();
                }

                foreach (var item in cItems)
                {
                    var orderDetail = _currentDbContext.OrderDetail.Find(item.OrderDetailID);

                    orderDetail.ProductId      = item.ProductId;
                    orderDetail.ExpectedDate   = item.ExpectedDate;
                    orderDetail.Qty            = item.Qty;
                    orderDetail.Price          = item.Price;
                    orderDetail.WarrantyID     = item.WarrantyID;
                    orderDetail.TaxID          = item.TaxID;
                    orderDetail.Notes          = item.Notes;
                    orderDetail.TaxAmount      = item.TaxAmount;
                    orderDetail.TotalAmount    = item.TotalAmount;
                    orderDetail.WarrantyAmount = item.WarrantyAmount;

                    _currentDbContext.Entry(orderDetail).State = EntityState.Modified;
                    total = total + item.TotalAmount;
                }

                _currentDbContext.SaveChanges();
            }

            else
            {
                foreach (var item in _currentDbContext.OrderDetail.Where(a => a.OrderID == order.OrderID && a.IsDeleted != true))
                {
                    item.IsDeleted = true;
                }
            }
            if (orderNotes != null)
            {
                if (orderNotes.Count == 0)
                {
                    var cItems = _currentDbContext.OrderNotes.Where(a => a.OrderID == order.OrderID && a.IsDeleted != true && a.TenantId == tenantId).ToList();
                    cItems.ForEach(m =>
                    {
                        m.DateUpdated = DateTime.UtcNow;
                        m.UpdatedBy   = userId;
                        m.IsDeleted   = true;
                    });
                }
                else
                {
                    orderNotes.Where(a => a.OrderNoteId < 0).ToList().ForEach(m =>
                    {
                        m.DateCreated = DateTime.UtcNow;
                        m.CreatedBy   = userId;
                        m.TenantId    = tenantId;
                        m.OrderID     = order.OrderID;
                        _currentDbContext.OrderNotes.Add(m);
                        _currentDbContext.SaveChanges();
                    });
                }
            }
            order.OrderTotal = total;

            if (shipmentAndRecipientInfo.AddAddressToAccount == true && shipmentAndRecipientInfo.ShipmentAddressLine1 != null && order.AccountID > 0 && (!order.ShipmentAccountAddressId.HasValue || order.ShipmentAccountAddressId < 1))
            {
                var account        = _accountServices.GetAccountsById(order.AccountID.Value);
                var accountAddress = new AccountAddresses()
                {
                    AccountID       = order.AccountID.Value,
                    AddressLine1    = shipmentAndRecipientInfo.ShipmentAddressLine1,
                    AddressLine2    = shipmentAndRecipientInfo.ShipmentAddressLine2,
                    AddressLine3    = shipmentAndRecipientInfo.ShipmentAddressLine3,
                    Town            = shipmentAndRecipientInfo.ShipmentAddressLine4,
                    PostCode        = shipmentAndRecipientInfo.ShipmentAddressPostcode,
                    AddTypeShipping = true,
                    CountryID       = account.CountryID,
                    CreatedBy       = userId,
                    DateCreated     = DateTime.UtcNow,
                    IsActive        = true,
                    Name            = account.CompanyName
                };
                _currentDbContext.AccountAddresses.Add(accountAddress);
            }

            var obj = _currentDbContext.Order.Find(order.OrderID);

            if (obj != null)
            {
                _currentDbContext.Entry(obj).State = System.Data.Entity.EntityState.Detached;
                order.CreatedBy   = obj.CreatedBy;
                order.DateCreated = obj.DateCreated;
                //order.OrderStatusID = obj.OrderStatusID;
                order.TenentId    = obj.TenentId;
                order.WarehouseId = obj.WarehouseId;
                if (order.ShipmentAccountAddressId < 1)
                {
                    order.ShipmentAccountAddressId = (int?)null;
                }
                order.InventoryTransactionTypeId = obj.InventoryTransactionTypeId;
                obj.OrderNumber = order.OrderNumber.Trim();
                obj.DateUpdated = DateTime.UtcNow;
                obj.UpdatedBy   = userId;
                obj.WarehouseId = warehouseId;
                if (order.ConsignmentTypeId == 4)
                {
                    order.ShipmentAddressLine1     = _currentDbContext.ConsignmentTypes.FirstOrDefault(u => u.ConsignmentTypeId == 4)?.ConsignmentType;
                    order.ShipmentAddressLine2     = null;
                    order.ShipmentAddressLine3     = null;
                    order.ShipmentAddressLine4     = null;
                    order.ShipmentAddressPostcode  = null;
                    order.ShipmentAccountAddressId = (int?)null;
                }

                #region SendEmailWithAttachment
                if (shipmentAndRecipientInfo.SendEmailWithAttachment)
                {
                    List <OrderPTenantEmailRecipient> accountids = _currentDbContext.OrderPTenantEmailRecipients.Where(a => a.OrderId == order.OrderID && a.IsDeleted != false).ToList();

                    if (accountids.Count > 0)
                    {
                        accountids.ForEach(u => u.IsDeleted = true);
                    }

                    if (shipmentAndRecipientInfo.AccountEmailContacts != null && shipmentAndRecipientInfo.AccountEmailContacts.Length > 0)
                    {
                        foreach (var item in shipmentAndRecipientInfo.AccountEmailContacts)
                        {
                            string email           = "";
                            var    secondryAddress = _currentDbContext.AccountContacts.Where(u => u.AccountContactId == item).AsNoTracking().FirstOrDefault();
                            if (secondryAddress != null)
                            {
                                email = secondryAddress.ContactEmail;
                            }

                            var recipient = new OrderPTenantEmailRecipient()
                            {
                                OrderId          = order.OrderID,
                                EmailAddress     = email,
                                AccountContactId = item,
                                UpdatedBy        = userId,
                                DateUpdated      = DateTime.UtcNow,
                            };
                            _currentDbContext.OrderPTenantEmailRecipients.Add(recipient);
                        }
                    }
                }
                else
                {
                    List <OrderPTenantEmailRecipient> accountids = _currentDbContext.OrderPTenantEmailRecipients.Where(a => a.OrderId == order.OrderID && a.IsDeleted != false).ToList();

                    if (accountids.Count > 0)
                    {
                        accountids.ForEach(u => u.IsDeleted = true);
                    }
                }

                #endregion

                _currentDbContext.Order.Attach(order);
                _currentDbContext.Entry(order).State = EntityState.Modified;
            }

            _currentDbContext.SaveChanges();
            Inventory.StockRecalculateByOrderId(order.OrderID, warehouseId, tenantId, caCurrent.CurrentUser().UserId);
            return(obj);
        }
示例#6
0
 public ActionResult EditAccountAddress(AccountAddresses model)
 {
     return(RedirectToAction("Edit", new { id = Session["account"] }));
 }
示例#7
0
        public void _SaveAddresses(AccountAddresses address)
        {
            var lst = Session["addresses"] as List <AccountAddresses>;

            lst.Add(address);
        }