Exemple #1
0
        public void Create(PurchaseRequestPusatResponse _response)
        {
            var searchPredicate = PredicateBuilder.New <PurchaseOrderPusat>(true);

            var purchaseorderpusatrequest = new PurchaseOrderPusatRequest
            {
                Data = Mapper.Map <PurchaseRequestPusatModel, PurchaseOrderPusatModel>(_response.Entity)
            };

            purchaseorderpusatrequest.Data.approve           = 1;
            purchaseorderpusatrequest.Data.podate            = DateTime.Now;
            purchaseorderpusatrequest.Data.Validasi          = null;
            purchaseorderpusatrequest.Data.approve_by        = OneLoginSession.Account.UserCode;
            purchaseorderpusatrequest.Data.PurchaseRequestId = Convert.ToInt32(_response.Entity.Id);
            purchaseorderpusatrequest.Data.Id = 0;

            var      lastponumber = _unitOfWork.PurchaseOrderPusatRepository.Get(searchPredicate, orderBy: a => a.OrderByDescending(x => x.CreatedDate)).Select(a => a.ponumber).FirstOrDefault();
            DateTime?getmonth     = _unitOfWork.PurchaseOrderPusatRepository.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";

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

            PurchaseOrderPusatResponse purchaseorderresponse = new PurchaseOrderPusatResponse();

            new PurchaseOrderPusatValidator(_unitOfWork).Validate(purchaseorderpusatrequest, out purchaseorderresponse);

            if (_response.Entity.purchaserequestPusatdetailModels != null)
            {
                int i = 0;
                foreach (var item in _response.Entity.purchaserequestPusatdetailModels)
                {
                    var purchaseorderdetailrequest = new PurchaseOrderPusatDetailRequest
                    {
                        Data = Mapper.Map <PurchaseRequestPusatDetailModel, PurchaseOrderPusatDetailModel>(item)
                    };
                    purchaseorderdetailrequest.Data.PurchaseOrderPusatId = 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;
                    PurchaseOrderPusatDetailResponse _purchaseorderdetailresponse = new PurchaseOrderPusatDetailResponse();
                    new PurchaseOrderPusatDetailValidator(_unitOfWork).Validate(purchaseorderdetailrequest, out _purchaseorderdetailresponse);
                    i++;
                }
            }
        }
