update PrintJob model and add Invoice
This commit is contained in:
@@ -2,13 +2,11 @@ package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"git.dynamicdiscord.de/kalipso/zineshop/models"
|
||||
"git.dynamicdiscord.de/kalipso/zineshop/repositories"
|
||||
"git.dynamicdiscord.de/kalipso/zineshop/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -136,47 +134,15 @@ func (rc *printController) PrintHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var coverPage models.Paper
|
||||
doPrintCoverpage := false
|
||||
var coverPage *models.Paper
|
||||
if variantCoverPages[idx] != "0" {
|
||||
coverPage, err = repositories.Papers.GetById(fmt.Sprintf("%v", variantCoverPages[idx]))
|
||||
coverPageTmp, err := repositories.Papers.GetById(fmt.Sprintf("%v", variantCoverPages[idx]))
|
||||
if err != nil {
|
||||
c.HTML(http.StatusBadRequest, "error.html", gin.H{"data": gin.H{"error": err}})
|
||||
return
|
||||
}
|
||||
|
||||
doPrintCoverpage = true
|
||||
}
|
||||
|
||||
calculatePrintCosts := func(shopItem models.ShopItem, paperType models.Paper, coverPagePaperType models.Paper, colored bool, amount int) (float64, error) {
|
||||
pageCount := utils.CountPagesAtPath(shopItem.Pdf)
|
||||
printMode := models.GetPrintMode(shopItem.PrintMode)
|
||||
|
||||
//Get actual pagecount depending on printmode
|
||||
actualPageCount := pageCount
|
||||
|
||||
if printMode == models.CreateBooklet {
|
||||
dividedCount := float64(pageCount) / 4.0
|
||||
actualPageCount = int(math.Ceil(dividedCount))
|
||||
}
|
||||
|
||||
if printMode == models.LongEdge || printMode == models.ShortEdge {
|
||||
dividedCount := float64(pageCount) / 2.0
|
||||
actualPageCount = int(math.Ceil(dividedCount))
|
||||
}
|
||||
|
||||
PPC := 0.002604
|
||||
partCost := 0.0067
|
||||
if colored {
|
||||
partCost = 0.0478
|
||||
}
|
||||
printingCosts := float64(actualPageCount) * paperType.Price
|
||||
printingCosts += float64(actualPageCount/2) * PPC
|
||||
printingCosts += partCost * float64(actualPageCount)
|
||||
|
||||
fmt.Printf("Printing Costs per Zine: %v\n", printingCosts)
|
||||
fmt.Printf("Printing Costs Total: %v\n", printingCosts*float64(amount))
|
||||
return printingCosts, nil
|
||||
coverPage = &coverPageTmp
|
||||
}
|
||||
|
||||
variantAmount, err := strconv.Atoi(variantAmounts[idx])
|
||||
@@ -187,15 +153,13 @@ func (rc *printController) PrintHandler(c *gin.Context) {
|
||||
|
||||
fmt.Println("Printing Costs:")
|
||||
|
||||
colored := variant.Name == "Colored"
|
||||
calculatePrintCosts(shopItem, paperType, coverPage, colored, int(variantAmount))
|
||||
|
||||
printJob, err := models.NewPrintJob(shopItem, variant, doPrintCoverpage, uint(variantAmount))
|
||||
printJob, err := models.NewPrintJob(shopItem, variant, paperType, coverPage, uint(variantAmount))
|
||||
|
||||
if err != nil {
|
||||
c.HTML(http.StatusBadRequest, "error.html", gin.H{"data": gin.H{"error": err}})
|
||||
return
|
||||
}
|
||||
printJob.CalculatePrintCosts()
|
||||
|
||||
printJobs = append(printJobs, printJob)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user