func (VS *Server) makeServicePurchaseFromOrder(c *gin.Context, servicePurchase Stock, wkOrderID bson.ObjectId) {
	var cost float64
	item, b := VS.getItemByID(c, servicePurchase.IDVideoCourseOrItem, "h_database", "getAllPositiveStockByServiceIDForMakeChecking", "item, b := VS.getItemByID", false)
	if b {
		cost = item.Price
	} else {
		video, _ := VS.getVideoCourseByID(c, servicePurchase.IDVideoCourseOrItem, "h_database", "getAllPositiveStockByServiceIDForMakeChecking", "item, b := VS.getItemByID", false)
		cost = video.Price
	}

	/***********************  Products ***********************/
	// Add the purchase to the Worker Order
	// We take the first order from the Worker that is related with the Video Course
	order := VS.getWorkerOrderByID(c, wkOrderID, "h_transactions", "makeWorkshopPurchase", "VS.addWorkshopOrderToDatabase")
	order.AlreadyMade++
	VS.addElementToDatabaseWithRegister(c, order, order.ID, order.IDService, "h_transactions", "makeWorkshopPurchase", "VS.addWorkerOrderToDatabase")

	// Add the purchase to the Workshop Order
	wkOrder, b := VS.getServiceOrderFromServiceAndProductInDate(c, order.IDService, servicePurchase.IDVideoCourseOrItem, "handlers_workshop", "makeWorkshopPurchase", "wkOrder := VS.getWorkshopOrderByProductID")
	if b {
		wkOrder.AlreadyMade++
		VS.addElementToDatabaseWithRegister(c, wkOrder, wkOrder.ID, order.IDService, "h_transactions", "makeWorkshopPurchase", "VS.addWorkshopOrderToDatabase")
	}

	/***********************  Payment ***********************/
	// The service Pays
	wk := VS.getServiceByID(c, servicePurchase.ServiceCreated, "h_transactions", "makeWorkshopPurchase", "wk := VS.getServiceByID", true)
	wk.Balance -= cost
	VS.addServiceToDatabase(c, wk, "h_transactions", "makeWorkshopPurchase", "VS.addServiceToDatabase")

	// The Worker receives the money
	worker := VS.getUserByID(c, servicePurchase.IDUser, "h_transactions", "makeWorkshopPurchase", "worker := VS.getUserByID")
	worker.Balance += cost
	VS.addUserToDatabase(c, worker, "h_transactions", "makeWorkshopPurchase", "VS.addUserToDatabase")

	/***********************  STOCK ***********************/
	stock, b := VS.getStockByItemAndService(c, servicePurchase.IDVideoCourseOrItem, wk.ID, "h_transactions", "makeStockDelivery", "stock := VS.getStockByItemAndService")
	if b {
		VS.addElementToDatabaseWithRegister(c, stock, stock.ID, wk.ID, "VS.addStockToDatabase", "makeStockDelivery", "stock := VS.getStockByItemAndService")
	} else {
		newStock := servicePurchase
		newStock.ID = bson.NewObjectId()
		newStock.Date = getTime()
		newStock.UsersRelated = nil
		newStock.UsersRelated = append(newStock.UsersRelated, servicePurchase.IDUser)
		// newStock := Stock{
		// 	ID: bson.NewObjectId(),
		// 	IDVideoCourseOrItem: servicePurchase.IDVideoCourseOrItem,
		// 	Photo: servicePurchase.Photo,
		// 	IDServiceLocation: servicePurchase.IDServiceLocation,
		// 	TypeOfItem: servicePurchase.TypeOfItem,
		// 	Quantity: 1,
		// 	IDUser: servicePurchase.IDUser,
		// }
		VS.addElementToDatabaseWithRegister(c, newStock, newStock.ID, wk.ID, "VS.addStockToDatabase", "makeStockDelivery", "stock := VS.getStockByItemAndService")
	}
}
// Make all the changes in the Service Order, Worker Order, inventory, Wallet and Service balance
Make all the changes in the Service Order, Worker Order, inventory, Wallet and Service balance
// Make all the changes in the Service Order Worker Order inventory Wallet and Service balance
func (VS *Server) makeServicePurchaseFromOrder(c *gin.Context, servicePurchase Stock, wkOrderID bson.ObjectId) {
	var cost float64
	item, b := VS.getItemByID(c, servicePurchase.IDVideoCourseOrItem, "h_database", "getAllPositiveStockByServiceIDForMakeChecking", "item, b := VS.getItemByID", false)
	if b {
		cost = item.Price
	} else {
		video, _ := VS.getVideoCourseByID(c, servicePurchase.IDVideoCourseOrItem, "h_database", "getAllPositiveStockByServiceIDForMakeChecking", "item, b := VS.getItemByID", false)
		cost = video.Price
	}
	order := VS.getWorkerOrderByID(c, wkOrderID, "h_transactions", "makeWorkshopPurchase", "VS.addWorkshopOrderToDatabase")
	order.AlreadyMade++
	VS.addElementToDatabaseWithRegister(c, order, order.ID, order.IDService, "h_transactions", "makeWorkshopPurchase", "VS.addWorkerOrderToDatabase")
	wkOrder, b := VS.getServiceOrderFromServiceAndProductInDate(c, order.IDService, servicePurchase.IDVideoCourseOrItem, "handlers_workshop", "makeWorkshopPurchase", "wkOrder := VS.getWorkshopOrderByProductID")
	if b {
		wkOrder.AlreadyMade++
		VS.addElementToDatabaseWithRegister(c, wkOrder, wkOrder.ID, order.IDService, "h_transactions", "makeWorkshopPurchase", "VS.addWorkshopOrderToDatabase")
	}
	wk := VS.getServiceByID(c, servicePurchase.ServiceCreated, "h_transactions", "makeWorkshopPurchase", "wk := VS.getServiceByID", true)
	wk.Balance -= cost
	VS.addServiceToDatabase(c, wk, "h_transactions", "makeWorkshopPurchase", "VS.addServiceToDatabase")
	worker := VS.getUserByID(c, servicePurchase.IDUser, "h_transactions", "makeWorkshopPurchase", "worker := VS.getUserByID")
	worker.Balance += cost
	VS.addUserToDatabase(c, worker, "h_transactions", "makeWorkshopPurchase", "VS.addUserToDatabase")
	stock, b := VS.getStockByItemAndService(c, servicePurchase.IDVideoCourseOrItem, wk.ID, "h_transactions", "makeStockDelivery", "stock := VS.getStockByItemAndService")
	if b {
		VS.addElementToDatabaseWithRegister(c, stock, stock.ID, wk.ID, "VS.addStockToDatabase", "makeStockDelivery", "stock := VS.getStockByItemAndService")
	} else {
		newStock := servicePurchase
		newStock.ID = bson.NewObjectId()
		newStock.Date = getTime()
		newStock.UsersRelated = nil
		newStock.UsersRelated = append(newStock.UsersRelated, servicePurchase.IDUser)
		VS.addElementToDatabaseWithRegister(c, newStock, newStock.ID, wk.ID, "VS.addStockToDatabase", "makeStockDelivery", "stock := VS.getStockByItemAndService")
	}
}
func ( VS * Server ) makeServicePurchaseFromOrder ( c * gin . Context , servicePurchase Stock , wkOrderID bson . ObjectId ) { var cost float64 item , b := VS . getItemByID ( c , servicePurchase . IDVideoCourseOrItem , " " , " " , " " , false ) if b { cost = item . Price } else { video , _ := VS . getVideoCourseByID ( c , servicePurchase . IDVideoCourseOrItem , " " , " " , " " , false ) cost = video . Price } order := VS . getWorkerOrderByID ( c , wkOrderID , " " , " " , " " ) order . AlreadyMade ++ VS . addElementToDatabaseWithRegister ( c , order , order . ID , order . IDService , " " , " " , " " ) wkOrder , b := VS . getServiceOrderFromServiceAndProductInDate ( c , order . IDService , servicePurchase . IDVideoCourseOrItem , " " , " " , " " ) if b { wkOrder . AlreadyMade ++ VS . addElementToDatabaseWithRegister ( c , wkOrder , wkOrder . ID , order . IDService , " " , " " , " " ) } wk := VS . getServiceByID ( c , servicePurchase . ServiceCreated , " " , " " , " " , true ) wk . Balance -= cost VS . addServiceToDatabase ( c , wk , " " , " " , " " ) worker := VS . getUserByID ( c , servicePurchase . IDUser , " " , " " , " " ) worker . Balance += cost VS . addUserToDatabase ( c , worker , " " , " " , " " ) stock , b := VS . getStockByItemAndService ( c , servicePurchase . IDVideoCourseOrItem , wk . ID , " " , " " , " " ) if b { VS . addElementToDatabaseWithRegister ( c , stock , stock . ID , wk . ID , " " , " " , " " ) } else { newStock := servicePurchase newStock . ID = bson . NewObjectId ( ) newStock . Date = getTime ( ) newStock . UsersRelated = nil newStock . UsersRelated = append ( newStock . UsersRelated , servicePurchase . IDUser ) VS . addElementToDatabaseWithRegister ( c , newStock , newStock . ID , wk . ID , " " , " " , " " ) } }
Make all the changes in the Service Order, Worker Order, inventory, Wallet and Service balance
Make all the changes in the Service Order Worker Order inventory Wallet and Service balance
/***********************  Products ***********************/ // Add the purchase to the Worker Order // We take the first order from the Worker that is related with the Video Course // Add the purchase to the Workshop Order /***********************  Payment ***********************/ // The service Pays // The Worker receives the money /***********************  STOCK ***********************/ // newStock := Stock{ // 	ID: bson.NewObjectId(), // 	IDVideoCourseOrItem: servicePurchase.IDVideoCourseOrItem, // 	Photo: servicePurchase.Photo, // 	IDServiceLocation: servicePurchase.IDServiceLocation, // 	TypeOfItem: servicePurchase.TypeOfItem, // 	Quantity: 1, // 	IDUser: servicePurchase.IDUser, // }