Exemple #2
0
        public void Create(PurchaseOrderResponse _response)
        {
            var searchPredicate = PredicateBuilder.New <Data.DataRepository.DeliveryOrder>(true);

            _response.Entity.approve   = null;
            _response.Entity.approveby = null;

            var request = new DeliveryOrderRequest
            {
                Data = Mapper.Map <PurchaseOrderModel, DeliveryOrderModel>(_response.Entity)
            };

            request.Data.dodate = DateTime.Now;
            request.Data.poid   = Convert.ToInt32(_response.Entity.Id);
            request.Data.Id     = 0;

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

            request.Data.donumber = "DO" + _response.Entity.Account.Organization + DateTime.Now.Year + DateTime.Now.Month + ponumber;
            request.Data.Account  = _response.Entity.Account;

            DeliveryOrderResponse deliveryorderresponse = new DeliveryOrderResponse();

            new DeliveryOrderValidator(_unitOfWork).Validate(request, out deliveryorderresponse);

            if (_response.Entity.PurchaseOrderDetails != null)
            {
                int i = 0;
                foreach (var item in _response.Entity.PurchaseOrderDetails)
                {
                    var deliveryorderdetailrequest = new DeliveryOrderDetailRequest
                    {
                        Data = Mapper.Map <PurchaseOrderDetailModel, DeliveryOrderDetailModel>(item)
                    };
                    deliveryorderdetailrequest.Data.DeliveryOderId = Convert.ToInt32(deliveryorderresponse.Entity.Id);
                    deliveryorderdetailrequest.Data.Account        = _response.Entity.Account;
                    deliveryorderdetailrequest.Data.Id             = 0;
                    //
                    var requestnamabarang = new ProductRequest
                    {
                        Data = new ProductModel
                        {
                            Id = Convert.ToInt32(item.ProductId)
                        }
                    };

                    ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);
                    deliveryorderdetailrequest.Data.namabarang = namabarang.Entity.Name;
                    DeliveryOrderDetailResponse _deliveryorderdetailresponse = new DeliveryOrderDetailResponse();
                    new DeliveryOrderDetailValidator(_unitOfWork).Validate(deliveryorderdetailrequest, out _deliveryorderdetailresponse);
                    i++;
                }
            }
        }
        public PurchaseRequestResponse GetListData(PurchaseRequestRequest request)
        {
            List <PurchaseRequestModel> lists = new List <PurchaseRequestModel>();
            dynamic qry             = null;
            var     searchPredicate = PredicateBuilder.New <Data.DataRepository.PurchaseRequest>(true);

            // add default filter to show the active data only
            searchPredicate = searchPredicate.And(x => x.RowStatus == 0 && x.GudangId == OneLoginSession.Account.GudangID);
            if ((GeneralHandler.authorized("APPROVE_M_PURCHASEREQUEST") == "false"))
            {
                searchPredicate.And(x => x.approve >= 1);
            }
            if (!String.IsNullOrEmpty(request.SearchValue) && !String.IsNullOrWhiteSpace(request.SearchValue))
            {
                searchPredicate = searchPredicate.And(p => p.prnumber.Contains(request.SearchValue));
            }

            if (!(string.IsNullOrEmpty(request.SortColumn) && string.IsNullOrEmpty(request.SortColumnDir)))
            {
                if (request.SortColumnDir == "asc")
                {
                    switch (request.SortColumn.ToLower())
                    {
                    case "prnumber":
                        qry = _unitOfWork.PurchaseRequestRepository.Get(searchPredicate, orderBy: q => q.OrderBy(x => x.prnumber));
                        break;

                    default:
                        qry = _unitOfWork.PurchaseRequestRepository.Get(searchPredicate, orderBy: q => q.OrderBy(x => x.id));
                        break;
                    }
                }
                else
                {
                    switch (request.SortColumn.ToLower())
                    {
                    case "prnumber":
                        qry = _unitOfWork.PurchaseRequestRepository.Get(searchPredicate, orderBy: q => q.OrderByDescending(x => x.prnumber));
                        break;

                    default:
                        qry = _unitOfWork.PurchaseRequestRepository.Get(searchPredicate, orderBy: q => q.OrderByDescending(x => x.id));
                        break;
                    }
                }
            }
            else
            {
                qry = _unitOfWork.PurchaseRequestRepository.Get(searchPredicate, null);
            }
            List <Data.DataRepository.PurchaseRequest> purchaseRequests = new List <Data.DataRepository.PurchaseRequest>();

            purchaseRequests = qry;

            foreach (var item in purchaseRequests)
            {
                var prData = new PurchaseRequestModel
                {
                    Id           = item.id,
                    prnumber     = item.prnumber,
                    prdate       = item.prdate,
                    approve_by   = item.approve_by,
                    approve      = item.approve,
                    request_by   = item.request_by,
                    ModifiedBy   = item.ModifiedBy,
                    CreatedBy    = item.CreatedBy,
                    ModifiedDate = item.ModifiedDate,
                    poid         = item.PurchaseOrders.Count > 0 ? item.PurchaseOrders.FirstOrDefault().id : 0,
                    doid         = item.PurchaseOrders.Count > 0 ? item.PurchaseOrders.FirstOrDefault().DeliveryOrders.Count > 0 ? item.PurchaseOrders.FirstOrDefault().DeliveryOrders.FirstOrDefault().id : 0 : 0,
                    ponumber     = item.PurchaseOrders.Count > 0 ? item.PurchaseOrders.FirstOrDefault().ponumber : "",
                    createpo     = item.PurchaseOrders.Count > 0 ? GeneralHandler.FormatDate(Convert.ToDateTime(item.PurchaseOrders.FirstOrDefault().podate)) : null,
                    donumber     = item.PurchaseOrders.Count > 0 ? item.PurchaseOrders.FirstOrDefault().DeliveryOrders.Count > 0 ? item.PurchaseOrders.FirstOrDefault().DeliveryOrders.FirstOrDefault().donumber : "" : "",
                    createdo     = item.PurchaseOrders.Count > 0 ? item.PurchaseOrders.FirstOrDefault().DeliveryOrders.Count > 0 ? GeneralHandler.FormatDate(Convert.ToDateTime(item.PurchaseOrders.FirstOrDefault().DeliveryOrders.FirstOrDefault().dodate)) : null : null,
                    Validasi     = item.Validasi,
                    Recived      = item.PurchaseOrders.Count > 0 ? item.PurchaseOrders.FirstOrDefault().DeliveryOrders.Count > 0 ? item.PurchaseOrders.FirstOrDefault().DeliveryOrders.FirstOrDefault().Recived : 0 : 0,
                    namaklinik   = _context.Users.Where(x => x.UserName == item.request_by).FirstOrDefault().Organization.Clinic != null?_context.Users.Where(x => x.UserName == item.request_by).FirstOrDefault().Organization.Clinic.Name : "",
                    createformat = GeneralHandler.FormatDate(Convert.ToDateTime(item.CreatedDate)),
                    Account      = OneLoginSession.Account,
                    status       = GeneralHandler.PurchaseRequestStatus(item.id),
                };

                lists.Add(prData);
            }

            int totalRequest = lists.Count();
            var data         = lists.Skip(request.Skip).Take(request.PageSize).ToList();

            var response = new PurchaseRequestResponse
            {
                Draw            = request.Draw,
                RecordsFiltered = totalRequest,
                RecordsTotal    = totalRequest,
                Data            = data
            };

            return(response);
        }
        public PurchaseOrderPusatResponse GetListData(PurchaseOrderPusatRequest request)
        {
            List <PurchaseOrderPusatModel> lists = new List <PurchaseOrderPusatModel>();
            dynamic qry             = null;
            var     searchPredicate = PredicateBuilder.New <Data.DataRepository.PurchaseOrderPusat>(true);

            // add default filter to show the active data only
            searchPredicate = searchPredicate.And(x => x.RowStatus == 0);
            if ((GeneralHandler.authorized("APPROVE_M_PURCHASEORDERPUSAT") == "false"))
            {
                searchPredicate.And(x => x.approve >= 1);
            }

            if (!String.IsNullOrEmpty(request.SearchValue) && !String.IsNullOrWhiteSpace(request.SearchValue))
            {
                searchPredicate = searchPredicate.And(p => p.ponumber.Contains(request.SearchValue));
            }

            if (!(string.IsNullOrEmpty(request.SortColumn) && string.IsNullOrEmpty(request.SortColumnDir)))
            {
                if (request.SortColumnDir == "asc")
                {
                    switch (request.SortColumn.ToLower())
                    {
                    case "ponumber":
                        qry = _unitOfWork.PurchaseOrderPusatRepository.Get(searchPredicate, orderBy: q => q.OrderBy(x => x.ponumber));
                        break;

                    default:
                        qry = _unitOfWork.PurchaseOrderPusatRepository.Get(searchPredicate, orderBy: q => q.OrderBy(x => x.id));
                        break;
                    }
                }
                else
                {
                    switch (request.SortColumn.ToLower())
                    {
                    case "ponumber":
                        qry = _unitOfWork.PurchaseOrderPusatRepository.Get(searchPredicate, orderBy: q => q.OrderByDescending(x => x.ponumber));
                        break;

                    default:
                        qry = _unitOfWork.PurchaseOrderPusatRepository.Get(searchPredicate, orderBy: q => q.OrderByDescending(x => x.id));
                        break;
                    }
                }
            }
            else
            {
                qry = _unitOfWork.PurchaseOrderPusatRepository.Get(searchPredicate, null);
            }

            foreach (var item in qry)
            {
                var prData = new PurchaseOrderPusatModel
                {
                    Id = item.id,
                    PurchaseRequestId = item.PurchaseRequestId,
                    ponumber          = item.ponumber,
                    podate            = item.podate,
                    approve_by        = item.approve_by,
                    approve           = item.approve,
                    request_by        = item.request_by,
                    ModifiedBy        = item.ModifiedBy,
                    CreatedBy         = item.CreatedBy,
                    ModifiedDate      = item.ModifiedDate,
                    createformat      = GeneralHandler.FormatDate(item.CreatedDate)
                };

                lists.Add(prData);
            }

            int totalRequest = lists.Count();
            var data         = lists.Skip(request.Skip).Take(request.PageSize).ToList();

            var response = new PurchaseOrderPusatResponse
            {
                Draw            = request.Draw,
                RecordsFiltered = totalRequest,
                RecordsTotal    = totalRequest,
                Data            = data
            };

            return(response);
        }
