Skip to content

Instantly share code, notes, and snippets.

@xerardoo
Created July 2, 2020 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xerardoo/0602871fc14433a62d1947a9b0067a5a to your computer and use it in GitHub Desktop.
Save xerardoo/0602871fc14433a62d1947a9b0067a5a to your computer and use it in GitHub Desktop.
var order OrderReq
err := c.BindJSON(&order)
if err != nil {
c.JSON(500, gin.H{"msg": err.Error()})
return
}
currentcb := m.GetCurrentCashBalance()
if currentcb.ID == 0 {
c.JSON(400, gin.H{"msg": "No cash balance opened - No existe corte de caja abierto"})
return
}
if len(order.Items) <= 0 {
c.JSON(400, gin.H{"msg": "No items - No existen articulos"})
return
}
var newitems []m.OrderLine
for _, item := range order.Items {
var newitem m.OrderLine
newitem.Qty = item.Qty
newitem.Price = item.Price
newitem.MenuItemID = item.MenuItemID
newitems = append(newitems, newitem)
}
var ord = new(m.Order)
neworder := m.Order{
Status: "pending",
CashBalanceID: currentcb.ID,
Total: order.Total,
OrderLine: newitems,
}
ord, err = neworder.Create()
if err != nil {
c.JSON(500, gin.H{"msg": err.Error()})
return
}
filepath, err := ord.ToPDF()
if err != nil {
c.JSON(500, gin.H{"msg": err.Error()})
return
}
c.JSON(201, gin.H{"msg": ord.ID, "file": filepath})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment