Skip to content

Commit

Permalink
Merge pull request #17 from hmrc/feature/HMA-1258-deploy-new-tax-calc
Browse files Browse the repository at this point in the history
Feature/hma 1258 deploy new tax calc
  • Loading branch information
chrisob55 authored Oct 23, 2019
2 parents 667fb99 + 5dbc1d0 commit c116eb5
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ gen
build
.gradle
/credentials.properties
local.properties
local.properties
.DS_Store
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.41'
id 'org.jetbrains.kotlin.multiplatform' version '1.3.50'
id 'jacoco'
id 'java'
id 'com.github.dawnwords.jacoco.badge' version '0.1.0'
Expand Down Expand Up @@ -76,7 +76,12 @@ kotlin {
}

sourceSets {
def klockVersion = "1.5.0"
all {
languageSettings {
useExperimentalAnnotation('kotlin.Experimental')
}
}
def klockVersion = "1.7.5"
commonMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
Expand Down
30 changes: 30 additions & 0 deletions package-ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
if [ -z "$2" ]; then
echo "ERROR: Please provide a Github token"
else
export export GITHUB_TOKEN=$2
if [ -z "$1" ]; then
echo "ERROR: Please provide a git tag"
else
if echo "$1" | grep -Eq "^\d{0,3}\.\d{1}\.\d{1}$"; then
DIRECTORY="Carthage"
ZIP="TaxKalculator.framework.zip"
if [ -d "$DIRECTORY" ]; then
rm -rf $DIRECTORY
fi
if [ -f "$ZIP" ]; then
rm $ZIP
fi
echo "INFO: Creating Carthage folder structure"
mkdir $DIRECTORY && mkdir $DIRECTORY/Build && mkdir $DIRECTORY/Build/iOS
echo "INFO: Copying artifact"
cp -r build/xcode-frameworks/TaxKalculator* $DIRECTORY/Build/iOS
echo "INFO: Zipping"
zip -r TaxKalculator.framework.zip $DIRECTORY
echo "INFO: Adding zipped artifact to release"
ghr "$1" $ZIP
else
echo "ERROR: Please use a valid git tag format e.g 1.0.3"
fi
fi
fi
32 changes: 25 additions & 7 deletions src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
*/
package uk.gov.hmrc.calculator

import uk.gov.hmrc.calculator.annotations.Throws
import uk.gov.hmrc.calculator.exception.InvalidTaxCodeException
import uk.gov.hmrc.calculator.exception.InvalidTaxYearException
import uk.gov.hmrc.calculator.exception.InvalidWagesException
import uk.gov.hmrc.calculator.exception.InvalidPayPeriodException
import uk.gov.hmrc.calculator.exception.InvalidHoursException
import uk.gov.hmrc.calculator.exception.InvalidTaxBandException
import uk.gov.hmrc.calculator.model.BandBreakdown
import uk.gov.hmrc.calculator.model.CalculatorResponse
import uk.gov.hmrc.calculator.model.CalculatorResponsePayPeriod
Expand All @@ -37,9 +44,6 @@ import uk.gov.hmrc.calculator.model.taxcodes.MarriageTaxCodes
import uk.gov.hmrc.calculator.model.taxcodes.NoTaxTaxCode
import uk.gov.hmrc.calculator.model.taxcodes.SingleBandTax
import uk.gov.hmrc.calculator.model.taxcodes.StandardTaxCode
import uk.gov.hmrc.calculator.exception.InvalidTaxBandException
import uk.gov.hmrc.calculator.exception.InvalidTaxCodeException
import uk.gov.hmrc.calculator.exception.InvalidWagesException
import uk.gov.hmrc.calculator.model.taxcodes.TaxCode
import uk.gov.hmrc.calculator.utils.TaxYear
import uk.gov.hmrc.calculator.utils.convertAmountFromYearlyToPayPeriod
Expand All @@ -58,6 +62,8 @@ class Calculator(

private val bandBreakdown: MutableList<BandBreakdown> = mutableListOf()

@Throws(InvalidTaxCodeException::class, InvalidTaxYearException::class, InvalidWagesException::class,
InvalidPayPeriodException::class, InvalidHoursException::class, InvalidTaxBandException::class)
fun run(): CalculatorResponse {
if (!isAboveMinimumWages(wages) || !isBelowMaximumWages(wages)) {
throw InvalidWagesException("Wages must be between 0 and 9999999.99")
Expand All @@ -69,13 +75,25 @@ class Calculator(

val taxBands = TaxBands(taxCode.country, taxYear).bands

val taxPayable = taxToPay(yearlyWages, taxCode)
val employeesNI = employeeNIToPay(yearlyWages)
val employersNI = employerNIToPay(yearlyWages)

val taxFreeAmount = adjustTaxBands(taxBands, taxCode)[0].upper
val amountToAddToWages = if (taxCode is KTaxCode) taxCode.amountToAddToWages else null

return createResponse(
yearlyWages,
taxFreeAmount,
amountToAddToWages
)
}

private fun createResponse(
yearlyWages: Double,
taxFreeAmount: Double,
amountToAddToWages: Double?
): CalculatorResponse {
val taxCode = this.taxCode.toTaxCode()
val taxPayable = taxToPay(yearlyWages, taxCode)
val employeesNI = employeeNIToPay(yearlyWages)
val employersNI = employerNIToPay(yearlyWages)
return CalculatorResponse(
taxCode = this.taxCode,
country = taxCode.country,
Expand Down
24 changes: 24 additions & 0 deletions src/commonMain/kotlin/uk/gov/hmrc/calculator/annotations/Throws.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2019 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uk.gov.hmrc.calculator.annotations

import kotlin.reflect.KClass

@UseExperimental(ExperimentalMultiplatform::class)
@OptionalExpectation
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
@Retention(AnnotationRetention.SOURCE)
expect annotation class Throws(vararg val exceptionClasses: KClass<out Throwable>)
18 changes: 18 additions & 0 deletions src/iosMain/kotlin/uk/gov/hmrc/calculator/annotations/Throws.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2019 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uk.gov.hmrc.calculator.annotations

actual typealias Throws = kotlin.native.Throws

0 comments on commit c116eb5

Please sign in to comment.