예제 #1
0
        private void CreateWorkOrderEventOnChange(Incident workOrder, ars_technician technician, EventType eventType, KeyValuePair <int, string> status)
        {
            var eventTypecode = GetEventTypeValue(eventType);
            var previouscode  = GetEventTypeValue(eventType == EventType.CheckIn ? EventType.CheckOut : EventType.CheckIn);
            var events        = _context.ars_workordereventSet.Where(e => e.ars_WorkOrder.Id == workOrder.IncidentId);
            var incidentEvent =
                events.Where(e => e.ars_EventType.Value == previouscode.Key)
                .OrderByDescending(e => e.ars_DateTime)
                .FirstOrDefault();
            decimal?hours = 0;

            if (incidentEvent != null && eventType == EventType.CheckOut)
            {
                var diff = DateTime.UtcNow.Subtract(incidentEvent.ars_DateTime.Value);
                hours = diff.Hours + (decimal)diff.Minutes / 60;
            }

            var workorderevent = new ars_workorderevent
            {
                ars_name            = string.Format("{0} - Status Change", workOrder.Title),
                ars_DateTime        = DateTime.UtcNow,
                ars_WorkOrder       = workOrder.ToEntityReference(),
                ars_Technician      = technician.ToEntityReference(),
                ars_WorkOrderStatus = status.Value,
                ars_EventType       = new OptionSetValue
                {
                    Value = Convert.ToInt32(eventTypecode.Key)
                },
                ars_Hours = hours
            };

            _context.AddObject(workorderevent);
        }
예제 #2
0
        public void IncreaseNte(Guid workOrderId, Guid technicianId, decimal money, decimal hours, string item1, string item2, string item3, string item4, string item5, string item6, string item7, string price1, string price2, string price3, string price4, string price5, string price6, string price7, string quantity1, string quantity2, string quantity3, string quantity4, string quantity5, string quantity6, string quantity7, string comment)
        {
            if (money < 0)
            {
                throw new ArgumentOutOfRangeException("money", money, "Money could not be negative");
            }

            if (hours < 0)
            {
                throw new ArgumentOutOfRangeException("hours", hours, "Hours could not be negative");
            }

            Incident workOrder = _context.IncidentSet.First(i => i.Id == workOrderId);

            var technician = _context.ars_technicianSet.Single(t => t.ars_technicianId == technicianId);
            //CreateWorkOrderEventOnNteIncrease(workOrder, technician, money, hours);

/*            var annotation = new Annotation
 *          {
 *              NoteText = String.Format("NTE Increase Request: {20} hours requested{25}{19}Name:   {0}   Price: {1}   Quantity: {2}{3}Name:   {4}   Price: {5}   Quantity: {6}{7}Name:   {8}   Price: {9}   Quantity: {10}{11}Name:   {12}   Price: {13}   Quantity: {14}{15}Name:   {16}   Price: {17}   Quantity: {18}{21}{24}Comments:{22}{23}", item1, price1, quantity1, Environment.NewLine, item2, price2, quantity2, Environment.NewLine, item3, price3, quantity3, Environment.NewLine, item4, price4, quantity4, Environment.NewLine, item5, price5, quantity5, Environment.NewLine, hours, Environment.NewLine, Environment.NewLine, comment, Environment.NewLine, Environment.NewLine),
 *              ObjectId = new EntityReference(Incident.EntityLogicalName, workOrderId)
 *          };
 */
            var eventTypecode = GetEventTypeValue(EventType.NteIncreaseRequest);

            var workorderevent = new ars_workorderevent
            {
                ars_name       = String.Format("{0} - NTE Increase Request", workOrder.Title),
                ars_DateTime   = DateTime.UtcNow,
                ars_WorkOrder  = workOrder.ToEntityReference(),
                ars_Technician = technician.ToEntityReference(),
                ars_EventType  = new OptionSetValue
                {
                    Value = Convert.ToInt32(eventTypecode.Key)
                },
                ars_Amount      = new Money(money),
                ars_Hours       = hours,
                new_description = String.Format("NTE Increase Request: {20} hours requested{25}{19}NAME:   {0}   PRICE: ${1}   QUANTITY: {2}{3}NAME:   {4}   PRICE: ${5}   QUANTITY: {6}{7}NAME:   {8}   PRICE: ${9}   QUANTITY: {10}{11}NAME:   {12}   PRICE: ${13}   QUANTITY: {14}{15}NAME:   {16}   PRICE: ${17}   QUANTITY: {18}{21}NAME:  {26}    PRICE: ${27}    QUANTITY: {28}{29}NAME: {30}    PRICE: ${31}    QUANTITY:   {32}{33}{24}Comments:{22}{23}", item1, price1, quantity1, Environment.NewLine, item2, price2, quantity2, Environment.NewLine, item3, price3, quantity3, Environment.NewLine, item4, price4, quantity4, Environment.NewLine, item5, price5, quantity5, Environment.NewLine, hours, Environment.NewLine, Environment.NewLine, comment, Environment.NewLine, Environment.NewLine, item6, price6, quantity6, Environment.NewLine, item7, price7, quantity7, Environment.NewLine)
            };

            _context.AddObject(workorderevent);
            _context.UpdateObject(workOrder);
            _context.SaveChanges();
        }
예제 #3
0
        public void CompleteWork(Guid workOrderId, Guid technicianId, string notes, string lunch)
        {
            Dictionary <string, int> workItemStatuses = GetWorkItemStatuses();
            bool hasIncompleteWorkItems =
                (from item in _context.ars_workitemSet
                 where item.ars_WorkOrderId.Id == workOrderId && item.statuscode.Value == workItemStatuses["Incomplete"]
                 select item.ars_workitemId)
                .FirstOrDefault()
                .HasValue;

            if (hasIncompleteWorkItems)
            {
                throw new Exception("All Work Items must be completed before marking this job as complete.");
            }
            var workOrder  = _context.IncidentSet.Single(i => i.IncidentId == workOrderId);
            var technician = _context.ars_technicianSet.Single(t => t.ars_technicianId == technicianId);

            ChangeWorkOrdersStatus(workOrder, technician, StatusCode.WorkComplete, EventType.CheckOut);
            AddNote(technicianId, workOrder, notes);

            var eventTypecode = GetEventTypeValue(EventType.Lunch);

            var workorderevent = new ars_workorderevent
            {
                ars_name       = String.Format("Lunch"),
                ars_DateTime   = DateTime.UtcNow,
                ars_WorkOrder  = workOrder.ToEntityReference(),
                ars_Technician = technician.ToEntityReference(),
                ars_Hours      = Decimal.Parse(lunch),
                ars_EventType  = new OptionSetValue
                {
                    Value = Convert.ToInt32(eventTypecode.Key)
                },
            };

            _context.AddObject(workorderevent);
            _context.SaveChanges();
        }