diff --git a/elm-package.json b/elm-package.json index 2d16aa9..ed58214 100644 --- a/elm-package.json +++ b/elm-package.json @@ -12,6 +12,7 @@ "NoRedInk/elm-decode-pipeline": "2.0.0 <= v < 3.0.0", "debois/elm-mdl": "7.6.0 <= v < 8.0.0", "elm-community/elm-test": "2.1.0 <= v < 3.0.0", + "elm-community/json-extra": "1.1.0 <= v < 2.0.0", "elm-lang/core": "4.0.5 <= v < 5.0.0", "elm-lang/html": "1.1.0 <= v < 2.0.0", "elm-lang/navigation": "1.0.0 <= v < 2.0.0", diff --git a/gulpfile.js b/gulpfile.js index 382b900..f4a91f1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,6 @@ var gulp = require('gulp'); var elm = require('gulp-elm'); +var watch = require('gulp-watch'); var uglify = require('gulp-uglify'); var rename = require('gulp-rename'); @@ -10,3 +11,9 @@ gulp.task('elm', function () { .pipe(rename('jarbas/frontend/static/app.js')) .pipe(gulp.dest('.')); }); + +gulp.task('watch', function () { + watch('**/*.elm', function () { + gulp.start('elm'); + }); +}); diff --git a/jarbas/api/serializers.py b/jarbas/api/serializers.py index 04c557f..d144471 100644 --- a/jarbas/api/serializers.py +++ b/jarbas/api/serializers.py @@ -31,7 +31,7 @@ def get_probability(self, obj): return self.to_float(obj.probability) def get_receipt(self, obj): - return dict(fecthed=obj.receipt_fetched, url=obj.receipt_url) + return dict(fetched=obj.receipt_fetched, url=obj.receipt_url) def get_remark_value(self, obj): return self.to_float(obj.remark_value) @@ -63,18 +63,24 @@ class Meta: class NewReceiptSerializer(serializers.ModelSerializer): + reimbursement = serializers.SerializerMethodField() url = serializers.SerializerMethodField() + def get_reimbursement(self, obj): + return dict( + year=obj.year, + applicant_id=obj.applicant_id, + document_id=obj.document_id + ) + def get_url(self, obj): return obj.receipt_url class Meta: model = Reimbursement fields = ( - 'applicant_id', - 'document_id', + 'reimbursement', 'url', - 'year' ) diff --git a/jarbas/api/tests/test_reimbursement_view.py b/jarbas/api/tests/test_reimbursement_view.py index 79f5fed..a0449c8 100644 --- a/jarbas/api/tests/test_reimbursement_view.py +++ b/jarbas/api/tests/test_reimbursement_view.py @@ -137,7 +137,7 @@ def test_contents(self): year=1970, probability=0.5, suspicions=suspicions, - receipt=dict(fecthed=False, url=None) + receipt=dict(fetched=False, url=None) ) self.assertEqual(expected, contents) @@ -154,8 +154,10 @@ def setUp(self): def test_fetch_existing_receipt(self, mocked_head): mocked_head.return_value.status_code = 200 resp = self.client.get(self.url) - expected = self.unique_id.copy() - expected['url'] = self.expected_receipt_url + expected = dict( + reimbursement=self.unique_id, + url=self.expected_receipt_url + ) content = loads(resp.content.decode('utf-8')) self.assertEqual(expected, content) @@ -165,7 +167,10 @@ def test_fetch_non_existing_receipt(self, mocked_head): cache.clear() resp = self.client.get(self.url) expected = self.unique_id.copy() - expected['url'] = None + expected = dict( + reimbursement=self.unique_id, + url=None + ) content = loads(resp.content.decode('utf-8')) self.assertEqual(expected, content) @@ -176,7 +181,9 @@ def test_refetch_existing_receipt(self, mocked_head): self.obj.save() mocked_head.return_value.status_code = 200 resp = self.client.get(self.url + '?force') - expected = self.unique_id.copy() - expected['url'] = self.expected_receipt_url + expected = dict( + reimbursement=self.unique_id, + url=self.expected_receipt_url + ) content = loads(resp.content.decode('utf-8')) self.assertEqual(expected, content) diff --git a/jarbas/core/migrations/0018_make_issue_date_required.py b/jarbas/core/migrations/0018_make_issue_date_required.py new file mode 100644 index 0000000..8576992 --- /dev/null +++ b/jarbas/core/migrations/0018_make_issue_date_required.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2016-12-18 16:25 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0017_make_some_fields_optional'), + ] + + operations = [ + migrations.AlterField( + model_name='reimbursement', + name='issue_date', + field=models.DateField(verbose_name='Issue date'), + ), + ] diff --git a/jarbas/core/models.py b/jarbas/core/models.py index ee4a827..f7c6a0c 100644 --- a/jarbas/core/models.py +++ b/jarbas/core/models.py @@ -58,7 +58,7 @@ class Reimbursement(models.Model): document_number = models.CharField('Document number', max_length=140, blank=True, null=True) document_value = models.DecimalField('Document value', max_digits=10, decimal_places=3) - issue_date = models.DateField('Issue date', blank=True, null=True) + issue_date = models.DateField('Issue date') month = models.IntegerField('Month', db_index=True) remark_value = models.DecimalField('Remark value', max_digits=10, decimal_places=3, blank=True, null=True) installment = models.IntegerField('Installment', blank=True, null=True) diff --git a/jarbas/core/tests/test_reimbursement_model.py b/jarbas/core/tests/test_reimbursement_model.py index 532f540..0342665 100644 --- a/jarbas/core/tests/test_reimbursement_model.py +++ b/jarbas/core/tests/test_reimbursement_model.py @@ -33,7 +33,6 @@ def test_optional_fields(self): 'subquota_group_id', 'subquota_group_description', 'cnpj_cpf', - 'issue_date', 'remark_value', 'installment', 'reimbursement_values', diff --git a/jarbas/frontend/elm/Documents/Decoder.elm b/jarbas/frontend/elm/Documents/Decoder.elm index 7d1a87c..9e8d0da 100644 --- a/jarbas/frontend/elm/Documents/Decoder.elm +++ b/jarbas/frontend/elm/Documents/Decoder.elm @@ -4,7 +4,8 @@ import Documents.Inputs.Update as InputsUpdate import Documents.Receipt.Decoder as ReceiptDecoder import Documents.Supplier.Model as SupplierModel import Internationalization exposing (Language(..), TranslationId(..), translate) -import Json.Decode exposing ((:=), Decoder, int, list, maybe, string) +import Json.Decode exposing ((:=), Decoder, bool, fail, float, int, list, keyValuePairs, string, succeed) +import Json.Decode.Extra exposing (date) import Json.Decode.Pipeline exposing (decode, hardcoded, nullable, required) import String import Documents.Model exposing (Model, Document, Results, results) @@ -60,36 +61,39 @@ singleDecoder lang apiKey = SupplierModel.model in decode Document - |> required "id" int + |> required "year" int |> required "document_id" int - |> required "congressperson_name" string - |> required "congressperson_id" int - |> required "congressperson_document" int - |> required "term" int - |> required "state" string - |> required "party" string + |> required "applicant_id" int + |> required "total_reimbursement_value" (nullable float) + |> required "total_net_value" float + |> required "all_reimbursement_numbers" (list int) + |> required "all_net_values" (list float) + |> required "congressperson_id" (nullable int) + |> required "congressperson_name" (nullable string) + |> required "congressperson_document" (nullable int) + |> required "state" (nullable string) + |> required "party" (nullable string) |> required "term_id" int - |> required "subquota_number" int + |> required "term" int + |> required "subquota_id" int |> required "subquota_description" string - |> required "subquota_group_id" int - |> required "subquota_group_description" string + |> required "subquota_group_id" (nullable int) + |> required "subquota_group_description" (nullable string) |> required "supplier" string - |> required "cnpj_cpf" string - |> required "document_number" string + |> required "cnpj_cpf" (nullable string) |> required "document_type" int - |> required "issue_date" (nullable string) - |> required "document_value" string - |> required "remark_value" string - |> required "net_value" string + |> required "document_number" (nullable string) + |> required "document_value" float + |> required "issue_date" date |> required "month" int - |> required "year" int - |> required "installment" int - |> required "passenger" string - |> required "leg_of_the_trip" string - |> required "batch_number" int - |> required "reimbursement_number" int - |> required "reimbursement_value" string - |> required "applicant_id" int + |> required "remark_value" (nullable float) + |> required "installment" (nullable int) + |> required "batch_number" (nullable int) + |> required "all_reimbursement_values" (nullable <| list float) + |> required "passenger" (nullable string) + |> required "leg_of_the_trip" (nullable string) + |> required "probability" (nullable float) + |> required "suspicions" (nullable <| keyValuePairs bool) |> required "receipt" (ReceiptDecoder.decoder lang) |> hardcoded { supplier | googleStreetViewApiKey = apiKey } @@ -104,12 +108,12 @@ updateDocumentLanguage lang document = { receipt | lang = lang } supplier = - document.supplier_info + document.supplierInfo newSupplier = { supplier | lang = lang } in - { document | receipt = newReceipt, supplier_info = newSupplier } + { document | receipt = newReceipt, supplierInfo = newSupplier } updateLanguage : Language -> Model -> Model diff --git a/jarbas/frontend/elm/Documents/Fields.elm b/jarbas/frontend/elm/Documents/Fields.elm index 4fbe1e8..acd9dc0 100644 --- a/jarbas/frontend/elm/Documents/Fields.elm +++ b/jarbas/frontend/elm/Documents/Fields.elm @@ -6,35 +6,39 @@ import Internationalization exposing (Language(..), TranslationId(..), translate names : List String names = - [ "document_id" - , "congressperson_name" - , "congressperson_id" - , "congressperson_document" - , "term" + [ "year" + , "documentId" + , "applicantId" + , "totalReimbursementValue" + , "totalNetValue" + , "reimbursementNumbers" + , "netValues" + , "congresspersonId" + , "congresspersonName" + , "congresspersonDocument" , "state" , "party" - , "term_id" - , "subquota_number" - , "subquota_description" - , "subquota_group_id" - , "subquota_group_description" + , "termId" + , "term" + , "subquotaId" + , "subquotaDescription" + , "subquotaGroupId" + , "subquotaGroupDescription" , "supplier" - , "cnpj_cpf" - , "document_number" - , "document_type" - , "issue_date" - , "document_value" - , "remark_value" - , "net_value" + , "cnpjCpf" + , "documentType" + , "documentNumber" + , "documentValue" + , "issueDate" , "month" - , "year" + , "remarkValue" , "installment" + , "batchNumber" + , "reimbursementValues" , "passenger" - , "leg_of_the_trip" - , "batch_number" - , "reimbursement_number" - , "reimbursement_value" - , "applicant_id" + , "legOfTheTrip" + , "probability" + , "suspicions" ] @@ -42,35 +46,39 @@ labels : Language -> List String labels lang = List.map (\f -> translate lang f) - [ FieldDocumentId - , FieldCongresspersonName + [ FieldYear + , FieldDocumentId + , FieldApplicantId + , FieldTotalReimbursementValue + , FieldTotalNetValue + , FieldReimbursementNumbers + , FieldNetValues , FieldCongresspersonId + , FieldCongresspersonName , FieldCongresspersonDocument - , FieldTerm , FieldState , FieldParty , FieldTermId - , FieldSubquotaNumber + , FieldTerm + , FieldSubquotaId , FieldSubquotaDescription , FieldSubquotaGroupId , FieldSubquotaGroupDescription , FieldSupplier - , FieldCNPJOrCPF - , FieldDocumentNumber + , FieldCnpjCpf , FieldDocumentType - , FieldIssueDate + , FieldDocumentNumber , FieldDocumentValue - , FieldRemarkValue - , FieldNetValue + , FieldIssueDate , FieldMonth - , FieldYear + , FieldRemarkValue , FieldInstallment + , FieldBatchNumber + , FieldReimbursementValues , FieldPassenger , FieldLegOfTheTrip - , FieldBatchNumber - , FieldReimbursementNumber - , FieldReimbursementValue - , FieldApplicantId + , FieldProbability + , FieldSuspicions ] @@ -88,18 +96,11 @@ isSearchable ( field, label ) = True else List.member field - [ "applicant_id" - , "cnpj_cpf" - , "congressperson_id" - , "document_id" - , "document_type" + [ "applicantId" + , "cnpjCpf" + , "documentId" , "month" - , "party" - , "reimbursement_number" - , "state" - , "subquota_group_id" - , "subquota_number" - , "term" + , "subquotaId" , "year" ] @@ -108,27 +109,11 @@ sets : Language -> List ( Int, ( String, List String ) ) sets lang = List.indexedMap (,) - [ ( translate lang SearchFieldsetReimbursement - , [ "document_id" - , "document_type" - , "applicant_id" - , "reimbursement_number" - , "subquota_number" - , "subquota_group_id" - ] + [ ( translate lang SearchFieldsetCongressperson + , [ "applicantId", "year", "month", "subquotaId", "cnpjCpf" ] ) - , ( translate lang SearchFieldsetCongressperson - , [ "congressperson_id" - , "party" - , "state" - , "term" - ] - ) - , ( translate lang SearchFieldsetExpense - , [ "cnpj_cpf" - , "year" - , "month" - ] + , ( translate lang SearchFieldsetReimbursement + , [ "applicantId", "year", "documentId" ] ) ] @@ -136,15 +121,11 @@ sets lang = isNumeric : String -> Bool isNumeric field = List.member field - [ "applicant_id" - , "cnpj_cpf" - , "congressperson_id" - , "document_id" - , "document_type" + [ "applicantId" + , "cnpjCpf" + , "congresspersonId" + , "documentId" , "month" - , "reimbursement_number" - , "subquota_group_id" - , "subquota_number" - , "term" + , "subquotaId" , "year" ] diff --git a/jarbas/frontend/elm/Documents/Inputs/View.elm b/jarbas/frontend/elm/Documents/Inputs/View.elm index 774ee9e..4785b07 100644 --- a/jarbas/frontend/elm/Documents/Inputs/View.elm +++ b/jarbas/frontend/elm/Documents/Inputs/View.elm @@ -62,7 +62,7 @@ viewFieldset loading model ( index, ( title, names ) ) = List.map (viewField model.mdl loading) indexedNamesAndFields in cell - [ size Desktop 4, size Tablet 4, size Phone 4 ] + [ size Desktop 6, size Tablet 6, size Phone 6 ] (List.append heading inputs) diff --git a/jarbas/frontend/elm/Documents/Map/View.elm b/jarbas/frontend/elm/Documents/Map/View.elm index 1d70e43..114d2dd 100644 --- a/jarbas/frontend/elm/Documents/Map/View.elm +++ b/jarbas/frontend/elm/Documents/Map/View.elm @@ -3,7 +3,7 @@ module Documents.Map.View exposing (view) import Material.Button as Button import Material.Icon as Icon import Html exposing (a, text) -import Html.Attributes exposing (href) +import Html.Attributes exposing (href, target) import Internationalization exposing (Language(..), TranslationId(..), translate) import String import Documents.Map.Model exposing (Model) @@ -21,7 +21,7 @@ view model = String.concat [ "https://ddg.gg/?q=!gm+", lat, ",", long ] in a - [ href mapUrl ] + [ href mapUrl, target "_blank" ] [ Button.render Mdl [ 0 ] diff --git a/jarbas/frontend/elm/Documents/Model.elm b/jarbas/frontend/elm/Documents/Model.elm index aa2d6b0..4abb3c6 100644 --- a/jarbas/frontend/elm/Documents/Model.elm +++ b/jarbas/frontend/elm/Documents/Model.elm @@ -1,5 +1,6 @@ module Documents.Model exposing (..) +import Date import Documents.Inputs.Model as Inputs import Documents.Receipt.Model as Receipt import Documents.Supplier.Model as Supplier @@ -9,38 +10,41 @@ import Material type alias Document = - { id : Int - , document_id : Int - , congressperson_name : String - , congressperson_id : Int - , congressperson_document : Int + { year : Int + , documentId : Int + , applicantId : Int + , totalReimbursementValue : Maybe Float + , totalNetValue : Float + , reimbursementNumbers : List Int + , netValues : List Float + , congresspersonId : Maybe Int + , congresspersonName : Maybe String + , congresspersonDocument : Maybe Int + , state : Maybe String + , party : Maybe String + , termId : Int , term : Int - , state : String - , party : String - , term_id : Int - , subquota_number : Int - , subquota_description : String - , subquota_group_id : Int - , subquota_group_description : String + , subquotaId : Int + , subquotaDescription : String + , subquotaGroupId : Maybe Int + , subquotaGroupDescription : Maybe String , supplier : String - , cnpj_cpf : String - , document_number : String - , document_type : Int - , issue_date : Maybe String - , document_value : String - , remark_value : String - , net_value : String + , cnpjCpf : Maybe String + , documentType : Int + , documentNumber : Maybe String + , documentValue : Float + , issueDate : Date.Date , month : Int - , year : Int - , installment : Int - , passenger : String - , leg_of_the_trip : String - , batch_number : Int - , reimbursement_number : Int - , reimbursement_value : String - , applicant_id : Int + , remarkValue : Maybe Float + , installment : Maybe Int + , batchNumber : Maybe Int + , reimbursementValues : Maybe (List Float) + , passenger : Maybe String + , legOfTheTrip : Maybe String + , probability : Maybe Float + , suspicions : Maybe (List ( String, Bool )) , receipt : Receipt.Model - , supplier_info : Supplier.Model + , supplierInfo : Supplier.Model } diff --git a/jarbas/frontend/elm/Documents/Receipt/Decoder.elm b/jarbas/frontend/elm/Documents/Receipt/Decoder.elm index 1945f4f..68cb001 100644 --- a/jarbas/frontend/elm/Documents/Receipt/Decoder.elm +++ b/jarbas/frontend/elm/Documents/Receipt/Decoder.elm @@ -1,11 +1,11 @@ module Documents.Receipt.Decoder exposing (decoder, urlDecoder) -import Json.Decode +import Json.Decode exposing (bool, int, string) import Json.Decode.Pipeline exposing (decode, hardcoded, nullable, required) import Internationalization exposing (Language(..), TranslationId(..), translate) import Material import Json.Decode exposing (at, maybe, string) -import Documents.Receipt.Model exposing (Model) +import Documents.Receipt.Model exposing (Model, ReimbursementId) urlDecoder : Json.Decode.Decoder (Maybe String) @@ -16,8 +16,9 @@ urlDecoder = decoder : Language -> Json.Decode.Decoder Model decoder lang = decode Model - |> required "url" (nullable Json.Decode.string) - |> required "fetched" Json.Decode.bool + |> hardcoded Nothing + |> required "url" (nullable string) + |> required "fetched" bool |> hardcoded False |> hardcoded Nothing |> hardcoded lang diff --git a/jarbas/frontend/elm/Documents/Receipt/Model.elm b/jarbas/frontend/elm/Documents/Receipt/Model.elm index d7aa0e0..b024e45 100644 --- a/jarbas/frontend/elm/Documents/Receipt/Model.elm +++ b/jarbas/frontend/elm/Documents/Receipt/Model.elm @@ -1,12 +1,20 @@ -module Documents.Receipt.Model exposing (Model, model) +module Documents.Receipt.Model exposing (Model, ReimbursementId, model) import Http import Internationalization exposing (Language(..), TranslationId(..), translate) import Material +type alias ReimbursementId = + { year : Int + , applicantId : Int + , documentId : Int + } + + type alias Model = - { url : Maybe String + { reimbursement : Maybe ReimbursementId + , url : Maybe String , fetched : Bool , loading : Bool , error : Maybe Http.Error @@ -17,4 +25,4 @@ type alias Model = model : Model model = - Model Nothing False False Nothing English Material.model + Model Nothing Nothing False False Nothing English Material.model diff --git a/jarbas/frontend/elm/Documents/Receipt/Update.elm b/jarbas/frontend/elm/Documents/Receipt/Update.elm index 2e24ed3..04de9e2 100644 --- a/jarbas/frontend/elm/Documents/Receipt/Update.elm +++ b/jarbas/frontend/elm/Documents/Receipt/Update.elm @@ -1,14 +1,16 @@ module Documents.Receipt.Update exposing (Msg(..), update) +import Documents.Receipt.Decoder exposing (urlDecoder) +import Documents.Receipt.Model exposing (Model, ReimbursementId) import Http import Material +import String import Task -import Documents.Receipt.Model exposing (Model) -import Documents.Receipt.Decoder exposing (urlDecoder) type Msg - = LoadUrl Int + = LoadUrl (Maybe ReimbursementId) + | UpdateReimbursementId ReimbursementId | ApiSuccess (Maybe String) | ApiFail Http.Error | Mdl (Material.Msg Msg) @@ -17,8 +19,14 @@ type Msg update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of - LoadUrl id -> - ( { model | loading = True }, loadUrl id ) + LoadUrl (Just reimbursement) -> + ( { model | loading = True }, loadUrl reimbursement ) + + LoadUrl Nothing -> + ( model, Cmd.none ) + + UpdateReimbursementId reimbursement -> + ( { model | reimbursement = Just reimbursement }, Cmd.none ) ApiSuccess maybeUrl -> ( { model | url = maybeUrl, loading = False, fetched = True }, Cmd.none ) @@ -34,14 +42,23 @@ update msg model = Material.update mdlMsg model -loadUrl : Int -> Cmd Msg -loadUrl id = +loadUrl : ReimbursementId -> Cmd Msg +loadUrl reimbursement = let query = - [ ( "format", "json" ) ] + [ ( "format", "json" ) + , ( "force", "true" ) + ] path = - "/api/receipt/" ++ (toString id) + String.join "/" + [ "/api" + , "reimbursement" + , toString reimbursement.year + , toString reimbursement.applicantId + , toString reimbursement.documentId + , "receipt/" + ] url = Http.url path query diff --git a/jarbas/frontend/elm/Documents/Receipt/View.elm b/jarbas/frontend/elm/Documents/Receipt/View.elm index 8a3b263..a70e23a 100644 --- a/jarbas/frontend/elm/Documents/Receipt/View.elm +++ b/jarbas/frontend/elm/Documents/Receipt/View.elm @@ -1,7 +1,7 @@ module Documents.Receipt.View exposing (view) import Html exposing (a, button, div, text) -import Html.Attributes exposing (href) +import Html.Attributes exposing (href, target) import Internationalization exposing (Language(..), TranslationId(..), translate) import Material.Button as Button import Material.Icon as Icon @@ -10,12 +10,12 @@ import Documents.Receipt.Model exposing (Model) import Documents.Receipt.Update exposing (Msg(Mdl, LoadUrl)) -view : Int -> Model -> Html.Html Msg -view id model = +view : Model -> Html.Html Msg +view model = case model.url of Just url -> a - [ href url ] + [ href url, target "_blank" ] [ Button.render Mdl [ 1 ] @@ -44,7 +44,7 @@ view id model = [ 0 ] model.mdl [ Button.minifab - , Button.onClick (LoadUrl id) + , Button.onClick (LoadUrl model.reimbursement) ] [ Icon.i "search" , text (translate model.lang ReceiptFetch) diff --git a/jarbas/frontend/elm/Documents/Supplier/Update.elm b/jarbas/frontend/elm/Documents/Supplier/Update.elm index 44a8f65..70a6dbd 100644 --- a/jarbas/frontend/elm/Documents/Supplier/Update.elm +++ b/jarbas/frontend/elm/Documents/Supplier/Update.elm @@ -54,20 +54,17 @@ update msg model = load : String -> Cmd Msg load cnpj = - let - query = - [ ( "format", "json" ) ] - - path = - "/api/supplier/" ++ (cleanUp cnpj) - - url = - Http.url path query - in - if path == "/api/supplier/" then - Cmd.none - else + if isValid cnpj then + let + path = + "/api/supplier/" ++ (cleanUp cnpj) + + url = + Http.url path [ ( "format", "json" ) ] + in Task.perform ApiFail ApiSuccess (Http.get decoder url) + else + Cmd.none diff --git a/jarbas/frontend/elm/Documents/Supplier/View.elm b/jarbas/frontend/elm/Documents/Supplier/View.elm index 9e691b9..321d015 100644 --- a/jarbas/frontend/elm/Documents/Supplier/View.elm +++ b/jarbas/frontend/elm/Documents/Supplier/View.elm @@ -1,7 +1,7 @@ module Documents.Supplier.View exposing (view) import Html exposing (a, br, div, img, p, span, text) -import Html.Attributes exposing (href, src, style) +import Html.Attributes exposing (href, src, style, target) import Http exposing (url) import Internationalization exposing (Language(..), TranslationId(..), translate) import Material.Icon as Icon @@ -41,7 +41,7 @@ streetImageTag apiKey latitude longitude heading = ] in a - [ href source ] + [ href source, target "_blank" ] [ img [ src source, style css ] [] ] Nothing -> diff --git a/jarbas/frontend/elm/Documents/Update.elm b/jarbas/frontend/elm/Documents/Update.elm index 79bacff..3e48de7 100644 --- a/jarbas/frontend/elm/Documents/Update.elm +++ b/jarbas/frontend/elm/Documents/Update.elm @@ -4,16 +4,18 @@ import Char import Documents.Fields as Fields import Documents.Inputs.Update as Inputs import Documents.Inputs.Model +import Documents.Receipt.Model exposing (ReimbursementId) import Documents.Receipt.Update as Receipt +import Documents.Decoder exposing (decoder) +import Documents.Model exposing (Model, Document, Results, results) import Documents.Supplier.Update as Supplier import Http import Internationalization exposing (Language(..), TranslationId(..), translate) import Material import Navigation +import Regex exposing (regex, replace) import String import Task -import Documents.Model exposing (Model, Document, Results, results) -import Documents.Decoder exposing (decoder) totalPages : Int -> Int @@ -56,7 +58,7 @@ update msg model = Submit -> let url = - Inputs.toQuery model.inputs |> toUrl + toUrl (Inputs.toQuery model.inputs) in ( { model | loading = True }, Navigation.newUrl url ) @@ -119,7 +121,7 @@ update msg model = getIndexedDocuments newModel indexedSupplierCmds = - List.map (\( idx, doc ) -> ( idx, Supplier.load doc.cnpj_cpf )) indexedDocuments + List.map (\( idx, doc ) -> ( idx, Maybe.withDefault "" doc.cnpjCpf |> Supplier.load )) indexedDocuments cmds = List.map (\( idx, cmd ) -> Cmd.map (SupplierMsg idx) cmd) indexedSupplierCmds @@ -158,7 +160,7 @@ updateSuppliers lang target msg ( index, document ) = if target == index then let updated = - Supplier.update msg document.supplier_info + Supplier.update msg document.supplierInfo newSupplier = fst updated @@ -166,7 +168,7 @@ updateSuppliers lang target msg ( index, document ) = newCmd = Cmd.map (SupplierMsg target) (snd updated) in - ( { document | supplier_info = { newSupplier | lang = lang } }, newCmd ) + ( { document | supplierInfo = { newSupplier | lang = lang } }, newCmd ) else ( document, Cmd.none ) @@ -178,13 +180,22 @@ updateReceipts lang target msg ( index, document ) = updated = Receipt.update msg document.receipt - newReceipt = + updatedReceipt = fst updated newCmd = - Cmd.map (ReceiptMsg target) (snd updated) + snd updated |> Cmd.map (ReceiptMsg target) + + reimbursement = + ReimbursementId document.year document.applicantId document.documentId + + newReceipt = + { updatedReceipt + | lang = lang + , reimbursement = Just reimbursement + } in - ( { document | receipt = { newReceipt | lang = lang } }, newCmd ) + ( { document | receipt = newReceipt }, newCmd ) else ( document, Cmd.none ) @@ -244,6 +255,34 @@ getDocumentsAndCmd model index targetUpdate targetMsg = ( { model | results = newResults }, Cmd.batch newCommands ) +{-| Convert from camelCase to underscore: + + >>> convertQueryKey "applicationId" + "application_id" + + >>> convertQueryKey "subquotaGroupId" + "subquota_group_id" + +-} +convertQueryKey : String -> String +convertQueryKey key = + key + |> replace Regex.All (regex "[A-Z]") (\{ match } -> "_" ++ match) + |> String.map Char.toLower + + +{-| Convert from keys from a query tuple to underscore: + + >>> convertQuery [("applicantId", "1"), ("subqotaGroupId", "2")] + [("applicant_id", "1"), ("subqota_group_id", "2")] + +-} +convertQuery : List ( String, a ) -> List ( String, a ) +convertQuery query = + query + |> List.map (\( key, value ) -> ( convertQueryKey key, value )) + + loadDocuments : Language -> String -> List ( String, String ) -> Cmd Msg loadDocuments lang apiKey query = if List.isEmpty query then @@ -251,12 +290,12 @@ loadDocuments lang apiKey query = else let jsonQuery = - ( "format", "json" ) :: query + ( "format", "json" ) :: convertQuery query request = Http.get (decoder lang apiKey jsonQuery) - (Http.url "/api/document/" jsonQuery) + (Http.url "/api/reimbursement/" jsonQuery) in Task.perform ApiFail diff --git a/jarbas/frontend/elm/Documents/View.elm b/jarbas/frontend/elm/Documents/View.elm index 671ac64..cb6541f 100644 --- a/jarbas/frontend/elm/Documents/View.elm +++ b/jarbas/frontend/elm/Documents/View.elm @@ -1,5 +1,6 @@ module Documents.View exposing (..) +import Date import Documents.Fields as Fields import Documents.Inputs.View as InputsView import Documents.Inputs.Update as InputsUpdate @@ -221,30 +222,166 @@ sourceUrl : Document -> String sourceUrl document = Http.url "http://www.camara.gov.br/cota-parlamentar/documento" - [ ( "nuDeputadoId", toString document.applicant_id ) + [ ( "nuDeputadoId", toString document.applicantId ) , ( "numMes", toString document.month ) , ( "numAno", toString document.year ) - , ( "despesa", toString document.subquota_number ) - , ( "cnpjFornecedor", document.cnpj_cpf ) - , ( "idDocumento", document.document_number ) + , ( "despesa", toString document.subquotaId ) + , ( "cnpjFornecedor", Maybe.withDefault "" document.cnpjCpf ) + , ( "idDocumento", Maybe.withDefault "" document.documentNumber ) ] -viewPrice : Language -> String -> String +viewPrice : Language -> Float -> String viewPrice lang price = + formatNumber + 2 + (translate lang ThousandSeparator) + (translate lang DecimalSeparator) + price + |> BrazilianCurrency + |> translate lang + + +viewPrices : Language -> List Float -> String +viewPrices lang prices = + List.map (viewPrice lang) prices + |> String.join ", " + + +maybeViewPrice : Language -> Maybe Float -> String +maybeViewPrice lang maybePrice = + case maybePrice of + Just price -> + viewPrice lang price + + Nothing -> + "" + + +maybeViewPrices : Language -> Maybe (List Float) -> String +maybeViewPrices lang maybePrices = + case maybePrices of + Just prices -> + viewPrices lang prices + + Nothing -> + "" + + +viewDate : Language -> Date.Date -> String +viewDate lang date = + FormattedDate date |> translate lang + + +viewSuspicions : Language -> Maybe (List ( String, Bool )) -> String +viewSuspicions lang maybeSuspicions = + case maybeSuspicions of + Just suspicions -> + suspicions + |> List.filter (\( key, value ) -> value) + |> List.map (\( key, value ) -> translate lang <| Suspicion key) + |> String.join ", " + + Nothing -> + "" + + +viewCpf : String -> String +viewCpf cpf = + let + part1 = + String.slice 0 3 cpf + + part2 = + String.slice 3 6 cpf + + part3 = + String.slice 6 9 cpf + + part4 = + String.slice 9 11 cpf + in + String.concat + [ part1 + , "." + , part2 + , "." + , part3 + , "-" + , part4 + ] + + +viewCnpj : String -> String +viewCnpj cnpj = let - num = - String.toFloat price |> Result.withDefault 0.0 - - formatted = - formatNumber - 2 - (translate lang ThousandSeparator) - (translate lang DecimalSeparator) - num + part1 = + String.slice 0 2 cnpj + + part2 = + String.slice 2 5 cnpj + + part3 = + String.slice 5 8 cnpj + + part4 = + String.slice 8 12 cnpj + + part5 = + String.slice 12 14 cnpj in - BrazilianCurrency formatted - |> translate lang + String.concat + [ part1 + , "." + , part2 + , "." + , part3 + , "/" + , part4 + , "-" + , part5 + ] + + +viewCnpjCpf : String -> String +viewCnpjCpf value = + case String.length value of + 11 -> + viewCpf value + + 14 -> + viewCnpj value + + _ -> + value + + +viewSupplier : Document -> String +viewSupplier document = + case document.cnpjCpf of + Just value -> + String.concat + [ document.supplier + , " (" + , viewCnpjCpf value + , ")" + ] + + Nothing -> + document.supplier + + +viewMaybeIntButZero : Maybe Int -> String +viewMaybeIntButZero maybeInt = + case maybeInt of + Just int -> + if int == 0 then + "" + else + toString int + + Nothing -> + "" viewError : Language -> Maybe Http.Error -> Html.Html Msg @@ -288,7 +425,7 @@ viewDocumentBlock lang ( title, icon, fields ) = Icon.view icon [ Options.css "transform" "translateY(0.4rem)" ] ps = - if title == (translate lang FieldsetSupplier) then + if title == (translate lang FieldsetSummary) then Options.styled p [ Typography.caption ] @@ -307,6 +444,107 @@ viewDocumentBlock lang ( title, icon, fields ) = ] +viewSummaryBlock : Language -> Document -> Html.Html Msg +viewSummaryBlock lang document = + let + congressperson = + String.concat + [ Maybe.withDefault "" document.congresspersonName + , " (" + , Maybe.withDefault "" document.party + , "/" + , Maybe.withDefault "" document.state + , ")" + ] + + claimedDate = + [ document.month, document.year ] + |> List.map toString + |> String.join "/" + + subquota = + String.concat + [ document.subquotaDescription + , " (" + , toString document.subquotaId + , ")" + ] + + fields = + [ ( translate lang FieldCongressperson, congressperson ) + , ( translate lang FieldIssueDate, viewDate lang document.issueDate ) + , ( translate lang FieldClaimDate, claimedDate ) + , ( translate lang FieldSubquotaDescription, subquota ) + , ( translate lang FieldSubquotaGroupDescription, Maybe.withDefault "" document.subquotaGroupDescription ) + , ( translate lang FieldSupplier, viewSupplier document ) + , ( translate lang FieldDocumentValue, viewPrice lang document.documentValue ) + , ( translate lang FieldRemarkValue, maybeViewPrice lang document.remarkValue ) + , ( translate lang FieldTotalNetValue, viewPrice lang document.totalNetValue ) + , ( translate lang FieldTotalReimbursementValue, maybeViewPrice lang document.totalReimbursementValue ) + , ( translate lang FieldSuspicions, viewSuspicions lang document.suspicions ) + ] + |> List.filter (\( key, value ) -> String.isEmpty value |> not) + in + viewDocumentBlock lang ( translate lang FieldsetSummary, "list", fields ) + + +viewReimbursementDetails : Language -> Document -> Html.Html Msg +viewReimbursementDetails lang document = + let + reimbursements = + document.reimbursementNumbers + |> List.map toString + |> String.join ", " + + documentType = + DocumentType document.documentType + |> translate lang + + fields = + [ ( translate lang FieldApplicantId, toString document.applicantId ) + , ( translate lang FieldDocumentId, toString document.documentId ) + , ( translate lang FieldNetValues, viewPrices lang document.netValues ) + , ( translate lang FieldReimbursementValues, maybeViewPrices lang document.reimbursementValues ) + , ( translate lang FieldReimbursementNumbers, reimbursements ) + , ( translate lang FieldDocumentType, documentType ) + , ( translate lang FieldDocumentNumber, Maybe.withDefault "" document.documentNumber ) + , ( translate lang FieldInstallment, viewMaybeIntButZero document.installment ) + , ( translate lang FieldBatchNumber, viewMaybeIntButZero document.batchNumber ) + ] + |> List.filter (\( key, value ) -> String.isEmpty value |> not) + in + viewDocumentBlock lang ( translate lang FieldsetReimbursement, "folder", fields ) + + +viewCongressPersonDetails : Language -> Document -> Html.Html Msg +viewCongressPersonDetails lang document = + let + fields = + [ ( translate lang FieldCongresspersonId, viewMaybeIntButZero document.congresspersonId ) + , ( translate lang FieldCongresspersonDocument, viewMaybeIntButZero document.congresspersonDocument ) + , ( translate lang FieldTerm, toString document.term ) + , ( translate lang FieldTermId, toString document.termId ) + ] + |> List.filter (\( key, value ) -> String.isEmpty value |> not) + in + viewDocumentBlock lang ( translate lang FieldsetCongressperson, "face", fields ) + + +viewTrip : Language -> Document -> Html.Html Msg +viewTrip lang document = + let + fields = + [ ( translate lang FieldPassenger, Maybe.withDefault "" document.passenger ) + , ( translate lang FieldLegOfTheTrip, Maybe.withDefault "" document.legOfTheTrip ) + ] + |> List.filter (\( key, value ) -> String.isEmpty value |> not) + in + if List.isEmpty fields then + text "" + else + viewDocumentBlock lang ( translate lang FieldsetTrip, "flight", fields ) + + viewDocument : Language -> Int -> Document -> List (Material.Grid.Cell Msg) viewDocument lang index document = let @@ -314,70 +552,17 @@ viewDocument lang index document = Fields.getLabel lang blocks = - [ ( translate lang FieldsetCongressperson - , "face" - , [ ( getLabel "congressperson_name", document.congressperson_name ) - , ( getLabel "congressperson_id", toString document.congressperson_id ) - , ( getLabel "congressperson_document", toString document.congressperson_document ) - , ( getLabel "state", document.state ) - , ( getLabel "party", document.party ) - , ( getLabel "term", toString document.term ) - , ( getLabel "term_id", toString document.term_id ) - ] - ) - , ( translate lang FieldsetSubquota - , "list" - , [ ( getLabel "subquota_number", toString document.subquota_number ) - , ( getLabel "subquota_description", document.subquota_description ) - , ( getLabel "subquota_group_id", toString document.subquota_group_id ) - , ( getLabel "subquota_group_description", document.subquota_group_description ) - ] - ) - , ( translate lang FieldsetSupplier - , "store" - , [ ( getLabel "supplier", document.supplier ) - , ( getLabel "cnpj_cpf", document.cnpj_cpf ) - ] - ) - , ( translate lang FieldsetDocument - , "receipt" - , [ ( getLabel "document_id", toString document.document_id ) - , ( getLabel "document_number", document.document_number ) - , ( getLabel "document_type", toString document.document_type ) - , ( getLabel "month", toString document.month ) - , ( getLabel "year", toString document.year ) - , ( getLabel "issue_date", Maybe.withDefault "" document.issue_date ) - ] - ) - , ( translate lang FieldsetValues - , "monetization_on" - , [ ( getLabel "document_value", viewPrice lang document.document_value ) - , ( getLabel "remark_value", viewPrice lang document.remark_value ) - , ( getLabel "net_value", viewPrice lang document.net_value ) - , ( getLabel "reimbursement_value", viewPrice lang document.reimbursement_value ) - , ( getLabel "installment", toString document.installment ) - ] - ) - , ( translate lang FieldsetTrip - , "flight" - , [ ( getLabel "passenger", document.passenger ) - , ( getLabel "leg_of_the_trip", document.leg_of_the_trip ) - ] - ) - , ( translate lang FieldsetApplication - , "folder" - , [ ( getLabel "applicant_id", toString document.applicant_id ) - , ( getLabel "batch_number", toString document.batch_number ) - , ( getLabel "reimbursement_number", toString document.reimbursement_number ) - ] - ) + [ viewSummaryBlock lang document + , viewTrip lang document + , viewReimbursementDetails lang document + , viewCongressPersonDetails lang document ] receipt = - Html.App.map (ReceiptMsg index) (ReceiptView.view document.id document.receipt) + Html.App.map (ReceiptMsg index) (ReceiptView.view document.receipt) mapModel = - MapModel.modelFrom lang document.supplier_info + MapModel.modelFrom lang document.supplierInfo mapButton = Html.App.map (\_ -> MapMsg) <| MapView.view mapModel @@ -386,10 +571,10 @@ viewDocument lang index document = Options.styled p [ Typography.headline, Color.text Color.primary ] - [ (translate lang DocumentTitle) ++ (toString document.document_id) |> text ] + [ (translate lang DocumentTitle) ++ (toString document.documentId) |> text ] supplier = - Html.App.map (SupplierMsg index) (SupplierView.view document.supplier_info) + Html.App.map (SupplierMsg index) (SupplierView.view document.supplierInfo) supplierTitle = Options.styled @@ -409,7 +594,7 @@ viewDocument lang index document = ] , cell [ size Desktop 6, size Tablet 8, size Phone 4 ] - [ Options.styled div [] (List.map (viewDocumentBlock lang) blocks) + [ Options.styled div [] blocks , Options.styled p [ Typography.caption, Options.css "margin-top" "1rem" ] @@ -441,13 +626,10 @@ viewDocuments model = InputsUpdate.toQuery model.inputs |> List.isEmpty |> not results = - if model.showForm then - if total == 1 then - (translate model.lang ResultTitleSingular) - else - (translate model.lang ResultTitlePlural) + if total == 1 then + (toString total) ++ (translate model.lang ResultTitleSingular) else - "" + (toString total) ++ (translate model.lang ResultTitlePlural) title = cell @@ -455,7 +637,7 @@ viewDocuments model = [ Options.styled div [ Typography.center, Typography.display1 ] - [ (toString total) ++ results |> text ] + [ results |> text ] ] pagination = diff --git a/jarbas/frontend/elm/Internationalization.elm b/jarbas/frontend/elm/Internationalization.elm index c0113fd..0b4f8f1 100644 --- a/jarbas/frontend/elm/Internationalization.elm +++ b/jarbas/frontend/elm/Internationalization.elm @@ -1,5 +1,8 @@ module Internationalization exposing (Language(..), TranslationId(..), translate) +import Date +import String + type alias TranslationSet = { english : String @@ -19,44 +22,46 @@ type TranslationId | AboutDatasets | SearchFieldsetReimbursement | SearchFieldsetCongressperson - | SearchFieldsetExpense + | FieldsetSummary + | FieldsetTrip + | FieldsetReimbursement | FieldsetCongressperson - | FieldsetSubquota - | FieldsetSupplier | FieldsetSupplierDetails - | FieldsetDocument - | FieldsetValues - | FieldsetTrip - | FieldsetApplication + | FieldYear | FieldDocumentId - | FieldCongresspersonName + | FieldApplicantId + | FieldTotalReimbursementValue + | FieldTotalNetValue + | FieldReimbursementNumbers + | FieldNetValues | FieldCongresspersonId + | FieldCongressperson + | FieldCongresspersonName | FieldCongresspersonDocument - | FieldTerm | FieldState | FieldParty | FieldTermId - | FieldSubquotaNumber + | FieldTerm + | FieldSubquotaId | FieldSubquotaDescription | FieldSubquotaGroupId | FieldSubquotaGroupDescription | FieldSupplier - | FieldCNPJOrCPF - | FieldDocumentNumber + | FieldCnpjCpf | FieldDocumentType - | FieldIssueDate + | FieldDocumentNumber | FieldDocumentValue - | FieldRemarkValue - | FieldNetValue + | FieldIssueDate | FieldMonth - | FieldYear + | FieldClaimDate + | FieldRemarkValue | FieldInstallment + | FieldBatchNumber + | FieldReimbursementValues | FieldPassenger | FieldLegOfTheTrip - | FieldBatchNumber - | FieldReimbursementNumber - | FieldReimbursementValue - | FieldApplicantId + | FieldProbability + | FieldSuspicions | DocumentSource | DocumentChamberOfDeputies | ReceiptFetch @@ -102,6 +107,49 @@ type TranslationId | BrazilianCurrency String | ThousandSeparator | DecimalSeparator + | FormattedDate Date.Date + | Suspicion String + | DocumentType Int + + +monthNumber : Date.Date -> Int +monthNumber date = + case Date.month date of + Date.Jan -> + 1 + + Date.Feb -> + 2 + + Date.Mar -> + 3 + + Date.Apr -> + 4 + + Date.May -> + 5 + + Date.Jun -> + 6 + + Date.Jul -> + 7 + + Date.Aug -> + 8 + + Date.Sep -> + 9 + + Date.Oct -> + 10 + + Date.Nov -> + 11 + + Date.Dec -> + 12 translate : Language -> TranslationId -> String @@ -131,84 +179,94 @@ translate lang trans = SearchFieldsetReimbursement -> TranslationSet - "Reimbursement" - "Reembolso" + "Reimbursement data" + "Dados do reembolso" SearchFieldsetCongressperson -> TranslationSet - "Congressperson" - "Deputado(a)" + "Congressperson & expense data" + "Dados do(a) deputado(a) e da despesa" - SearchFieldsetExpense -> + FieldsetSummary -> TranslationSet - "Expense" - "Despesa" + "Summary" + "Resumo" - FieldsetCongressperson -> + FieldsetTrip -> TranslationSet - "Congressperson" - "Deputado(a)" + "Ticket details" + "Detalhes da passagem" - FieldsetSubquota -> + FieldsetCongressperson -> TranslationSet - "Subquota" - "Subquota" + "Congressperson details" + "Detalhes do(a) deputado(a)" - FieldsetSupplier -> + FieldsetReimbursement -> TranslationSet - "Supplier" - "Fornecedor" + "Reimbursement details" + "Detalhes do reembolso" FieldsetSupplierDetails -> TranslationSet "If we can find the CNPJ of this supplier in our database more info will be available in the sidebar." "Se o CNPJ estiver no nosso banco de dados mais detalhes sobre o fornecedor aparecerão ao lado." - FieldsetDocument -> + FieldYear -> TranslationSet - "Document" - "Documento" + "Year" + "Ano" - FieldsetValues -> + FieldDocumentId -> TranslationSet - "Values" - "Valores" + "Document ID" + "ID do documento" - FieldsetTrip -> + FieldApplicantId -> TranslationSet - "Trip" - "Viagens" + "Applicant ID" + "Identificador do Solicitante" - FieldsetApplication -> + FieldTotalReimbursementValue -> TranslationSet - "Application" - "Solicitante" + "Total reimbursement value" + "Valor total dos reembolsos" - FieldDocumentId -> + FieldTotalNetValue -> TranslationSet - "Document ID" - "ID do documento" + "Total net value" + "Valor líquido total" - FieldCongresspersonName -> + FieldReimbursementNumbers -> TranslationSet - "Congressperson name" - "Nome do parlamentar" + "Reimbursement number" + "Número dos reembolsos" + + FieldNetValues -> + TranslationSet + "Net values" + "Valores líquidos" FieldCongresspersonId -> TranslationSet "Congressperson ID" "Cadastro do Parlamentar" + FieldCongressperson -> + TranslationSet + "Congressperson" + "Deputado(a)" + + FieldCongresspersonName -> + TranslationSet + "Congressperson nome" + "Nome do(a) deputado(a)" + FieldCongresspersonDocument -> TranslationSet "Congressperson document" "Número da Carteira Parlamentar" - FieldTerm -> - TranslationSet - "Term" - "Número da legislatura" - FieldState -> TranslationSet "State" @@ -224,81 +282,91 @@ translate lang trans = "Term ID" "Código da legislatura" - FieldSubquotaNumber -> + FieldTerm -> + TranslationSet + "Term" + "Número da legislatura" + + FieldSubquotaId -> TranslationSet "Subquota number" "Número da Subcota" FieldSubquotaDescription -> TranslationSet - "Subquota description" - "Descrição da subquota" + "Subquota" + "Subquota" FieldSubquotaGroupId -> TranslationSet - "Subquota group ID" - "Número da Especificação da Subcota" + "Subquota group number" + "Número da especificação da subcota" FieldSubquotaGroupDescription -> TranslationSet - "Subquota group description" - "Descrição da Especificação da Subcota" + "Subquota group" + "Especificação da subcota" FieldSupplier -> TranslationSet "Supplier" "Fornecedor" - FieldCNPJOrCPF -> + FieldCnpjCpf -> TranslationSet "CNPJ or CPF" "CNPJ ou CPF" - FieldDocumentNumber -> - TranslationSet - "Document number" - "Número do documento" - FieldDocumentType -> TranslationSet "Document type" "Tipo do documento" - FieldIssueDate -> + FieldDocumentNumber -> TranslationSet - "Issue date" - "Data de emissão" + "Document number" + "Número do documento" FieldDocumentValue -> TranslationSet - "Document value" - "Valor do documento" + "Expense value" + "Valor da despesa" - FieldRemarkValue -> + FieldIssueDate -> TranslationSet - "Remark value" - "Valor da glosa" + "Expense date" + "Data da despesa" - FieldNetValue -> + FieldClaimDate -> TranslationSet - "Net value" - "Valor líquido" + "Claim date" + "Data do pedido de reembolso" FieldMonth -> TranslationSet "Month" "Mês" - FieldYear -> + FieldRemarkValue -> TranslationSet - "Year" - "Ano" + "Remark value" + "Valor da glosa" FieldInstallment -> TranslationSet "Installment" "Número da parcela" + FieldBatchNumber -> + TranslationSet + "Batch number" + "Número do lote" + + FieldReimbursementValues -> + TranslationSet + "Reimbursement values" + "Valor dos reembolsos" + FieldPassenger -> TranslationSet "Passenger" @@ -309,25 +377,15 @@ translate lang trans = "Leg of the trip" "Trecho" - FieldBatchNumber -> - TranslationSet - "Batch number" - "Número do lote" - - FieldReimbursementNumber -> + FieldProbability -> TranslationSet - "Reimbursement number" - "Número do Ressarcimento" + "Probability" + "Probabilidade" - FieldReimbursementValue -> + FieldSuspicions -> TranslationSet - "Reimbursement value" - "Valor da Restituição" - - FieldApplicantId -> - TranslationSet - "Applicant ID" - "Identificador do Solicitante" + "Suspicions" + "Suspeitas" DocumentSource -> TranslationSet @@ -553,6 +611,69 @@ translate lang trans = TranslationSet "." "," + + FormattedDate date -> + TranslationSet + (String.concat + [ Date.month date |> toString + , " " + , Date.day date |> toString + , ", " + , Date.year date |> toString + ] + ) + (List.map + toString + [ Date.day date + , monthNumber date + , Date.year date + ] + |> String.join "/" + ) + + Suspicion suspicion -> + case suspicion of + "meal_price_outlier" -> + TranslationSet + "Meal price is an outlier" + "Preço de refeição muito incomum" + + "over_monthly_subquota_limit" -> + TranslationSet + "Expenses over the (sub)quota limit" + "Extrapolou limita da (sub)quota" + + "suspicious_traveled_speed_day" -> + TranslationSet + "Many expenses in different cities at the same day" + "Muitas despesas em diferentes cidades no mesmo dia" + + _ -> + TranslationSet + suspicion + suspicion + + DocumentType value -> + case value of + 0 -> + TranslationSet + "Bill of sale" + "Nota fiscal" + + 1 -> + TranslationSet + "Simple receipt" + "Recibo simples" + + 2 -> + TranslationSet + "Expesne made abroad" + "Despesa no exterior" + + _ -> + TranslationSet + "" + "" in case lang of English -> diff --git a/jarbas/frontend/elm/Routes.elm b/jarbas/frontend/elm/Routes.elm index 5cb303d..9882766 100644 --- a/jarbas/frontend/elm/Routes.elm +++ b/jarbas/frontend/elm/Routes.elm @@ -25,7 +25,7 @@ fromUrl hash = List.map (\header -> if header == "document" then - "document_id" + "documentId" else header ) diff --git a/package.json b/package.json index 62ba6f1..2ae3a19 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "scripts": { "postinstall": "elm-package install --yes", "test": "elm-test jarbas/frontend/tests/elm-tests/Main.elm", - "assets": "gulp elm" + "assets": "gulp elm", + "watch": "gulp watch" }, "dependencies": { "elm": "^0.17.1", @@ -16,6 +17,7 @@ "gulp-cli": "^1.2.2", "gulp-elm": "^0.5.0", "gulp-rename": "^1.2.2", - "gulp-uglify": "^2.0.0" + "gulp-uglify": "^2.0.0", + "gulp-watch": "^4.3.11" } }