add whatsapp contact button and prepayment/full payment badge
This commit is contained in:
@@ -0,0 +1 @@
|
||||
ALTER TABLE deliveries DROP COLUMN payment_status;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE deliveries
|
||||
ADD COLUMN payment_status varchar(20) NOT NULL DEFAULT 'prepaid';
|
||||
@@ -32,9 +32,9 @@ SELECT * FROM deliveries WHERE date = $1;
|
||||
INSERT INTO deliveries (
|
||||
date, pickup_location, pickup_location_2, warehouse_request_source, warehouse_request_source_2, product_name, product_name_2,
|
||||
customer_name, address, street, house, apartment, entrance, floor,
|
||||
phone, additional_phone, has_elevator, service_info, comment
|
||||
phone, additional_phone, has_elevator, payment_status, service_info, comment
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetDeliveryByID :one
|
||||
@@ -62,10 +62,11 @@ UPDATE deliveries SET
|
||||
phone = $15,
|
||||
additional_phone = $16,
|
||||
has_elevator = $17,
|
||||
service_info = $18,
|
||||
comment = $19,
|
||||
payment_status = $18,
|
||||
service_info = $19,
|
||||
comment = $20,
|
||||
updated_at = NOW()
|
||||
WHERE id = $20;
|
||||
WHERE id = $21;
|
||||
|
||||
-- name: GetDeliveryCount :many
|
||||
SELECT COUNT(*) as count, date FROM deliveries
|
||||
|
||||
@@ -32,6 +32,7 @@ type Delivery struct {
|
||||
Floor pgtype.Text `db:"floor" json:"floor"`
|
||||
WarehouseRequestSource pgtype.Text `db:"warehouse_request_source" json:"warehouse_request_source"`
|
||||
WarehouseRequestSource2 pgtype.Text `db:"warehouse_request_source_2" json:"warehouse_request_source_2"`
|
||||
PaymentStatus string `db:"payment_status" json:"payment_status"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
|
||||
@@ -15,10 +15,10 @@ const createDelivery = `-- name: CreateDelivery :one
|
||||
INSERT INTO deliveries (
|
||||
date, pickup_location, pickup_location_2, warehouse_request_source, warehouse_request_source_2, product_name, product_name_2,
|
||||
customer_name, address, street, house, apartment, entrance, floor,
|
||||
phone, additional_phone, has_elevator, service_info, comment
|
||||
phone, additional_phone, has_elevator, payment_status, service_info, comment
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)
|
||||
RETURNING id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor, warehouse_request_source, warehouse_request_source_2
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)
|
||||
RETURNING id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor, warehouse_request_source, warehouse_request_source_2, payment_status
|
||||
`
|
||||
|
||||
type CreateDeliveryParams struct {
|
||||
@@ -39,6 +39,7 @@ type CreateDeliveryParams struct {
|
||||
Phone string `db:"phone" json:"phone"`
|
||||
AdditionalPhone pgtype.Text `db:"additional_phone" json:"additional_phone"`
|
||||
HasElevator bool `db:"has_elevator" json:"has_elevator"`
|
||||
PaymentStatus string `db:"payment_status" json:"payment_status"`
|
||||
ServiceInfo pgtype.Text `db:"service_info" json:"service_info"`
|
||||
Comment pgtype.Text `db:"comment" json:"comment"`
|
||||
}
|
||||
@@ -62,6 +63,7 @@ func (q *Queries) CreateDelivery(ctx context.Context, arg CreateDeliveryParams)
|
||||
arg.Phone,
|
||||
arg.AdditionalPhone,
|
||||
arg.HasElevator,
|
||||
arg.PaymentStatus,
|
||||
arg.ServiceInfo,
|
||||
arg.Comment,
|
||||
)
|
||||
@@ -90,6 +92,7 @@ func (q *Queries) CreateDelivery(ctx context.Context, arg CreateDeliveryParams)
|
||||
&i.Floor,
|
||||
&i.WarehouseRequestSource,
|
||||
&i.WarehouseRequestSource2,
|
||||
&i.PaymentStatus,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -129,7 +132,7 @@ func (q *Queries) DeleteDelivery(ctx context.Context, id pgtype.UUID) error {
|
||||
}
|
||||
|
||||
const getDeliveriesByDate = `-- name: GetDeliveriesByDate :many
|
||||
SELECT id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor, warehouse_request_source, warehouse_request_source_2 FROM deliveries WHERE date = $1
|
||||
SELECT id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor, warehouse_request_source, warehouse_request_source_2, payment_status FROM deliveries WHERE date = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetDeliveriesByDate(ctx context.Context, date pgtype.Date) ([]Delivery, error) {
|
||||
@@ -165,6 +168,7 @@ func (q *Queries) GetDeliveriesByDate(ctx context.Context, date pgtype.Date) ([]
|
||||
&i.Floor,
|
||||
&i.WarehouseRequestSource,
|
||||
&i.WarehouseRequestSource2,
|
||||
&i.PaymentStatus,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -177,7 +181,7 @@ func (q *Queries) GetDeliveriesByDate(ctx context.Context, date pgtype.Date) ([]
|
||||
}
|
||||
|
||||
const getDeliveryByID = `-- name: GetDeliveryByID :one
|
||||
SELECT id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor, warehouse_request_source, warehouse_request_source_2 FROM deliveries WHERE id = $1
|
||||
SELECT id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor, warehouse_request_source, warehouse_request_source_2, payment_status FROM deliveries WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetDeliveryByID(ctx context.Context, id pgtype.UUID) (Delivery, error) {
|
||||
@@ -207,6 +211,7 @@ func (q *Queries) GetDeliveryByID(ctx context.Context, id pgtype.UUID) (Delivery
|
||||
&i.Floor,
|
||||
&i.WarehouseRequestSource,
|
||||
&i.WarehouseRequestSource2,
|
||||
&i.PaymentStatus,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -317,10 +322,11 @@ UPDATE deliveries SET
|
||||
phone = $15,
|
||||
additional_phone = $16,
|
||||
has_elevator = $17,
|
||||
service_info = $18,
|
||||
comment = $19,
|
||||
payment_status = $18,
|
||||
service_info = $19,
|
||||
comment = $20,
|
||||
updated_at = NOW()
|
||||
WHERE id = $20
|
||||
WHERE id = $21
|
||||
`
|
||||
|
||||
type UpdateDeliveryParams struct {
|
||||
@@ -341,6 +347,7 @@ type UpdateDeliveryParams struct {
|
||||
Phone string `db:"phone" json:"phone"`
|
||||
AdditionalPhone pgtype.Text `db:"additional_phone" json:"additional_phone"`
|
||||
HasElevator bool `db:"has_elevator" json:"has_elevator"`
|
||||
PaymentStatus string `db:"payment_status" json:"payment_status"`
|
||||
ServiceInfo pgtype.Text `db:"service_info" json:"service_info"`
|
||||
Comment pgtype.Text `db:"comment" json:"comment"`
|
||||
ID pgtype.UUID `db:"id" json:"id"`
|
||||
@@ -365,6 +372,7 @@ func (q *Queries) UpdateDelivery(ctx context.Context, arg UpdateDeliveryParams)
|
||||
arg.Phone,
|
||||
arg.AdditionalPhone,
|
||||
arg.HasElevator,
|
||||
arg.PaymentStatus,
|
||||
arg.ServiceInfo,
|
||||
arg.Comment,
|
||||
arg.ID,
|
||||
|
||||
@@ -37,6 +37,7 @@ type DeliveryRequest struct {
|
||||
Phone string `json:"phone" binding:"required"`
|
||||
AdditionalPhone *string `json:"additional_phone"`
|
||||
HasElevator bool `json:"has_elevator"`
|
||||
PaymentStatus string `json:"payment_status" binding:"omitempty,oneof=prepaid paid"`
|
||||
ServiceInfo *string `json:"service_info"`
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
@@ -107,6 +108,7 @@ func (h *Handler) CreateDelivery(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
normalizePaymentStatus(&req)
|
||||
|
||||
// Parse date from DD-MM-YYYY
|
||||
t, err := parseDate(req.Date)
|
||||
@@ -133,6 +135,7 @@ func (h *Handler) CreateDelivery(c *gin.Context) {
|
||||
Phone: req.Phone,
|
||||
AdditionalPhone: pgtype.Text{String: derefString(req.AdditionalPhone), Valid: req.AdditionalPhone != nil},
|
||||
HasElevator: req.HasElevator,
|
||||
PaymentStatus: req.PaymentStatus,
|
||||
ServiceInfo: pgtype.Text{String: derefString(req.ServiceInfo), Valid: req.ServiceInfo != nil},
|
||||
Comment: pgtype.Text{String: req.Comment, Valid: true},
|
||||
}
|
||||
@@ -158,6 +161,7 @@ func (h *Handler) UpdateDelivery(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
normalizePaymentStatus(&req)
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
@@ -196,6 +200,7 @@ func (h *Handler) UpdateDelivery(c *gin.Context) {
|
||||
Phone: req.Phone,
|
||||
AdditionalPhone: pgtype.Text{String: derefString(req.AdditionalPhone), Valid: req.AdditionalPhone != nil},
|
||||
HasElevator: req.HasElevator,
|
||||
PaymentStatus: req.PaymentStatus,
|
||||
ServiceInfo: pgtype.Text{String: derefString(req.ServiceInfo), Valid: req.ServiceInfo != nil},
|
||||
Comment: pgtype.Text{String: req.Comment, Valid: true},
|
||||
}); err != nil {
|
||||
@@ -308,3 +313,9 @@ func normalizeWarehouseRequestSources(req *DeliveryRequest) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizePaymentStatus(req *DeliveryRequest) {
|
||||
if req.PaymentStatus == "" {
|
||||
req.PaymentStatus = "prepaid"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user