func (VS *Server) newPurchase(isFreePurchase bool) gin.HandlerFunc {
	return func(c *gin.Context) {
		service, b := VS.getOurService(c, "h_records", "newPurchase", "service, b := VS.getOurService")
		if !b {
			return
		}
		var workerID bson.ObjectId
		if isFreePurchase {
			workerID, b = VS.getIDFromHTML(c, "workerID", "Item")
			if !b {
				return
			}
		} else {
			workerID, b = VS.getIDParamFromURL(c, "idworker")
			if !b {
				return
			}
		}

		var users []bson.ObjectId
		users = append(users, workerID)
		stock := Stock{
			IDUser:            workerID,
			ServiceCreated:    service.ID,
			IDServiceLocation: service.ID,
			Date:              getTime(),
			IDManager:         ManagerID,
			TypeOfItem:        ServiceProduct,
			UsersRelated:      users,
		}

		// We check if the original source if from a video course or from a Item
		videoID, _ := VS.getIDFromHTMLWithoutChecking(c, "videoID")
		itemID, isItem := VS.getIDFromHTMLWithoutChecking(c, "itemID")
		orderID, isOrder := VS.getIDFromHTMLWithoutChecking(c, "orderID")
		fmt.Print(itemID)
		fmt.Println(isItem)

		var i Item

		if isOrder {
			order := VS.getWorkerOrderByID(c, orderID, "h_records", "newPurchase", "order := VS.getServiceOrderByID")
			i, isItem = VS.getItemByID(c, order.IDProduct, "h_records", "newPurchase", "i, isItem = VS.getItemByID", true)
			if !isItem {
				videoID = order.IDProduct
			} else {
				itemID = i.ID
			}
		}

		if !isItem {
			video, _ := VS.getVideoCourseByID(c, videoID, "h_records", "newPurchase", "video, _ := VS.getVideoCourseByID", true)
			fmt.Print("videoID 2")
			fmt.Println(videoID)

			QR, b := VS.getQRFromHTMLNew(c, ServiceProduct)
			if !b {
				return
			}
			stock.ID = QR
			stock.IsTrackable = true
			stock.IDVideoCourseOrItem = video.ID
			stock.Photo, b = VS.getFileFromHTML(c, "photo", "Purchase", basePath+"/local-resources/video-courses/"+video.Name+"/purchases/")
			if !b {
				return
			}
			stock.UsersRelated = append(stock.UsersRelated, VS.getUsersRelatedFromStock(c, stock.IDVideoCourseOrItem)...)
		} else {
			item, _ := VS.getItemByID(c, itemID, "h_records", "newPurchase", "item, _ := VS.getItemByID", true)
			cat := VS.getCategoryByID(c, item.IDCategory, "h_records", "newPurchase", "cat := VS.getCategoryByID")
			stock.IsTrackable = cat.IsTrackable
			stock.IDVideoCourseOrItem = item.ID
			tpe := VS.getCategoryTypeByID(c, cat.Type, "h_records", "newPurchase", "tpe := VS.getCategoryTypeByID")
			stock.Photo, b = VS.getFileFromHTML(c, "photo", "Purchase", basePath+"/local-resources/categories/"+tpe.Name+"/"+cat.Name+"/purchases/")
			if !b {
				return
			}
			if cat.IsTrackable {
				QR, b := VS.getQRFromHTMLNew(c, ServiceProduct)
				if !b {
					return
				}
				stock.ID = QR
			} else {
				stock.ID = bson.NewObjectId()
			}
		}
		fmt.Print("This is stock.VideoCourseOrItemID")
		fmt.Print(stock.IDVideoCourseOrItem)

		if isOrder {
			VS.makeServicePurchaseFromOrder(c, stock, orderID)
		} else {
			VS.makeServiceFreePurchase(c, stock)
		}
		idservicetype, b := VS.getIDParamFromURL(c, "idservicetype")
		if !b {
			return
		}
		VS.addElementToDatabaseWithRegister(c, stock, stock.ID, service.ID, "h_records", "newPurchase", "VS.addElementToDatabaseWithRegister")
		VS.goodFeedback(c, "records/stock-generated/"+idservicetype.Hex())
	}
}
// Stores the new Transaction information into the DataBase
// The isFreePurchase indicates if the purchase is related to a ServiceOrder or no
Stores the new Transaction information into the DataBase
The isFreePurchase indicates if the purchase is related to a ServiceOrder or no
// Stores the new Transaction information into the DataBase // The isFreePurchase indicates if the purchase is related to a ServiceOrder or no
func (VS *Server) newPurchase(isFreePurchase bool) gin.HandlerFunc {
	return func(c *gin.Context) {
		service, b := VS.getOurService(c, "h_records", "newPurchase", "service, b := VS.getOurService")
		if !b {
			return
		}
		var workerID bson.ObjectId
		if isFreePurchase {
			workerID, b = VS.getIDFromHTML(c, "workerID", "Item")
			if !b {
				return
			}
		} else {
			workerID, b = VS.getIDParamFromURL(c, "idworker")
			if !b {
				return
			}
		}
		var users []bson.ObjectId
		users = append(users, workerID)
		stock := Stock{
			IDUser:            workerID,
			ServiceCreated:    service.ID,
			IDServiceLocation: service.ID,
			Date:              getTime(),
			IDManager:         ManagerID,
			TypeOfItem:        ServiceProduct,
			UsersRelated:      users,
		}
		videoID, _ := VS.getIDFromHTMLWithoutChecking(c, "videoID")
		itemID, isItem := VS.getIDFromHTMLWithoutChecking(c, "itemID")
		orderID, isOrder := VS.getIDFromHTMLWithoutChecking(c, "orderID")
		fmt.Print(itemID)
		fmt.Println(isItem)
		var i Item
		if isOrder {
			order := VS.getWorkerOrderByID(c, orderID, "h_records", "newPurchase", "order := VS.getServiceOrderByID")
			i, isItem = VS.getItemByID(c, order.IDProduct, "h_records", "newPurchase", "i, isItem = VS.getItemByID", true)
			if !isItem {
				videoID = order.IDProduct
			} else {
				itemID = i.ID
			}
		}
		if !isItem {
			video, _ := VS.getVideoCourseByID(c, videoID, "h_records", "newPurchase", "video, _ := VS.getVideoCourseByID", true)
			fmt.Print("videoID 2")
			fmt.Println(videoID)
			QR, b := VS.getQRFromHTMLNew(c, ServiceProduct)
			if !b {
				return
			}
			stock.ID = QR
			stock.IsTrackable = true
			stock.IDVideoCourseOrItem = video.ID
			stock.Photo, b = VS.getFileFromHTML(c, "photo", "Purchase", basePath+"/local-resources/video-courses/"+video.Name+"/purchases/")
			if !b {
				return
			}
			stock.UsersRelated = append(stock.UsersRelated, VS.getUsersRelatedFromStock(c, stock.IDVideoCourseOrItem)...)
		} else {
			item, _ := VS.getItemByID(c, itemID, "h_records", "newPurchase", "item, _ := VS.getItemByID", true)
			cat := VS.getCategoryByID(c, item.IDCategory, "h_records", "newPurchase", "cat := VS.getCategoryByID")
			stock.IsTrackable = cat.IsTrackable
			stock.IDVideoCourseOrItem = item.ID
			tpe := VS.getCategoryTypeByID(c, cat.Type, "h_records", "newPurchase", "tpe := VS.getCategoryTypeByID")
			stock.Photo, b = VS.getFileFromHTML(c, "photo", "Purchase", basePath+"/local-resources/categories/"+tpe.Name+"/"+cat.Name+"/purchases/")
			if !b {
				return
			}
			if cat.IsTrackable {
				QR, b := VS.getQRFromHTMLNew(c, ServiceProduct)
				if !b {
					return
				}
				stock.ID = QR
			} else {
				stock.ID = bson.NewObjectId()
			}
		}
		fmt.Print("This is stock.VideoCourseOrItemID")
		fmt.Print(stock.IDVideoCourseOrItem)
		if isOrder {
			VS.makeServicePurchaseFromOrder(c, stock, orderID)
		} else {
			VS.makeServiceFreePurchase(c, stock)
		}
		idservicetype, b := VS.getIDParamFromURL(c, "idservicetype")
		if !b {
			return
		}
		VS.addElementToDatabaseWithRegister(c, stock, stock.ID, service.ID, "h_records", "newPurchase", "VS.addElementToDatabaseWithRegister")
		VS.goodFeedback(c, "records/stock-generated/"+idservicetype.Hex())
	}
}
func ( VS * Server ) newPurchase ( isFreePurchase bool ) gin . HandlerFunc { return func ( c * gin . Context ) { service , b := VS . getOurService ( c , " " , " " , " " ) if ! b { return } var workerID bson . ObjectId if isFreePurchase { workerID , b = VS . getIDFromHTML ( c , " " , " " ) if ! b { return } } else { workerID , b = VS . getIDParamFromURL ( c , " " ) if ! b { return } } var users [ ] bson . ObjectId users = append ( users , workerID ) stock := Stock { IDUser : workerID , ServiceCreated : service . ID , IDServiceLocation : service . ID , Date : getTime ( ) , IDManager : ManagerID , TypeOfItem : ServiceProduct , UsersRelated : users , } videoID , _ := VS . getIDFromHTMLWithoutChecking ( c , " " ) itemID , isItem := VS . getIDFromHTMLWithoutChecking ( c , " " ) orderID , isOrder := VS . getIDFromHTMLWithoutChecking ( c , " " ) fmt . Print ( itemID ) fmt . Println ( isItem ) var i Item if isOrder { order := VS . getWorkerOrderByID ( c , orderID , " " , " " , " " ) i , isItem = VS . getItemByID ( c , order . IDProduct , " " , " " , " " , true ) if ! isItem { videoID = order . IDProduct } else { itemID = i . ID } } if ! isItem { video , _ := VS . getVideoCourseByID ( c , videoID , " " , " " , " " , true ) fmt . Print ( " " ) fmt . Println ( videoID ) QR , b := VS . getQRFromHTMLNew ( c , ServiceProduct ) if ! b { return } stock . ID = QR stock . IsTrackable = true stock . IDVideoCourseOrItem = video . ID stock . Photo , b = VS . getFileFromHTML ( c , " " , " " , basePath + " " + video . Name + " " ) if ! b { return } stock . UsersRelated = append ( stock . UsersRelated , VS . getUsersRelatedFromStock ( c , stock . IDVideoCourseOrItem ) ... ) } else { item , _ := VS . getItemByID ( c , itemID , " " , " " , " " , true ) cat := VS . getCategoryByID ( c , item . IDCategory , " " , " " , " " ) stock . IsTrackable = cat . IsTrackable stock . IDVideoCourseOrItem = item . ID tpe := VS . getCategoryTypeByID ( c , cat . Type , " " , " " , " " ) stock . Photo , b = VS . getFileFromHTML ( c , " " , " " , basePath + " " + tpe . Name + " " + cat . Name + " " ) if ! b { return } if cat . IsTrackable { QR , b := VS . getQRFromHTMLNew ( c , ServiceProduct ) if ! b { return } stock . ID = QR } else { stock . ID = bson . NewObjectId ( ) } } fmt . Print ( " " ) fmt . Print ( stock . IDVideoCourseOrItem ) if isOrder { VS . makeServicePurchaseFromOrder ( c , stock , orderID ) } else { VS . makeServiceFreePurchase ( c , stock ) } idservicetype , b := VS . getIDParamFromURL ( c , " " ) if ! b { return } VS . addElementToDatabaseWithRegister ( c , stock , stock . ID , service . ID , " " , " " , " " ) VS . goodFeedback ( c , " " + idservicetype . Hex ( ) ) } }
Stores the new Transaction information into the DataBase
The isFreePurchase indicates if the purchase is related to a ServiceOrder or no
Stores the new Transaction information into the DataBase The isFreePurchase indicates if the purchase is related to a ServiceOrder or no
// We check if the original source if from a video course or from a Item