コード例 #1
0
ファイル: SalesOrdersController.cs プロジェクト: Monolite/mbe
        public ActionResult SetRecipient(int id, string value)
        {
            var    entity = SalesOrder.Find(id);
            string val    = (value ?? string.Empty).Trim();

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

            var item = entity.Customer.Taxpayers.Single(x => x.Id == val);

            entity.Recipient     = item.Id;
            entity.RecipientName = item.Name;

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

            return(Json(new {
                id = id,
                value = item.Name
            }));
        }
コード例 #2
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
        public ActionResult SetCustomerShipTo(int id, string value)
        {
            var    entity = SalesOrder.Find(id);
            string val    = (value ?? string.Empty).Trim();

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

            entity.CustomerShipTo   = string.IsNullOrEmpty(val) ? null : val;
            entity.Updater          = CurrentUser.Employee;
            entity.ModificationTime = DateTime.Now;

            if (string.IsNullOrEmpty(entity.CustomerShipTo))
            {
                foreach (var payment in entity.Payments)
                {
                    payment.Delete();
                }
            }

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

            return(Json(new { id = id, value = value }));
        }
コード例 #3
0
ファイル: SalesOrdersController.cs プロジェクト: Monolite/mbe
        public ActionResult SetShipTo(int id, int value)
        {
            var entity = SalesOrder.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.CustomerShipTo   = item.ToString();
                entity.Updater          = CurrentUser.Employee;
                entity.ModificationTime = DateTime.Now;

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

            return(Json(new {
                id = id,
                value = entity.ShipTo.ToString()
            }));
        }
コード例 #4
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
        public ActionResult Cancel(int id)
        {
            var entity = SalesOrder.Find(id);

            if (!entity.IsCompleted || entity.IsCancelled || entity.IsPaid)
            {
                return(RedirectToAction("Index"));
            }

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

            using (var scope = new TransactionScope()) {
                foreach (var item in entity.Payments)
                {
                    var payment = PaymentOnDelivery.Find(item.Id);
                    if (payment != null)
                    {
                        payment.DeleteAndFlush();
                    }
                    item.Delete();
                }

                entity.UpdateAndFlush();
            }

            return(RedirectToAction("Index"));
        }
コード例 #5
0
ファイル: SalesOrdersController.cs プロジェクト: Monolite/mbe
        public ActionResult SetPromiseDate(int id, DateTime?value)
        {
            var entity = SalesOrder.Find(id);

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

            if (value != null)
            {
                entity.PromiseDate      = 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.PromiseDate)
            }));
        }
コード例 #6
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
        public ActionResult GetSalesOrderBalance(int id)
        {
            var item = SalesOrder.Find(id);

            item.Details.ToList();
            item.Payments.ToList();

            return(PartialView("_SalesOrderBalance", item));
        }
コード例 #7
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
        public ActionResult Print(int id)
        {
            var model = SalesOrder.Find(id);

            if (model.IsPaid)
            {
                return(PdfTicketView("Print", model));
            }
            return(RedirectToAction("Index"));
        }
コード例 #8
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
        public ActionResult PrintDeliveryTicket(int id)
        {
            var model = SalesOrder.Find(id);

            if (model.IsPaid && model.ShipTo == null)
            {
                return(PdfTicketView("DeliveryTicket", model));
            }
            return(RedirectToAction("Index"));
        }
コード例 #9
0
        public ActionResult Confirm(int id)
        {
            var item = SalesOrder.Find(id);

            item.Updater          = CurrentUser.Employee;
            item.ModificationTime = DateTime.Now;
            item.IsDelivered      = true;

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

            return(RedirectToAction("Index"));
        }
コード例 #10
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
        public ActionResult ConfirmPayment(int id)
        {
            var item = SalesOrder.Find(id);

            item.IsPaid           = true;
            item.ModificationTime = DateTime.Now;
            item.Updater          = CurrentUser.Employee;

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

            return(PartialView("_DetailsView", item));
        }
コード例 #11
0
        public ActionResult SetExchangeRate(int id, string value)
        {
            var     entity = SalesOrder.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
            }));
        }
コード例 #12
0
ファイル: SalesOrdersController.cs プロジェクト: Monolite/mbe
        public ActionResult SetTerms(int id, string value)
        {
            bool         success;
            PaymentTerms val;
            var          entity = SalesOrder.Find(id);

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

            success = Enum.TryParse(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
            }));
        }
コード例 #13
0
ファイル: SalesOrdersController.cs プロジェクト: Monolite/mbe
        public ActionResult Edit(int id)
        {
            var item = SalesOrder.Find(id);

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

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

            return(View(item));
        }
コード例 #14
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
        public ActionResult PayOrder(int id)
        {
            var drawer  = WebConfig.CashDrawer;
            var session = GetSession();

            if (drawer == null)
            {
                return(View("InvalidCashDrawer"));
            }

            if (session == null)
            {
                return(RedirectToAction("OpenSession"));
            }

            var item = SalesOrder.Find(id);

            return(View(item));
        }
