예제 #1
0
        public ActionResult AddWOItem(LaborPartsModel model)
        {
            var workOrder = repository.SearchFor <SageWorkOrder>(x => x.WorkOrder == model.WorkOrder).SingleOrDefault();

            if (workOrder == null)
            {
                return(Error("Work Order does not exist", $"There are no Work Orders with ID: {model.WorkOrder}. workOrder == null"));
            }

            var workOrderItem = Mapper.Map <SageWorkOrderItem>(model);

            workOrderItem.Employee = UserModel.Name;

            if (model.WorkOrderItem == 0)
            {
                workOrderItem.WorkOrder = model.WorkOrder;
                workOrderItem.TotalSale = workOrderItem.Quantity * workOrderItem.UnitSale;
                if (workOrderItem.ItemType == "Parts")
                {
                    workOrderItem.PartsSale = workOrderItem.UnitSale;
                }
                else
                {
                    workOrderItem.LaborSale = workOrderItem.UnitSale;
                }

                var result = sageApiProxy.AddWorkOrderItem(workOrderItem);
                if (result != null && result.IsSucceed && result.Entity != null)
                {
                    var woiResult = sageApiProxy.GetWorkorderItemsByWorkOrderId(workOrder.WorkOrder);
                    if (woiResult.IsSucceed)
                    {
                        workOrder.WorkOrderItems = woiResult.Entities;
                        repository.Update(workOrder);
                        _hub.UpdateSageWorkOrder(workOrder);
                    }
                }
                else
                {
                    _log.ErrorFormat("Was not able to save workorderItem to sage. !result.IsSucceed");
                    return(Error("Work order item save failed", $"AddWorkOrderItem method IsSucceed==false. {result?.ErrorMassage}"
                                 ));
                }
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var resultUpdate = sageApiProxy.EditWorkOrderItem(workOrderItem);
                if (resultUpdate != null && resultUpdate.IsSucceed && resultUpdate.Entity != null)
                {
                    var woiResult = sageApiProxy.GetWorkorderItemsByWorkOrderId(workOrder.WorkOrder);
                    if (woiResult.IsSucceed)
                    {
                        workOrder.WorkOrderItems = woiResult.Entities;
                        repository.Update(workOrder);
                    }
                }
                else
                {
                    _log.ErrorFormat("Was not able to update workorderItem to sage. !result.IsSucceed");
                    return(Error("Work order item update failed", $"EditWorkOrderItem method IsSucceed==false. {resultUpdate?.ErrorMassage}."
                                 ));
                }
                return(Json(resultUpdate, JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
        public ActionResult SaveWorkOrder(WorkOrderModel model)
        {
            _log.InfoFormat("Method: SaveWorkOrder. Model ID {0}", model.Id);

            if (model.Emploee == 0)
            {
                return(Error("Employee is required"));
            }
            if (model.Location == null)
            {
                return(Error("Location is required"));
            }
            if (model.Problem == null)
            {
                return(Error("Problem is required"));
            }


            var workorder = new SageWorkOrder()
            {
                ARCustomer           = model.Customer,
                Location             = model.Location,
                CallType             = model.Calltype,
                CallDate             = model.Calldate.GetLocalDate(),
                Problem              = model.Problem,
                RateSheet            = model.Ratesheet,
                Employee             = model.Emploee.ToString(),
                EstimatedRepairHours = Convert.ToDecimal(model.Estimatehours),
                NottoExceed          = model.Nottoexceed,
                Comments             = model.Locationcomments,
                CustomerPO           = model.Customerpo,
                PermissionCode       = model.Permissiocode,
                PayMethod            = model.Paymentmethods,
                WorkOrder            = model.WorkOrder,
                Id        = model.Id,
                Status    = WorkOrderStatus.ById(model.Status),
                JCJob     = model.JCJob,
                Contact   = model.Contact,
                Equipment = model.Equipment
            };

            var workOrderResult = _sageApiProxy.EditWorkOrder(workorder);

            workOrderResult.Entity.LocationNumber = long.Parse(model.Location);
            if (!workOrderResult.IsSucceed)
            {
                _log.ErrorFormat("Was not able to update workorder to sage. !result.IsSucceed");
                return(Error("Was not able to update workorder to sage"));
            }

            if (model.Emploee != 0)
            {
                var assignmentDb     = _repository.SearchFor <SageAssignment>(x => x.WorkOrder == model.WorkOrder).Single();
                var editedAssignment = new AssignmentViewModel();
                editedAssignment.Employee             = model.Emploee;
                editedAssignment.EndDate              = model.AssignmentDate.Date.Add((model.AssignmentTime).TimeOfDay).AddHours(assignmentDb.EstimatedRepairHours.AsDouble() == 0 ? 1 : assignmentDb.EstimatedRepairHours.AsDouble());
                editedAssignment.EstimatedRepairHours = workorder.EstimatedRepairHours.ToString();
                editedAssignment.Id           = assignmentDb.Id;
                editedAssignment.ScheduleDate = model.AssignmentDate.Date.Add((model.AssignmentTime).TimeOfDay);
                editedAssignment.WorkOrder    = assignmentDb.WorkOrder;
                _scheduleService.CerateAssignment(editedAssignment);

                var locations    = _repository.GetAll <SageLocation>().ToArray();
                var itemLocation = locations.FirstOrDefault(l => l.Name == workOrderResult.Entity.Location);
                workOrderResult.Entity.ScheduleDate = model.AssignmentDate.Date.Add((model.AssignmentTime).TimeOfDay);
                workOrderResult.Entity.Latitude     = itemLocation.Latitude;
                workOrderResult.Entity.Longitude    = itemLocation.Longitude;
            }

            this.ResolveWorkOrderItems(model);
            this.ResolveWorkOrderNotes(model);

            workOrderResult.Entity.Status         = WorkOrderStatus.ById(model.Status);
            workOrderResult.Entity.Id             = workorder.Id;
            workOrderResult.Entity.IsValid        = true;
            workOrderResult.Entity.WorkOrderItems = _sageApiProxy.GetWorkorderItemsByWorkOrderId(workorder.WorkOrder).Entities;
            workOrderResult.Entity.WorkNotes      = this._sageApiProxy.GetNotes(workorder.WorkOrder).Entities;
            _repository.Update(workOrderResult.Entity);

            _log.InfoFormat("Repository update workorder. Name {0}, ID {1}", workorder.Name, workorder.Id);
            _hub.UpdateWorkOrder(model);
            if (model.Status == WorkOrderStatus.WorkCompleteId)
            {
                _hub.ShowAlert(new SweetAlertModel()
                {
                    Message = $"Workorder #{model.WorkOrder} closed",
                    Title   = "Workorder completed",
                    Type    = "success"
                });
            }
            return(Success());
        }