Ejemplo n.º 1
0
        public ActionResult CreateOrEditDeliveryOrder()
        {
            DeliveryOrderResponse _response = new DeliveryOrderResponse();

            if (Request.QueryString["id"] != null)
            {
                var request = new DeliveryOrderRequest
                {
                    Data = new DeliveryOrderModel
                    {
                        Id = long.Parse(Request.QueryString["id"].ToString())
                    }
                };

                DeliveryOrderResponse resp   = new DeliveryOrderHandler(_unitOfWork).GetDetail(request);
                DeliveryOrderModel    _model = resp.Entity;
                ViewBag.Response = _response;
                return(View(_model));
            }
            else
            {
                ViewBag.Response   = _response;
                ViewBag.ActionType = ClinicEnums.Action.Add;
                return(View());
            }
        }
Ejemplo n.º 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++;
                }
            }
        }
Ejemplo n.º 3
0
        public ActionResult ReceivedOrder(int id)
        {
            DeliveryOrderResponse _response = new DeliveryOrderResponse();

            var request = new DeliveryOrderRequest
            {
                Data = new DeliveryOrderModel
                {
                    Id = id
                }
            };

            DeliveryOrderResponse resp = new DeliveryOrderHandler(_unitOfWork).GetDetail(request);

            resp.Entity.Account = (AccountModel)Session["UserLogon"];
            resp.Entity.Recived = 1;
            resp.Entity.approve = 1;
            var receiveddeliveryorder = new DeliveryOrderRequest
            {
                Data   = resp.Entity,
                Action = ClinicEnums.Action.APPROVE.ToString()
            };

            new DeliveryOrderValidator(_unitOfWork).Validate(receiveddeliveryorder, out _response);
            DeliveryOrderModel _model = resp.Entity;

            foreach (var item in resp.Entity.deliveryOrderDetailModels)
            {
                var requestproductingudang = new ProductInGudangRequest
                {
                    Data = new ProductInGudangModel
                    {
                        Account   = (AccountModel)Session["UserLogon"],
                        stock     = Convert.ToInt32(item.qty_request) > 0 ? Convert.ToInt32(item.qty_request) : Convert.ToInt32(item.qty_request),
                        GudangId  = _model.GudangId,
                        ProductId = item.ProductId
                    }
                };

                var requesthistoryproductingudang = new HistoryProductInGudangRequest
                {
                    Data = new HistoryProductInGudangModel
                    {
                        Account   = (AccountModel)Session["UserLogon"],
                        value     = Convert.ToInt32(item.qty_request) > 0 ? Convert.ToInt32(item.qty_request) : Convert.ToInt32(item.qty_request),
                        GudangId  = Convert.ToInt32(_model.GudangId),
                        ProductId = item.ProductId
                    }
                };

                var saveproductingudang        = new ProductInGudangHandler(_unitOfWork).CreateOrEdit(requestproductingudang);
                var savehistoryproductingudang = new HistoryProductInGudangHandler(_unitOfWork).CreateOrEdit(requesthistoryproductingudang);
            }
            return(RedirectToAction("DeliveryOrderList"));
        }
Ejemplo n.º 4
0
        public void Validate(DeliveryOrderRequest request, out DeliveryOrderResponse response)
        {
            response = new DeliveryOrderResponse();

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

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

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

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

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

                if (response.Status)
                {
                    response = new DeliveryOrderHandler(_unitOfWork).CreateOrEdit(request);
                }
            }
        }
