Skip to content

Commit

Permalink
Merge pull request #30 from joelbyford/assetArray
Browse files Browse the repository at this point in the history
Adding support for batch of assets calculated in one post resolving #18.
  • Loading branch information
joelbyford authored May 31, 2024
2 parents cf24e66 + cc863b3 commit 622ac11
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
77 changes: 77 additions & 0 deletions Controllers/CalculateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,83 @@ public CalculateController(ILogger<CalculateController> logger)
_logger = logger;
}

/// <summary>
/// Returns an array of Assets with calculated Accounting and Tax Depreciation 'tables' along with the asset information originally submitted.
/// </summary>
/// <remarks>
/// Sample Request:
///
/// POST /Calculate/DepreciateArray?GaapMethod=SL&amp;TaxMethod=MACRSHY
/// [
/// {
/// "name": "New Asset",
/// "purchaseDate": "2011-01-01",
/// "purchasePrice": 1000,
/// "residualValue": 0,
/// "section179": 0,
/// "usefulLife": 5,
/// "taxLife": 5
/// },
/// {
/// "name": "New Asset",
/// "purchaseDate": "2011-01-01",
/// "purchasePrice": 1000,
/// "residualValue": 0,
/// "section179": 0,
/// "usefulLife": 5,
/// "taxLife": 5
/// }
/// ]
/// </remarks>
/// <param name="assets">Array of Asset JSON dictionaries in the body of the post</param>
/// <param name="GaapMethod" example="SL">GAAP Depreciation Method (SL, DB200, DB150 OR SYD)</param>
/// <param name="TaxMethod" example="MACRSHY">Tax Depreciation Method (MACRSHY or MACRSMQ)</param>
/// <returns>Array of Asset objects with both accounting and tax depreciation calculations added</returns>
/// <response code="200">Returns array of asset objects</response>
/// <response code="422">If GAAP Method, Tax Method or Tax Life are invalid</response>
/// <response code="500">Any other error</response>
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
[Route("[controller]/DepreciateArray")]
public ActionResult<Asset[]> PostDepreciateArray([FromBody]Asset[] assets, [RequiredFromQuery] string GaapMethod, [RequiredFromQuery] string TaxMethod)
{
foreach(Asset asset in assets)
{
switch(GaapMethod)
{
case "SL":
asset.calcSL();
break;
case "DB200":
asset.calcDB200();
break;
case "DB150":
asset.calcDB150();
break;
case "SYD":
asset.calcSYD();
break;
default:
throw new Exception("INVALID_GAAP_METHOD");
}

switch(TaxMethod)
{
case "MACRSHY":
asset.calcMacrsHY();
break;
case "MACRSMQ":
asset.calcMacrsMQ();
break;
default:
throw new Exception("INVALID_TAX_METHOD");
}
}

return assets;
}

/// <summary>
/// Returns an Asset with calculated Accounting and Tax Depreciation 'tables' along with the asset information originally submitted.
/// </summary>
Expand Down
30 changes: 29 additions & 1 deletion test/manualTesting.http
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,32 @@ Authorization: Basic testUser:testPassword
"section179": 0,
"usefulLife": 5,
"taxLife": 7
}
}


############################################
# Full Array/Batch Calculation via JSON POST
# ==========================================
POST http://localhost:5000/Calculate/DepreciateArray?GaapMethod=SL&TaxMethod=MACRSHY
Content-Type: application/json

[
{
"name": "New Asset",
"purchaseDate": "2011-01-01",
"purchasePrice": 1000,
"residualValue": 0,
"section179": 0,
"usefulLife": 5,
"taxLife": 5
},
{
"name": "New Asset 2",
"purchaseDate": "2001-01-01",
"purchasePrice": 2000,
"residualValue": 0,
"section179": 0,
"usefulLife": 7,
"taxLife": 7
}
]

0 comments on commit 622ac11

Please sign in to comment.