Exemple #5
0
        public DeliveryOrderResponse GetListData(DeliveryOrderRequest request)
        {
            List <DeliveryOrderModel> lists = new List <DeliveryOrderModel>();
            dynamic qry             = null;
            var     searchPredicate = PredicateBuilder.New <Data.DataRepository.DeliveryOrder>(true);

            // add default filter to show the active data only
            searchPredicate = searchPredicate.And(x => x.RowStatus == 0);

            if (!String.IsNullOrEmpty(request.SearchValue) && !String.IsNullOrWhiteSpace(request.SearchValue))
            {
                searchPredicate = searchPredicate.And(p => p.donumber.Contains(request.SearchValue));
            }

            if (!(string.IsNullOrEmpty(request.SortColumn) && string.IsNullOrEmpty(request.SortColumnDir)))
            {
                if (request.SortColumnDir == "asc")
                {
                    switch (request.SortColumn.ToLower())
                    {
                    case "donumber":
                        qry = _unitOfWork.DeliveryOrderRepository.Get(searchPredicate, orderBy: q => q.OrderBy(x => x.donumber));
                        break;

                    default:
                        qry = _unitOfWork.DeliveryOrderRepository.Get(searchPredicate, orderBy: q => q.OrderBy(x => x.id));
                        break;
                    }
                }
                else
                {
                    switch (request.SortColumn.ToLower())
                    {
                    case "donumber":
                        qry = _unitOfWork.DeliveryOrderRepository.Get(searchPredicate, orderBy: q => q.OrderByDescending(x => x.donumber));
                        break;

                    default:
                        qry = _unitOfWork.DeliveryOrderRepository.Get(searchPredicate, orderBy: q => q.OrderByDescending(x => x.id));
                        break;
                    }
                }
            }
            else
            {
                qry = _unitOfWork.DeliveryOrderRepository.Get(searchPredicate, null);
            }

            foreach (var item in qry)
            {
                var prData = new DeliveryOrderModel
                {
                    Id           = item.id,
                    poid         = item.poid,
                    donumber     = item.donumber,
                    dodate       = item.dodate,
                    dodest       = item.dodest,
                    approveby    = item.approveby,
                    approve      = item.approve,
                    ModifiedBy   = item.ModifiedBy,
                    CreatedBy    = item.CreatedBy,
                    ModifiedDate = item.ModifiedDate,
                    Recived      = item.Recived,
                    createformat = GeneralHandler.FormatDate(item.CreatedDate)
                };

                lists.Add(prData);
            }

            int totalRequest = lists.Count();
            var data         = lists.Skip(request.Skip).Take(request.PageSize).ToList();

            var response = new DeliveryOrderResponse
            {
                Draw            = request.Draw,
                RecordsFiltered = totalRequest,
                RecordsTotal    = totalRequest,
                Data            = data
            };

            return(response);
        }