public ActionResult Create([Bind("ixReceipt,sReceipt,ixInventoryLocation,ixInboundOrder,ixHandlingUnit,ixMaterial,ixMaterialHandlingUnitConfiguration,ixHandlingUnitType,nHandlingUnitQuantity,sSerialNumber,sBatchNumber,dtExpireAt,nBaseUnitQuantityReceived,ixInventoryState,ixStatus")] ReceivingPost receiving)
        {
            //var modelState = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => x.Key).ToList();
            if (ModelState.IsValid)
            {
                receiving.UserName = User.Identity.Name;
                _receivingService.Create(receiving);

                //Custom Code Start | Replaced Code Block
                //Replaced Code Block Start
                //return RedirectToAction("Index");
                //Replaced Code Block End
                return(RedirectToAction("Create"));
                //Custom Code End
            }
            ViewBag.ixHandlingUnit     = new SelectList(_receivingService.selectHandlingUnits().Select(x => new { x.ixHandlingUnit, x.sHandlingUnit }), "ixHandlingUnit", "sHandlingUnit");
            ViewBag.ixHandlingUnitType = new SelectList(_receivingService.selectHandlingUnitTypes().Select(x => new { x.ixHandlingUnitType, x.sHandlingUnitType }), "ixHandlingUnitType", "sHandlingUnitType");
            //Custom Code Start | Replaced Code Block
            //Replaced Code Block Start
            //ViewBag.ixInboundOrder = new SelectList(_receivingService.selectInboundOrders().Select(x => new { x.ixInboundOrder, x.sInboundOrder }), "ixInboundOrder", "sInboundOrder");
            //Replaced Code Block End
            ViewBag.ixInboundOrder = new SelectList(_receivingService.selectInboundOrdersFirst().Select(x => new { ixInboundOrder = x.Key, sInboundOrder = x.Value }), "ixInboundOrder", "sInboundOrder");
            //Custom Code End
            ViewBag.ixInventoryLocation = new SelectList(_receivingService.selectInventoryLocations().Select(x => new { x.ixInventoryLocation, x.sInventoryLocation }), "ixInventoryLocation", "sInventoryLocation");
            ViewBag.ixInventoryState    = new SelectList(_receivingService.selectInventoryStates().Select(x => new { x.ixInventoryState, x.sInventoryState }), "ixInventoryState", "sInventoryState");
            ViewBag.ixMaterial          = new SelectList(_receivingService.selectMaterials().Select(x => new { x.ixMaterial, x.sMaterial }), "ixMaterial", "sMaterial");
            ViewBag.ixMaterialHandlingUnitConfiguration = new SelectList(_receivingService.selectMaterialHandlingUnitConfigurations().Select(x => new { x.ixMaterialHandlingUnitConfiguration, x.sMaterialHandlingUnitConfiguration }), "ixMaterialHandlingUnitConfiguration", "sMaterialHandlingUnitConfiguration");
            ViewBag.ixStatus = new SelectList(_receivingService.selectStatuses().Select(x => new { x.ixStatus, x.sStatus }), "ixStatus", "sStatus");

            return(View(receiving));
        }
        public ActionResult DeleteConfirmed(long id)
        {
            ReceivingPost receiving = _receivingService.GetPost(id);

            receiving.UserName = User.Identity.Name;
            _receivingService.Delete(receiving);
            return(RedirectToAction("Index"));
        }
        public Task Delete(ReceivingPost receivingPost)
        {
            // Additional validations

            // Pre-process

            // Process
            this._receivingRepository.RegisterDelete(receivingPost);
            try
            {
                this._receivingRepository.Commit();
            }
            catch (Exception ex)
            {
                this._receivingRepository.Rollback();
                // Log exception
                throw;
            }

            // Post-process

            return(Task.CompletedTask);
        }
        public ActionResult Edit(long id)
        {
            ReceivingPost receiving = _receivingService.GetPost(id);

            if (receiving == null)
            {
                return(NotFound());
            }
            ViewBag.ixHandlingUnit     = new SelectList(_receivingService.selectHandlingUnits().Select(x => new { x.ixHandlingUnit, x.sHandlingUnit }), "ixHandlingUnit", "sHandlingUnit", receiving.ixHandlingUnit);
            ViewBag.ixHandlingUnitType = new SelectList(_receivingService.selectHandlingUnitTypesNullable().Select(x => new { ixHandlingUnitType = x.Key, sHandlingUnitType = x.Value }), "ixHandlingUnitType", "sHandlingUnitType", receiving.ixHandlingUnitType);
            //Custom Code Start | Replaced Code Block
            //Replaced Code Block Start
            //ViewBag.ixInboundOrder = new SelectList(_receivingService.selectInboundOrders().Select(x => new { x.ixInboundOrder, x.sInboundOrder }), "ixInboundOrder", "sInboundOrder");
            //Replaced Code Block End
            ViewBag.ixInboundOrder = new SelectList(_receivingService.selectInboundOrdersFirst().Select(x => new { ixInboundOrder = x.Key, sInboundOrder = x.Value }), "ixInboundOrder", "sInboundOrder");
            //Custom Code End
            ViewBag.ixInventoryLocation = new SelectList(_receivingService.selectInventoryLocations().Select(x => new { x.ixInventoryLocation, x.sInventoryLocation }), "ixInventoryLocation", "sInventoryLocation", receiving.ixInventoryLocation);
            ViewBag.ixInventoryState    = new SelectList(_receivingService.selectInventoryStates().Select(x => new { x.ixInventoryState, x.sInventoryState }), "ixInventoryState", "sInventoryState", receiving.ixInventoryState);
            ViewBag.ixMaterial          = new SelectList(_receivingService.selectMaterials().Select(x => new { x.ixMaterial, x.sMaterial }), "ixMaterial", "sMaterial", receiving.ixMaterial);
            ViewBag.ixMaterialHandlingUnitConfiguration = new SelectList(_receivingService.selectMaterialHandlingUnitConfigurationsNullable().Select(x => new { ixMaterialHandlingUnitConfiguration = x.Key, sMaterialHandlingUnitConfiguration = x.Value }), "ixMaterialHandlingUnitConfiguration", "sMaterialHandlingUnitConfiguration", receiving.ixMaterialHandlingUnitConfiguration);
            ViewBag.ixStatus = new SelectList(_receivingService.selectStatuses().Select(x => new { x.ixStatus, x.sStatus }), "ixStatus", "sStatus", receiving.ixStatus);

            return(View(receiving));
        }
        public Task <Int64> Create(ReceivingPost receivingPost)
        {
            // Additional validations

            // Pre-process

            //Custom Code Start | Added Code Block
            //If the handling unit does not exist we create it
            if (!HandlingUnitsDb().Where(x => x.sHandlingUnit == receivingPost.sReceipt.Trim()).Any())
            {
                HandlingUnitsPost handlingUnitsPost = new HandlingUnitsPost();
                handlingUnitsPost.sHandlingUnit      = receivingPost.sReceipt;
                handlingUnitsPost.ixHandlingUnitType = receivingPost.ixHandlingUnitType ?? 0;
                handlingUnitsPost.UserName           = receivingPost.UserName;
                receivingPost.ixHandlingUnit         = _handlingunitsService.Create(handlingUnitsPost).Result;
            }
            else
            {
                receivingPost.ixHandlingUnit = HandlingUnitsDb().Where(x => x.sHandlingUnit == receivingPost.sReceipt.Trim()).Select(x => x.ixHandlingUnit).FirstOrDefault();
            }

            InventoryUnitsPost inventoryUnit = new InventoryUnitsPost();
            var inboundOrder = _inboundordersService.GetPost(receivingPost.ixInboundOrder);

            inventoryUnit.ixFacility          = inboundOrder.ixFacility;
            inventoryUnit.ixCompany           = inboundOrder.ixCompany;
            inventoryUnit.ixMaterial          = receivingPost.ixMaterial;
            inventoryUnit.ixInventoryState    = receivingPost.ixInventoryState;
            inventoryUnit.ixHandlingUnit      = receivingPost.ixHandlingUnit;
            inventoryUnit.ixInventoryLocation = receivingPost.ixInventoryLocation;
            inventoryUnit.sSerialNumber       = receivingPost.sSerialNumber;
            inventoryUnit.sBatchNumber        = receivingPost.sBatchNumber;
            inventoryUnit.dtExpireAt          = receivingPost.dtExpireAt;
            inventoryUnit.UserName            = receivingPost.UserName;

            if ((inventoryUnit.sSerialNumber ?? "").Trim() != "")
            {
                //We create an iu
                inventoryUnit.nBaseUnitQuantity = receivingPost.nBaseUnitQuantityReceived;
                _inventoryunitsService.Create(inventoryUnit, _ixInventoryUnitTransactionContext);
            }
            else if (_inventoryunitsService.IndexDb().Where(x =>
                                                            x.ixFacility == inventoryUnit.ixFacility &&
                                                            x.ixCompany == inventoryUnit.ixCompany &&
                                                            x.ixMaterial == inventoryUnit.ixMaterial &&
                                                            x.ixInventoryState == inventoryUnit.ixInventoryState &&
                                                            x.ixHandlingUnit == inventoryUnit.ixHandlingUnit &&
                                                            x.ixInventoryLocation == inventoryUnit.ixInventoryLocation &&
                                                            x.sBatchNumber == inventoryUnit.sBatchNumber &&
                                                            x.dtExpireAt == inventoryUnit.dtExpireAt && x.ixStatus == 5
                                                            ).Select(x => x.ixInventoryUnit).Any()
                     )
            {
                //We edit the iu
                inventoryUnit.ixInventoryUnit = _inventoryunitsService.IndexDb().Where(x =>
                                                                                       x.ixFacility == inventoryUnit.ixFacility &&
                                                                                       x.ixCompany == inventoryUnit.ixCompany &&
                                                                                       x.ixMaterial == inventoryUnit.ixMaterial &&
                                                                                       x.ixInventoryState == inventoryUnit.ixInventoryState &&
                                                                                       x.ixHandlingUnit == inventoryUnit.ixHandlingUnit &&
                                                                                       x.ixInventoryLocation == inventoryUnit.ixInventoryLocation &&
                                                                                       x.sBatchNumber == inventoryUnit.sBatchNumber &&
                                                                                       x.dtExpireAt == inventoryUnit.dtExpireAt && x.ixStatus == 5
                                                                                       ).Select(x => x.ixInventoryUnit).FirstOrDefault();
                inventoryUnit.nBaseUnitQuantity = _inventoryunitsService.GetPost(inventoryUnit.ixInventoryUnit).nBaseUnitQuantity + receivingPost.nBaseUnitQuantityReceived;
                _inventoryunitsService.Edit(inventoryUnit, _ixInventoryUnitTransactionContext);
            }
            else
            {
                //We create an iu
                inventoryUnit.nBaseUnitQuantity = receivingPost.nBaseUnitQuantityReceived;
                _inventoryunitsService.Create(inventoryUnit, _ixInventoryUnitTransactionContext);
            }


            //Custom Code End

            // Process
            this._receivingRepository.RegisterCreate(receivingPost);
            try
            {
                this._receivingRepository.Commit();
            }
            catch (Exception ex)
            {
                this._receivingRepository.Rollback();
                // Log exception
                throw;
            }

            // Post-process

            //Custom Code Start | Added Code Block
            //Now we update the inbound order lines - for now we apply entire qty to the matching line
            var _ixInboundOrderLine = _inboundorderlinesService.IndexDb().Where(x => x.ixInboundOrder == receivingPost.ixInboundOrder && x.ixMaterial == receivingPost.ixMaterial).Select(x => x.ixInboundOrderLine).FirstOrDefault();
            var inboundOrderLine    = _inboundorderlinesService.GetPost(_ixInboundOrderLine);

            inboundOrderLine.nBaseUnitQuantityReceived += receivingPost.nBaseUnitQuantityReceived;
            inboundOrderLine.UserName = receivingPost.UserName;
            if ((inboundOrderLine.nBaseUnitQuantityExpected - inboundOrderLine.nBaseUnitQuantityReceived) == 0)
            {
                inboundOrderLine.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault();
            }
            _inboundorderlinesService.Edit(inboundOrderLine);

            //If there are no open qtys we set the inbound order/line status to complete
            if (_inboundorderlinesService.IndexDb().Where(x => x.ixInboundOrder == receivingPost.ixInboundOrder).Select(x => x.nBaseUnitQuantityExpected - x.nBaseUnitQuantityReceived).Sum() == 0)
            {
                var inboundorder = _inboundordersService.GetPost(receivingPost.ixInboundOrder);
                inboundorder.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault();
                _inboundordersService.Edit(inboundorder);
            }

            //Custom Code End

            return(Task.FromResult(receivingPost.ixReceipt));
        }
Beispiel #6
0
 public void RegisterDelete(ReceivingPost receivingPost)
 {
     _context.ReceivingPost.Remove(receivingPost);
 }
Beispiel #7
0
 public void RegisterEdit(ReceivingPost receivingPost)
 {
     _context.Entry(receivingPost).State = EntityState.Modified;
 }
Beispiel #8
0
 public void RegisterCreate(ReceivingPost receivingPost)
 {
     _context.ReceivingPost.Add(receivingPost);
 }