Skip to content

Commit

Permalink
Merge pull request #66 from BaptTF/main
Browse files Browse the repository at this point in the history
add the calcululations for every price when restocking and add a refresh after finishing the restock
  • Loading branch information
yyewolf authored Feb 19, 2024
2 parents 4e72a73 + 4ff0b87 commit 173c492
Show file tree
Hide file tree
Showing 7 changed files with 1,101 additions and 6 deletions.
32 changes: 30 additions & 2 deletions backend/api/restock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"go.mongodb.org/mongo-driver/mongo"
)

func arrondiAuMutilple(x uint64, a uint64) uint64 {
return ((x + a/2) / a) * a
}

// (GET /restocks)
func (s *Server) GetRestocks(c echo.Context, params autogen.GetRestocksParams) error {
_, err := MustGetAdmin(c)
Expand Down Expand Up @@ -100,8 +104,32 @@ func (s *Server) CreateRestock(c echo.Context) error {

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

item.Prices.Coutant = uint64(math.Ceil((10000.0 + float64(restockItem.Tva)) * float64(restockItem.BundleCostHt) / (10000.0 * float64(restockItem.AmountPerBundle))))
if item.Prices.Coutant < 30 {
item.Prices.Externe = arrondiAuMutilple(item.Prices.Coutant+30, 5)
item.Prices.Ceten = arrondiAuMutilple(item.Prices.Coutant+15, 5)
item.Prices.StaffBar = arrondiAuMutilple(item.Prices.Coutant+5, 5)
item.Prices.Privilegies = arrondiAuMutilple(item.Prices.Coutant+5, 5)
item.Prices.Menu = arrondiAuMutilple(item.Prices.Coutant+10, 5)
} else if item.Prices.Coutant >= 30 && item.Prices.Coutant < 130 {
item.Prices.Externe = arrondiAuMutilple(item.Prices.Coutant*2, 5)
item.Prices.Ceten = arrondiAuMutilple(item.Prices.Coutant*14/10, 5)
item.Prices.StaffBar = arrondiAuMutilple(item.Prices.Coutant*125/100, 5)
item.Prices.Privilegies = arrondiAuMutilple(item.Prices.Coutant*12/10, 5)
item.Prices.Menu = arrondiAuMutilple(item.Prices.Coutant*13/10, 5)
} else if item.Prices.Coutant >= 130 && item.Prices.Coutant <= 300 {
item.Prices.Externe = arrondiAuMutilple(item.Prices.Coutant*15/10, 5)
item.Prices.Ceten = arrondiAuMutilple(item.Prices.Coutant*125/100, 5)
item.Prices.StaffBar = arrondiAuMutilple(item.Prices.Coutant*115/100, 5)
item.Prices.Privilegies = arrondiAuMutilple(item.Prices.Coutant*11/10, 5)
item.Prices.Menu = arrondiAuMutilple(item.Prices.Coutant*12/10, 5)
} else if item.Prices.Coutant >= 300 {
item.Prices.Externe = arrondiAuMutilple(item.Prices.Coutant*13/10, 5)
item.Prices.Ceten = arrondiAuMutilple(item.Prices.Coutant*115/100, 5)
item.Prices.StaffBar = arrondiAuMutilple(item.Prices.Coutant*11/10, 5)
item.Prices.Privilegies = arrondiAuMutilple(item.Prices.Coutant*11/10, 5)
item.Prices.Menu = arrondiAuMutilple(item.Prices.Coutant*125/1000, 5)
}
err = s.DBackend.UpdateItem(c.Request().Context(), item)
if err != nil {
logrus.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/borne/carousel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</div>

<div class="bg-slate-900">
<Carousel autoplay autoplayDuration={3000} arrows={false} dots={false}>
<Carousel autoplay autoplayDuration={6000} arrows={false} dots={false}>
{#each images as image, i}
<img
src={api() + image.image_url}
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/lib/components/panel/modules.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
color: 'bg-blue-600',
link: '/panel/treso'
});
modules.push({
name: 'Incohérances',
color: 'bg-green-600',
link: '/panel/products/incoherants'
});
// Sort the modules by name
modules.sort((a, b) => a.name.localeCompare(b.name));
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/routes/admin/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@
href="/admin/produits"
aria-current="page">Produits</a
>
<a
class="font-medium text-white/[.8] hover:text-white sm:py-6"
href="/panel"
aria-current="page">Panel</a
>

<div
class="hs-dropdown [--strategy:static] sm:[--strategy:fixed] [--adaptive:none] sm:[--trigger:hover] sm:py-4"
Expand Down
140 changes: 137 additions & 3 deletions frontend/src/routes/panel/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
class="flex flex-wrap sm:justify-start sm:flex-nowrap z-50 w-full bg-blue-600 dark:bg-blue-900 text-sm py-3 sm:py-0"
>
<nav
class="relative max-w-[85rem] w-full mx-auto px-4 sm:flex sm:items-center sm:justify-between sm:px-6 lg:px-8 p-5"
class="relative max-w-[85rem] w-full mx-auto px-4 sm:flex sm:items-center sm:justify-between sm:px-6 lg:px-8"
aria-label="Global"
>
<div class="flex items-center justify-between">
<a class="flex-none text-xl font-semibold text-white" href="/panel" aria-label="Panel admin"
>(Nouveau) Panel admin</a
<a class="flex-none text-xl font-semibold text-white" href="#" aria-label="Panel admin"
>Panel admin</a
>
<div class="sm:hidden">
<button
Expand Down Expand Up @@ -65,6 +65,140 @@
</button>
</div>
</div>
<div
id="navbar-collapse-with-animation"
class="hs-collapse hidden overflow-hidden transition-all duration-300 basis-full grow sm:block"
>
<div
class="flex flex-col gap-y-4 gap-x-0 mt-5 sm:flex-row sm:items-center sm:justify-end sm:gap-y-0 sm:gap-x-7 sm:mt-0 sm:pl-7"
>
{#if can_restore}
<div
class="hs-dropdown [--strategy:static] sm:[--strategy:fixed] [--adaptive:none] sm:[--trigger:hover] sm:py-4"
>
<button
type="button"
class="flex items-center w-full text-white/[.8] hover:text-white font-medium"
>
Restauration
<svg
class="ml-2 w-2.5 h-2.5"
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M2 5L8.16086 10.6869C8.35239 10.8637 8.64761 10.8637 8.83914 10.6869L15 5"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
/>
</svg>
</button>

<div
class="hs-dropdown-menu transition-[opacity,margin] duration-[0.1ms] sm:duration-[150ms] hs-dropdown-open:opacity-100 opacity-0 sm:w-48 hidden z-10 bg-white sm:shadow-md rounded-lg p-2 dark:bg-gray-800 dark:divide-gray-700 before:absolute top-full sm:border before:-top-5 before:left-0 before:w-full before:h-5"
>
<a
class="flex items-center gap-x-3.5 py-2 px-3 rounded-md text-sm text-gray-800 hover:bg-gray-100 focus:ring-2 focus:ring-blue-500 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300"
href="/admin/restore/accounts"
>
Comptes
</a>
<a
class="flex items-center gap-x-3.5 py-2 px-3 rounded-md text-sm text-gray-800 hover:bg-gray-100 focus:ring-2 focus:ring-blue-500 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300"
href="/admin/restore/categories"
>
Catégories
</a>
<a
class="flex items-center gap-x-3.5 py-2 px-3 rounded-md text-sm text-gray-800 hover:bg-gray-100 focus:ring-2 focus:ring-blue-500 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300"
href="/admin/restore/produits"
>
Produits
</a>
<a
class="flex items-center gap-x-3.5 py-2 px-3 rounded-md text-sm text-gray-800 hover:bg-gray-100 focus:ring-2 focus:ring-blue-500 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300"
href="/admin/restore/carousel/textes"
>
Textes du carousel
</a>
<a
class="flex items-center gap-x-3.5 py-2 px-3 rounded-md text-sm text-gray-800 hover:bg-gray-100 focus:ring-2 focus:ring-blue-500 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300"
href="/admin/restore/carousel/images"
>
Images du carousel
</a>
</div>
</div>
{/if}
<a
class="font-medium text-white/[.8] hover:text-white sm:py-6"
href="/admin/accounts"
aria-current="page">Comptes</a
>
<a
class="font-medium text-white/[.8] hover:text-white sm:py-6"
href="/admin/categories"
aria-current="page">Catégories</a
>
<a
class="font-medium text-white/[.8] hover:text-white sm:py-6"
href="/admin/produits"
aria-current="page">Produits</a
>
<a
class="font-medium text-white/[.8] hover:text-white sm:py-6"
href="/panel"
aria-current="page">Panel</a
>

<div
class="hs-dropdown [--strategy:static] sm:[--strategy:fixed] [--adaptive:none] sm:[--trigger:hover] sm:py-4"
>
<button
type="button"
class="flex items-center w-full text-white/[.8] hover:text-white font-medium"
>
Carousel
<svg
class="ml-2 w-2.5 h-2.5"
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M2 5L8.16086 10.6869C8.35239 10.8637 8.64761 10.8637 8.83914 10.6869L15 5"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
/>
</svg>
</button>

<div
class="hs-dropdown-menu transition-[opacity,margin] duration-[0.1ms] sm:duration-[150ms] hs-dropdown-open:opacity-100 opacity-0 sm:w-48 hidden z-10 bg-white sm:shadow-md rounded-lg p-2 dark:bg-gray-800 dark:divide-gray-700 before:absolute top-full sm:border before:-top-5 before:left-0 before:w-full before:h-5"
>
<a
class="flex items-center gap-x-3.5 py-2 px-3 rounded-md text-sm text-gray-800 hover:bg-gray-100 focus:ring-2 focus:ring-blue-500 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300"
href="/admin/carousel/textes"
>
Textes
</a>
<a
class="flex items-center gap-x-3.5 py-2 px-3 rounded-md text-sm text-gray-800 hover:bg-gray-100 focus:ring-2 focus:ring-blue-500 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300"
href="/admin/carousel/images"
>
Images
</a>
</div>
</div>
</div>
</div>
</nav>
</header>
<slot />
Expand Down
Loading

0 comments on commit 173c492

Please sign in to comment.