Ejemplo n.º 5
0
        public JsonResult ApproveDeliveryOrder(int id)
        {
            DeliveryOrderResponse _response = new DeliveryOrderResponse();
            var request = new DeliveryOrderRequest
            {
                Data = new DeliveryOrderModel
                {
                    Id      = id,
                    Account = Session["UserLogon"] == null ? new AccountModel() : (AccountModel)Session["UserLogon"]
                },
                Action = ClinicEnums.Action.APPROVE.ToString()
            };

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

            return(Json(new { Status = _response.Status, Message = _response.Message }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        private void ValidateForApprove(DeliveryOrderRequest request, out DeliveryOrderResponse response)
        {
            response = new DeliveryOrderResponse();

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

            if (response.Status)
            {
                response = new DeliveryOrderHandler(_unitOfWork).ApproveData(request);
            }
        }
Ejemplo n.º 7
0
        public JsonResult CreateOrEditDeliveryOrder(DeliveryOrderModel _deliveryorder, List <DeliveryOrderDetailModel> deliveryOrderDetailModels)
        {
            if (Session["UserLogon"] != null)
            {
                _deliveryorder.Account = (AccountModel)Session["UserLogon"];
            }
            _deliveryorder.Id = Convert.ToInt32(_deliveryorder.Id) > 0 ? _deliveryorder.Id : 0;
            var request = new DeliveryOrderRequest
            {
                Data = _deliveryorder
            };

            DeliveryOrderResponse _response = new DeliveryOrderResponse();

            new DeliveryOrderValidator(_unitOfWork).Validate(request, out _response);
            DeliveryOrderDetailResponse _deliveryorderdetailresponse = new DeliveryOrderDetailResponse();

            if (deliveryOrderDetailModels != null)
            {
                foreach (var item in deliveryOrderDetailModels)
                {
                    var deliveryorderdetailrequest = new DeliveryOrderDetailRequest
                    {
                        Data = item
                    };
                    deliveryorderdetailrequest.Data.Account = (AccountModel)Session["UserLogon"];
                    //
                    var requestnamabarang = new ProductRequest
                    {
                        Data = new ProductModel
                        {
                            Id = item.ProductId
                        }
                    };

                    ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);
                    deliveryorderdetailrequest.Data.namabarang = namabarang.Entity.Name;
                    new DeliveryOrderDetailValidator(_unitOfWork).Validate(deliveryorderdetailrequest, out _deliveryorderdetailresponse);
                }
            }

            return(Json(new { data = _deliveryorderdetailresponse.Data }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 8
0
        public async Task ConfirmDeliveryOrderAsync(DeliveryOrderResponse response)
        {
            var shipment = await _warehouseContext.Shipments.FirstOrDefaultAsync(g => g.OrderNumber == response.OrderNumber);

            if (shipment == null)
            {
                throw new Exception($"Order with number={response.OrderNumber} is not exist");
            }

            _eshopServiceClient.AddHeader(Constants.USERID_HEADER, shipment.UserId.ToString());
            var user = await _eshopServiceClient.UserAsync(shipment.UserId);

            if (user == null)
            {
                throw new Exception($"User with id={shipment.UserId} not exist");
            }
            if (response.IsCanDelivery)
            {
                shipment.Status       = ShipmentOrderStatus.DeliveryConfirmed;
                shipment.ShipmentDate = response.ShipmentDate;

                await _mqSender.SendMessageAsync(new OrderReadyToDelivery
                {
                    UserEmail   = user.UserName,
                    OrderNumber = shipment.OrderNumber
                });
            }
            else
            {
                shipment.WasCancelled     = false;
                shipment.Status           = ShipmentOrderStatus.ErrorShipment;
                shipment.ErrorDescription = response.ErrorDescription;
                // здесь нужна логика по возврату заказа пользователю
            }
            _warehouseContext.Shipments.Update(shipment);
            await _warehouseContext.SaveChangesAsync();
        }
Ejemplo n.º 9
0
        public ActionResult PrintDeliveryOrder(int id)
        {
            DeliveryOrderResponse _response = new DeliveryOrderResponse();

            var request = new DeliveryOrderRequest
            {
                Data = new DeliveryOrderModel
                {
                    Id = id
                }
            };

            DeliveryOrderResponse resp   = new DeliveryOrderHandler(_unitOfWork).GetDetail(request);
            DeliveryOrderModel    _model = resp.Entity;

            ViewBag.Response = _response;
            return(new PartialViewAsPdf(_model)
            {
                PageOrientation = Orientation.Portrait,
                PageSize = Size.Folio,

                FileName = "DeliveryOrder" + _model.donumber + ".pdf"
            });
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 微盟-订单发货(单个)(ec/order/deliveryOrder)
        /// </summary>
        public void DeliveryOrderToWm(DateTime startDate, DateTime endDate)
        {
            string preMsg = "微盟 订单发货(单个) ";

            string    sql     = @"select a.F_BillID, F_ExpressNum, F_ExpressCode 
                        from T_OrderLogisticsInformation a ";
            DataTable dtOrder = sd.GetDataTable(sql);

            Log.WriteLog(preMsg + "取得的记录数:" + dtOrder.Rows.Count + "行。", 1);
            if (dtOrder.Rows.Count == 0)
            {
                return;
            }


            foreach (DataRow drDetail in dtOrder.Rows)
            {
                DeliveryOrderRequest request = new DeliveryOrderRequest();
                request.orderNo             = NumUtil.ToLong(drDetail["F_BillID"]);
                request.deliveryNo          = drDetail["F_ExpressNum"].ToString();
                request.deliveryCompanyCode = drDetail["F_ExpressCode"].ToString();
                DeliveryOrderResponse response = HttpPostToWm <DeliveryOrderResponse>("ec/order/deliveryOrder", request, preMsg);
            }
        }