Example #1
0
        public ActionResult SetCustomer(int id, int value)
        {
            var entity = SalesQuote.Find(id);
            var item   = Customer.TryFind(value);

            if (entity.IsCompleted || entity.IsCancelled)
            {
                Response.StatusCode = 400;
                return(Content(Resources.ItemAlreadyCompletedOrCancelled));
            }

            if (item != null)
            {
                entity.Customer = item;
                entity.Contact  = null;
                entity.ShipTo   = null;

                if (item.SalesPerson == null)
                {
                    entity.SalesPerson = CurrentUser.Employee;
                }
                else
                {
                    entity.SalesPerson = item.SalesPerson;
                }

                if (entity.Terms == PaymentTerms.NetD && !entity.Customer.HasCredit)
                {
                    entity.Terms = PaymentTerms.Immediate;
                }

                switch (entity.Terms)
                {
                case PaymentTerms.Immediate:
                    entity.DueDate = entity.Date;
                    break;

                case PaymentTerms.NetD:
                    entity.DueDate = entity.Date.AddDays(entity.Customer.CreditDays);
                    break;
                }

                entity.Updater          = CurrentUser.Employee;
                entity.ModificationTime = DateTime.Now;

                using (var scope = new TransactionScope()) {
                    entity.UpdateAndFlush();
                }
            }

            return(Json(new {
                id = id,
                value = entity.FormattedValueFor(x => x.Customer),
                terms = entity.Terms,
                termsText = entity.Terms.GetDisplayName(),
                dueDate = entity.FormattedValueFor(x => x.DueDate),
                salesPerson = entity.SalesPerson.Id,
                salesPersonName = entity.SalesPerson.Name
            }));
        }
Example #2
0
        public ActionResult SetDate(int id, DateTime?value)
        {
            var entity = SalesQuote.Find(id);

            if (entity.IsCompleted || entity.IsCancelled)
            {
                Response.StatusCode = 400;
                return(Content(Resources.ItemAlreadyCompletedOrCancelled));
            }

            if (value != null)
            {
                entity.Date             = value.Value;
                entity.Updater          = CurrentUser.Employee;
                entity.ModificationTime = DateTime.Now;

                using (var scope = new TransactionScope()) {
                    entity.UpdateAndFlush();
                }
            }

            return(Json(new {
                id = id,
                value = entity.FormattedValueFor(x => x.Date)
            }));
        }
Example #3
0
        public ActionResult SetShipTo(int id, int value)
        {
            var entity = SalesQuote.Find(id);
            var item   = Address.TryFind(value);

            if (entity.IsCompleted || entity.IsCancelled)
            {
                Response.StatusCode = 400;
                return(Content(Resources.ItemAlreadyCompletedOrCancelled));
            }

            if (item != null)
            {
                entity.ShipTo           = item;
                entity.Updater          = CurrentUser.Employee;
                entity.ModificationTime = DateTime.Now;

                using (var scope = new TransactionScope()) {
                    entity.UpdateAndFlush();
                }
            }

            return(Json(new {
                id = id,
                value = entity.ShipTo.ToString()
            }));
        }
Example #4
0
        public ActionResult Pdf(int id)
        {
            var model = SalesQuote.Find(id);

            if (model.IsCompleted == true || model.IsCancelled == true)
            {
                return(PdfView("Print", model));
            }

            return(RedirectToAction("Edit", new { id = id }));
        }
Example #5
0
        public ActionResult View(int id)
        {
            var item = SalesQuote.Find(id);

            if (item.IsCancelled == true || item.IsCompleted == true)
            {
                return(View(item));
            }

            return(RedirectToAction("Edit", new { id = id }));
        }
