Skip to content

Commit

Permalink
fix(restock): take tva into account
Browse files Browse the repository at this point in the history
  • Loading branch information
yyewolf committed Dec 12, 2023
1 parent aa64435 commit 991a536
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/api/restock.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *Server) CreateRestock(c echo.Context) error {

item.AmountLeft += restockItem.AmountOfBundle * restockItem.AmountPerBundle
item.LastTva = &restockItem.Tva
item.Prices.Coutant = uint64(float64(restockItem.BundleCostHt) / float64(restockItem.AmountPerBundle))
item.Prices.Coutant = uint64(float64(restockItem.Tva) * float64(restockItem.BundleCostHt) / (100.0 * float64(restockItem.AmountPerBundle)))

err = s.DBackend.UpdateItem(c.Request().Context(), item)
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions backend/cmd/migration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ var Categories = make(map[string]uuid.UUID)
func part2(mongoDB db.DBackend, mariaDB *sql.DB) {
// SELECT product.name, price as exte, cetenPrice as ceten, privilegePrice as vip, barMemberPrice staff, privilegePrice as privilegie, cost as bureau, product.image, stock, type, product_type.name, product_type.image from product join product_type on product.type = product_type.productTypeId;

rq := `SELECT product.hidden, product.criticalStock, product.name, price as exte, cetenPrice as ceten, privilegePrice as vip, barMemberPrice staff, privilegePrice as privilegie, cost as bureau, product.image, stock, type, product_type.name as categorie, product_type.image as image_categorie, product_type.boolean as categorie_hidden from product join product_type on product.type = product_type.productTypeId;`
rq := `SELECT product.hidden, product.criticalStock, product.name, price as exte, cetenPrice as ceten, privilegePrice as vip, barMemberPrice staff, privilegePrice as privilegie, cost as bureau, menuMemberPrice as menu, product.image, stock, type, product_type.name as categorie, product_type.image as image_categorie, product_type.boolean as categorie_hidden from product join product_type on product.type = product_type.productTypeId;`

rows, err := mariaDB.Query(rq)
if err != nil {
Expand All @@ -194,6 +194,7 @@ func part2(mongoDB db.DBackend, mariaDB *sql.DB) {
var priceStaff string
var pricePrivilegie string
var priceBureau string
var priceMenu string
var image []byte
var stock int
var type_ string
Expand All @@ -205,7 +206,7 @@ func part2(mongoDB db.DBackend, mariaDB *sql.DB) {
continue
}

var err = rows.Scan(&hidden, &criticalStock, &productName, &priceExte, &priceCeten, &priceVip, &priceStaff, &pricePrivilegie, &priceBureau, &image, &stock, &type_, &categorie, &imageCategorie, &categorieHidden)
var err = rows.Scan(&hidden, &criticalStock, &productName, &priceExte, &priceCeten, &priceVip, &priceStaff, &pricePrivilegie, &priceBureau, &priceMenu, &image, &stock, &type_, &categorie, &imageCategorie, &categorieHidden)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -239,13 +240,15 @@ func part2(mongoDB db.DBackend, mariaDB *sql.DB) {
privilegiePrice, _ := strconv.Atoi(strings.ReplaceAll(pricePrivilegie, ".", ""))
bureauPrice, _ := strconv.Atoi(strings.ReplaceAll(priceBureau, ".", ""))
extePrice, _ := strconv.Atoi(strings.ReplaceAll(priceExte, ".", ""))
menuPrice, _ := strconv.Atoi(strings.ReplaceAll(priceMenu, ".", ""))

prices := autogen.ItemPrices{
Ceten: uint64(cetenPrice),
StaffBar: uint64(staffPrice),
Privilegies: uint64(privilegiePrice),
Coutant: uint64(bureauPrice),
Externe: uint64(extePrice),
Menu: uint64(menuPrice),
}

uid := uuid.New()
Expand Down

0 comments on commit 991a536

Please sign in to comment.