public ActionResult Confirm(int id)
        {
            var  dt      = DateTime.Now;
            bool changed = false;
            var  entity  = CustomerRefund.Find(id);

            using (var scope = new TransactionScope()) {
                foreach (var item in entity.Details)
                {
                    var qty = GetRefundableQuantity(item.SalesOrderDetail.Id);

                    if (qty < item.Quantity)
                    {
                        changed = true;

                        if (qty > 0.0m)
                        {
                            item.Quantity = qty;
                            item.Update();
                        }
                        else
                        {
                            item.Delete();
                        }
                    }
                }

                if (changed)
                {
                    entity.Updater          = CurrentUser.Employee;
                    entity.ModificationTime = dt;
                    entity.UpdateAndFlush();

                    return(RedirectToAction("Edit", new { id = entity.Id, notify = true }));
                }
            }

            using (var scope = new TransactionScope()) {
                foreach (var detail in entity.Details.Where(x => !(x.Quantity > 0.0m)).ToList())
                {
                    detail.DeleteAndFlush();
                }

                foreach (var x in entity.Details)
                {
                    InventoryHelpers.ChangeNotification(TransactionType.CustomerRefund, entity.Id, dt,
                                                        x.SalesOrderDetail.Warehouse, null, x.Product, x.Quantity);
                }

                entity.Updater          = CurrentUser.Employee;
                entity.ModificationTime = dt;
                entity.Date             = dt;
                entity.IsCompleted      = true;
                entity.UpdateAndFlush();
            }

            return(RedirectToAction("View", new { id = entity.Id }));
        }
        public ActionResult Cancel(int id)
        {
            var entity = CustomerRefund.Find(id);

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

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

            return(RedirectToAction("Index"));
        }
        public ActionResult Totals(int id)
        {
            var item = CustomerRefund.Find(id);

            return(PartialView("_Totals", item));
        }
        public ActionResult Edit(int id)
        {
            var entity = CustomerRefund.Find(id);

            return(View(entity));
        }
        public ActionResult CreateFromSalesOrder(string value)
        {
            int        id     = 0;
            SalesOrder entity = null;

            if (int.TryParse(value, out id))
            {
                entity = SalesOrder.TryFind(id);
            }

            if (entity == null)
            {
                Response.StatusCode = 400;
                return(Content(Resources.SalesOrderNotFound));
            }

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

            if (entity.Store != WebConfig.Store)
            {
                Response.StatusCode = 400;
                return(Content(Resources.InvalidStore));
            }

            var item = new CustomerRefund();

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

            item.SalesOrder   = entity;
            item.SalesPerson  = entity.SalesPerson;
            item.Customer     = entity.Customer;
            item.Currency     = entity.Currency;
            item.ExchangeRate = entity.ExchangeRate;

            item.CreationTime     = DateTime.Now;
            item.Date             = DateTime.Now;
            item.Creator          = CurrentUser.Employee;
            item.Updater          = item.Creator;
            item.ModificationTime = item.CreationTime;

            foreach (var x in entity.Details)
            {
                var qty = GetRefundableQuantity(x.Id);

                if (qty <= 0)
                {
                    continue;
                }

                var detail = new CustomerRefundDetail {
                    Refund           = item,
                    SalesOrderDetail = x,
                    Product          = x.Product,
                    ProductCode      = x.ProductCode,
                    ProductName      = x.ProductName,
                    DiscountRate     = x.DiscountRate,
                    TaxRate          = x.TaxRate,
                    IsTaxIncluded    = x.IsTaxIncluded,
                    Quantity         = 0,
                    Price            = x.Price,
                    ExchangeRate     = x.ExchangeRate,
                    Currency         = x.Currency
                };

                item.Details.Add(detail);
            }

            if (item.Details.Count == 0)
            {
                Response.StatusCode = 400;
                return(Content(Resources.RefundableItemsNotFound));
            }

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

                foreach (var detail in item.Details)
                {
                    detail.Create();
                }
            }

            return(Json(new { url = Url.Action("Edit", new { id = item.Id }) }));
        }
        public ViewResult Print(int id)
        {
            var entity = CustomerRefund.Find(id);

            return(View(entity));
        }