Example #6
0
        public ActionResult SetTerms(int id, string value)
        {
            var          entity = SalesQuote.Find(id);
            PaymentTerms val;
            bool         success;

            if (entity.IsCompleted || entity.IsCancelled)
            {
                Response.StatusCode = 400;
                return(Content(Resources.ItemAlreadyCompletedOrCancelled));
            }

            success = Enum.TryParse <PaymentTerms> (value.Trim(), out val);

            if (success)
            {
                if (val == PaymentTerms.NetD && !entity.Customer.HasCredit)
                {
                    Response.StatusCode = 400;
                    return(Content(Resources.CreditLimitIsNotSet));
                }

                entity.Terms            = val;
                entity.Updater          = CurrentUser.Employee;
                entity.ModificationTime = DateTime.Now;

                switch (entity.Terms)
                {
                case PaymentTerms.Immediate:
                    entity.DueDate = entity.Date;
                    break;

                case PaymentTerms.NetD:
                    entity.DueDate = entity.Date.AddDays(entity.Customer.CreditDays);
                    break;
                }

                using (var scope = new TransactionScope()) {
                    entity.UpdateAndFlush();
                }
            }

            return(Json(new {
                id = id,
                value = entity.Terms,
                dueDate = entity.FormattedValueFor(x => x.DueDate),
                totalsChanged = success
            }));
        }
Example #7
0
        public ActionResult SetExchangeRate(int id, string value)
        {
            var     entity = SalesQuote.Find(id);
            bool    success;
            decimal val;

            if (entity.IsCompleted || entity.IsCancelled)
            {
                Response.StatusCode = 400;
                return(Content(Resources.ItemAlreadyCompletedOrCancelled));
            }

            success = decimal.TryParse(value.Trim(), out val);

            if (success)
            {
                if (entity.Currency == WebConfig.BaseCurrency)
                {
                    Response.StatusCode = 400;
                    return(Content(Resources.Message_InvalidBaseExchangeRate));
                }

                if (val <= 0m)
                {
                    Response.StatusCode = 400;
                    return(Content(Resources.Message_InvalidExchangeRate));
                }

                entity.ExchangeRate     = val;
                entity.Updater          = CurrentUser.Employee;
                entity.ModificationTime = DateTime.Now;

                using (var scope = new TransactionScope()) {
                    foreach (var item in entity.Details)
                    {
                        item.ExchangeRate = val;
                        item.Update();
                    }

                    entity.UpdateAndFlush();
                }
            }

            return(Json(new {
                id = entity.Id,
                value = entity.FormattedValueFor(x => x.ExchangeRate),
                itemsChanged = success
            }));
        }
Example #8
0
        public ActionResult Edit(int id)
        {
            var item = SalesQuote.Find(id);

            if (item.IsCompleted || item.IsCancelled)
            {
                return(RedirectToAction("View", new {
                    id = item.Id
                }));
            }

            if (!CashHelpers.ValidateExchangeRate())
            {
                return(View("InvalidExchangeRate"));
            }

            return(View(item));
        }
Example #9
0
        public ActionResult SendEmail(int id, string email)
        {
            var model       = SalesQuote.Find(id);
            var filename    = string.Format(Resources.SalesQuoteFilenameFormatString, model.Id, model.Serial);
            var subject     = string.Format(Resources.SalesQuoteEmailSubjectFormatString, WebConfig.Company, model.Serial);
            var message     = string.Format(Resources.SalesQuoteEmailBodyFormatString, model.Id, model.SalesPerson.Name);
            var attachments = new List <MimePart> ();

            attachments.Add(new MimePart {
                Content                 = new MimeContent(GetPdf("Print", model), ContentEncoding.Default),
                ContentDisposition      = new ContentDisposition(ContentDisposition.Attachment),
                ContentTransferEncoding = ContentEncoding.Base64,
                FileName                = filename + ".pdf"
            });

            SendEmailWithAttachments(WebConfig.DefaultSender, email, subject, message, attachments);

            return(PartialView("_SendEmailSuccesful"));
        }
Example #10
0
        public ActionResult Cancel(int id)
        {
            var entity = SalesQuote.Find(id);

            if (entity.IsCancelled)
            {
                return(RedirectToAction("Index"));
            }

            entity.Updater          = CurrentUser.Employee;
            entity.ModificationTime = DateTime.Now;
            entity.IsCancelled      = true;

            using (var scope = new TransactionScope()) {
                entity.UpdateAndFlush();
            }

            return(RedirectToAction("Index"));
        }