コード例 #15
0
ファイル: SalesOrdersController.cs プロジェクト: Monolite/mbe
        public ActionResult Cancel(int id)
        {
            var entity = SalesOrder.Find(id);

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

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

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

            return(RedirectToAction("Index"));
        }
コード例 #16
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
        public ActionResult SetCustomer(int id, int value)
        {
            var entity   = SalesOrder.Find(id);
            var customer = Customer.TryFind(value);

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

            if (customer == null)
            {
                Response.StatusCode = 400;
                return(Content(Resources.CustomerNotFound));
            }

            foreach (var payment in entity.Payments)
            {
                payment.Delete();
            }

            if (entity.Customer.Id != WebConfig.DefaultCustomer)
            {
                entity.CustomerName = string.Empty;
            }

            entity.ShipTo           = null;
            entity.CustomerShipTo   = null;
            entity.Customer         = customer;
            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)
            }));
        }
コード例 #17
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
        public ActionResult SetCustomerName(int id, string value)
        {
            var    entity = SalesOrder.Find(id);
            string val    = (value ?? string.Empty).Trim();

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

            entity.CustomerName     = (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 = value }));
        }
コード例 #18
0
        public ViewResult Print(int id)
        {
            var item = SalesOrder.Find(id);

            return(View(item));
        }
コード例 #19
0
ファイル: POSController.cs プロジェクト: mictlanix/mbe
        public override ActionResult Pdf(int id)
        {
            var model = SalesOrder.Find(id);

            return(PdfTicketView("Print", model));
        }
コード例 #20
0
ファイル: SalesOrdersController.cs プロジェクト: Monolite/mbe
        public ActionResult Totals(int id)
        {
            var entity = SalesOrder.Find(id);

            return(PartialView("_Totals", entity));
        }
コード例 #21
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
        public ActionResult GetPayments(int id)
        {
            var item = SalesOrder.Find(id);

            return(PartialView("_Payments", item));
        }
コード例 #22
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
        public JsonResult AddPayment(int id, int type, decimal amount, string reference, int?fee, bool ondelivery)
        {
            var dt          = DateTime.Now;
            var session     = GetSession();
            var store       = session.CashDrawer.Store;
            var sales_order = SalesOrder.Find(id);
            var employee    = CurrentUser.Employee;
            var item        = new SalesOrderPayment {
                SalesOrder = sales_order,
                Payment    = new CustomerPayment {
                    Creator          = employee,
                    CreationTime     = dt,
                    Updater          = employee,
                    ModificationTime = dt,
                    CashSession      = session,
                    /* SalesOrder = sales_order, */
                    Customer  = sales_order.Customer,
                    Method    = (PaymentMethod)type,
                    Amount    = amount,
                    Date      = DateTime.Now,
                    Reference = reference,
                    Currency  = sales_order.Currency
                },
                Amount = amount
            };

            if (fee.HasValue)
            {
                item.Payment.ExtraFee   = PaymentMethodOption.Find(fee.Value);
                item.Payment.Commission = item.Payment.ExtraFee.CommissionByManage;
            }

            // Store and Serial

            item.Payment.Store = store;

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

            if (item.Amount > item.SalesOrder.Balance)
            {
                if (item.Payment.Method == PaymentMethod.Cash)
                {
                    item.Change = item.Amount - item.SalesOrder.Balance;
                }
                else
                {
                    item.Payment.Amount = item.SalesOrder.Balance;
                }

                item.Amount = item.SalesOrder.Balance;
            }

            if (ondelivery && !string.IsNullOrEmpty(sales_order.CustomerShipTo))
            {
                item.Payment.CashSession = null;
            }

            using (var scope = new TransactionScope()) {
                item.Payment.Create();
                item.CreateAndFlush();
            }

            return(Json(new {
                id = item.Id
            }));
        }
コード例 #23
0
ファイル: SalesOrdersController.cs プロジェクト: Monolite/mbe
        public ViewResult Print(int id)
        {
            var model = SalesOrder.Find(id);

            return(View(model));
        }
コード例 #24
0
ファイル: SalesOrdersController.cs プロジェクト: Monolite/mbe
        public virtual ActionResult Pdf(int id)
        {
            var model = SalesOrder.Find(id);

            return(PdfView("Print", model));
        }
コード例 #25
0
ファイル: SalesOrdersController.cs プロジェクト: Monolite/mbe
        public ActionResult Items(int id)
        {
            var entity = SalesOrder.Find(id);

            return(PartialView("_Items", entity.Details));
        }
コード例 #26
0
ファイル: PaymentsController.cs プロジェクト: Monolite/mbe
 public ActionResult GetCustomerName(int id)
 {
     return(PartialView("_CustomerName", SalesOrder.Find(id)));
 }
コード例 #27
0
ファイル: SalesOrdersController.cs プロジェクト: Monolite/mbe
        public ActionResult SetCustomer(int id, int value)
        {
            var entity = SalesOrder.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;
                entity.CustomerShipTo = null;
                entity.CustomerName   = 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;
                entity.Recipient        = string.Empty;
                entity.RecipientName    = string.Empty;
                entity.RecipientAddress = null;

                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
            }));
        }