func (VS *Server) addItemsDeliveryFromService(c *gin.Context) {
	serviceEmitterHTML, _ := VS.getOurService(c, "h_deliveries", "addItemsDeliveryFromService", "serviceEmitterHTML, _ := VS.getOurService")

	idServiceReceiver, b := VS.getIDParamFromURL(c, "idservice")
	if !b {
		return
	}
	serviceReceiver := VS.getServiceByID(c, idServiceReceiver, "h_deliveries", "addItemsDeliveryFromService", "serviceReceiver := VS.getServiceByID", true)

	idDelivery, b := VS.getIDParamFromURL(c, "iddelivery")
	if !b {
		return
	}
	idServiceType, b := VS.getIDParamFromURL(c, "idservicetype")
	if !b {
		return
	}
	delivery, isDelivery := VS.getDeliveryByID(c, idDelivery, "h_deliveries", "addItemsDeliveryFromService", "delivery, isDelivery := VS.getDeliveryByID", true)
	if !isDelivery {
		delivery = Delivery{
			ID:                idDelivery,
			IDServiceEmitter:  serviceEmitterHTML.ID,
			IDServiceReceiver: serviceReceiver.ID,
			Date:              getTime(),
			IsSent:            false,
		}
	}

	// CHECKING about that the action is not to deliver
	// If is already send, we redirect to see the delivery, not to add or edit
	if delivery.IsSent {
		c.Redirect(http.StatusFound, "/deliveries/stock-created")
		return
	}

	// Check if the action is to deliver instead of add an item
	sent := VS.getCheckBoxFromHTML(c, "sent")
	if sent {
		delivery.IsSent = true
		VS.addElementToDatabaseWithRegister(c, delivery, delivery.ID, serviceEmitterHTML.ID, "h_deliveries", "addItemsDeliveryFromService", "VS.addElementToDatabaseWithRegister(c, delivery")
		VS.goodFeedback(c, "deliveries/new-delivery/"+idServiceReceiver.Hex()+"/"+idDelivery.Hex()+"/"+idServiceType.Hex())
		return
	}

	// Nothing to deliver
	quantityToDeliver, _ := VS.getIntFromHTML(c, "slider-range", "Item")
	if quantityToDeliver == 0 {
		VS.wrongFeedback(c, "You can not deliver 0 items")
		return
	}

	// We clean the extra information needed for the slider
	itemToDeliverID, b := VS.getIDFromHTMLCleaningIt(c, "|", "stock", "Stock")
	if !b {
		return
	}

	// We check the QR if is trackable
	item, b := VS.getItemByID(c, itemToDeliverID, "h_deliveries", "addItemsDeliveryFromService", "item, b := VS.getItemByID", false)
	var cat Category
	if b {
		cat = VS.getCategoryByID(c, item.IDCategory, "h_deliveries", "addItemsDeliveryFromService", "cat = VS.getCategoryByID")
	} else {
		// Is product from a video
		cat.IsTrackable = true
		video, _ := VS.getVideoCourseByID(c, item.IDCategory, "h_deliveries", "addItemsDeliveryFromService", "video, _ := VS.getVideoCourseByID", false)
		item.ID = video.ID
	}
	stock := VS.getStockByItemOrVideoID(c, itemToDeliverID, "h_deliveries", "addItemsDeliveryFromService", "stock := VS.getStockByItemOrVideoID")
	if cat.IsTrackable {
		QR, b := VS.getQRFromHTML(c)
		if !b {
			return
		}
		stock = VS.getStockByID(c, QR, "h_deliveries", "addItemsDeliveryFromService", "stock = VS.getStockByID(c, QR,")
	}
	if stock.IDServiceLocation != serviceEmitterHTML.ID {
		VS.wrongFeedback(c, "This object does not belong to this service")
		return
	}
	if stock.IDVideoCourseOrItem != item.ID {
		VS.wrongFeedback(c, "The QR does not belong to this object")
		return
	}
	stock.IDServiceLocation = delivery.ID
	VS.addElementToDatabaseWithRegister(c, stock, stock.ID, serviceEmitterHTML.ID, "h_deliveries", "addItemsDeliveryFromService", "addElementToDatabaseWithRegister(c, stock, stock")
	// Delivery
	delivery.Stocks = append(delivery.Stocks, stock.ID)
	VS.addElementToDatabaseWithoutRegister(c, delivery, delivery.ID, "h_deliveries", "addItemsDeliveryFromService", "VS.addElementToDatabaseWithoutRegister(c, delivery")
	// Refresh the page
	c.Redirect(http.StatusFound, "/deliveries/new-delivery/"+serviceReceiver.ID.Hex()+"/"+delivery.ID.Hex()+"/"+serviceEmitterHTML.TypeID.Hex())
}
// This handler adds the item of the Service to the delivery
This handler adds the item of the Service to the delivery
// This handler adds the item of the Service to the delivery
func (VS *Server) addItemsDeliveryFromService(c *gin.Context) {
	serviceEmitterHTML, _ := VS.getOurService(c, "h_deliveries", "addItemsDeliveryFromService", "serviceEmitterHTML, _ := VS.getOurService")
	idServiceReceiver, b := VS.getIDParamFromURL(c, "idservice")
	if !b {
		return
	}
	serviceReceiver := VS.getServiceByID(c, idServiceReceiver, "h_deliveries", "addItemsDeliveryFromService", "serviceReceiver := VS.getServiceByID", true)
	idDelivery, b := VS.getIDParamFromURL(c, "iddelivery")
	if !b {
		return
	}
	idServiceType, b := VS.getIDParamFromURL(c, "idservicetype")
	if !b {
		return
	}
	delivery, isDelivery := VS.getDeliveryByID(c, idDelivery, "h_deliveries", "addItemsDeliveryFromService", "delivery, isDelivery := VS.getDeliveryByID", true)
	if !isDelivery {
		delivery = Delivery{
			ID:                idDelivery,
			IDServiceEmitter:  serviceEmitterHTML.ID,
			IDServiceReceiver: serviceReceiver.ID,
			Date:              getTime(),
			IsSent:            false,
		}
	}
	if delivery.IsSent {
		c.Redirect(http.StatusFound, "/deliveries/stock-created")
		return
	}
	sent := VS.getCheckBoxFromHTML(c, "sent")
	if sent {
		delivery.IsSent = true
		VS.addElementToDatabaseWithRegister(c, delivery, delivery.ID, serviceEmitterHTML.ID, "h_deliveries", "addItemsDeliveryFromService", "VS.addElementToDatabaseWithRegister(c, delivery")
		VS.goodFeedback(c, "deliveries/new-delivery/"+idServiceReceiver.Hex()+"/"+idDelivery.Hex()+"/"+idServiceType.Hex())
		return
	}
	quantityToDeliver, _ := VS.getIntFromHTML(c, "slider-range", "Item")
	if quantityToDeliver == 0 {
		VS.wrongFeedback(c, "You can not deliver 0 items")
		return
	}
	itemToDeliverID, b := VS.getIDFromHTMLCleaningIt(c, "|", "stock", "Stock")
	if !b {
		return
	}
	item, b := VS.getItemByID(c, itemToDeliverID, "h_deliveries", "addItemsDeliveryFromService", "item, b := VS.getItemByID", false)
	var cat Category
	if b {
		cat = VS.getCategoryByID(c, item.IDCategory, "h_deliveries", "addItemsDeliveryFromService", "cat = VS.getCategoryByID")
	} else {
		cat.IsTrackable = true
		video, _ := VS.getVideoCourseByID(c, item.IDCategory, "h_deliveries", "addItemsDeliveryFromService", "video, _ := VS.getVideoCourseByID", false)
		item.ID = video.ID
	}
	stock := VS.getStockByItemOrVideoID(c, itemToDeliverID, "h_deliveries", "addItemsDeliveryFromService", "stock := VS.getStockByItemOrVideoID")
	if cat.IsTrackable {
		QR, b := VS.getQRFromHTML(c)
		if !b {
			return
		}
		stock = VS.getStockByID(c, QR, "h_deliveries", "addItemsDeliveryFromService", "stock = VS.getStockByID(c, QR,")
	}
	if stock.IDServiceLocation != serviceEmitterHTML.ID {
		VS.wrongFeedback(c, "This object does not belong to this service")
		return
	}
	if stock.IDVideoCourseOrItem != item.ID {
		VS.wrongFeedback(c, "The QR does not belong to this object")
		return
	}
	stock.IDServiceLocation = delivery.ID
	VS.addElementToDatabaseWithRegister(c, stock, stock.ID, serviceEmitterHTML.ID, "h_deliveries", "addItemsDeliveryFromService", "addElementToDatabaseWithRegister(c, stock, stock")
	delivery.Stocks = append(delivery.Stocks, stock.ID)
	VS.addElementToDatabaseWithoutRegister(c, delivery, delivery.ID, "h_deliveries", "addItemsDeliveryFromService", "VS.addElementToDatabaseWithoutRegister(c, delivery")
	c.Redirect(http.StatusFound, "/deliveries/new-delivery/"+serviceReceiver.ID.Hex()+"/"+delivery.ID.Hex()+"/"+serviceEmitterHTML.TypeID.Hex())
}
func ( VS * Server ) addItemsDeliveryFromService ( c * gin . Context ) { serviceEmitterHTML , _ := VS . getOurService ( c , " " , " " , " " ) idServiceReceiver , b := VS . getIDParamFromURL ( c , " " ) if ! b { return } serviceReceiver := VS . getServiceByID ( c , idServiceReceiver , " " , " " , " " , true ) idDelivery , b := VS . getIDParamFromURL ( c , " " ) if ! b { return } idServiceType , b := VS . getIDParamFromURL ( c , " " ) if ! b { return } delivery , isDelivery := VS . getDeliveryByID ( c , idDelivery , " " , " " , " " , true ) if ! isDelivery { delivery = Delivery { ID : idDelivery , IDServiceEmitter : serviceEmitterHTML . ID , IDServiceReceiver : serviceReceiver . ID , Date : getTime ( ) , IsSent : false , } } if delivery . IsSent { c . Redirect ( http . StatusFound , " " ) return } sent := VS . getCheckBoxFromHTML ( c , " " ) if sent { delivery . IsSent = true VS . addElementToDatabaseWithRegister ( c , delivery , delivery . ID , serviceEmitterHTML . ID , " " , " " , " " ) VS . goodFeedback ( c , " " + idServiceReceiver . Hex ( ) + " " + idDelivery . Hex ( ) + " " + idServiceType . Hex ( ) ) return } quantityToDeliver , _ := VS . getIntFromHTML ( c , " " , " " ) if quantityToDeliver == 0 { VS . wrongFeedback ( c , " " ) return } itemToDeliverID , b := VS . getIDFromHTMLCleaningIt ( c , " " , " " , " " ) if ! b { return } item , b := VS . getItemByID ( c , itemToDeliverID , " " , " " , " " , false ) var cat Category if b { cat = VS . getCategoryByID ( c , item . IDCategory , " " , " " , " " ) } else { cat . IsTrackable = true video , _ := VS . getVideoCourseByID ( c , item . IDCategory , " " , " " , " " , false ) item . ID = video . ID } stock := VS . getStockByItemOrVideoID ( c , itemToDeliverID , " " , " " , " " ) if cat . IsTrackable { QR , b := VS . getQRFromHTML ( c ) if ! b { return } stock = VS . getStockByID ( c , QR , " " , " " , " " ) } if stock . IDServiceLocation != serviceEmitterHTML . ID { VS . wrongFeedback ( c , " " ) return } if stock . IDVideoCourseOrItem != item . ID { VS . wrongFeedback ( c , " " ) return } stock . IDServiceLocation = delivery . ID VS . addElementToDatabaseWithRegister ( c , stock , stock . ID , serviceEmitterHTML . ID , " " , " " , " " ) delivery . Stocks = append ( delivery . Stocks , stock . ID ) VS . addElementToDatabaseWithoutRegister ( c , delivery , delivery . ID , " " , " " , " " ) c . Redirect ( http . StatusFound , " " + serviceReceiver . ID . Hex ( ) + " " + delivery . ID . Hex ( ) + " " + serviceEmitterHTML . TypeID . Hex ( ) ) }
This handler adds the item of the Service to the delivery
This handler adds the item of the Service to the delivery
// CHECKING about that the action is not to deliver // If is already send, we redirect to see the delivery, not to add or edit // Check if the action is to deliver instead of add an item // Nothing to deliver // We clean the extra information needed for the slider // We check the QR if is trackable // Is product from a video // Delivery // Refresh the page