add payment terms api
This commit is contained in:
parent
a8f7cd51ce
commit
70a4a757f2
|
|
@ -0,0 +1,15 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace OnlineSalesAutoCrop.CoreAPI.Models.Objects.Integrations;
|
||||||
|
|
||||||
|
internal class IntegrationPaymentTerm
|
||||||
|
{
|
||||||
|
public int CreditCodeId { get; set; }
|
||||||
|
public string CreditCode { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public DateTime ValidFrom { get; set; }
|
||||||
|
public DateTime ValidTo { get; set; }
|
||||||
|
public string SalesOrg { get; set; }
|
||||||
|
public DateTime CreatedDate { get; set; }
|
||||||
|
public DateTime? ModifiedDate { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Objects.Systems;
|
|
||||||
using System;
|
using OnlineSalesAutoCrop.CoreAPI.Models.Objects.Systems;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
|
namespace OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
|
||||||
|
|
||||||
|
|
||||||
|
public class IntegrationPaymentTermRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "CreditCode is required.")]
|
||||||
|
[StringLength(4, MinimumLength = 1, ErrorMessage = "CreditCode must be between 1 and 4 characters.")]
|
||||||
|
public string CreditCode { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Description is required.")]
|
||||||
|
[StringLength(30, MinimumLength = 1, ErrorMessage = "Description must be between 1 and 30 characters.")]
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "ValidFrom is required.")]
|
||||||
|
public DateTime ValidFrom { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "ValidTo is required.")]
|
||||||
|
public DateTime ValidTo { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "SalesOrg is required.")]
|
||||||
|
[StringLength(4, MinimumLength = 1, ErrorMessage = "SalesOrg must be between 1 and 4 characters.")]
|
||||||
|
public string SalesOrg { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetIntegrationPaymentTermRequest
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "CreditCode is required.")]
|
||||||
|
[StringLength(4, MinimumLength = 1, ErrorMessage = "CreditCode must be between 1 and 4 characters.")]
|
||||||
|
public string CreditCode { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "SalesOrg is required.")]
|
||||||
|
[StringLength(4, MinimumLength = 1, ErrorMessage = "SalesOrg must be between 1 and 4 characters.")]
|
||||||
|
public string SalesOrg { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Objects.Systems;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
||||||
|
|
||||||
|
|
@ -21,9 +18,9 @@ public class IntegrationRrefreshTokenResponse : ResponseBase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class RefreshTokenResponse : ResponseBase
|
public class RefreshTokenResponse : ResponseBase
|
||||||
{
|
{
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
public string TokenHash { get; set; }
|
public string TokenHash { get; set; }
|
||||||
public string IpAddress { get; set; }
|
public string IpAddress { get; set; }
|
||||||
public DateTime ExpiredAt { get; set; }
|
public DateTime ExpiredAt { get; set; }
|
||||||
|
|
@ -35,7 +32,7 @@ public class RefreshTokenResponse : ResponseBase
|
||||||
public class GenerateRefreshTokenResponse : ResponseBase
|
public class GenerateRefreshTokenResponse : ResponseBase
|
||||||
{
|
{
|
||||||
public string RefreshToken { get; set; }
|
public string RefreshToken { get; set; }
|
||||||
public DateTime ExpireTime { get; set; }
|
public DateTime ExpireTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UserByRefreshTokenResponse : ResponseBase
|
public class UserByRefreshTokenResponse : ResponseBase
|
||||||
|
|
@ -44,5 +41,5 @@ public class UserByRefreshTokenResponse : ResponseBase
|
||||||
public string LoginId { get; set; }
|
public string LoginId { get; set; }
|
||||||
public string EmailAddress { get; set; }
|
public string EmailAddress { get; set; }
|
||||||
public string AuthKey { get; set; }
|
public string AuthKey { get; set; }
|
||||||
public bool IsActive { set; get; }
|
public bool IsActive { set; get; }
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
||||||
|
|
||||||
|
public class IntegrationPaymentTermResponse : ResponseBase
|
||||||
|
{
|
||||||
|
public int CreditCodeId { get; set; }
|
||||||
|
public string CreditCode { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public DateTime ValidFrom { get; set; }
|
||||||
|
public DateTime ValidTo { get; set; }
|
||||||
|
public string SalesOrg { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IntegrationPaymentTermReqResponse : ResponseBase
|
||||||
|
{
|
||||||
|
public string CreditCode { get; set; }
|
||||||
|
public string SalesOrg { get; set; }
|
||||||
|
public bool IsUpdated { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -27,4 +27,8 @@ public interface IIntegrationService
|
||||||
//Material Free Goods
|
//Material Free Goods
|
||||||
Task<MaterialFreeGoodsByReqResponse> UpsertMaterialFreeGoodsAsync(IntegrationMaterialFreeGoodsRequest request);
|
Task<MaterialFreeGoodsByReqResponse> UpsertMaterialFreeGoodsAsync(IntegrationMaterialFreeGoodsRequest request);
|
||||||
Task<IntegrationMaterialFreeGoodsResponse> GetMaterialFreeGoodseByFilterAsync(GetMaterialFreeGoodsByFilterRequest request);
|
Task<IntegrationMaterialFreeGoodsResponse> GetMaterialFreeGoodseByFilterAsync(GetMaterialFreeGoodsByFilterRequest request);
|
||||||
|
|
||||||
|
//Payment Terms
|
||||||
|
Task<IntegrationPaymentTermReqResponse> UpsertPaymentTermsAsync(IntegrationPaymentTermRequest request);
|
||||||
|
Task<IntegrationPaymentTermResponse> GetPaymentTermsByFilterAsync(GetIntegrationPaymentTermRequest request);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -369,6 +369,71 @@ public class IntegrationService : IIntegrationService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<IntegrationPaymentTermReqResponse> UpsertPaymentTermsAsync(IntegrationPaymentTermRequest request)
|
||||||
|
{
|
||||||
|
IntegrationPaymentTermReqResponse response = new IntegrationPaymentTermReqResponse();
|
||||||
|
|
||||||
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IntegrationPaymentTermResponse paymentTerms = await GetPaymentTermByFilterAsync(tc,
|
||||||
|
new GetIntegrationPaymentTermRequest()
|
||||||
|
{
|
||||||
|
CreditCode = request.CreditCode,
|
||||||
|
SalesOrg = request.SalesOrg
|
||||||
|
});
|
||||||
|
|
||||||
|
if (paymentTerms != null && !string.IsNullOrWhiteSpace(paymentTerms.CreditCode))
|
||||||
|
{
|
||||||
|
UpdatePaymentTerm(tc, request);
|
||||||
|
response.IsUpdated = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CreatePaymentTerm(tc, request);
|
||||||
|
response.IsUpdated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
response.SalesOrg = request.SalesOrg;
|
||||||
|
response.CreditCode = request.CreditCode;
|
||||||
|
tc.End();
|
||||||
|
}
|
||||||
|
catch (Exception ie)
|
||||||
|
{
|
||||||
|
tc?.HandleError();
|
||||||
|
|
||||||
|
throw DBCustomError.GenerateCustomError(ie);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IntegrationPaymentTermResponse> GetPaymentTermsByFilterAsync(GetIntegrationPaymentTermRequest request)
|
||||||
|
{
|
||||||
|
IntegrationPaymentTermResponse response = new();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = await GetPaymentTermByFilterAsync(tc, request);
|
||||||
|
tc.End();
|
||||||
|
}
|
||||||
|
catch (Exception ie)
|
||||||
|
{
|
||||||
|
tc?.HandleError();
|
||||||
|
|
||||||
|
throw DBCustomError.GenerateCustomError(ie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
#region Customer Private Functions
|
#region Customer Private Functions
|
||||||
|
|
||||||
private async Task<CustomerByCompanyCodeResponse> GetCustomerByCompanyCodeAsync(TransactionContext tc, CustomerByCompanyCodeRequest request)
|
private async Task<CustomerByCompanyCodeResponse> GetCustomerByCompanyCodeAsync(TransactionContext tc, CustomerByCompanyCodeRequest request)
|
||||||
|
|
@ -1146,5 +1211,102 @@ public class IntegrationService : IIntegrationService
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Credit Code Private Functions
|
||||||
|
|
||||||
|
private async Task<IntegrationPaymentTermResponse> GetPaymentTermByFilterAsync(TransactionContext tc,
|
||||||
|
GetIntegrationPaymentTermRequest request)
|
||||||
|
{
|
||||||
|
IntegrationPaymentTermResponse response = new IntegrationPaymentTermResponse();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam("@CreditCode", SqlDbType.NVarChar, request.CreditCode),
|
||||||
|
SqlHelperExtension.CreateInParam("@SalesOrg", SqlDbType.NVarChar, request.SalesOrg)
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetPaymentTermByFilter", parameterValues: p))
|
||||||
|
{
|
||||||
|
if (dr.Read())
|
||||||
|
{
|
||||||
|
response=new IntegrationPaymentTermResponse()
|
||||||
|
{
|
||||||
|
CreditCodeId = dr.GetInt32(0),
|
||||||
|
CreditCode = dr.GetString(1),
|
||||||
|
Description = dr.GetString(2),
|
||||||
|
ValidFrom = dr.GetDateTime(3),
|
||||||
|
ValidTo = dr.GetDateTime(4),
|
||||||
|
SalesOrg = dr.GetString(5)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw DBCustomError.GenerateCustomError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CreatePaymentTerm(TransactionContext tc, IntegrationPaymentTermRequest request)
|
||||||
|
{
|
||||||
|
bool response = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam("@CreditCode", SqlDbType.NVarChar, request.CreditCode),
|
||||||
|
SqlHelperExtension.CreateInParam("@Description", SqlDbType.NVarChar, request.Description),
|
||||||
|
SqlHelperExtension.CreateInParam("@ValidFrom", SqlDbType.DateTime, request.ValidFrom),
|
||||||
|
SqlHelperExtension.CreateInParam("@ValidTo", SqlDbType.DateTime, request.ValidTo),
|
||||||
|
SqlHelperExtension.CreateInParam("@SalesOrg", SqlDbType.NVarChar, request.SalesOrg)
|
||||||
|
];
|
||||||
|
|
||||||
|
_ = tc.ExecuteNonQuerySp(spName: "dbo.InsertIntegrationPaymentTerm", parameterValues: p);
|
||||||
|
|
||||||
|
response = true;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool UpdatePaymentTerm(TransactionContext tc, IntegrationPaymentTermRequest request)
|
||||||
|
{
|
||||||
|
bool returnValue = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam("@CreditCode", SqlDbType.NVarChar, request.CreditCode),
|
||||||
|
SqlHelperExtension.CreateInParam("@Description", SqlDbType.NVarChar, request.Description),
|
||||||
|
SqlHelperExtension.CreateInParam("@ValidFrom", SqlDbType.DateTime, request.ValidFrom),
|
||||||
|
SqlHelperExtension.CreateInParam("@ValidTo", SqlDbType.DateTime, request.ValidTo),
|
||||||
|
SqlHelperExtension.CreateInParam("@SalesOrg", SqlDbType.NVarChar, request.SalesOrg)
|
||||||
|
];
|
||||||
|
|
||||||
|
_ = tc.ExecuteNonQuerySp(spName: "dbo.UpdateIntegrationPaymentTerms", parameterValues: p);
|
||||||
|
|
||||||
|
returnValue = true;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -238,5 +238,48 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError, response);
|
return StatusCode(StatusCodes.Status500InternalServerError, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Insert or Update Payment Terms for SAP
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns>if created return 201 or if updated return 200 true</returns>
|
||||||
|
[HttpPost("PaymentTerms")]
|
||||||
|
[IgnoreAntiforgeryToken]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IntegrationPaymentTermReqResponse))]
|
||||||
|
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(IntegrationPaymentTermReqResponse))]
|
||||||
|
public async Task<IActionResult> UpsertPaymentTerms(IntegrationPaymentTermRequest request)
|
||||||
|
{
|
||||||
|
IntegrationPaymentTermReqResponse response = new IntegrationPaymentTermReqResponse();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = await _integrationService.UpsertPaymentTermsAsync(request);
|
||||||
|
if (!response.IsUpdated)
|
||||||
|
{
|
||||||
|
response.ReturnMessage.Add($"Payment Terms Created Successfully for SalesOrg :{request.SalesOrg} " +
|
||||||
|
$"And CreditCode : {request.CreditCode} ");
|
||||||
|
response.ReturnStatus = StatusCodes.Status201Created;
|
||||||
|
return StatusCode(StatusCodes.Status201Created, response);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response.ReturnMessage.Add($"Payment Terms Updated Successfully for SalesOrg :{request.SalesOrg} " +
|
||||||
|
$"And CreditCode : {request.CreditCode} ");
|
||||||
|
response.ReturnStatus = StatusCodes.Status200OK;
|
||||||
|
return StatusCode(StatusCodes.Status200OK, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string msg = $"Exception Occur in Payment Terms for SalesOrg :{request.SalesOrg} " +
|
||||||
|
$"And CreditCode : {request.CreditCode} ";
|
||||||
|
_logger.LogError(exception: ex, msg);
|
||||||
|
response.ReturnStatus = StatusCodes.Status500InternalServerError;
|
||||||
|
response.ReturnMessage.Add(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user