public void Save(PurchaseOrderViewModel model)
        {
            var order = _orderMainRepository.GetById(model.Id);
            if(order==null)
            {

                var costcenter = _costCentreRepository.GetById(model.DistributorId);
                if(costcenter==null)
                    throw new Exception("Invalid Distributor ");
                var user = _userRepository.GetByCostCentre(model.DistributorId).FirstOrDefault();
                if (user == null)
                    throw new Exception("Distributor requires atleast one user");
               
                var date = DateTime.Now;
                string referenceNo = "PO_" + costcenter.Name + "_" + date.ToString("yyyyMMdd") + "_" + date.ToString("hhmmss");
               
                order = _mainOrderFactory.Create(costcenter, Guid.Empty, costcenter, user, costcenter,
                                                 OrderType.DistributorToProducer, referenceNo, model.Id, "",
                                                 model.RequiredDate, 0, "");
                 foreach (var item in model.Items)
                {
                    var lineitem = _mainOrderFactory.CreateLineItem(item.ProductId, item.Quantity, item.UnitPrice, "", 0);
                    order.AddLineItem(lineitem);
                }
                order.Status=DocumentStatus.Confirmed;
                order.Confirm();
                foreach (var item in order.PendingConfirmationLineItems)
                {
                    order.ApprovePLineItem(item);
                }
                order.ApproveP();
                _purchaseOrderWorkflow.Submit(order);
            }

        }
예제 #2
0
        public JsonResult SavePurchaseOrder(PurchaseOrderViewModel model)
        {
            ResponseBasic response= new ResponseBasic();
            try
            {
                var user = this.User.Identity.Name;
                model.Username = user;
                _purchaseOrderViewModelBuilder.Save(model);
                response.Result = "Ok";
                response.ResultInfo = "Purchase order saved and approved successfully";
            }catch(Exception ex)
            {
                response.Result = "Fail";
                response.ErrorInfo = ex.Message;

            }
            return Json(response, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet);
            
        }