diff --git a/Controllers/CalculateController.cs b/Controllers/CalculateController.cs index 4e9c519..c70dcf7 100644 --- a/Controllers/CalculateController.cs +++ b/Controllers/CalculateController.cs @@ -16,6 +16,83 @@ public CalculateController(ILogger logger) _logger = logger; } + /// + /// Returns an array of Assets with calculated Accounting and Tax Depreciation 'tables' along with the asset information originally submitted. + /// + /// + /// Sample Request: + /// + /// POST /Calculate/DepreciateArray?GaapMethod=SL&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 + /// } + /// ] + /// + /// Array of Asset JSON dictionaries in the body of the post + /// GAAP Depreciation Method (SL, DB200, DB150 OR SYD) + /// Tax Depreciation Method (MACRSHY or MACRSMQ) + /// Array of Asset objects with both accounting and tax depreciation calculations added + /// Returns array of asset objects + /// If GAAP Method, Tax Method or Tax Life are invalid + /// Any other error + [HttpPost] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] + [Route("[controller]/DepreciateArray")] + public ActionResult 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; + } + /// /// Returns an Asset with calculated Accounting and Tax Depreciation 'tables' along with the asset information originally submitted. /// diff --git a/test/manualTesting.http b/test/manualTesting.http index 3d35347..f426005 100644 --- a/test/manualTesting.http +++ b/test/manualTesting.http @@ -72,4 +72,32 @@ Authorization: Basic testUser:testPassword "section179": 0, "usefulLife": 5, "taxLife": 7 -} \ No newline at end of file +} + + +############################################ +# 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 + } +]