From 8bf59da423c31361eb03bfaf2d1ca8a2516c9a6d Mon Sep 17 00:00:00 2001 From: dibakor Date: Mon, 13 Jul 2026 18:32:45 +0600 Subject: [PATCH] complete foc and foc material endpoints --- .../MobileApp/MobileMasterDataRequest.cs | 30 ++++- .../MobileApp/MobileMasterDataResponse.cs | 28 ++++- .../MobileApp/IMobileMasterDataService.cs | 2 + .../MobileApp/MobileMasterDataService.cs | 119 +++++++++++++++++- .../Mobile/MobileMasterDataController.cs | 54 ++++++++ 5 files changed, 226 insertions(+), 7 deletions(-) diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/MobileMasterDataRequest.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/MobileMasterDataRequest.cs index 96807ba..094e262 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/MobileMasterDataRequest.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/MobileMasterDataRequest.cs @@ -110,8 +110,6 @@ public class GetDiscountRequest : PagedRequest [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 : PagedRequest @@ -132,7 +130,9 @@ public class GetDiscountMaterialRequest : PagedRequest public string? DiscountCode { get; set; } } -public class GetDiscountCustomerRequest : PagedRequest + + +public class GetFOCRequest : PagedRequest { [StringLength(10, MinimumLength = 3, ErrorMessage = "Sales organization code must be between 1 and 10 characters.")] public string SalesOrgCode { get; set; } @@ -147,5 +147,25 @@ public class GetDiscountCustomerRequest : PagedRequest 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 + public string? FOCCode { get; set; } + +} + +public class GetFOCMaterialRequest : PagedRequest +{ + [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? FOCCode { get; set; } +} + diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs index 645b4f8..c03b3a9 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.AspNetCore.Mvc.Formatters; +using System; using System.Collections.Generic; namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp; @@ -168,6 +169,7 @@ public class GetDiscountResponse public string DiscountName { get; set; } public string DistributorChannelCode { get; set; } public string DistributorChannelName { get; set; } + public string CalculationType { get; set; } } @@ -181,4 +183,28 @@ public class GetDiscountMaterialResponse public decimal DiscountValue { get; set; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } +} + +public class GetFOCResponse +{ + public string SalesOrgcCode { get; set; } + public string FOCCode { get; set; } + public string FOCName { get; set; } + public string DistributorChannelCode { get; set; } + public string DistributorChannelName { get; set; } + +} + +public class GetFOCMaterialResponse +{ + public string FOCCode { get; set; } + public string CustomerCode { get; set; } + public string MaterialCode { get; set; } + public string UnitOfMeasurement { get; set; } + public decimal MinimumOrderQty { get; set; } + public decimal ForQuantity { get; set; } + public decimal FreeQty { get; set; } + public string FOCUnitOfMeasurement { 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 a52a05a..9305cfd 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/MobileApp/IMobileMasterDataService.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/MobileApp/IMobileMasterDataService.cs @@ -17,4 +17,6 @@ public interface IMobileMasterDataService Task UpsertAttendanceByEmpAsync(UpsertAttendanceByEmpRequest request); Task> GetDiscountAsync(GetDiscountRequest request); Task> GetDiscountMaterialsAsync(GetDiscountMaterialRequest request); + Task> GetFOCsAsync(GetFOCRequest request); + Task> GetFOCMaterialsAsync(GetFOCMaterialRequest request); } diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs index f3be735..5cc489a 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs @@ -677,7 +677,8 @@ public class MobileMasterDataService : IMobileMasterDataService DiscountCode = dr.GetString(1), DiscountName = dr.GetString(2), DistributorChannelCode = dr.GetString(3), - DistributorChannelName = dr.GetString(4) + DistributorChannelName = dr.GetString(4), + CalculationType = dr.GetString(5) }); } dr.Close(); @@ -760,5 +761,121 @@ public class MobileMasterDataService : IMobileMasterDataService return response; } + + + public async Task> GetFOCsAsync(GetFOCRequest request) + { + PagedResult response = new(); + try + { + using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode); + try + { + SqlParameter[] p = + [ + SqlHelperExtension.CreateInParam(pName: "@SalesOrgCode", pType: SqlDbType.VarChar, pValue: request.SalesOrgCode), + SqlHelperExtension.CreateInParam(pName: "@CustomerCode", pType: SqlDbType.VarChar, pValue: request.CustomerCode), + SqlHelperExtension.CreateInParam(pName: "@EmployeeNumber", pType: SqlDbType.VarChar, pValue: request.EmployeeNumber), + SqlHelperExtension.CreateInParam(pName: "@MaterialCode", pType: SqlDbType.VarChar, pValue: request.MaterialCode), + SqlHelperExtension.CreateInParam(pName: "@DiscountCode", pType: SqlDbType.VarChar, pValue: request.FOCCode), + SqlHelperExtension.CreateInParam(pName: "@PageNumber", pType: SqlDbType.Int, pValue: request.PageNumber), + SqlHelperExtension.CreateInParam(pName: "@PageSize", pType: SqlDbType.Int, pValue: request.PageSize) + ]; + + using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetFOCPaginated", parameterValues: p)) + { + while (dr.Read()) + { + response.Items.Add(new GetFOCResponse + { + SalesOrgcCode = dr.GetString(0), + FOCCode = dr.GetString(1), + FOCName = dr.GetString(2), + DistributorChannelCode = dr.GetString(3), + DistributorChannelName = dr.GetString(4) + }); + } + dr.Close(); + + response.TotalCount = response.Items.Count; + response.PageNumber = request.PageNumber; + response.PageSize = request.PageSize; + } + tc.End(); + } + catch (Exception ie) + { + tc?.HandleError(); + + throw DBCustomError.GenerateCustomError(ie); + } + } + catch (Exception ex) + { + throw; + } + + return response; + } + + public async Task> GetFOCMaterialsAsync(GetFOCMaterialRequest request) + { + PagedResult response = new(); + try + { + using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode); + try + { + SqlParameter[] p = + [ + SqlHelperExtension.CreateInParam(pName: "@SalesOrgCode", pType: SqlDbType.VarChar, pValue: request.SalesOrgCode), + SqlHelperExtension.CreateInParam(pName: "@CustomerCode", pType: SqlDbType.VarChar, pValue: request.CustomerCode), + SqlHelperExtension.CreateInParam(pName: "@EmployeeNumber", pType: SqlDbType.VarChar, pValue: request.EmployeeNumber), + SqlHelperExtension.CreateInParam(pName: "@MaterialCode", pType: SqlDbType.VarChar, pValue: request.MaterialCode), + SqlHelperExtension.CreateInParam(pName: "@DiscountCode", pType: SqlDbType.VarChar, pValue: request.FOCCode), + SqlHelperExtension.CreateInParam(pName: "@PageNumber", pType: SqlDbType.Int, pValue: request.PageNumber), + SqlHelperExtension.CreateInParam(pName: "@PageSize", pType: SqlDbType.Int, pValue: request.PageSize) + ]; + + using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetFOCMaterialsPaginated", parameterValues: p)) + { + while (dr.Read()) + { + response.Items.Add(new GetFOCMaterialResponse + { + FOCCode = dr.GetString(0), + CustomerCode = dr.GetString(1), + MaterialCode = dr.GetString(2), + UnitOfMeasurement = dr.GetString(3), + MinimumOrderQty = dr.GetDecimal(4), + ForQuantity = dr.GetDecimal(5), + FreeQty = dr.GetDecimal(6), + FOCUnitOfMeasurement = dr.GetString(7), + StartDate = dr.GetDateTime(8), + EndDate = dr.GetDateTime(9), + }); + } + dr.Close(); + + response.TotalCount = response.Items.Count; + response.PageNumber = request.PageNumber; + response.PageSize = request.PageSize; + } + tc.End(); + } + catch (Exception ie) + { + tc?.HandleError(); + + throw DBCustomError.GenerateCustomError(ie); + } + } + catch (Exception ex) + { + throw; + } + + return response; + } } diff --git a/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/Mobile/MobileMasterDataController.cs b/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/Mobile/MobileMasterDataController.cs index 83f18bc..8b015c1 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/Mobile/MobileMasterDataController.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/Mobile/MobileMasterDataController.cs @@ -279,5 +279,59 @@ 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("MaterialFOCs")] + [IgnoreAntiforgeryToken] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetFOCResponse))] + public async Task GetMaterialFOCs([FromQuery] GetFOCRequest request) + { + PagedResult response = new(); + try + { + response = await _service.GetFOCsAsync(request); + return Ok(MobileResponseBase>.Success(response)); + } + catch (Exception ex) + { + string msg = $"Exception occur on Get MaterialFOCs endpoint with request - {request?.EmployeeNumber} -{request?.FOCCode}"; + _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("FOCsMaterials")] + [IgnoreAntiforgeryToken] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetFOCMaterialResponse))] + public async Task GetFOCsMaterials([FromQuery] GetFOCMaterialRequest request) + { + PagedResult response = new(); + try + { + response = await _service.GetFOCMaterialsAsync(request); + return Ok(MobileResponseBase>.Success(response)); + } + catch (Exception ex) + { + string msg = $"Exception occur on Get FOCsMaterials endpoint with request - {request?.MaterialCode} -{request?.FOCCode}"; + _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