func (VS *Server) addItemsDeliveryGlobal(c *gin.Context) {
	serviceEmitter := VS.getCentralWarehouse(c, "h_deliveries", "addItemsDeliveryGlobal", "serviceEmitter := VS.getCentralWarehouse")
	idServiceReceiver, b := VS.getIDParamFromURL(c, "idservice")
	if !b {
		return
	}
	serviceReceiver := VS.getServiceByID(c, idServiceReceiver, "h_deliveries", "addItemsDeliveryGlobal", "serviceReceiver := VS.getServiceByID", true)

	// Create the delivery if does not exist
	idDelivery, b := VS.getIDParamFromURL(c, "iddelivery")
	if !b {
		return
	}
	delivery, isDelivery := VS.getDeliveryByID(c, idDelivery, "h_deliveries", "addItemsDeliveryGlobal", "delivery, isDelivery := VS.getDeliveryByID", true)
	if !isDelivery {
		delivery = Delivery{
			ID:                idDelivery,
			IDServiceEmitter:  serviceEmitter.ID,
			IDServiceReceiver: serviceReceiver.ID,
			Date:              getTime(),
			IsSent:            false,
			IDManager:         VS.getUserFomCookie(c, "h_deliveries", "addItemsDeliveryGlobal", "VS.getUserFomCookie").ID,
		}
	}

	// 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 {
		fmt.Print("Line 127")
		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.addElementToDatabaseWithRegisterFromCentral(c, delivery, delivery.ID, "h_deliveries", "addItemsDeliveryGlobal", "VS.addElementToDatabaseWithRegisterFromCentral")
		// Audit
		audit := VS.getAuditFromCentral(c, delivery, idDelivery, Modified)
		VS.registerAuditAndEvent(c, audit, delivery, delivery.ID)
		VS.goodFeedback(c, "/data/new-stock/"+serviceReceiver.ID.Hex()+"/"+delivery.ID.Hex())
		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, _ := VS.getItemByID(c, itemToDeliverID, "h_deliveries", "addItemsDeliveryGlobal", "item, _ := VS.getItemByID", false)
	cat := VS.getCategoryByID(c, item.IDCategory, "h_deliveries", "addItemsDeliveryGlobal", "cat := VS.getCategoryByID")

	stockInDelivery := Stock{
		ID:                  bson.NewObjectId(),
		Photo:               item.Photo,
		IDServiceLocation:   delivery.ID,
		TypeOfItem:          cat.TypeOfItem,
		IDVideoCourseOrItem: item.ID,
		IDUser:              VS.getUserFomCookie(c, "h_deliveries", "addItemsDeliveryGlobal", "UserID: VS.getUserFomCookie").ID,
		Date:                getTime(),
		ServiceCreated:      serviceEmitter.ID,
		IsTrackable:         cat.IsTrackable,
	}
	if cat.IsTrackable {
		QR, b := VS.getQRFromHTMLNew(c, Tool)
		if !b {
			return
		}
		stockInDelivery.ID = QR
	}
	if !isDelivery {
		VS.addElementToDatabaseWithRegisterFromCentral(c, delivery, delivery.ID, "h_deliveries", "addItemsDeliveryGlobal", "VS.addElementToDatabaseWithRegisterFromCentral")
	}
	VS.addElementToDatabaseWithRegisterFromCentral(c, stockInDelivery, stockInDelivery.ID, "h_deliveries", "addItemsDeliveryGlobal", "VS.addElementToDatabaseWithRegisterFromCentral")
	// Delivery
	delivery.Stocks = append(delivery.Stocks, stockInDelivery.ID)
	VS.addElementToDatabaseWithRegisterFromCentral(c, delivery, delivery.ID, "h_deliveries", "addItemsDeliveryGlobal", "VS.addElementToDatabaseWithRegisterFromCentral")
	c.Redirect(http.StatusFound, "/deliveries/new-stock/"+serviceReceiver.ID.Hex()+"/"+delivery.ID.Hex())
}
// This handler adds the items of the global delivery
This handler adds the items of the global delivery
// This handler adds the items of the global delivery
func (VS *Server) addItemsDeliveryGlobal(c *gin.Context) {
	serviceEmitter := VS.getCentralWarehouse(c, "h_deliveries", "addItemsDeliveryGlobal", "serviceEmitter := VS.getCentralWarehouse")
	idServiceReceiver, b := VS.getIDParamFromURL(c, "idservice")
	if !b {
		return
	}
	serviceReceiver := VS.getServiceByID(c, idServiceReceiver, "h_deliveries", "addItemsDeliveryGlobal", "serviceReceiver := VS.getServiceByID", true)
	idDelivery, b := VS.getIDParamFromURL(c, "iddelivery")
	if !b {
		return
	}
	delivery, isDelivery := VS.getDeliveryByID(c, idDelivery, "h_deliveries", "addItemsDeliveryGlobal", "delivery, isDelivery := VS.getDeliveryByID", true)
	if !isDelivery {
		delivery = Delivery{
			ID:                idDelivery,
			IDServiceEmitter:  serviceEmitter.ID,
			IDServiceReceiver: serviceReceiver.ID,
			Date:              getTime(),
			IsSent:            false,
			IDManager:         VS.getUserFomCookie(c, "h_deliveries", "addItemsDeliveryGlobal", "VS.getUserFomCookie").ID,
		}
	}
	if delivery.IsSent {
		fmt.Print("Line 127")
		c.Redirect(http.StatusFound, "/deliveries/stock-created")
		return
	}
	sent := VS.getCheckBoxFromHTML(c, "sent")
	if sent {
		delivery.IsSent = true
		VS.addElementToDatabaseWithRegisterFromCentral(c, delivery, delivery.ID, "h_deliveries", "addItemsDeliveryGlobal", "VS.addElementToDatabaseWithRegisterFromCentral")
		audit := VS.getAuditFromCentral(c, delivery, idDelivery, Modified)
		VS.registerAuditAndEvent(c, audit, delivery, delivery.ID)
		VS.goodFeedback(c, "/data/new-stock/"+serviceReceiver.ID.Hex()+"/"+delivery.ID.Hex())
		return
	}
	itemToDeliverID, b := VS.getIDFromHTMLCleaningIt(c, "|", "stock", "Stock")
	if !b {
		return
	}
	item, _ := VS.getItemByID(c, itemToDeliverID, "h_deliveries", "addItemsDeliveryGlobal", "item, _ := VS.getItemByID", false)
	cat := VS.getCategoryByID(c, item.IDCategory, "h_deliveries", "addItemsDeliveryGlobal", "cat := VS.getCategoryByID")
	stockInDelivery := Stock{
		ID:                  bson.NewObjectId(),
		Photo:               item.Photo,
		IDServiceLocation:   delivery.ID,
		TypeOfItem:          cat.TypeOfItem,
		IDVideoCourseOrItem: item.ID,
		IDUser:              VS.getUserFomCookie(c, "h_deliveries", "addItemsDeliveryGlobal", "UserID: VS.getUserFomCookie").ID,
		Date:                getTime(),
		ServiceCreated:      serviceEmitter.ID,
		IsTrackable:         cat.IsTrackable,
	}
	if cat.IsTrackable {
		QR, b := VS.getQRFromHTMLNew(c, Tool)
		if !b {
			return
		}
		stockInDelivery.ID = QR
	}
	if !isDelivery {
		VS.addElementToDatabaseWithRegisterFromCentral(c, delivery, delivery.ID, "h_deliveries", "addItemsDeliveryGlobal", "VS.addElementToDatabaseWithRegisterFromCentral")
	}
	VS.addElementToDatabaseWithRegisterFromCentral(c, stockInDelivery, stockInDelivery.ID, "h_deliveries", "addItemsDeliveryGlobal", "VS.addElementToDatabaseWithRegisterFromCentral")
	delivery.Stocks = append(delivery.Stocks, stockInDelivery.ID)
	VS.addElementToDatabaseWithRegisterFromCentral(c, delivery, delivery.ID, "h_deliveries", "addItemsDeliveryGlobal", "VS.addElementToDatabaseWithRegisterFromCentral")
	c.Redirect(http.StatusFound, "/deliveries/new-stock/"+serviceReceiver.ID.Hex()+"/"+delivery.ID.Hex())
}
func ( VS * Server ) addItemsDeliveryGlobal ( c * gin . Context ) { serviceEmitter := VS . getCentralWarehouse ( c , " " , " " , " " ) idServiceReceiver , b := VS . getIDParamFromURL ( c , " " ) if ! b { return } serviceReceiver := VS . getServiceByID ( c , idServiceReceiver , " " , " " , " " , true ) idDelivery , b := VS . getIDParamFromURL ( c , " " ) if ! b { return } delivery , isDelivery := VS . getDeliveryByID ( c , idDelivery , " " , " " , " " , true ) if ! isDelivery { delivery = Delivery { ID : idDelivery , IDServiceEmitter : serviceEmitter . ID , IDServiceReceiver : serviceReceiver . ID , Date : getTime ( ) , IsSent : false , IDManager : VS . getUserFomCookie ( c , " " , " " , " " ) . ID , } } if delivery . IsSent { fmt . Print ( " " ) c . Redirect ( http . StatusFound , " " ) return } sent := VS . getCheckBoxFromHTML ( c , " " ) if sent { delivery . IsSent = true VS . addElementToDatabaseWithRegisterFromCentral ( c , delivery , delivery . ID , " " , " " , " " ) audit := VS . getAuditFromCentral ( c , delivery , idDelivery , Modified ) VS . registerAuditAndEvent ( c , audit , delivery , delivery . ID ) VS . goodFeedback ( c , " " + serviceReceiver . ID . Hex ( ) + " " + delivery . ID . Hex ( ) ) return } itemToDeliverID , b := VS . getIDFromHTMLCleaningIt ( c , " " , " " , " " ) if ! b { return } item , _ := VS . getItemByID ( c , itemToDeliverID , " " , " " , " " , false ) cat := VS . getCategoryByID ( c , item . IDCategory , " " , " " , " " ) stockInDelivery := Stock { ID : bson . NewObjectId ( ) , Photo : item . Photo , IDServiceLocation : delivery . ID , TypeOfItem : cat . TypeOfItem , IDVideoCourseOrItem : item . ID , IDUser : VS . getUserFomCookie ( c , " " , " " , " " ) . ID , Date : getTime ( ) , ServiceCreated : serviceEmitter . ID , IsTrackable : cat . IsTrackable , } if cat . IsTrackable { QR , b := VS . getQRFromHTMLNew ( c , Tool ) if ! b { return } stockInDelivery . ID = QR } if ! isDelivery { VS . addElementToDatabaseWithRegisterFromCentral ( c , delivery , delivery . ID , " " , " " , " " ) } VS . addElementToDatabaseWithRegisterFromCentral ( c , stockInDelivery , stockInDelivery . ID , " " , " " , " " ) delivery . Stocks = append ( delivery . Stocks , stockInDelivery . ID ) VS . addElementToDatabaseWithRegisterFromCentral ( c , delivery , delivery . ID , " " , " " , " " ) c . Redirect ( http . StatusFound , " " + serviceReceiver . ID . Hex ( ) + " " + delivery . ID . Hex ( ) ) }
This handler adds the items of the global delivery
This handler adds the items of the global delivery
// Create the delivery if does not exist // 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 // Audit // We clean the extra information needed for the slider // We check the QR if is trackable // Delivery