feat: atualizar fluxo OT, dashboard, transacoes e PDFs
This commit is contained in:
@@ -105,7 +105,7 @@ func createInvoiceH() fiber.Handler {
|
||||
return fiber.NewError(500, "erro ao criar fatura")
|
||||
}
|
||||
|
||||
docType := "Orcamento"
|
||||
docType := "Orçamento"
|
||||
prefix := "ORC"
|
||||
if b.Type == "invoice" {
|
||||
docType = "Fatura"
|
||||
@@ -121,6 +121,7 @@ func createInvoiceH() fiber.Handler {
|
||||
CompanyIBAN: sett["company_iban"],
|
||||
CompanyPhone: sett["company_phone"],
|
||||
CompanyEmail: sett["company_email"],
|
||||
CompanyLogo: sett["company_logo"],
|
||||
DocType: docType,
|
||||
DocNumber: fmt.Sprintf("%s/%d/%04d", prefix, inv.IssuedAt.Year(), inv.Number),
|
||||
IssuedAt: inv.IssuedAt.Format("02/01/2006"),
|
||||
|
||||
@@ -21,7 +21,7 @@ type Invoice struct {
|
||||
|
||||
func ListInvoices(ctx context.Context, conn *pgxpool.Conn) ([]*Invoice, error) {
|
||||
rows, err := conn.Query(ctx,
|
||||
`SELECT id, work_order_id, type, number, COALESCE(pdf_path,''), issued_at, created_at
|
||||
`SELECT id, work_order_id, type, number, COALESCE(pdf_path,''), issued_at, issued_at AS created_at
|
||||
FROM invoices ORDER BY issued_at DESC`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invoice: list: %w", err)
|
||||
@@ -41,7 +41,7 @@ func ListInvoices(ctx context.Context, conn *pgxpool.Conn) ([]*Invoice, error) {
|
||||
|
||||
func GetInvoice(ctx context.Context, conn *pgxpool.Conn, id string) (*Invoice, error) {
|
||||
row := conn.QueryRow(ctx,
|
||||
`SELECT id, work_order_id, type, number, COALESCE(pdf_path,''), issued_at, created_at
|
||||
`SELECT id, work_order_id, type, number, COALESCE(pdf_path,''), issued_at, issued_at AS created_at
|
||||
FROM invoices WHERE id = $1`, id)
|
||||
var inv Invoice
|
||||
err := row.Scan(&inv.ID, &inv.WorkOrderID, &inv.Type, &inv.Number,
|
||||
@@ -59,7 +59,7 @@ func CreateInvoice(ctx context.Context, conn *pgxpool.Conn, woID, docType string
|
||||
row := conn.QueryRow(ctx,
|
||||
`INSERT INTO invoices (work_order_id, type, issued_at)
|
||||
VALUES ($1, $2, NOW())
|
||||
RETURNING id, work_order_id, type, number, COALESCE(pdf_path,''), issued_at, created_at`,
|
||||
RETURNING id, work_order_id, type, number, COALESCE(pdf_path,''), issued_at, issued_at AS created_at`,
|
||||
woID, docType)
|
||||
var inv Invoice
|
||||
if err := row.Scan(&inv.ID, &inv.WorkOrderID, &inv.Type, &inv.Number,
|
||||
|
||||
@@ -14,6 +14,7 @@ var AllowedKeys = map[string]bool{
|
||||
"company_iban": true,
|
||||
"company_phone": true,
|
||||
"company_email": true,
|
||||
"company_logo": true,
|
||||
}
|
||||
|
||||
func GetSettings(ctx context.Context, conn *pgxpool.Conn) (map[string]string, error) {
|
||||
|
||||
@@ -48,6 +48,7 @@ type WorkOrderDetail struct {
|
||||
}
|
||||
|
||||
var allowedTransitions = map[string][]string{
|
||||
"quote": {"open", "cancelled"},
|
||||
"open": {"in_progress", "cancelled"},
|
||||
"in_progress": {"completed", "cancelled"},
|
||||
"completed": {"invoiced", "cancelled"},
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestWorkOrderCRUD(t *testing.T) {
|
||||
wo, err := workorder.CreateWorkOrder(ctx, conn, "", "", "", "")
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, wo.ID)
|
||||
assert.Equal(t, "open", wo.Status)
|
||||
assert.Equal(t, "quote", wo.Status)
|
||||
|
||||
list, err := workorder.ListWorkOrders(ctx, conn, "")
|
||||
require.NoError(t, err)
|
||||
@@ -55,9 +55,9 @@ func TestWorkOrderTransition(t *testing.T) {
|
||||
wo, err := workorder.CreateWorkOrder(ctx, conn, "", "", "", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
wo2, err := workorder.TransitionStatus(ctx, conn, wo.ID, "in_progress", "")
|
||||
wo2, err := workorder.TransitionStatus(ctx, conn, wo.ID, "open", "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "in_progress", wo2.Status)
|
||||
assert.Equal(t, "open", wo2.Status)
|
||||
|
||||
_, err = workorder.TransitionStatus(ctx, conn, wo.ID, "cancelled_invalid", "")
|
||||
assert.Error(t, err, "invalid transition should error")
|
||||
@@ -69,6 +69,9 @@ func TestAllowedTransitions(t *testing.T) {
|
||||
to string
|
||||
valid bool
|
||||
}{
|
||||
{"quote", "open", true},
|
||||
{"quote", "cancelled", true},
|
||||
{"quote", "in_progress", false},
|
||||
{"open", "in_progress", true},
|
||||
{"open", "cancelled", true},
|
||||
{"open", "completed", false},
|
||||
|
||||
Reference in New Issue
Block a user