public ActionResult Receive(ReceiveTransDTO receiveModel)
        {
            try
            {
                //validate receive trans
                if (receiveModel.InvoiceNum == null || receiveModel.DeliveryOrderNum == null)
                {
                    throw new Exception("Delivery Order Number and Invoice Number are required fields");
                }
                if (!ModelState.IsValid)
                {
                    throw new Exception("IT Error: please contact your administrator");
                }

                //set date if null
                var receive = receiveModel.ConvertToReceiveTran();
                if (receive.ReceiveDate == new DateTime())
                {
                    receive.ReceiveDate = DateTime.Today;
                }

                //check validity
                ValidateReceiveTrans(receive);

                //create receive trans, update PO and stationery
                CreateReceiveTrans(receive);

                return(RedirectToAction("Summary"));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Receive", new { p = receiveModel.PoNum.ToString(), error = e.Message }));
            }
        }
        public ActionResult Receive(int?p = null, string error = null)
        {
            //catch error from redirect (from POST) and display back into page
            ViewBag.Error = error;

            var receive = new ReceiveTransDTO(); //model to bind data

            if (p == null)
            {
                ViewBag.OrderedPO = _poRepo.GetPOByStatus(Ordered);
                return(View());
            }

            //populate PO and ReceiveTrans if PO number is given
            var po = new PurchaseOrderDTO(_poRepo.GetById(Convert.ToInt32(p)));

            if (po.Status != Ordered)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            for (int i = 0; i < po.PurchaseOrderDetails.Count; i++)
            {
                var rdetail = new ReceiveTransDetail
                {
                    ItemNum  = po.PurchaseOrderDetails.Skip(i).First().ItemNum,
                    Quantity = 0
                };
                receive.ReceiveTransDetails.Add(rdetail);
            }

            receive.ReceiveDate = DateTime.Today;

            ViewBag.PurchaseOrder = po;
            return(View(receive));
        }