2020-04-16 19:41:37 +00:00
/ *
*
* ( c ) Copyright Ascensio System Limited 2010 - 2018
*
* This program is freeware . You can redistribute it and / or modify it under the terms of the GNU
* General Public License ( GPL ) version 3 as published by the Free Software Foundation ( https : //www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7 ( a ) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non - infringement of any third - party rights .
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY ; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE . For more details , see GNU GPL at https : //www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales @onlyoffice . com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices , as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3 ( b ) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software . If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons , you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute .
* Pursuant to Section 7 § 3 ( e ) we decline to grant you any rights under trademark law for use of our trademarks .
*
* /
using ASC.Common.Threading.Progress ;
using ASC.CRM.Core ;
using ASC.CRM.Core.Entities ;
2020-04-18 17:49:09 +00:00
using ASC.CRM.Core.Enums ;
using ASC.CRM.Resources ;
2020-04-16 19:41:37 +00:00
using ASC.MessagingSystem ;
using ASC.Web.Api.Routing ;
using ASC.Web.Core.Utility ;
using ASC.Web.CRM.Classes ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Security ;
namespace ASC.Api.CRM
{
public partial class CRMController
{
/// <summary>
/// Returns the list of all currencies currently available on the portal
/// </summary>
/// <short>Get currency list</short>
/// <category>Common</category>
/// <returns>
/// List of available currencies
/// </returns>
[Read(@"settings/currency")]
public IEnumerable < CurrencyInfoWrapper > GetAvaliableCurrency ( )
{
2020-04-18 17:49:09 +00:00
return CurrencyProvider . GetAll ( ) . ConvertAll ( item = > CurrencyInfoWrapperHelper . Get ( item ) ) ;
2020-04-16 19:41:37 +00:00
}
/// <summary>
/// Returns the result of convertation from one currency to another
/// </summary>
/// <param name="amount">Amount to convert</param>
/// <param name="fromcurrency">Old currency key</param>
/// <param name="tocurrency">New currency key</param>
/// <short>Get the result of convertation</short>
/// <category>Common</category>
/// <returns>
/// Decimal result of convertation
/// </returns>
[Read(@"settings/currency/convert")]
public Decimal ConvertAmount ( Decimal amount , String fromcurrency , String tocurrency )
{
return CurrencyProvider . MoneyConvert ( amount , fromcurrency , tocurrency ) ;
}
/// <summary>
/// Returns the summary table with rates for selected currency
/// </summary>
/// <param name="currency" remark="Allowed values: EUR, RUB etc. You can get the whole list of available currencies by api">Currency (Abbreviation)</param>
/// <short>Get the summary table</short>
/// <category>Common</category>
/// <returns>
/// Dictionary of currencies and rates
/// </returns>
/// <exception cref="ArgumentException"></exception>
[Read(@"settings/currency/summarytable")]
public IEnumerable < CurrencyRateInfoWrapper > GetSummaryTable ( String currency )
{
var result = new List < CurrencyRateInfoWrapper > ( ) ;
if ( string . IsNullOrEmpty ( currency ) )
{
throw new ArgumentException ( ) ;
}
var cur = CurrencyProvider . Get ( currency . ToUpper ( ) ) ;
if ( cur = = null ) throw new ArgumentException ( ) ;
var table = CurrencyProvider . MoneyConvert ( cur ) ;
2020-04-18 17:49:09 +00:00
table . ToList ( ) . ForEach ( tableItem = > result . Add ( CurrencyRateInfoWrapperHelper . Get ( tableItem . Key , tableItem . Value ) ) ) ;
2020-04-16 19:41:37 +00:00
return result ;
}
/// <summary>
///
/// </summary>
/// <param name="changeContactStatusGroupAuto" remark="true, false or null">Change contact status group auto</param>
/// <short></short>
/// <category>Contacts</category>
/// <returns>
/// ChangeContactStatusGroupAuto setting value (true, false or null)
/// </returns>
/// <exception cref="SecurityException"></exception>
[Update(@"contact/status/settings")]
public Boolean ? UpdateCRMContactStatusSettings ( Boolean ? changeContactStatusGroupAuto )
2020-04-18 17:49:09 +00:00
{
var tenantSettings = SettingsManager . Load < CRMSettings > ( ) ;
2020-04-16 19:41:37 +00:00
tenantSettings . ChangeContactStatusGroupAuto = changeContactStatusGroupAuto ;
2020-04-18 17:49:09 +00:00
SettingsManager . Save < CRMSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
MessageService . Send ( MessageAction . ContactTemperatureLevelSettingsUpdated ) ;
return changeContactStatusGroupAuto ;
}
/// <summary>
///
/// </summary>
/// <param name="writeMailToHistoryAuto" remark="true or false">Write mail to history auto</param>
/// <short></short>
/// <category>Contacts</category>
/// <returns>
/// WriteMailToHistoryAuto setting value (true or false)
/// </returns>
/// <exception cref="SecurityException"></exception>
[Update(@"contact/mailtohistory/settings")]
public Boolean UpdateCRMWriteMailToHistorySettings ( Boolean writeMailToHistoryAuto )
{
2020-04-18 17:49:09 +00:00
var tenantSettings = SettingsManager . Load < CRMSettings > ( ) ;
2020-04-16 19:41:37 +00:00
tenantSettings . WriteMailToHistoryAuto = writeMailToHistoryAuto ;
2020-04-18 17:49:09 +00:00
SettingsManager . Save < CRMSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
//MessageService.Send( MessageAction.ContactTemperatureLevelSettingsUpdated);
return writeMailToHistoryAuto ;
}
/// <summary>
///
/// </summary>
/// <param name="addTagToContactGroupAuto" remark="true, false or null">add tag to contact group auto</param>
/// <short></short>
/// <category>Contacts</category>
/// <returns>
/// AddTagToContactGroupAuto setting value (true, false or null)
/// </returns>
/// <exception cref="SecurityException"></exception>
[Update(@"contact/tag/settings")]
public Boolean ? UpdateCRMContactTagSettings ( Boolean ? addTagToContactGroupAuto )
{
2020-04-18 17:49:09 +00:00
var tenantSettings = SettingsManager . Load < CRMSettings > ( ) ;
2020-04-16 19:41:37 +00:00
tenantSettings . AddTagToContactGroupAuto = addTagToContactGroupAuto ;
2020-04-18 17:49:09 +00:00
SettingsManager . Save < CRMSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
MessageService . Send ( MessageAction . ContactsTagSettingsUpdated ) ;
return addTagToContactGroupAuto ;
}
/// <summary>
/// Set IsConfiguredPortal tenant setting and website contact form key specified in the request
/// </summary>
/// <short>Set tenant settings</short>
/// <category>Common</category>
/// <returns>
/// IsConfiguredPortal setting value (true or false)
/// </returns>
[Update(@"settings")]
public Boolean SetIsPortalConfigured ( Boolean ? configured , Guid ? webFormKey )
{
if ( ! CRMSecurity . IsAdmin ) throw CRMSecurity . CreateSecurityException ( ) ;
2020-04-18 17:49:09 +00:00
var tenantSettings = SettingsManager . Load < CRMSettings > ( ) ;
2020-04-16 19:41:37 +00:00
tenantSettings . IsConfiguredPortal = configured ? ? true ;
tenantSettings . WebFormKey = webFormKey ? ? Guid . NewGuid ( ) ;
2020-04-18 17:49:09 +00:00
SettingsManager . Save < CRMSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
return tenantSettings . IsConfiguredPortal ;
}
/// <summary>
/// Save organisation company name
/// </summary>
/// <param name="companyName">Organisation company name</param>
/// <short>Save organisation company name</short>
/// <category>Organisation</category>
/// <returns>Organisation company name</returns>
/// <exception cref="SecurityException"></exception>
[Update(@"settings/organisation/base")]
public String UpdateOrganisationSettingsCompanyName ( String companyName )
{
if ( ! CRMSecurity . IsAdmin ) throw CRMSecurity . CreateSecurityException ( ) ;
2020-04-18 17:49:09 +00:00
var tenantSettings = SettingsManager . Load < CRMSettings > ( ) ;
2020-04-16 19:41:37 +00:00
if ( tenantSettings . InvoiceSetting = = null )
{
tenantSettings . InvoiceSetting = InvoiceSetting . DefaultSettings ;
}
tenantSettings . InvoiceSetting . CompanyName = companyName ;
2020-04-18 17:49:09 +00:00
SettingsManager . Save < CRMSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
MessageService . Send ( MessageAction . OrganizationProfileUpdatedCompanyName , companyName ) ;
return companyName ;
}
/// <summary>
/// Save organisation company address
/// </summary>
/// <param name="street">Organisation company street/building/apartment address</param>
/// <param name="city">City</param>
/// <param name="state">State</param>
/// <param name="zip">Zip</param>
/// <param name="country">Country</param>
/// <short>Save organisation company address</short>
/// <category>Organisation</category>
/// <returns>Returns a JSON object with the organization company address details</returns>
/// <exception cref="SecurityException"></exception>
[Update(@"settings/organisation/address")]
public String UpdateOrganisationSettingsCompanyAddress ( String street , String city , String state , String zip , String country )
{
if ( ! CRMSecurity . IsAdmin ) throw CRMSecurity . CreateSecurityException ( ) ;
2020-04-18 17:49:09 +00:00
var tenantSettings = SettingsManager . Load < CRMSettings > ( ) ;
2020-04-16 19:41:37 +00:00
if ( tenantSettings . InvoiceSetting = = null )
{
tenantSettings . InvoiceSetting = InvoiceSetting . DefaultSettings ;
}
var companyAddress = Newtonsoft . Json . JsonConvert . SerializeObject ( new
{
type = AddressCategory . Billing . ToString ( ) ,
street ,
city ,
state ,
zip ,
country
} ) ;
tenantSettings . InvoiceSetting . CompanyAddress = companyAddress ;
2020-04-18 17:49:09 +00:00
SettingsManager . Save < CRMSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
MessageService . Send ( MessageAction . OrganizationProfileUpdatedAddress ) ;
return companyAddress ;
}
/// <summary>
/// Save organisation logo
/// </summary>
/// <param name="reset">Reset organisation logo</param>
/// <short>Save organisation logo</short>
/// <category>Organisation</category>
/// <returns>Organisation logo ID</returns>
/// <exception cref="SecurityException"></exception>
/// <exception cref="Exception"></exception>
[Update(@"settings/organisation/logo")]
public Int32 UpdateOrganisationSettingsLogo ( bool reset )
{
if ( ! CRMSecurity . IsAdmin ) throw CRMSecurity . CreateSecurityException ( ) ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
int companyLogoID ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
if ( ! reset )
{
companyLogoID = OrganisationLogoManager . TryUploadOrganisationLogoFromTmp ( DaoFactory ) ;
if ( companyLogoID = = 0 )
{
throw new Exception ( "Downloaded image not found" ) ;
}
}
else
{
companyLogoID = 0 ;
}
2020-04-18 17:49:09 +00:00
var tenantSettings = SettingsManager . Load < CRMSettings > ( ) ;
2020-04-16 19:41:37 +00:00
if ( tenantSettings . InvoiceSetting = = null )
{
tenantSettings . InvoiceSetting = InvoiceSetting . DefaultSettings ;
}
tenantSettings . InvoiceSetting . CompanyLogoID = companyLogoID ;
2020-04-18 17:49:09 +00:00
SettingsManager . Save < CRMSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
MessageService . Send ( MessageAction . OrganizationProfileUpdatedInvoiceLogo ) ;
return companyLogoID ;
}
/// <summary>
/// Get organisation logo in base64 format (if 'id' is 0 then take current logo)
/// </summary>
/// <param name="id">organisation logo id</param>
/// <short>Get organisation logo</short>
/// <category>Organisation</category>
/// <returns>Organisation logo content in base64</returns>
/// <exception cref="Exception"></exception>
[Read(@"settings/organisation/logo")]
public String GetOrganisationSettingsLogo ( int id )
{
if ( id ! = 0 )
{
return OrganisationLogoManager . GetOrganisationLogoBase64 ( id ) ;
}
else
{
2020-04-18 17:49:09 +00:00
var tenantSettings = SettingsManager . Load < CRMSettings > ( ) ;
2020-04-16 19:41:37 +00:00
if ( tenantSettings . InvoiceSetting = = null )
{
return string . Empty ;
}
return OrganisationLogoManager . GetOrganisationLogoBase64 ( tenantSettings . InvoiceSetting . CompanyLogoID ) ;
}
}
/// <summary>
/// Change Website Contact Form key
/// </summary>
/// <short>Change web form key</short>
/// <category>Common</category>
/// <returns>Web form key</returns>
/// <exception cref="SecurityException"></exception>
[Update(@"settings/webformkey/change")]
public string ChangeWebToLeadFormKey ( )
{
if ( ! CRMSecurity . IsAdmin ) throw CRMSecurity . CreateSecurityException ( ) ;
2020-04-18 17:49:09 +00:00
var tenantSettings = SettingsManager . Load < CRMSettings > ( ) ;
2020-04-16 19:41:37 +00:00
tenantSettings . WebFormKey = Guid . NewGuid ( ) ;
2020-04-18 17:49:09 +00:00
SettingsManager . Save < CRMSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
MessageService . Send ( MessageAction . WebsiteContactFormUpdatedKey ) ;
return tenantSettings . WebFormKey . ToString ( ) ;
}
/// <summary>
/// Change default CRM currency
/// </summary>
/// <param name="currency" remark="Allowed values: EUR, RUB etc. You can get the whole list of available currencies by api">Currency (Abbreviation)</param>
/// <short>Change currency</short>
/// <category>Common</category>
/// <returns>currency</returns>
/// <exception cref="SecurityException"></exception>
/// <exception cref="ArgumentException"></exception>
[Update(@"settings/currency")]
public CurrencyInfoWrapper UpdateCRMCurrency ( String currency )
{
if ( ! CRMSecurity . IsAdmin ) throw CRMSecurity . CreateSecurityException ( ) ;
if ( string . IsNullOrEmpty ( currency ) )
{
throw new ArgumentException ( ) ;
}
currency = currency . ToUpper ( ) ;
var cur = CurrencyProvider . Get ( currency ) ;
if ( cur = = null ) throw new ArgumentException ( ) ;
Global . SaveDefaultCurrencySettings ( cur ) ;
MessageService . Send ( MessageAction . CrmDefaultCurrencyUpdated ) ;
2020-04-18 17:49:09 +00:00
return CurrencyInfoWrapperHelper . Get ( cur ) ;
2020-04-16 19:41:37 +00:00
}
/// <visible>false</visible>
[Create(@"{entityType:(contact|opportunity|case|task)}/import/start")]
public string StartImportFromCSV ( string entityType , string csvFileURI , string jsonSettings )
{
EntityType entityTypeObj ;
if ( string . IsNullOrEmpty ( entityType ) | | string . IsNullOrEmpty ( csvFileURI ) | | string . IsNullOrEmpty ( jsonSettings ) ) throw new ArgumentException ( ) ;
switch ( entityType . ToLower ( ) )
{
case "contact" :
entityTypeObj = EntityType . Contact ;
break ;
case "opportunity" :
entityTypeObj = EntityType . Opportunity ;
break ;
case "case" :
entityTypeObj = EntityType . Case ;
break ;
case "task" :
entityTypeObj = EntityType . Task ;
break ;
default :
throw new ArgumentException ( ) ;
}
2021-03-01 17:36:18 +00:00
ImportFromCSVManager . StartImport ( entityTypeObj , csvFileURI , jsonSettings ) ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
return "" ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
}
/// <visible>false</visible>
[Read(@"{entityType:(contact|opportunity|case|task)}/import/status")]
public IProgressItem GetImportFromCSVStatus ( string entityType )
{
EntityType entityTypeObj ;
if ( string . IsNullOrEmpty ( entityType ) ) throw new ArgumentException ( ) ;
switch ( entityType . ToLower ( ) )
{
case "contact" :
entityTypeObj = EntityType . Contact ;
break ;
case "opportunity" :
entityTypeObj = EntityType . Opportunity ;
break ;
case "case" :
entityTypeObj = EntityType . Case ;
break ;
case "task" :
entityTypeObj = EntityType . Task ;
break ;
default :
throw new ArgumentException ( ) ;
}
return ImportFromCSV . GetStatus ( entityTypeObj ) ;
}
2021-03-01 17:36:18 +00:00
///// <visible>false</visible>
//[Read(@"import/samplerow")]
//public String GetImportFromCSVSampleRow(string csvFileURI, int indexRow, string jsonSettings)
//{
// if (String.IsNullOrEmpty(csvFileURI) || indexRow < 0) throw new ArgumentException();
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
// if (!Global.GetStore().IsFile("temp", csvFileURI)) throw new ArgumentException();
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
// var CSVFileStream = Global.GetStore().GetReadStream("temp", csvFileURI);
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
// return ImportFromCSV.GetRow(CSVFileStream, indexRow, jsonSettings);
//}
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
///// <visible>false</visible>
//[Create(@"import/uploadfake")]
//public FileUploadResult ProcessUploadFake(string csvFileURI, string jsonSettings)
//{
// return ImportFromCSVManager.ProcessUploadFake(csvFileURI, jsonSettings);
//}
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
///// <visible>false</visible>
//[Read(@"export/status")]
//public IProgressItem GetExportStatus()
//{
// if (!CRMSecurity.IsAdmin) throw CRMSecurity.CreateSecurityException();
2020-04-18 17:49:09 +00:00
2021-03-01 17:36:18 +00:00
// return ExportToCsv.GetStatus(false);
2020-04-18 17:49:09 +00:00
2021-03-01 17:36:18 +00:00
//}
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
///// <visible>false</visible>
//[Update(@"export/cancel")]
//public IProgressItem CancelExport()
//{
// if (!CRMSecurity.IsAdmin) throw CRMSecurity.CreateSecurityException();
2020-04-18 17:49:09 +00:00
2021-03-01 17:36:18 +00:00
// ExportToCsv.Cancel(false);
2020-04-18 17:49:09 +00:00
2021-03-01 17:36:18 +00:00
// return ExportToCsv.GetStatus(false);
2020-04-18 17:49:09 +00:00
2021-03-01 17:36:18 +00:00
//}
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
///// <visible>false</visible>
//[Create(@"export/start")]
//public IProgressItem StartExport()
//{
// if (!CRMSecurity.IsAdmin) throw CRMSecurity.CreateSecurityException();
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
// MessageService.Send( MessageAction.CrmAllDataExported);
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
// return ExportToCsv.Start(null, CRMSettingResource.Export + ".zip");
//}
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
///// <visible>false</visible>
//[Read(@"export/partial/status")]
//public IProgressItem GetPartialExportStatus()
//{
// return ExportToCsv.GetStatus(true);
//}
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
///// <visible>false</visible>
//[Update(@"export/partial/cancel")]
//public IProgressItem CancelPartialExport()
//{
2020-04-18 17:49:09 +00:00
2021-03-01 17:36:18 +00:00
// ExportToCsv.Cancel(true);
2020-04-18 17:49:09 +00:00
2021-03-01 17:36:18 +00:00
// return ExportToCsv.GetStatus(true);
2020-04-18 17:49:09 +00:00
2021-03-01 17:36:18 +00:00
//}
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
///// <visible>false</visible>
//[Create(@"export/partial/{entityType:(contact|opportunity|case|task|invoiceitem)}/start")]
//public IProgressItem StartPartialExport(string entityType, string base64FilterString)
//{
// if (string.IsNullOrEmpty(base64FilterString)) throw new ArgumentException();
2020-04-16 19:41:37 +00:00
2021-03-01 17:36:18 +00:00
// FilterObject filterObject;
// String fileName;
// switch (entityType.ToLower())
// {
// case "contact":
// filterObject = new ContactFilterObject(base64FilterString);
// fileName = CRMContactResource.Contacts + ".csv";
// MessageService.Send( MessageAction.ContactsExportedToCsv);
// break;
// case "opportunity":
// filterObject = new DealFilterObject(base64FilterString);
// fileName = CRMCommonResource.DealModuleName + ".csv";
// MessageService.Send( MessageAction.OpportunitiesExportedToCsv);
// break;
// case "case":
// filterObject = new CasesFilterObject(base64FilterString);
// fileName = CRMCommonResource.CasesModuleName + ".csv";
// MessageService.Send( MessageAction.CasesExportedToCsv);
// break;
// case "task":
// filterObject = new TaskFilterObject(base64FilterString);
// fileName = CRMCommonResource.TaskModuleName + ".csv";
// MessageService.Send( MessageAction.CrmTasksExportedToCsv);
// break;
// case "invoiceitem":
// fileName = CRMCommonResource.ProductsAndServices + ".csv";
// filterObject = new InvoiceItemFilterObject(base64FilterString);
// break;
// default:
// throw new ArgumentException();
// }
// return ExportToCsv.Start(filterObject, fileName);
//}
2020-04-16 19:41:37 +00:00
}
}