/// <summary>
        /// List expenses with pagination.
        /// </summary>
        /// <param name="parameters">The parameters is the dictionary object which contains the filters in the form of key,value pairs to refine the list.<br></br>The possible filters are listed below <br></br>
        /// <table>
        /// <tr><td>description</td><td>Search expenses by description.<br></br>Variants: <i>description_startswith</i> and <i>description_contains</i></td></tr>
        /// <tr><td>reference_number</td><td>Search expenses by reference number.<br></br>Variants: <i>reference_number_startswith</i> and <i>reference_number_contains</i></td></tr>
        /// <tr><td>date</td><td>Search expenses by expense date.<br></br>Variants: <i>date_start, date_end, date_before</i> and <i>date_after</i></td></tr>
        /// <tr><td>status</td><td>Search expenses by expense status.<br></br>Allowed Values: <i>unbilled, invoiced, reimbursed, non-billable</i> and <i>billable</i></td></tr>
        /// <tr><td>account_name</td><td>Search expenses by expense account name.<br></br>Variants: <i>account_name_startswith</i> and <i>account_name_contains</i></td></tr>
        /// <tr><td>amount</td><td>Search expenses by amount.<br></br>Variants: <i>amount_less_than, amount_less_equals, amount_greater_than</i> and <i>amount_greater_equals</i></td></tr>
        /// <tr><td>customer_name</td><td>Search expenses by customer name.<br></br>Variants: <i>customer_name_startswith</i> and <i>customer_name_contains</i></td></tr>
        /// <tr><td>vendor_name</td><td>Search expenses by vendor name.<br></br>Variants: <i>vendor_name_startswith</i> and <i>vendor_name_contains</i></td></tr>
        /// <tr><td>customer_id</td><td>Search expenses by customer id.</td></tr>
        /// <tr><td>vendor_id</td><td>Search expenses by vendor id.</td></tr>
        /// <tr><td>recurring_expense_id</td><td>Search expenses by recurring expense id.</td></tr>
        /// <tr><td>paid_through_account_id</td><td>Search expenses by paid through account id.</td></tr>
        /// <tr>filter_by<td></td><td>Filter expenses by expense status.<br></br>Allowed Values: <i>Status.All, Status.Billable, Status.Nonbillable, Status.Reimbursed, Status.Invoiced</i> and <i>Status.Unbilled</i></td></tr>
        /// <tr><td>search_text</td><td>Search expenses by category name or description or customer name or vendor name.</td></tr>
        /// <tr><td>sort_column</td><td>ort expenses.<br></br>Allowed Values: <i>date, account_name, paid_through_account_name, total, bcy_total, reference_number, customer_name, vendor_name</i> and <i>created_time</i></td></tr>
        /// </table>
        /// </param>
        /// <returns>ExpenseList object.</returns>
        public ExpenseList GetExpenses(Dictionary <object, object> parameters)
        {
            string url      = baseAddress;
            var    responce = ZohoHttpClient.get(url, getQueryParameters(parameters));

            return(ExpenseParser.getExpenseList(responce));
        }
        /// <summary>
        /// Get the details of an expense.
        /// </summary>
        /// <param name="expense_id">The expense_id is the identifier of the expense.</param>
        /// <returns>Expense object.</returns>
        public Expense Get(string expense_id)
        {
            string url      = baseAddress + "/" + expense_id;
            var    responce = ZohoHttpClient.get(url, getQueryParameters());

            return(ExpenseParser.getExpense(responce));
        }
Exemple #3
0
        public void SampleData()
        {
            string sampleText =
                @"Hi Yvaine,
Please create an expense claim for the below.Relevant details are marked up as
requested…
<expense><cost_centre>DEV002</cost_centre>
<total>1024.01</total><payment_method>personal card</payment_method>
</expense>
From: Ivan Castle
Sent: Friday, 16 February 2018 10:32 AM
To: Antoine Lloyd <Antoine.Lloyd @example.com>
Subject: test
Hi Antoine,
Please create a reservation at the <vendor>Viaduct Steakhouse</vendor> our
<description> development team’s project end celebration dinner</description> on
<date>Thursday 27 April 2017</date>. We expect to arrive around
7.15pm.Approximately 12 people but I’ll confirm exact numbers closer to the day.
Regards,
Ivan";
            var ExpenseParser = new ExpenseParser();
            var Expense       = ExpenseParser.ExtractExpenseData(sampleText);

            Assert.AreEqual("DEV002", Expense.cost_centre);
            Assert.AreEqual((Decimal)1024.01, Expense.total);
            Assert.AreEqual("personal card", Expense.payment_method);
            Assert.AreEqual("Viaduct Steakhouse", Expense.vendor);
            Assert.AreEqual(" development team’s project end celebration dinner", Expense.description);
            Assert.AreEqual(new DateTime(2017, 4, 27), Expense.date.Date);
        }
        /// <summary>
        /// Deletes the receipt attached to the expense.
        /// </summary>
        /// <param name="expense_id">The expense_id is the identifier of the expense.</param>
        /// <returns>System.String.<br></br>The success message is "The attached expense receipt has been deleted."</returns>
        public string DeleteReceipt(string expense_id)
        {
            string url      = baseAddress + "/" + expense_id + "/receipt";
            var    responce = ZohoHttpClient.delete(url, getQueryParameters());

            return(ExpenseParser.getMessage(responce));
        }
