Esempio n. 1
0
        /// <summary>
        /// Vendor Invoice Payment
        /// Operation: ExecuteMultiple(CommandRequest[])
        /// Update the retrieved list of Invoices as follows:
        ///     Set
        ///       Invoice Status = "Paid"
        ///     Where
        ///       Invoice Id IN (list of Invoice IDs)
        ///     Return
        ///       List of Invoice IDs
        ///       Check Number
        /// </summary>
        /// <param name="corrigoService"></param>
        /// <param name="invoiceIDs">Invoice id and its payment id has the same value</param>
        /// <returns></returns>
        public static WorkOrderCost[] VendorInvoicePayment(CorrigoService corrigoService, int[] invoiceIDs)
        {
            CommandRequest[] commands = invoiceIDs.Select(i =>
                                                          new ApSubmitPaymentCommand
            {
                WorkOrderId   = i,   // Invoice Id is equal to Work Order Id, Payment Id.
                CheckNumber   = "CN#" + i,
                PaymentAmount = 100
            }).ToArray();

            CommandResponse[] commandResponses = corrigoService.ExecuteMultiple(commands);

            Console.WriteLine(
                $"# of ApSubmitPaymentCommand executed with success/total: {commandResponses.Count(cr => cr.ErrorInfo == null)} / {commands.Length}");
            //Console.ReadKey();

            WorkOrderCost[] results = corrigoService.RetrieveMultiple(
                new QueryExpression
            {
                EntityType  = EntityType.WorkOrderCost,
                PropertySet = new PropertySet
                {
                    Properties = new string[]
                    {
                        "Id",
                        "CheckNumber",
                        "ApStateId",
                        "PaymentAmount"
                    }
                },
                Criteria = new FilterExpression
                {
                    Conditions = new ConditionExpression[]
                    {
                        new ConditionExpression
                        {
                            PropertyName = "Id",
                            Operator     = ConditionOperator.In,
                            Values       = invoiceIDs.Cast <object>().ToArray()
                        }
                    },
                },
                Orders = new[]
                {
                    new OrderExpression
                    {
                        PropertyName = "Id",
                        OrderType    = OrderType.Ascending
                    }
                },
            }).Cast <WorkOrderCost>().ToArray();


            return(results);
        }
Esempio n. 2
0
        /// <summary>
        /// Update the status of specified invoices to "Exported"
        /// Operation: ExecuteMultiple(CommandRequest[])
        /// Update the retrieved list of Invoices as follows:
        ///     Set
        ///       Invoice Status = "Exported"
        ///     Where
        ///       Invoice Id IN (list of Invoice IDs)
        /// </summary>
        /// <param name="corrigoService"></param>
        /// <param name="invoiceIDs"></param>
        /// <param name="invoiceStatus"></param>
        /// <returns></returns>
        public static CommandResponse[] UpdateInvoiceStatus(CorrigoService corrigoService,
                                                            int[] invoiceIDs,
                                                            APInvoiceStatus invoiceStatus)
        {
            CommandRequest[] commands = invoiceIDs.Select(i =>
                                                          new ApStatusChangeCommand

            {
                WorkOrderId           = i, // Invoice Id is equal to Work Order Id.
                VendorInvoiceStatusId = invoiceStatus
            }).ToArray();

            CommandResponse[] commandResponses = corrigoService.ExecuteMultiple(commands);

            Console.WriteLine(
                $"# of ApStatusChangeCommand executed with success/total: {commandResponses.Count(cr => cr.ErrorInfo == null)} / {commands.Length}");
            //Console.ReadKey();

            return(commandResponses);
        }
Esempio n. 3
0
        /// <summary>
        /// Use Case1: Place Work Orders "On Hold"
        /// Operation: ExecuteMultiple(QueryByProperty)
        /// Update a list of Work Orders as follows:
        ///   Set
        ///       Work Order Status = "On Hold"
        ///       Action Reason Id = Id
        ///  Where
        ///       Work Order Status not in ("Completed", "Open: Paused", "On Hold")
        ///       AND Work Order Create Date >= Some Date
        /// </summary>
        /// <param name="corrigoService"></param>
        public static void ExecuteMultipleWoOnHoldCommand(CorrigoService corrigoService)
        {
            var workOrders = corrigoService.RetrieveMultiple(
                new QueryExpression
            {
                EntityType  = EntityType.WorkOrder,
                PropertySet = new PropertySet
                {
                    Properties = new[] { "Id" }
                },
                Criteria = new FilterExpression
                {
                    Conditions = new ConditionExpression[]
                    {
                        new ConditionExpression
                        {
                            PropertyName = "StatusId",
                            Operator     = ConditionOperator.NotIn,
                            Values       = new object[] { WorkOrderStatus.Completed, WorkOrderStatus.Paused, WorkOrderStatus.OnHold }
                        },
                        new ConditionExpression
                        {
                            PropertyName = "CreatedDateUtc",
                            Operator     = ConditionOperator.GreaterOrEqual,
                            Values       = new object[] { DateTime.Now.AddDays(-1) }
                        }
                    },
                    FilterOperator = LogicalOperator.And
                },
                Orders = new[]
                {
                    new OrderExpression
                    {
                        OrderType    = OrderType.Ascending,
                        PropertyName = "Id"
                    }
                },
            });


            int otherReasonLookupId = corrigoService.RetrieveMultiple(
                new QueryByProperty
            {
                EntityType  = EntityType.WoActionReasonLookup,
                PropertySet = new PropertySet
                {
                    Properties = new[] { "Id", "ReasonId" }
                },
                Conditions = new[]
                {
                    new PropertyValuePair {
                        PropertyName = "ActionId", Value = WOActionType.OnHold
                    }
                }
            }).FirstOrDefault(ar =>
                              ((WoActionReasonLookup)ar).ReasonId == 4)?.Id ?? 0;

            //4 "Other reason" Id. One of pre-defined reasons ids, expectation is user/contact provides a more specific description in comments
            //See reasons in Admin & Settings->Work Order and workflow->action reasons
            //Get reason ids is possible only from settings html or from db, there are predefined reasons

            //for OnHold:
            //ReasonID	Name
            //   3       Request Needs Customer Approval
            //   4       Other
            //   5       Estimate Needs Customer Approval
            //   6       Waiting for Estimate
            //   9       Dependency
            //   23      Deferred

            //for Cancel:
            //ReasonID    Name
            //     2     Customer Cancel Request
            //     4     Other
            //     7     All Work Items Removed from Work Order

            //for Flagging
            //ReasonID	Name
            //   6	    Other
            //   8	    Estimate Rejected
            //   11	    Rejected by {!{Provider}!}



            CommandRequest[] commands = workOrders.Select(wo =>
                                                          new WoOnHoldCommand
            {
                WorkOrderId    = wo.Id,
                ActionReasonId = otherReasonLookupId
            }).ToArray();

            CommandResponse[] commandResponses = corrigoService.ExecuteMultiple(commands);

            Console.WriteLine($"# of WoOnHoldCommand executed with success/total: {commandResponses.Count(cr => cr.ErrorInfo == null)} / {commands.Length}");
            //Console.ReadKey();
        }