Exemplo n.º 1
0
        public ActionResult EditPurchaseOrderDetail(PurchaseOrderDetailModel purchaseOrderDetail)
        {
            if (Session["UserLogon"] != null)
            {
                purchaseOrderDetail.Account = (AccountModel)Session["UserLogon"];
            }
            PurchaseOrderDetailResponse _purchaseorderdetailresponse = new PurchaseOrderDetailResponse();
            var purchaserequestdetailrequest = new PurchaseOrderDetailRequest
            {
                Data = purchaseOrderDetail
            };
            var requestnamabarang = new ProductRequest
            {
                Data = new ProductModel
                {
                    Id = Convert.ToInt32(purchaseOrderDetail.ProductId)
                }
            };

            ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);

            purchaserequestdetailrequest.Data.namabarang = purchaserequestdetailrequest.Data.namabarang != null ? purchaserequestdetailrequest.Data.namabarang : namabarang.Entity.Name;
            new PurchaseOrderDetailValidator(_unitOfWork).Validate(purchaserequestdetailrequest, out _purchaseorderdetailresponse);
            return(Json(new { data = _purchaseorderdetailresponse.Entity }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public void Create(PurchaseRequestResponse _response)
        {
            var searchPredicate = PredicateBuilder.New <PurchaseOrder>(true);

            var purchaseorderrequest = new PurchaseOrderRequest
            {
                Data = Mapper.Map <PurchaseRequestModel, PurchaseOrderModel>(_response.Entity)
            };

            purchaseorderrequest.Data.approve           = null;
            purchaseorderrequest.Data.podate            = DateTime.Now;
            purchaseorderrequest.Data.Validasi          = null;
            purchaseorderrequest.Data.approveby         = null;
            purchaseorderrequest.Data.PurchaseRequestId = Convert.ToInt32(_response.Entity.Id);
            purchaseorderrequest.Data.Id = 0;

            var      lastponumber = _unitOfWork.PurchaseOrderRepository.Get(searchPredicate, orderBy: a => a.OrderByDescending(x => x.CreatedDate)).Select(a => a.ponumber).FirstOrDefault();
            DateTime?getmonth     = _unitOfWork.PurchaseOrderRepository.Get(searchPredicate, orderBy: a => a.OrderByDescending(x => x.CreatedDate)).Select(a => a.podate).FirstOrDefault();
            DateTime?month        = getmonth != null ? getmonth : DateTime.Now;
            string   ponumber     = lastponumber != null?GeneralHandler.stringincrement(lastponumber, Convert.ToDateTime(month)) : "00001";

            purchaseorderrequest.Data.ponumber = "PO" + _response.Entity.Account.Organization + DateTime.Now.Year + DateTime.Now.Month + ponumber;
            purchaseorderrequest.Data.Account  = _response.Entity.Account;

            PurchaseOrderResponse purchaseorderresponse = new PurchaseOrderResponse();

            new PurchaseOrderValidator(_unitOfWork).Validate(purchaseorderrequest, out purchaseorderresponse);

            if (_response.Entity.purchaserequestdetailModels != null)
            {
                int i = 0;
                foreach (var item in _response.Entity.purchaserequestdetailModels)
                {
                    var purchaseorderdetailrequest = new PurchaseOrderDetailRequest
                    {
                        Data = Mapper.Map <PurchaseRequestDetailModel, PurchaseOrderDetailModel>(item)
                    };
                    purchaseorderdetailrequest.Data.PurchaseOrderId = Convert.ToInt32(purchaseorderresponse.Entity.Id);
                    purchaseorderdetailrequest.Data.Account         = _response.Entity.Account;
                    purchaseorderdetailrequest.Data.Id = 0;
                    //
                    var requestnamabarang = new ProductRequest
                    {
                        Data = new ProductModel
                        {
                            Id = Convert.ToInt32(item.ProductId)
                        }
                    };

                    ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);
                    purchaseorderdetailrequest.Data.namabarang = namabarang.Entity.Name;
                    PurchaseOrderDetailResponse _purchaseorderdetailresponse = new PurchaseOrderDetailResponse();
                    new PurchaseOrderDetailValidator(_unitOfWork).Validate(purchaseorderdetailrequest, out _purchaseorderdetailresponse);
                    i++;
                }
            }
        }
Exemplo n.º 3
0
        public JsonResult CreateOrEditPurchaseOrder(PurchaseOrderModel _purchaseorder, List <PurchaseOrderDetailModel> purchaseOrderDetailModels)
        {
            if (Session["UserLogon"] != null)
            {
                _purchaseorder.Account = (AccountModel)Session["UserLogon"];
            }
            _purchaseorder.Id = Convert.ToInt32(_purchaseorder.Id) > 0 ? _purchaseorder.Id : 0;
            var request = new PurchaseOrderRequest
            {
                Data = _purchaseorder
            };

            PurchaseOrderResponse _response = new PurchaseOrderResponse();

            new PurchaseOrderValidator(_unitOfWork).Validate(request, out _response);
            if (purchaseOrderDetailModels != null)
            {
                int i = 0;
                foreach (var item in purchaseOrderDetailModels)
                {
                    item.OrderNumber = i + 1;
                    var purchaseorderdetailrequest = new PurchaseOrderDetailRequest
                    {
                        Data = item
                    };
                    purchaseorderdetailrequest.Data.PurchaseOrderId = Convert.ToInt32(_response.Entity.Id);
                    purchaseorderdetailrequest.Data.Account         = (AccountModel)Session["UserLogon"];
                    //
                    var requestnamabarang = new ProductRequest
                    {
                        Data = new ProductModel
                        {
                            Id = item.ProductId
                        }
                    };

                    ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);
                    purchaseorderdetailrequest.Data.namabarang = namabarang.Entity.Name;
                    PurchaseOrderDetailResponse _purchaseorderdetailresponse = new PurchaseOrderDetailResponse();
                    new PurchaseOrderDetailValidator(_unitOfWork).Validate(purchaseorderdetailrequest, out _purchaseorderdetailresponse);
                    i++;
                }
            }
            return(Json(new { data = _response.Data }, JsonRequestBehavior.AllowGet));
        }
        public void Validate(PurchaseOrderDetailRequest request, out PurchaseOrderDetailResponse response)
        {
            response = new PurchaseOrderDetailResponse();

            if (request.Action != null && request.Action.Equals(ClinicEnums.Action.DELETE.ToString()))
            {
                ValidateForDelete(request, out response);
            }
            else
            {
                bool isHavePrivilege = true;

                if (request.Data.namabarang == null || String.IsNullOrWhiteSpace(request.Data.namabarang))
                {
                    errorFields.Add("namabarang");
                }

                if (errorFields.Any())
                {
                    response.Status  = false;
                    response.Message = string.Format(Messages.ValidationErrorFields, String.Join(",", errorFields));
                }

                if (request.Data.Id == 0)
                {
                    isHavePrivilege = IsHaveAuthorization(ADD_M_PURCHASEORDER, request.Data.Account.Privileges.PrivilegeIDs);
                }
                else
                {
                    isHavePrivilege = IsHaveAuthorization(EDIT_M_PURCHASEORDER, request.Data.Account.Privileges.PrivilegeIDs);
                }

                if (!isHavePrivilege)
                {
                    response.Status  = false;
                    response.Message = Messages.UnauthorizedAccess;
                }

                if (response.Status)
                {
                    response = new PurchaseOrderDetailHandler(_unitOfWork).CreateOrEdit(request);
                }
            }
        }
        private void ValidateForDelete(PurchaseOrderDetailRequest request, out PurchaseOrderDetailResponse response)
        {
            response = new PurchaseOrderDetailResponse();

            if (request.Action == ClinicEnums.Action.DELETE.ToString())
            {
                bool isHavePrivilege = IsHaveAuthorization(DELETE_M_PURCHASEORDER, request.Data.Account.Privileges.PrivilegeIDs);
                if (!isHavePrivilege)
                {
                    response.Status  = false;
                    response.Message = Messages.UnauthorizedAccess;
                }
            }

            if (response.Status)
            {
                //response = new DeliveryOrderHandler(_unitOfWork).RemoveData(request);
            }
        }