Example #7
0
        public override Int64 Set(string parametersArr)
        {
            List <Foodics.NetSuite.Shared.Model.PaymentMethodEntity> lstitemsAll = new CustomDAO().SelectCustomerPayment(5).Take(2000).ToList();
            int Exe_length = 200;
            int lstend     = Exe_length;

            if (lstitemsAll.Count > 0)
            {
                for (int Index = 0; Index < lstitemsAll.Count; Index += Exe_length)
                {
                    if (Index + Exe_length >= lstitemsAll.Count)
                    {
                        lstend = lstitemsAll.Count - Index;
                    }
                    List <Foodics.NetSuite.Shared.Model.PaymentMethodEntity> returnList = lstitemsAll.GetRange(Index, lstend);
                    try
                    {
                        if (returnList.Count > 0)
                        {
                            CustomerRefund[] memoList = new CustomerRefund[returnList.Count];
                            for (int i = 0; i < returnList.Count; i++)
                            {
                                PaymentMethodEntity     invoiceReturn            = returnList[i];
                                CustomerRefund          memo                     = new CustomerRefund();
                                CustomerRefundApply[]   payApply                 = new CustomerRefundApply[1];
                                CustomerRefundApplyList AplyList                 = new CustomerRefundApplyList();
                                Foodics.NetSuite.Shared.Model.Invoice invoiceobj = new GenericeDAO <Foodics.NetSuite.Shared.Model.Invoice>().GetWhere(" Foodics_Id = '" + invoiceReturn.Foodics_Id + "'").FirstOrDefault();
                                Setting objSetting = new GenericeDAO <Setting>().GetWhere("Subsidiary_Netsuite_Id=" + invoiceobj.Subsidiary_Id).FirstOrDefault();
                                //Customer

                                RecordRef entity = new RecordRef();
                                entity.internalId = invoiceobj.Customer_Netsuite_Id > 0 ? invoiceobj.Customer_Netsuite_Id.ToString() : objSetting.Customer_Netsuite_Id.ToString();
                                entity.type       = RecordType.customer;
                                memo.customer     = entity;

                                //currency
                                RecordRef currency = new RecordRef();
                                currency.internalId = objSetting.Currency_Netsuite_Id.ToString();
                                currency.type       = RecordType.currency;
                                memo.currency       = currency;

                                //date
                                memo.tranDateSpecified = true;
                                memo.tranDate          = TimeZoneInfo.ConvertTimeToUtc(invoiceobj.Date, TimeZoneInfo.Local);

                                //exchange rate
                                memo.exchangeRate = invoiceobj.Exchange_Rate;

                                //subsidary
                                RecordRef subsid = new RecordRef();
                                subsid.internalId = invoiceobj.Subsidiary_Id.ToString();
                                subsid.type       = RecordType.subsidiary;
                                memo.subsidiary   = subsid;

                                //cp.location
                                RecordRef location = new RecordRef();
                                location.internalId = invoiceobj.Location_Id.ToString();
                                location.type       = RecordType.location;
                                memo.location       = location;

                                #region Apply Invoice
                                // Invoice
                                payApply[0]                 = new CustomerRefundApply();
                                payApply[0].apply           = true;
                                payApply[0].docSpecified    = true;
                                payApply[0].amountSpecified = true;
                                payApply[0].currency        = currency.internalId;
                                payApply[0].type            = "CreditMemo";
                                payApply[0].doc             = invoiceobj.Netsuite_Id;
                                payApply[0].total           = invoiceobj.Paid;
                                payApply[0].amount          = invoiceobj.Paid;
                                payApply[0].applyDate       = invoiceobj.Date;

                                AplyList.apply = payApply;
                                memo.applyList = AplyList;
                                #endregion

                                #region payment Method
                                RecordRef payment_method = new RecordRef();
                                payment_method.internalId = invoiceReturn.Payment_Method_Id.ToString();
                                payment_method.type       = RecordType.customerPayment;
                                memo.paymentMethod        = payment_method;
                                #endregion

                                memoList[i] = memo;
                            }


                            if (memoList.Length > 0)
                            {
                                WriteResponseList wr = Service(true).addList(memoList.ToArray());
                                bool result          = wr.status.isSuccess;
                                UpdatedLst(returnList, wr);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                    }
                }
            }
            return(0);
        }
        public ActionResult CreateFromSalesOrder(string value)
        {
            int id = 0;
            SalesOrder entity = null;

            if (int.TryParse (value, out id)) {
                entity = SalesOrder.TryFind (id);
            }

            if (entity == null) {
                Response.StatusCode = 400;
                return Content (Resources.SalesOrderNotFound);
            }

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

            if (entity.Store != WebConfig.Store) {
                Response.StatusCode = 400;
                return Content (Resources.InvalidStore);
            }

            var item = new CustomerRefund ();

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

            item.SalesOrder = entity;
            item.SalesPerson = entity.SalesPerson;
            item.Customer = entity.Customer;
            item.Currency = entity.Currency;
            item.ExchangeRate = entity.ExchangeRate;

            item.CreationTime = DateTime.Now;
            item.Creator = CurrentUser.Employee;
            item.Updater = item.Creator;
            item.ModificationTime = item.CreationTime;

            foreach (var x in entity.Details) {
                var qty = GetRefundableQuantity (x.Id);

                if (qty <= 0)
                    continue;

                var detail = new CustomerRefundDetail {
                    Refund = item,
                    SalesOrderDetail = x,
                    Product = x.Product,
                    ProductCode = x.ProductCode,
                    ProductName = x.ProductName,
                    Discount = x.Discount,
                    TaxRate = x.TaxRate,
                    IsTaxIncluded = x.IsTaxIncluded,
                    Quantity = qty,
                    Price = x.Price,
                    ExchangeRate = x.ExchangeRate,
                    Currency = x.Currency
                };

                item.Details.Add (detail);
            }

            if (item.Details.Count == 0) {
                Response.StatusCode = 400;
                return Content (Resources.RefundableItemsNotFound);
            }

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

                foreach (var detail in item.Details) {
                    detail.Create ();
                }
            }

            return Json (new { url = Url.Action ("Edit", new { id = item.Id }) });
        }