From 66e52442df782df81a1ba7923b99994907380adc Mon Sep 17 00:00:00 2001 From: dibakor Date: Sun, 12 Jul 2026 18:27:00 +0600 Subject: [PATCH] add discount endpoints without service implementation --- .../MobileApp/MobileMasterDataRequest.cs | 64 ++++++++++++++- .../MobileApp/MobileMasterDataResponse.cs | 36 ++++++++ .../MobileApp/IMobileMasterDataService.cs | 5 +- .../MobileApp/MobileMasterDataService.cs | 15 ++++ .../Mobile/MobileMasterDataController.cs | 82 +++++++++++++++++++ 5 files changed, 197 insertions(+), 5 deletions(-) diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/MobileMasterDataRequest.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/MobileMasterDataRequest.cs index 3d2e7d1..033cb87 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/MobileMasterDataRequest.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/MobileMasterDataRequest.cs @@ -42,16 +42,16 @@ public class GetMaterialsRequest : PagedRequest public class GetCustomersRequest : PagedRequest { - [StringLength(10, MinimumLength = 1, ErrorMessage = "Sales organization code must be between 1 and 10 characters.")] + [StringLength(10, MinimumLength = 3, ErrorMessage = "Sales organization code must be between 1 and 10 characters.")] public string SalesOrgCode { get; set; } - [StringLength(5, MinimumLength = 1, ErrorMessage = "Teritory Code must be between 1 and 5 characters.")] + [StringLength(5, MinimumLength = 3, ErrorMessage = "Teritory Code must be between 1 and 5 characters.")] public string? TeritoryCode { get; set; } - [StringLength(10, MinimumLength = 1, ErrorMessage = "Customer Code must be between 1 and 10 characters.")] + [StringLength(10, MinimumLength = 5, ErrorMessage = "Customer Code must be between 1 and 10 characters.")] public string? CustomerCode { get; set; } - [StringLength(10, MinimumLength = 1, ErrorMessage = "Employee number must be between 1 and 10 characters.")] + [StringLength(10, MinimumLength = 5, ErrorMessage = "Employee number must be between 1 and 10 characters.")] public string? EmployeeNumber { get; set; } } @@ -76,4 +76,60 @@ public class UpsertAttendanceByEmpRequest public string? CheckOutLocationName { get; set; } public bool IsCheckIn => CheckInTime.HasValue ? true : false; public bool IsCheckOut => CheckOutTime.HasValue ? true : false; +} + +public class GetDiscountRequest +{ + [StringLength(10, MinimumLength = 3, ErrorMessage = "Sales organization code must be between 1 and 10 characters.")] + public string SalesOrgCode { get; set; } + + [StringLength(10, MinimumLength = 5, ErrorMessage = "Customer Code must be between 1 and 10 characters.")] + public string? CustomerCode { get; set; } + + [StringLength(10, MinimumLength = 5, ErrorMessage = "Employee number must be between 1 and 10 characters.")] + public string? EmployeeNumber { get; set; } + + [StringLength(10, MinimumLength = 3, ErrorMessage = "Material Code must be between 1 and 10 characters.")] + public string? MaterialCode { get; set; } + + [StringLength(10, MinimumLength = 1, ErrorMessage = "Discount Code must be between 1 and 10 characters.")] + public string? DiscountCode { get; set; } + + public bool IsIncludeChild { get; set; } = false; +} + +public class GetDiscountMaterialRequest +{ + [StringLength(10, MinimumLength = 3, ErrorMessage = "Sales organization code must be between 1 and 10 characters.")] + public string SalesOrgCode { get; set; } + + [StringLength(10, MinimumLength = 5, ErrorMessage = "Customer Code must be between 1 and 10 characters.")] + public string? CustomerCode { get; set; } + + [StringLength(10, MinimumLength = 5, ErrorMessage = "Employee number must be between 1 and 10 characters.")] + public string? EmployeeNumber { get; set; } + + [StringLength(10, MinimumLength = 3, ErrorMessage = "Material Code must be between 1 and 10 characters.")] + public string? MaterialCode { get; set; } + + [StringLength(10, MinimumLength = 1, ErrorMessage = "Discount Code must be between 1 and 10 characters.")] + public string? DiscountCode { get; set; } +} + +public class GetDiscountCustomerRequest +{ + [StringLength(10, MinimumLength = 3, ErrorMessage = "Sales organization code must be between 1 and 10 characters.")] + public string SalesOrgCode { get; set; } + + [StringLength(10, MinimumLength = 5, ErrorMessage = "Customer Code must be between 1 and 10 characters.")] + public string? CustomerCode { get; set; } + + [StringLength(10, MinimumLength = 5, ErrorMessage = "Employee number must be between 1 and 10 characters.")] + public string? EmployeeNumber { get; set; } + + [StringLength(10, MinimumLength = 3, ErrorMessage = "Material Code must be between 1 and 10 characters.")] + public string? MaterialCode { get; set; } + + [StringLength(10, MinimumLength = 1, ErrorMessage = "Discount Code must be between 1 and 10 characters.")] + public string? DiscountCode { get; set; } } \ No newline at end of file diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs index 6efb113..efdfc81 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs @@ -153,4 +153,40 @@ public class GetAttendanceByEmpResponse public string? CheckOutLocationName { get; set; } public bool? IsCheckIn => CheckInTime.HasValue ? true : false; public bool? IsCheckOut => CheckOutTime.HasValue ? true : false; +} + +public class GetDiscountResponse +{ + public GetDiscountResponse() + { + Customers = new List(); + Materials = new List(); + } + public string DiscountCode { get; set; } + public string SalesOrgcCode { get; set; } + public string DistributorChannelCode { get; set; } + public DateTime StartDate { get; set; } + public DateTime EndDate { get; set; } + + public List Customers { get; set; } + public List Materials { get; set; } +} + +public class GetDiscountCustomerResponse +{ + public string DiscountCode { get; set; } + public string CustomerCode { get; set; } + public DateTime FromDate { get; set; } + public DateTime EndDate { get; set; } +} + +public class GetDiscountMaterialResponse +{ + public string DiscountCode { get; set; } + public string MaterialCode { get; set; } + public string UnitOfMeasurement { get; set; } + public string CalculationType { get; set; } + public decimal DiscountValue { get; set; } + public DateTime StartDate { get; set; } + public DateTime EndDate { get; set; } } \ No newline at end of file diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/MobileApp/IMobileMasterDataService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/MobileApp/IMobileMasterDataService.cs index aed700e..1c3f518 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/MobileApp/IMobileMasterDataService.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/MobileApp/IMobileMasterDataService.cs @@ -1,6 +1,7 @@ using OnlineSalesAutoCrop.CoreAPI.Models.Requests.MobileApp; using OnlineSalesAutoCrop.CoreAPI.Models.Responses; using OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp; +using System.Collections.Generic; using System.Threading.Tasks; namespace OnlineSalesAutoCrop.CoreAPI.Services.Contracts.MobileApp; @@ -13,5 +14,7 @@ public interface IMobileMasterDataService Task> GetCustomersAsync(GetCustomersRequest request); Task GetAttendanceByEmpAsync(GetAttendanceByEmpRequest request); Task UpsertAttendanceByEmpAsync(UpsertAttendanceByEmpRequest request); - + Task> GetDiscountAsync(GetDiscountRequest request); + Task> GetDiscountCustomersAsync(GetDiscountCustomerRequest request); + Task> GetDiscountMaterialsAsync(GetDiscountMaterialRequest request); } diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs index 9915e20..ae9a193 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs @@ -595,4 +595,19 @@ public class MobileMasterDataService : IMobileMasterDataService CheckOutLocationName = dr.IsDBNull(9) ? null : dr.GetString(9) }; } + + public Task> GetDiscountAsync(GetDiscountRequest request) + { + throw new NotImplementedException(); + } + + public Task> GetDiscountCustomersAsync(GetDiscountCustomerRequest request) + { + throw new NotImplementedException(); + } + + public Task> GetDiscountMaterialsAsync(GetDiscountMaterialRequest request) + { + throw new NotImplementedException(); + } } diff --git a/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/Mobile/MobileMasterDataController.cs b/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/Mobile/MobileMasterDataController.cs index a8fc4df..ede6c66 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/Mobile/MobileMasterDataController.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/Mobile/MobileMasterDataController.cs @@ -1,4 +1,5 @@ using Asp.Versioning; +using DocumentFormat.OpenXml.Office2010.ExcelAc; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -11,6 +12,7 @@ using OnlineSalesAutoCrop.CoreAPI.Models.Responses; using OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp; using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.MobileApp; using System; +using System.Collections.Generic; using System.Threading.Tasks; namespace OnlineSalesAutoCrop.CoreAPI.Controllers @@ -197,5 +199,85 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError)); } } + + + /// + /// Login using your credential data retrieve from SqlServer + /// + /// + /// + /// + /// If login successful Return Attendance List + [HttpGet("Discounts")] + [IgnoreAntiforgeryToken] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetDiscountResponse))] + public async Task GetDiscounts([FromQuery] GetDiscountRequest request) + { + List response = new(); + try + { + response = await _service.GetDiscountAsync(request); + return Ok(MobileResponseBase>.Success(response)); + } + catch (Exception ex) + { + string msg = $"Exception occur on Get Discounts endpoint with request - {request?.EmployeeNumber} -{request?.DiscountCode}"; + _logger.LogError(exception: ex, message: msg); + return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError)); + } + } + + /// + /// Login using your credential data retrieve from SqlServer + /// + /// + /// + /// + /// If login successful Return Attendance List + [HttpGet("DiscountCustomers")] + [IgnoreAntiforgeryToken] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetDiscountCustomerResponse))] + public async Task GetDiscountCustomers([FromQuery] GetDiscountCustomerRequest request) + { + List response = new(); + try + { + response = await _service.GetDiscountCustomersAsync(request); + return Ok(MobileResponseBase>.Success(response)); + } + catch (Exception ex) + { + string msg = $"Exception occur on Get DiscountCustomers endpoint with request - {request?.EmployeeNumber} -{request?.DiscountCode}"; + _logger.LogError(exception: ex, message: msg); + return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError)); + } + } + + + /// + /// Login using your credential data retrieve from SqlServer + /// + /// + /// + /// + /// If login successful Return Attendance List + [HttpGet("DiscountMaterials")] + [IgnoreAntiforgeryToken] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetDiscountMaterialResponse))] + public async Task GetDiscountMaterials([FromQuery] GetDiscountMaterialRequest request) + { + List response = new(); + try + { + response = await _service.GetDiscountMaterialsAsync(request); + return Ok(MobileResponseBase>.Success(response)); + } + catch (Exception ex) + { + string msg = $"Exception occur on Get DiscountMaterials endpoint with request - {request?.MaterialCode} -{request?.DiscountCode}"; + _logger.LogError(exception: ex, message: msg); + return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError)); + } + } } } \ No newline at end of file