Skip to content

Commit

Permalink
documenting and adding gh actions
Browse files Browse the repository at this point in the history
  • Loading branch information
zp1ke committed May 20, 2024
1 parent 062bba4 commit ecb7160
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 21 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test

on:
push:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1

- run: dart pub get
- run: dart analyze
- run: dart test
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
-->

Library for sales calculations.
# Salert

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.
Library for sales data calculations.

## Getting started
## Features

TODO: List prerequisites and provide or point to information on how to
start using the package.
- Sales items calculations (discount, subtotal, taxes, total).
- Sales calculations (discount, subtotal, taxes, total).

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

Example for SRI invoice (Ecuador):
```dart
const like = 'sample';
// VAT tax with 13%.
final vat = Tax(code: 'IVA13', unitValue: 13);
// Invoice item (product or service).
final item = Item(code: 'productX', quantity: 1, unitPrice: 10, taxes: [vat]);
// The sale (aka Invoice)
final sale = Sale(items: [item], tip: 1);
// Calculate sale values.
print('SUBTOTAL ${sale.subtotal}');
print('TAX ${sale.tax}');
print('TOTAL ${sale.total}');
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
2 changes: 1 addition & 1 deletion example/salert_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void ecuadorSriExample() {
final ice = Tax(code: 'iceX', unitValue: 15, affectTax: true);
// VAT tax with 13%.
final vat = Tax(code: 'IVA13', unitValue: 13);
// Some item (product / service).
// Some item (product or service).
final item = Item(
code: 'productX',
quantity: 2,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/discount.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import 'dart:math';

/// Represents a discount.
class Discount {
/// Amount for calculations.
final double amount;
/// Unitary applies calculation for every item.
final bool isUnitary;
/// If amount represents a percentage.
final bool isPercentage;
/// True if applies before taxes.
final bool affectTax;

Discount({
Expand Down
2 changes: 2 additions & 0 deletions lib/src/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Item implements Sellable {
return 0;
}

/// Calculates tax amount.
@override
double get tax {
return _taxAmountOf(subtotal);
Expand Down Expand Up @@ -94,6 +95,7 @@ class Item implements Sellable {
return baseSubtotal - subtotal;
}

/// Calculates total amount.
@override
double get total {
return subtotal + tax;
Expand Down
7 changes: 4 additions & 3 deletions lib/src/sale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Sale implements Sellable {
.reduce((s1, s2) => s1 + s2);
}

/// Calculates tax amount including [discount].
/// Calculates tax amount.
@override
double get tax {
return _items.map((item) => item.tax).reduce((s1, s2) => s1 + s2);
Expand All @@ -51,9 +51,10 @@ class Sale implements Sellable {
.reduce((s1, s2) => s1 + s2);
}

/// Calculates total amount.
@override
double get total {
return subtotal + tax;
return subtotal + tax + tip;
}

List<Item> get _items {
Expand Down Expand Up @@ -81,7 +82,7 @@ class Sale implements Sellable {
final baseSubtotal =
items.map((item) => item.subtotal).reduce((s1, s2) => s1 + s2);
final baseTax = items.map((item) => item.tax).reduce((s1, s2) => s1 + s2);
final baseTotal = baseSubtotal + baseTax;
final baseTotal = baseSubtotal + baseTax + tip;
var discountValue = discount!.discountOf(baseTotal);
final discountedSubtotal = _inverseSubtotalOf(baseTotal - discountValue);
discountValue = baseSubtotal - discountedSubtotal;
Expand Down
2 changes: 2 additions & 0 deletions lib/src/sellable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ abstract class Sellable {
/// Calculates subtotal amount including [discount] for given [taxCode] (before taxes).
double subtotalOf(String taxCode);

/// Calculates tax amount.
double get tax;

/// Calculates tax amount including [discount] for given [taxCode].
Expand All @@ -13,5 +14,6 @@ abstract class Sellable {
// Calculates discount amount before taxes.
double get discountAmount;

/// Calculates total amount.
double get total;
}

0 comments on commit ecb7160

Please sign in to comment.