Exemple #5
0
 public Expense ReadText(string expenseText)
 {
     try
     {
         var expenseParser = new ExpenseParser();
         return(expenseParser.ExtractExpenseData(expenseText));
     }
     //report back the specified errors
     catch (CustomExpenseException ex)
     {
         var response = new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content      = new StringContent(ex.Message),
             ReasonPhrase = "Error:" + ex.Message
         };
         throw new HttpResponseException(response);
     }
     //everything else, dont expose, todo: either log or notify in windows event log
     catch (Exception)
     {
         var response = new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content      = new StringContent("Internal error"),
             ReasonPhrase = "Internal Error"
         };
         throw new HttpResponseException(response);
     }
 }
        /// <summary>
        /// Attach a receipt to an expense.
        /// </summary>
        /// <param name="expense_id">The expense_id is the identifier of the expense.</param>
        /// <param name="receipt_path">The receipt_path is the path of the file which is going to be attaches as a receipt to the expense.</param>
        /// <returns>System.String.<br></br>The success message is "The expense receipt has been attached."</returns>
        public string AddReceipt(string expense_id, string receipt_path)
        {
            string url         = baseAddress + "/" + expense_id + "/receipt";
            var    attachments = new string[] { receipt_path };
            var    file        = new KeyValuePair <string, string[]>("receipt", attachments);
            var    responce    = ZohoHttpClient.post(url, getQueryParameters(), null, file);

            return(ExpenseParser.getMessage(responce));
        }
        /// <summary>
        /// Create a billable or non-billable expense.
        /// </summary>
        /// <param name="new_expense">The new_expense is the Expense object which contains the new expense information with account_id and amount as mandatory attributes.</param>
        /// <param name="receipt_path">The receipt_path is the path of the file which is going to be attaches as a receipt to the expense.</param>
        /// <returns>Expense object.</returns>
        public Expense Create(Expense new_expense, string receipt_path)
        {
            string url        = baseAddress;
            var    json       = JsonConvert.SerializeObject(new_expense);
            var    jsonstring = new Dictionary <object, object>();

            jsonstring.Add("JSONString", json);
            var attachments = new string[] { receipt_path };
            var file        = new KeyValuePair <string, string[]>("receipt", attachments);
            var responce    = ZohoHttpClient.post(url, getQueryParameters(), jsonstring, file);

            return(ExpenseParser.getExpense(responce));
        }
        /// <summary>
        /// Update an existing expense.
        /// </summary>
        /// <param name="expense_id">The expense_id is the identifier of the expense.</param>
        /// <param name="update_info">The update_info is the Expense object which contains the update information.</param>
        /// <param name="receipt_path">The receipt_path is the path of the file which is going to be attaches as a receipt to the expense.</param>
        /// <returns>Expense object.</returns>
        public Expense Update(string expense_id, Expense update_info, string receipt_path)
        {
            string url = baseAddress + "/" + expense_id;

            var file       = new KeyValuePair <string, string>("receipt", receipt_path);
            var json       = JsonConvert.SerializeObject(update_info);
            var jsonstring = new Dictionary <object, object>();

            jsonstring.Add("JSONString", json);
            var responce = ZohoHttpClient.put(url, getQueryParameters(), jsonstring, file);

            return(ExpenseParser.getExpense(responce));
        }
Exemple #9
0
        public void UnknownCostCentre()
        {
            var    ExpenseParser     = new ExpenseParser();
            string UnknownCostCentre =
                @"Hi Yvaine,
Please create an expense claim for the below.Relevant details are marked up as
requested…
<expense>
<payment_method>personal card</payment_method>
</expense><total>100.00</total> xxzbc ";
            var Expense = ExpenseParser.ExtractExpenseData(UnknownCostCentre);

            Assert.AreEqual("UNKNOWN", Expense.cost_centre);
        }
Exemple #10
0
        public void MissingClosingTag()
        {
            var ExpenseParser = new ExpenseParser();


            string MissingTotalText =
                @"Hi Yvaine,
Please create an expense claim for the below.Relevant details are marked up as
requested…
<expense><cost_centre>DEV002</cost_centre>
<payment_method>personal card</payment_method>
</expense><total>100.00</total> xx <date> zbc ";

            try
            {
                var Expense = ExpenseParser.ExtractExpenseData(MissingTotalText);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(NoClosingTagException), ex.GetType());
                Assert.AreEqual("No Closing Tag for: date", ex.Message);
            }
        }