Skip to content

Commit

Permalink
Form Invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
ciukstar committed Dec 4, 2023
1 parent 7ec4e8d commit 796bf1e
Show file tree
Hide file tree
Showing 17 changed files with 290 additions and 75 deletions.
17 changes: 11 additions & 6 deletions README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,19 @@ Tous les utilisateurs peuvent devenir clients par simple inscription et utilisat
## Intégration avec des API externes

* Passerelle de paiement: [Stripe](https://stripe.com/)
```
ENV: YESOD_STRIPE_PK, YESOD_STRIPE_SK
```
```
ENV: YESOD_STRIPE_PK, YESOD_STRIPE_SK
```

Pour simuler un paiement réussi, utilisez les cartes de test de la [liste suivante](https://stripe.com/docs/testing?testing-method=card-numbers#cards).

Pour simuler les paiements refusés par l'émetteur, utilisez les cartes de test de la [liste suivante](https://stripe.com/docs/testing?testing-method=card-numbers#declined-payments).


* Cartes en ligne: [Mapbox](https://www.mapbox.com/)
```
ENV: YESOD_MAPBOX_PK
```
```
ENV: YESOD_MAPBOX_PK
```

## Diagramme ERD

Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ All users can become customers by simply registering and using the services offe
## Integration with external APIs

* Payment gateway: [Stripe](https://stripe.com/)
```
ENV: YESOD_STRIPE_PK, YESOD_STRIPE_SK
```
```
ENV: YESOD_STRIPE_PK, YESOD_STRIPE_SK
```
To simulate a successful payment, use test cards from the [following list](https://stripe.com/docs/testing?testing-method=card-numbers#cards).

To simulate payments that the issuer declines, use test cards from the [following list](https://stripe.com/docs/testing?testing-method=card-numbers#declined-payments).

* Online maps: [Mapbox](https://www.mapbox.com/)
```
ENV: YESOD_MAPBOX_PK
```
```
ENV: YESOD_MAPBOX_PK
```

## ERD Diagram

Expand Down
16 changes: 10 additions & 6 deletions README.ro.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@ Toți utilizatorii pot deveni clienți prin simpla înregistrare și utilizarea

## Integrare cu API-uri externe
* Gateway de plată: [Stripe](https://stripe.com/)
```
ENV: YESOD_STRIPE_PK, YESOD_STRIPE_SK
```
```
ENV: YESOD_STRIPE_PK, YESOD_STRIPE_SK
```

Pentru a simula o plată reușită, utilizați carduri de test din [lista următoare](https://stripe.com/docs/testing?testing-method=card-numbers#cards).

Pentru a simula plățile pe care emitentul le refuză, utilizați carduri de testare din [următoarea listă](https://stripe.com/docs/testing?testing-method=card-numbers#declined-payments).

* Hărți online: [Mapbox](https://www.mapbox.com/)
```
ENV: YESOD_MAPBOX_PK
```
```
ENV: YESOD_MAPBOX_PK
```


## Diagrama ERD
Expand Down
16 changes: 10 additions & 6 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@

## Интеграция с внешними API
* Платежный шлюз: [Stripe](https://stripe.com/)
```
ENV: YESOD_STRIPE_PK, YESOD_STRIPE_SK
```
```
ENV: YESOD_STRIPE_PK, YESOD_STRIPE_SK
```

Для имитации успешного платежа используйте тестовые карты из [следующего списка](https://stripe.com/docs/testing?testing-method=card-numbers#cards).

Для имитации платежей, от которых эмитент отклоняет, используйте тестовые карты из [следующего списка](https://stripe.com/docs/testing?testing-method=card-numbers#declined-payments).

* Онлайн карты: [Mapbox](https://www.mapbox.com/)
```
ENV: YESOD_MAPBOX_PK
```
```
ENV: YESOD_MAPBOX_PK
```

## ER-диаграмма

Expand Down
10 changes: 9 additions & 1 deletion messages/en.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Uncollectible: Uncollectible
Void: Void
Open: Open
Draft: Draft
DueDate: Due date
DateCreated: Date created
InvoiceDate: Invoice date
Expand Down Expand Up @@ -418,4 +422,8 @@ Doc013: Any user who is also registered as a staff member has the role "Employee

Doc014: All users can become customers by simply registering and using the services offered.

Doc015: Integration with external APIs
Doc015: Integration with external APIs

Doc016 href@Text: To simulate a successful payment, use test cards from the <a href=#{href}>following list</a>.

Doc017 href@Text: To simulate payments that the issuer declines, use test cards from the <a href=#{href}>following list</a>.
10 changes: 9 additions & 1 deletion messages/fr.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Uncollectible: Irrecouvrable
Void: Annulé
Open: Ouverte
Draft: Brouillon
DueDate: Date d'échéance
DateCreated: Date créée
InvoiceDate: Date de facture
Expand Down Expand Up @@ -420,4 +424,8 @@ Doc013: Tout utilisateur également enregistré en tant que membre du personnel

Doc014: Tous les utilisateurs peuvent devenir clients par simple inscription et utilisation des services proposés.

Doc015: Intégration avec des API externes
Doc015: Intégration avec des API externes

Doc016 href: Pour simuler un paiement réussi, utilisez les cartes de test de la <a href=#{href}>liste suivante</a>.

Doc017 href: Pour simuler les paiements refusés par l'émetteur, utilisez les cartes de test de la <a href=#{href}>liste suivante</a>.
10 changes: 9 additions & 1 deletion messages/ro.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Uncollectible: Necolectabilă
Void: Nulă
Open: Deschisă
Draft: Ciornă
DueDate: Data scadenței
DateCreated: Data creării
InvoiceDate: Data facturii
Expand Down Expand Up @@ -420,4 +424,8 @@ Doc013: Orice utilizator care este înregistrat și ca membru al personalului ar

Doc014: Toți utilizatorii pot deveni clienți prin simpla înregistrare și utilizarea serviciilor oferite.

Doc015: Integrare cu API-uri externe
Doc015: Integrare cu API-uri externe

Doc016 href: Pentru a simula o plată reușită, utilizați carduri de test din <a href=#{href}>lista următoare</a>.

Doc017 href: Pentru a simula plățile pe care emitentul le refuză, utilizați carduri de testare din <a href=#{href}>următoarea listă</a>.
10 changes: 9 additions & 1 deletion messages/ru.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Uncollectible: Не подлежит взысканию
Void: Аннулирован
Open: Открыто
Draft: Черновик
DueDate: Срок оплаты
DateCreated: Дата создания
InvoiceDate: Дата счета-фактуры
Expand Down Expand Up @@ -420,4 +424,8 @@ Doc013: Любой пользователь, который также заре

Doc014: Все пользователи могут стать клиентами, просто зарегистрировавшись и воспользовавшись предлагаемыми услугами.

Doc015: Интеграция с внешними API
Doc015: Интеграция с внешними API

Doc016 href: Для имитации успешного платежа используйте тестовые карты из <a href=#{href}>следующего списка</a>.

Doc017 href: Для имитации платежей, от которых эмитент отклоняет, используйте тестовые карты из <a href=#{href}>следующего списка</a>.
80 changes: 45 additions & 35 deletions src/Handler/Billing.hs → src/Admin/Billing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}

module Handler.Billing
module Admin.Billing
( getAdmInvoicesR
, postAdmInvoicesR
, getAdmInvoiceCreateR
Expand All @@ -13,22 +13,23 @@ import Text.Hamlet (Html)

import Yesod.Auth (Route (LoginR), maybeAuth)
import Yesod.Core
( Yesod(defaultLayout), newIdent, whamlet, SomeMessage (SomeMessage) )
import Yesod.Core.Handler (getCurrentRoute)
( Yesod(defaultLayout), newIdent, SomeMessage (SomeMessage)
, MonadHandler (liftHandler)
)
import Yesod.Core.Widget (setTitleI)
import Yesod.Form.Functions (generateFormPost, mreq, mopt)
import Yesod.Form.Types
( MForm, FormResult (FormSuccess), FieldView (fvInput)
( MForm, FormResult, FieldView (fvInput, fvErrors, fvLabel, fvId)
, FieldSettings (FieldSettings, fsLabel, fsTooltip, fsId, fsName, fsAttrs)
)
import Yesod.Form.Fields (textField, selectFieldList, dayField)
import Yesod.Form.Fields (textField, dayField, hiddenField)
import Settings (widgetFile)

import Yesod.Persist (Entity (Entity, entityVal))
import Yesod.Persist.Core (YesodPersist(runDB))
import Database.Esqueleto.Experimental
( select, from, table, where_, val
, (^.), (==.)
( select, from, table
, (^.), orderBy, asc, fromSqlKey
)

import Foundation
Expand All @@ -37,25 +38,32 @@ import Foundation
( AuthR, PhotoPlaceholderR, AccountPhotoR
, ProfileR, AdminR
)
, AdminR (AdmInvoicesR, AdmInvoiceCreateR)
, AdminR (AdmInvoicesR, AdmInvoiceCreateR, AdmStaffPhotoR)
, AppMessage
( MsgInvoices, MsgLogin, MsgPhoto, MsgUserProfile, MsgNavigationMenu
, MsgNoInvoicesYet, MsgInvoice, MsgCancel, MsgSave, MsgCustomer
, MsgEmployee, MsgInvoiceNumber, MsgStatus, MsgInvoiceDate, MsgDueDate
, MsgBack, MsgPaid, MsgDraft, MsgOpen, MsgVoid, MsgUncollectible
)
)

import Model
( UserId, StaffId, InvoiceStatus
( InvoiceStatus
( InvoiceStatusDraft, InvoiceStatusOpen, InvoiceStatusPaid
, InvoiceStatusUncollectible, InvoiceStatusVoid
)
, User (User)
, Invoice
( Invoice, invoiceNumber, invoiceStatus, invoiceDay, invoiceDueDay
, invoiceCustomer, invoiceStaff
)
, EntityField (InvoiceCustomer, UserId, StaffId, InvoiceStatus)
, EntityField
( UserFullName, StaffName)
, Staff (Staff)
)

import Menu (menu)
import Data.Maybe (isJust)


getAdmInvoiceCreateR :: Handler Html
Expand All @@ -67,55 +75,58 @@ getAdmInvoiceCreateR = do


formInvoice :: Maybe (Entity Invoice) -> Html -> MForm Handler (FormResult Invoice,Widget)
formInvoice invoice extra = do
(custR,custV) <- mreq (selectFieldList ([] :: [(AppMessage,UserId)])) FieldSettings
formInvoice invoice extra = do
(custR,custV) <- mreq hiddenField FieldSettings
{ fsLabel = SomeMessage MsgCustomer
, fsTooltip = Nothing, fsId = Nothing, fsName = Nothing
, fsAttrs = []
} (invoiceCustomer . entityVal <$> invoice)
(emplR,emplV) <- mreq (selectFieldList ([] :: [(AppMessage,StaffId)])) FieldSettings
(emplR,emplV) <- mreq hiddenField FieldSettings
{ fsLabel = SomeMessage MsgEmployee
, fsTooltip = Nothing, fsId = Nothing, fsName = Nothing
, fsAttrs = []
} (invoiceStaff . entityVal <$> invoice)
(noR,noV) <- mreq textField FieldSettings
{ fsLabel = SomeMessage MsgInvoiceNumber
, fsTooltip = Nothing, fsId = Nothing, fsName = Nothing
, fsAttrs = []
, fsAttrs = [("class","mdc-text-field__input")]
} (invoiceNumber . entityVal <$> invoice)
(statusR,statusV) <- mreq (selectFieldList ([] :: [(AppMessage,InvoiceStatus)])) FieldSettings
(statusR,statusV) <- mreq hiddenField FieldSettings
{ fsLabel = SomeMessage MsgStatus
, fsTooltip = Nothing, fsId = Nothing, fsName = Nothing
, fsAttrs = []
} (invoiceStatus . entityVal <$> invoice)
} (show . invoiceStatus . entityVal <$> invoice)
(dayR,dayV) <- mreq dayField FieldSettings
{ fsLabel = SomeMessage MsgInvoiceDate
, fsTooltip = Nothing, fsId = Nothing, fsName = Nothing
, fsAttrs = []
, fsAttrs = [("class","mdc-text-field__input")]
} (invoiceDay . entityVal <$> invoice)
(dueR,dueV) <- mopt dayField FieldSettings
{ fsLabel = SomeMessage MsgDueDate
, fsTooltip = Nothing, fsId = Nothing, fsName = Nothing
, fsAttrs = []
, fsAttrs = [("class","mdc-text-field__input")]
} (invoiceDueDay . entityVal <$> invoice)

customers <- liftHandler $ runDB $ select $ do
x <- from $ table @User
orderBy [asc (x ^. UserFullName)]
return x

employees <- liftHandler $ runDB $ select $ do
x <- from $ table @Staff
orderBy [asc (x ^. StaffName)]
return x

return ( Invoice <$> custR <*> emplR <*> noR <*> statusR <*> dayR <*> dueR
, [whamlet|
#{extra}
<div>
^{fvInput custV}
<div>
^{fvInput emplV}
<div>
^{fvInput noV}
<div>
^{fvInput statusV}
<div>
^{fvInput dayV}
<div>
^{fvInput dueV}
|]
return ( Invoice <$> custR <*> emplR <*> noR <*> (read <$> statusR) <*> dayR <*> dueR
, $(widgetFile "admin/billing/form")
)
where
statuses = [ (InvoiceStatusDraft,MsgDraft)
, (InvoiceStatusOpen,MsgOpen)
, (InvoiceStatusPaid,MsgPaid)
, (InvoiceStatusVoid,MsgVoid)
, (InvoiceStatusUncollectible,MsgUncollectible)
]


postAdmInvoicesR :: Handler Html
Expand All @@ -128,7 +139,6 @@ getAdmInvoicesR = do

invoices <- runDB $ select $ from $ table @Invoice

curr <- getCurrentRoute
fabAddInvoice <- newIdent
defaultLayout $ do
setTitleI MsgInvoices
Expand Down
6 changes: 3 additions & 3 deletions src/Application.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ import Demo.DemoDataEN (populateEN)

import Handler.Scratch (getScratchR)

import Handler.Billing
( getAdmInvoicesR, postAdmInvoicesR, getAdmInvoiceCreateR )

import Handler.Requests
( getRequestsR, getRequestR, postRequestR
, getRequestsSearchR, postRequestApproveR
Expand Down Expand Up @@ -111,6 +108,9 @@ import Handler.Stats
, getStatsAovR, getAovDetailsR
)

import Admin.Billing
( getAdmInvoicesR, postAdmInvoicesR, getAdmInvoiceCreateR )

import Admin.Business
( getBusinessR, postBusinessR, getBusinessCreateR
, getBusinessEditR, postBusinessEditR, postBusinessDeleteR
Expand Down
5 changes: 3 additions & 2 deletions src/Handler/Resources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module Handler.Resources (getDocsR) where

import Data.Text (pack)
import Text.Hamlet (Html)
import Text.Shakespeare.I18N (renderMessage)
import Yesod.Core
Expand Down Expand Up @@ -32,7 +33,7 @@ import Foundation
, MsgDoc005, MsgDoc0061, MsgDoc0062, MsgDoc0063, MsgDoc0064
, MsgDoc0065, MsgDoc0066, MsgDoc0067, MsgDoc0068
, MsgDoc007, MsgDoc008, MsgDoc009, MsgDoc010, MsgDoc011, MsgDoc012
, MsgDoc013, MsgDoc014, MsgDoc015
, MsgDoc013, MsgDoc014, MsgDoc015, MsgDoc016, MsgDoc017
)
)

Expand Down Expand Up @@ -60,7 +61,7 @@ getDocsR = do
topAppBar <- newIdent

business <- runDB $ selectOne $ from $ table @Business

defaultLayout $ do
setTitleI MsgDocumentation
$(widgetFile "resources/docs")
Loading

0 comments on commit 796bf1e

Please sign in to comment.