コード例 #1
0
        // GET: Stationeries/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //get stationery data
            var stationery = _stationeryRepo.GetById(id);

            if (stationery == null)
            {
                return(HttpNotFound());
            }

            //put stationery and the 3 suppliers into the view
            ViewBag.Stationery = stationery;
            ViewBag.Supplier1  = stationery.PrimarySupplier().SupplierName;
            ViewBag.Supplier2  = stationery.StationerySuppliers.First(x => x.Rank == 2).Supplier.SupplierName;
            ViewBag.Supplier3  = stationery.StationerySuppliers.First(x => x.Rank == 3).Supplier.SupplierName;

            //get full list of receive+disburse+adjust transactions for the stationery and put into view
            var receiveList = _poRepo.GetReceiveTransDetailByItem(id).Select(
                x => new StationeryTransactionDTO
            {
                Date      = x.ReceiveTran.ReceiveDate,
                Qty       = x.Quantity,
                Transtype = "received",
                Remarks   = x.ReceiveTran.PurchaseOrder.Supplier.SupplierName
            }).ToList();
            var disburseList = _disbursementRepo.GetAllDisbursementDetailByItem(id).Select(
                x => new StationeryTransactionDTO
            {
                Date      = x.Disbursement.CollectionDate,
                Qty       = -x.ActualQty,
                Transtype = "disburse",
                Remarks   = x.Disbursement.DeptCode
            }).ToList();
            var adjustList = _adjustmentRepo.GetApprovedAdjVoucherByItem(id).Select(
                x => new StationeryTransactionDTO
            {
                Date      = x.CreateDate,
                Qty       = x.Quantity,
                Transtype = "adjust",
                Remarks   = x.Reason
            }).ToList();

            receiveList.AddRange(disburseList);
            receiveList.AddRange(adjustList);
            var p = receiveList.Sum(x => x.Qty);

            ViewBag.InitBal          = stationery.CurrentQty - p;
            ViewBag.StationeryTxList = receiveList.OrderBy(x => x.Date);

            return(View());
        }