Example #11
0
        public ActionResult SetComment(int id, string value)
        {
            var    entity = SalesQuote.Find(id);
            string val    = (value ?? string.Empty).Trim();

            if (entity.IsCompleted || entity.IsCancelled)
            {
                Response.StatusCode = 400;
                return(Content(Resources.ItemAlreadyCompletedOrCancelled));
            }

            entity.Comment          = (value.Length == 0) ? null : val;
            entity.Updater          = CurrentUser.Employee;
            entity.ModificationTime = DateTime.Now;

            using (var scope = new TransactionScope()) {
                entity.UpdateAndFlush();
            }

            return(Json(new {
                id = id,
                value = entity.Comment
            }));
        }
Example #12
0
        public ActionResult SendEmail(int id)
        {
            var model = SalesQuote.Find(id);

            return(PartialView("_SendEmail", model));
        }
Example #13
0
        public ActionResult Totals(int id)
        {
            var entity = SalesQuote.Find(id);

            return(PartialView("_Totals", entity));
        }
Example #14
0
        public ActionResult Items(int id)
        {
            var entity = SalesQuote.Find(id);

            return(PartialView("_Items", entity.Details));
        }
Example #15
0
        public ViewResult Print(int id)
        {
            var model = SalesQuote.Find(id);

            return(View(model));
        }
Example #16
0
        public ActionResult CreateFromSalesQuote(int id)
        {
            var dt         = DateTime.Now;
            var item       = new SalesOrder();
            var salesquote = SalesQuote.Find(id);

            item.PointOfSale = WebConfig.PointOfSale;

            if (item.PointOfSale == null)
            {
                return(View("InvalidPointOfSale"));
            }

            if (!CashHelpers.ValidateExchangeRate())
            {
                return(View("InvalidExchangeRate"));
            }

            if (salesquote.IsCancelled || !salesquote.IsCompleted)
            {
                return(RedirectToAction("Index", "Quotations"));
            }

            // Store and Serial
            item.Store = item.PointOfSale.Store;

            try {
                item.Serial = (from x in SalesOrder.Queryable
                               where x.Store.Id == item.Store.Id
                               select x.Serial).Max() + 1;
            } catch {
                item.Serial = 1;
            }

            item.Customer       = salesquote.Customer;
            item.SalesPerson    = salesquote.SalesPerson;
            item.Date           = dt;
            item.PromiseDate    = dt;
            item.Terms          = salesquote.Terms;
            item.DueDate        = dt.AddDays(item.Customer.CreditDays);
            item.Currency       = salesquote.Currency;
            item.ExchangeRate   = salesquote.ExchangeRate;
            item.Contact        = salesquote.Contact;
            item.Comment        = salesquote.Comment;
            item.ShipTo         = salesquote.ShipTo;
            item.CustomerShipTo = salesquote.ShipTo == null ? "" : salesquote.ShipTo.ToString();

            item.Creator          = CurrentUser.Employee;
            item.CreationTime     = dt;
            item.Updater          = item.Creator;
            item.ModificationTime = dt;

            var details = salesquote.Details.Select(x => new SalesOrderDetail {
                Currency      = x.Currency,
                ExchangeRate  = x.ExchangeRate,
                IsTaxIncluded = x.IsTaxIncluded,
                Price         = x.Price,
                Product       = x.Product,
                ProductCode   = x.ProductCode,
                ProductName   = x.ProductName,
                Quantity      = x.Quantity,
                SalesOrder    = item,
                TaxRate       = x.TaxRate,
                Warehouse     = item.PointOfSale.Warehouse,
                Comment       = x.Comment,
                DiscountRate  = x.DiscountRate
            }).ToList();


            using (var scope = new TransactionScope()) {
                item.CreateAndFlush();
                details.ForEach(x => x.CreateAndFlush());
            }


            return(RedirectToAction("Edit", new {
                id = item.Id
            }));
        }