Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

Added ZohoInvoice and fixed some typos #10

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Deveel.ZohoCRM/Deveel.Web.Zoho/AccountDefaultFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class AccountDefaultFields {
public const string ShippingState = "Shipping State";
public const string ShippingCountry = "Shipping Country";
public const string ShippingCode = "Shipping Code";
public const string Emplyees = "Employees";
public const string Employees = "Employees";
public const string Ownership = "Ownership";
public const string Website = "Website";

Expand All @@ -43,7 +43,7 @@ public static class AccountDefaultFields {
ShippingState,
ShippingCountry,
ShippingCode,
Emplyees,
Employees,
Ownership,
Website
};
Expand Down
7 changes: 5 additions & 2 deletions src/Deveel.ZohoCRM/Deveel.Web.Zoho/ContactDefaultFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
namespace Deveel.Web.Zoho {
public static class ContactDefaultFields {
public const string ContactId = "CONTACTID";
public const string ProductId = "PRODUCTID";
public const string Email = "Email";
public const string FirstName = "First Name";
public const string LastName = "Last Name";
public const string AccountName = "Account Name";
public const string AccountId = "ACCOUNTID";
public const string EmailOptOut = "Email Opt Out";
public const string Phone = "Phone";
public const string HomePhone = "Home Phone";
Expand All @@ -27,7 +29,7 @@ public static class ContactDefaultFields {
public const string MailingCountry = "Mailing Country";
public const string MailingState = "Mailing State";
public const string MailingStreet = "Mailing Street";
public const string MailingCode = "Mailing Code";
public const string MailingCode = "Mailing Zip";

public static readonly IEnumerable<string> All = new[] {
Email,
Expand All @@ -53,7 +55,8 @@ public static class ContactDefaultFields {
MailingCountry,
MailingCode,
MailingStreet,
MailingState
MailingState,
ProductId
};
}
}
8 changes: 4 additions & 4 deletions src/Deveel.ZohoCRM/Deveel.Web.Zoho/ZohoAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public string ShippingCity {
}

public string ShippingState {
get { return GetString(AccountDefaultFields.BillingState); }
set { SetValue(AccountDefaultFields.BillingState, value); }
get { return GetString(AccountDefaultFields.ShippingState); }
set { SetValue(AccountDefaultFields.ShippingState, value); }
}

public string ShippingCountry {
Expand All @@ -103,8 +103,8 @@ public string ShippingZipCode {
}

public int Employees {
get { return GetInt32(AccountDefaultFields.Emplyees); }
set { SetValue(AccountDefaultFields.Emplyees, value); }
get { return GetInt32(AccountDefaultFields.Employees); }
set { SetValue(AccountDefaultFields.Employees, value); }
}

public string Ownership {
Expand Down
12 changes: 11 additions & 1 deletion src/Deveel.ZohoCRM/Deveel.Web.Zoho/ZohoContact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ protected override string IdFieldName {
get { return ContactDefaultFields.ContactId; }
}

public string ProductId {
get { return ContactDefaultFields.ProductId; }
set { SetValue(ContactDefaultFields.ProductId, value); }
}

public string FirstName {
get { return GetString(ContactDefaultFields.FirstName); }
set { SetValue(ContactDefaultFields.FirstName, value); }
Expand All @@ -43,6 +48,11 @@ public string AccountName {
set { SetValue(ContactDefaultFields.AccountName, value); }
}

public string AccountId {
get { return GetString(ContactDefaultFields.AccountId); }
set { SetValue(ContactDefaultFields.AccountId, value); }
}

public bool EmailOptOut {
get { return GetBoolean(ContactDefaultFields.EmailOptOut); }
set { SetValue(ContactDefaultFields.EmailOptOut, value); }
Expand Down Expand Up @@ -138,7 +148,7 @@ public string MailingStreet {
set { SetValue(ContactDefaultFields.MailingStreet, value); }
}

public string MialingCode {
public string MailingCode {
get { return GetString(ContactDefaultFields.MailingCode); }
set { SetValue(ContactDefaultFields.MailingCode, value);}
}
Expand Down
32 changes: 30 additions & 2 deletions src/Deveel.ZohoCRM/Deveel.Web.Zoho/ZohoCrmClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ private string GetData(string module, string method, IEnumerable<KeyValuePair<st
}

var response = client.Execute(request);
if (response.StatusCode != HttpStatusCode.OK)
var uri = client.BuildUri(request);

if (response.StatusCode != HttpStatusCode.OK)
throw response.ErrorException;


return response.Content;
}

Expand Down Expand Up @@ -153,10 +156,15 @@ private ZohoInsertResponse PostData(string module, string method, IDictionary<st
if (!String.IsNullOrEmpty(xmlData))
request.AddParameter("xmlData", xmlData);


var response = client.Execute(request);
var uri = client.BuildUri(request);

if (response.StatusCode != HttpStatusCode.OK)
throw response.ErrorException;



return new ZohoInsertResponse(module, method, response.Content);
}

Expand Down Expand Up @@ -250,6 +258,26 @@ public ZohoEntityCollection<TRelated> GetRelatedRecordsTo<TSource, TRelated>(str
return GetEntities<TRelated>(ModuleName<TRelated>(), "getRelatedRecords", paremeters);
}

public bool UpdateRelatedRecords<TSource, TRelated>(string id, TRelated record) where TSource : ZohoEntity where TRelated : ZohoEntity {
AssertTypeIsNotAbstract(typeof(TSource));
AssertTypeIsNotAbstract(typeof(TRelated));

var parentModuleName = ModuleName<TSource>();
var relatedModuleName = ModuleName(typeof(TRelated));
var parameters = new Dictionary<string, string>();
parameters.Add("id", id);
parameters.Add("relatedModule", relatedModuleName);


var collection = new ZohoEntityCollection<TRelated> { record };
var xmlData = collection.ToXmlString();
var response = PostData(parentModuleName, "updateRelatedRecords", parameters, xmlData);
if (response.IsError)
throw new InvalidOperationException("Error updating records");

return response.IsError;
}

public ZohoEntityCollection<ZohoAttachment> GetRecordAttachments<T>(string id) where T : ZohoEntity {
return GetRelatedRecordsTo<T, ZohoAttachment>(id, null, null);
}
Expand Down Expand Up @@ -309,5 +337,5 @@ public UserContext CreateUserContext(string userEmail) {

return new UserContext(this, user);
}
}
}
}
10 changes: 9 additions & 1 deletion src/Deveel.ZohoCRM/Deveel.Web.Zoho/ZohoEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,15 @@ public XElement ToXml() {
internal virtual void LoadFromXml(XElement element) {
var fieldNodes = element.Descendants();
foreach (var node in fieldNodes) {
LoadFieldFromXml(node);
try
{
LoadFieldFromXml(node);
}
// Skip over malformed XLM - atb
catch (FormatException e)
{
continue;
}
}
}

Expand Down
80 changes: 80 additions & 0 deletions src/Deveel.ZohoCRM/Deveel.Web.Zoho/ZohoInvoice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;

namespace Deveel.Web.Zoho {
[ModuleName("Invoices")]
public sealed class ZohoInvoice : ZohoOrderBase {
public ZohoInvoice(string subject)
: base(subject) {
}

internal ZohoInvoice() {
}

protected override string IdFieldName {
get { return "INVOICEID"; }
}

public string AccountName {
get { return GetString("Account Name"); }
set { SetValue("Account Name", value); }
}

public string ContactID {
get { return GetString("CONTACTID"); }
set { SetValue("CONTACTID", value); }
}


public string CustomerNumber {
get { return GetString("Customer No"); }
set { SetValue("Customer No", value); }
}

public string PurchaseOrder {
get { return GetString("Purchase Order"); }
set { SetValue("Purchase Order", value); }
}

public string QuoteName {
get { return GetString("Invoice Number"); }
set { SetValue("Invoice Number", value); }
}

public string Status {
get { return GetString("Status"); }
set { SetValue("Status", value); }
}

public decimal Discount {
get { return GetDecimal("Discount"); }
set { SetValue("Discount", value); }
}

public decimal GrandTotal {
get { return GetDecimal("Grand Total"); }
set { SetValue("Grand Total", value); }
}

public decimal Tax {
get { return GetDecimal("Tax"); }
set { SetValue("Tax", value); }
}

public decimal SubTotal {
get { return GetDecimal("Sub Total"); }
set { SetValue("Sub Total", value); }
}

public decimal NetTotal {
get { return GetDecimal("Net Total"); }
set { SetValue("Net Total", value); }
}

public DateTime InvoiceDate
{
get { return GetDateTime("Invoice Date"); }
set { SetValue("Invoice Date", value); }
}

}
}
10 changes: 8 additions & 2 deletions src/Deveel.ZohoCRM/Deveel.Web.Zoho/ZohoProduct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ internal ZohoProduct()
{
}

protected override string IdFieldName
//protected override string IdFieldName
//{
// get { return "PRODUCTID"; }
//}

public string productId
{
get { return "PRODUCTID"; }
get { return GetString("PRODUCTID"); }
set { SetValue("PRODUCTID", value); }
}

public string Name
Expand Down
19 changes: 11 additions & 8 deletions src/Deveel.ZohoCRM/Deveel.ZohoCRM.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -10,9 +10,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Deveel.Web</RootNamespace>
<AssemblyName>Deveel.ZohoCRM</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
Expand All @@ -24,6 +25,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -32,6 +34,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
Expand All @@ -41,11 +44,9 @@
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="RestSharp">
<HintPath>..\packages\RestSharp.104.1\lib\net35\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -79,6 +80,7 @@
<Compile Include="Deveel.Web.Zoho\ZohoEntity.cs" />
<Compile Include="Deveel.Web.Zoho\ZohoEntityCollection.cs" />
<Compile Include="Deveel.Web.Zoho\ZohoInsertResponse.cs" />
<Compile Include="Deveel.Web.Zoho\ZohoInvoice.cs" />
<Compile Include="Deveel.Web.Zoho\ZohoLead.cs" />
<Compile Include="Deveel.Web.Zoho\ZohoEntityContext.cs" />
<Compile Include="Deveel.Web.Zoho\ZohoOrderBase.cs" />
Expand All @@ -95,9 +97,10 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<PackageReference Include="RestSharp">
<Version>106.6.9</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
4 changes: 0 additions & 4 deletions src/Deveel.ZohoCRM/packages.config

This file was deleted.