Esempio n. 1
0
// Update the Product.
func productUpdateHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {

		// Get the value of the "id" parameters.
		productNum := bone.GetValue(r, "id")
		product := getProduct(productNum)
		productData := &ProductUpdate{}
		productData.Product = *product

		displayProductUpdateTemplate(w, productData)
	} else {
		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// Validate data
		val := formData.Validator()
		val.Require("PartNumber")

		// Use data to create a user object
		product := getProduct(formData.Get("PartNumber"))
		product.PartNumber = formData.Get("PartNumber")
		product.Desc = formData.Get("Desc")
		product.ReferenceDes = formData.Get("ReferenceDes")
		product.UnitPrice = formData.GetFloat("UnitPrice")
		product.ListPrice = formData.GetFloat("ListPrice")
		product.Type = formData.Get("Type")
		product.Qty = formData.GetInt("Qty")
		product.UnitOfMeasure = formData.Get("UnitOfMeasure")
		product.Cost = formData.GetFloat("Cost")
		product.Modified = time.Now().Local()

		fmt.Printf("Product Update: %s\n", product.PartNumber)

		// Update the Product in DB
		updateProduct(product)

		// Go to the list of Products
		http.Redirect(w, r, "/product", http.StatusFound)
	}
}
Esempio n. 2
0
// List all the WaterTests.
func watertestListHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method waterTestListHandler:", r.Method) // get request method
	if r.Method == "GET" {

		// Init
		waterTestData := &WaterTestData{}

		// Get data form DB
		err := Vault.Mongo.C("WaterTestResults").Find(bson.M{}).Sort("-Created").All(&waterTestData.WaterTests)
		CheckError(err)
		fmt.Println("Number of WaterTests: ", len(waterTestData.WaterTests))

		// Get the path to the PlotModel
		for index, element := range waterTestData.WaterTests {
			waterTestData.WaterTests[index].PlotReport = getWaterTestPlotModelPath(element.PlotReport, element.SerialNumber)
		}

		// Display data to page
		t, _ := template.ParseFiles("header.html", "watertest_list.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", waterTestData)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, waterTestData)
	} else {

		// Init
		waterTestData := &WaterTestData{}

		// Get the partial serial number
		formData, err := forms.Parse(r)
		CheckError(err)
		var partialSerial = formData.Get("PartialSerialNumber")
		waterTestData.WaterTests = *getWaterTestContain(partialSerial)
		fmt.Println("Number of WaterTests: ", len(waterTestData.WaterTests))

		// Get the path to the PlotModel
		for index, element := range waterTestData.WaterTests {
			waterTestData.WaterTests[index].PlotReport = getWaterTestPlotModelPath(element.PlotReport, element.SerialNumber)
		}

		// Display data to page
		t, _ := template.ParseFiles("header.html", "watertest_list.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", waterTestData)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, waterTestData)
	}
}
Esempio n. 3
0
// Add the Product.
func productAddHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		// Display blank form
		productData := &ProductUpdate{}
		displayProductTemplate(w, productData)
	} else {
		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// Validate data
		val := formData.Validator()
		val.Require("PartNumber")
		val.Require("Desc")

		// Use data to create a user object
		product := &Product{
			PartNumber:    formData.Get("PartNumber"),
			Desc:          formData.Get("Desc"),
			ReferenceDes:  formData.Get("ReferenceDes"),
			UnitPrice:     formData.GetFloat("UnitPrice"),
			ListPrice:     formData.GetFloat("ListPrice"),
			Type:          formData.Get("Type"),
			Qty:           formData.GetInt("Qty"),
			UnitOfMeasure: formData.Get("UnitOfMeasure"),
			Cost:          formData.GetFloat("Cost"),
			Created:       time.Now().Local(),
		}

		// Add the Products to the DB
		err = Vault.Mongo.C("Products").Insert(product)
		CheckError(err)

		// Go to the list of products
		http.Redirect(w, r, "/product", http.StatusFound)
	}
}
Esempio n. 4
0
func (p People) Create(res http.ResponseWriter, req *http.Request) {
	personData, err := forms.Parse(req)
	if err != nil {
		log.Fatal(err)
	}
	val := personData.Validator()
	val.Require("name")
	val.Require("age")
	val.TypeInt("age")
	val.Greater("age", 0)
	if val.HasErrors() {
		switch req.Header.Get("Accept") {
		case contentTypeJSON:
			r := render.New()
			r.JSON(res, 422, val.ErrorMap())
		default:
			session, err := store.Get(req, "flash-session")
			if err != nil {
				panic(err)
			}
			for _, errMsg := range val.Messages() {
				session.AddFlash(errMsg, "errors")
			}
			session.AddFlash(personData.Get("name"), "person.name")
			session.AddFlash(personData.Get("age"), "person.age")
			session.Save(req, res)
			http.Redirect(res, req, "/people/new", http.StatusFound)
			return
		}
	}
	person := &models.Person{
		Name: personData.Get("name"),
		Age:  personData.GetInt("age"),
	}
	if err := models.People.Save(person); err != nil {
		panic(err)
	}
	switch req.Header.Get("Accept") {
	case contentTypeJSON:
		r := render.New()
		r.JSON(res, http.StatusOK, person)
	default:
		http.Redirect(res, req, "/people", http.StatusSeeOther)
	}
}
Esempio n. 5
0
// List all the ADCPs.
func adcpListHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method adcpListHander:", r.Method) // get request method
	if r.Method == "GET" {

		// Init
		adcpData := &AdcpData{}

		// Get data form DB
		err := Vault.Mongo.C("adcps").Find(bson.M{}).Sort("-created").All(&adcpData.Adcps)
		CheckError(err)
		fmt.Println("Number of ADCPs: ", len(adcpData.Adcps))

		// Display data to page
		t, _ := template.ParseFiles("header.html", "adcp_list.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", adcpData)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, adcpData)
	} else {

		// Init
		adcpData := &AdcpData{}

		// Get the partial serial number
		formData, err := forms.Parse(r)
		CheckError(err)
		var partialSerial = formData.Get("PartialSerialNumber")
		adcpData.Adcps = *getAdcpContain(partialSerial)
		fmt.Println("Number of ADCPs: ", len(adcpData.Adcps))

		// Display data to page
		t, _ := template.ParseFiles("header.html", "adcp_list.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", adcpData)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, adcpData)
	}
}
Esempio n. 6
0
// List all the Products.
func productListHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method productListHander:", r.Method) // get request method
	if r.Method == "GET" {

		// Init
		data := &ProductData{}

		// Get data form DB
		err := Vault.Mongo.C("Products").Find(bson.M{}).Sort("-created").All(&data.Products)
		CheckError(err)
		fmt.Println("Number of Products: ", len(data.Products))

		// Display data to page
		t, _ := template.ParseFiles("header.html", "product_list.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", data)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, data)
	} else {

		// Init
		data := &ProductData{}

		// Get the partial serial number
		formData, err := forms.Parse(r)
		CheckError(err)
		var partial = formData.Get("PartialProduct")
		data.Products = *getProductContain(partial)
		fmt.Println("Number of Products: ", len(data.Products))

		// Display data to page
		t, _ := template.ParseFiles("header.html", "product_list.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", data)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, data)
	}
}
Esempio n. 7
0
// List all the ADCPs.
func salesOrderHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method salesorderListHandler:", r.Method) // get request method
	if r.Method == "GET" {

		// Init
		soData := &SalesOrderData{}

		// Get data form DB
		err := Vault.Mongo.C("SalesOrders").Find(bson.M{}).Sort("-created").All(&soData.SO)
		CheckError(err)
		fmt.Println("Number of SOs: ", len(soData.SO))

		// Display data to page
		t, _ := template.ParseFiles("header.html", "salesorder_list.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", soData)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, soData)
	} else {

		// Init
		soData := &SalesOrderData{}

		// Get the partial serial number
		formData, err := forms.Parse(r)
		CheckError(err)
		var partialSO = formData.Get("PartialSalesOrderNumber")
		soData.SO = *getSalesOrderContain(partialSO)
		fmt.Println("Number of SOs: ", len(soData.SO))

		// Display data to page
		t, _ := template.ParseFiles("header.html", "salesorder_list.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", soData)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, soData)
	}
}
Esempio n. 8
0
// List all the RMAs.
func rmaHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method rmaListHandler:", r.Method) // get request method
	if r.Method == "GET" {

		// Init
		rmaData := &RmaData{}

		// Get data form DB
		err := Vault.Mongo.C("RMAs").Find(bson.M{}).Sort("-Modified").All(&rmaData.RMA)
		CheckError(err)
		fmt.Println("Number of RMAs: ", len(rmaData.RMA))

		// Display data to page
		t, _ := template.ParseFiles("header.html", "rma_list.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", rmaData)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, rmaData)
	} else {

		// Init
		rmaData := &RmaData{}

		// Get the partial serial number
		formData, err := forms.Parse(r)
		CheckError(err)
		var partialRMA = formData.Get("PartialRmaNumber")
		rmaData.RMA = *getRmaContain(partialRMA)
		fmt.Println("Number of RMAs: ", len(rmaData.RMA))

		// Display data to page
		t, _ := template.ParseFiles("header.html", "rma_list.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", rmaData)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, rmaData)
	}
}
Esempio n. 9
0
// Update the ADCP data
func adcpUpdateHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method:", r.Method) // get request method

	if r.Method == "GET" {

		// Get the value of the "id" parameters.
		val := bone.GetValue(r, "id")
		adcp := getAdcp(val)

		// Generate a token
		token := genToken()

		//var adcpData = {"SerialNumber": "1000056", "Desc": "1200 kHz", "token":token}
		//adcp := &Adcp{SerialNumber: "100001212", Frequency: "1200 kHz"}
		adcpData := &AdcpDataUpdate{Adcp: *adcp, Token: token}

		t, _ := template.ParseFiles("header.html", "adcp_update.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", adcpData)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, adcpData)
	} else {
		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		fmt.Println("Update the ADCP")

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// Use data to create a adcp object
		adcp := getAdcp(formData.Get("SerialNumber"))
		adcp.Customer = formData.Get("Customer")
		adcp.OrderNumber = formData.Get("OrderNumber")
		adcp.Application = formData.Get("Application")
		adcp.ConnectorType = formData.Get("ConnectorType")
		adcp.DepthRating = formData.Get("DepthRating")
		adcp.Firmware = formData.Get("Firmware")
		adcp.Hardware = formData.Get("Hardware")
		adcp.HeadType = formData.Get("HeadType")
		adcp.Modified = time.Now()
		adcp.PressureSensorPresent = formData.GetBool("PressureSensorPresent")
		adcp.PressureSensorRating = formData.Get("PressureSensorRating")
		adcp.RecorderFormatted = formData.GetBool("RecorderFormatted")
		adcp.RecorderSize = formData.Get("RecorderSize")
		adcp.Software = formData.Get("Software")
		adcp.SystemType = formData.Get("SystemType")
		adcp.TemperaturePresent = formData.GetBool("TemperaturePresent")

		fmt.Println("Serial: ", adcp.SerialNumber)
		fmt.Println("Customer: ", adcp.Customer)
		fmt.Println("OrderNumber: ", adcp.OrderNumber)

		// Save the data to the DB
		updateAdcp(adcp)

		// Add the ADCP checklist to the DB if it does not exist
		CheckAdcpChecklist(adcp.SerialNumber)

		// Go to the list of ADCP
		http.Redirect(w, r, "/adcp", http.StatusFound)
	}
}
Esempio n. 10
0
// Update the WaterTest.
func watertestUpdateHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Printf("method watertestUpdateHandler: %s\n", r.Method) // get request method
	if r.Method == "GET" {

		// Get the value of the "id" parameters.
		id := bone.GetValue(r, "id")

		watertest := getWaterTestResultsID(id)
		watertestData := &WaterTestUpdate{}
		watertestData.WaterTest = *watertest
		watertestData.IsSelectedList = getSelectedList(watertest.IsSelected)

		fmt.Printf("%v\n", watertestData.WaterTest)
		fmt.Printf("SerialNum: %v\n", watertestData.WaterTest.SerialNumber)
		fmt.Printf("GpsDistance: %v\n", watertestData.WaterTest.GpsDistance)

		displayWaterTestUpdateTemplate(w, watertestData)
	} else {
		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// Validate data
		val := formData.Validator()
		val.Require("SerialNumber")
		val.Require("ID")

		fmt.Printf("ID: %s\n", formData.Get("ID"))

		//wt := getWaterTestResultsID(bson.ObjectId(formData.Get("ID")))
		wt := getWaterTestResultsID(formData.Get("ID"))
		wt.SerialNumber = formData.Get("SerialNumber")
		wt.TestOrientation = formData.GetInt("TestOrientation")
		wt.Beam0NoiseFloor = formData.GetFloat("Beam0NoiseFloor")
		wt.Beam1NoiseFloor = formData.GetFloat("Beam1NoiseFloor")
		wt.Beam2NoiseFloor = formData.GetFloat("Beam2NoiseFloor")
		wt.Beam3NoiseFloor = formData.GetFloat("Beam3NoiseFloor")
		wt.Beam0SignalLake = formData.GetFloat("Beam0SignalLake")
		wt.Beam1SignalLake = formData.GetFloat("Beam1SignalLake")
		wt.Beam2SignalLake = formData.GetFloat("Beam2SignalLake")
		wt.Beam3SignalLake = formData.GetFloat("Beam3SignalLake")
		wt.Beam0SignalOcean = formData.GetFloat("Beam0SignalOcean")
		wt.Beam1SignalOcean = formData.GetFloat("Beam1SignalOcean")
		wt.Beam2SignalOcean = formData.GetFloat("Beam2SignalOcean")
		wt.Beam3SignalOcean = formData.GetFloat("Beam3SignalOcean")
		wt.Beam0SnrLake = formData.GetFloat("Beam0SnrLake")
		wt.Beam1SnrLake = formData.GetFloat("Beam1SnrLake")
		wt.Beam2SnrLake = formData.GetFloat("Beam2SnrLake")
		wt.Beam3SnrLake = formData.GetFloat("Beam3SnrLake")
		wt.Beam0SnrOcean = formData.GetFloat("Beam0SnrOcean")
		wt.Beam1SnrOcean = formData.GetFloat("Beam1SnrOcean")
		wt.Beam2SnrOcean = formData.GetFloat("Beam2SnrOcean")
		wt.Beam3SnrOcean = formData.GetFloat("Beam3SnrOcean")
		wt.GpsDistance = formData.Get("GpsDistance")
		wt.GpsDirection = formData.Get("GpsDirection")
		wt.BtDistance = formData.Get("BtDistance")
		wt.BtDirection = formData.Get("BtDirection")
		wt.DistanceError = formData.Get("DistanceError")
		wt.DirectionError = formData.Get("DirectionError")
		wt.ProfileRangeBeam0 = formData.GetFloat("ProfileRangeBeam0")
		wt.ProfileRangeBeam1 = formData.GetFloat("ProfileRangeBeam1")
		wt.ProfileRangeBeam2 = formData.GetFloat("ProfileRangeBeam2")
		wt.ProfileRangeBeam3 = formData.GetFloat("ProfileRangeBeam3")
		wt.GlitchCountBeam0 = formData.GetFloat("GlitchCountBeam0")
		wt.GlitchCountBeam1 = formData.GetFloat("GlitchCountBeam1")
		wt.GlitchCountBeam2 = formData.GetFloat("GlitchCountBeam2")
		wt.GlitchCountBeam3 = formData.GetFloat("GlitchCountBeam3")
		wt.BottomTrackAmplitudeBeam0 = formData.GetFloat("BottomTrackAmplitudeBeam0")
		wt.BottomTrackAmplitudeBeam1 = formData.GetFloat("BottomTrackAmplitudeBeam1")
		wt.BottomTrackAmplitudeBeam2 = formData.GetFloat("BottomTrackAmplitudeBeam2")
		wt.BottomTrackAmplitudeBeam3 = formData.GetFloat("BottomTrackAmplitudeBeam3")
		wt.PlotReport = formData.Get("PlotReport")
		wt.Notes = formData.Get("Notes")
		wt.Modified = time.Now().Local()

		// Get selected checkbox
		isChecked := formData.Get("IsSelected")
		fmt.Printf("WaterTest selected: %v\n", isChecked)
		if isChecked == "Selected" {
			wt.IsSelected = true
		} else {
			wt.IsSelected = false
		}

		fmt.Printf("WaterTest Update: %s\n", wt.SerialNumber)

		// Update the WaterTest in DB
		updateWaterTest(wt)

		// Go to the list of Products
		http.Redirect(w, r, "/adcp/wt", http.StatusFound)
	}
}
Esempio n. 11
0
// Add the SalesOrder.
func salesOrderUpdateHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {

		// Get the value of the "id" parameters.
		salesorderNum := bone.GetValue(r, "id")
		so := getSalesOrder(salesorderNum)
		soData := &SalesOrderUpdate{}
		soData.SO = *so

		displaySalesOrderUpdateTemplate(w, soData)
	} else {
		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// Validate data
		val := formData.Validator()
		val.Require("SalesOrderNumber")

		// Use data to create a user object
		so := getSalesOrder(formData.Get("SalesOrderNumber"))
		so.IsSelected = formData.GetBool("IsSelected")
		so.UserName = formData.Get("UserName")
		so.SalesPerson = formData.Get("SalesPerson")
		so.POReference = formData.Get("POReference")
		//PODateIssued:             formData.get("PODateIssued"),
		//PODateReceived:           formData.Get("PODateReceived"),
		//DueDate:                  formData.Get("DueDate"),
		//EstShipDate:              formData.Get("EstShipDate"),
		so.Qty = formData.GetInt("Qty")
		so.UnitPrice = formData.Get("UnitPrice")
		so.TotalPrice = formData.Get("TotalPrice")
		so.EUS = formData.Get("EUS")
		so.BuildStatusPurchase = formData.Get("BuildStatusPurchase")
		so.BuildStatusPurchaseNotes = formData.Get("BuildStatusPurchaseNotes")
		so.BuildStatusXdcr = formData.Get("BuildStatusXdcr")
		so.BuildStatusXdcrNotes = formData.Get("BuildStatusXdcrNotes")
		so.BuildStatusAssembly = formData.Get("BuildStatusAssembly")
		so.BuildStatusAssemblyNotes = formData.Get("BuildStatusAssemblyNotes")
		so.BuildStatusTesting = formData.Get("BuildStatusTesting")
		so.BuildStatusTestingNotes = formData.Get("BuildStatusTestingNotes")
		//DateShiped:               formData.Get("DateShiped"),
		so.SerialNumber = formData.Get("SerialNumber")
		//DeliveryDate:             formData.Get("DeliveryDate"),
		so.Region = formData.Get("Region")
		so.BeamAngle = formData.Get("BeamAngle")
		so.ElectronicsType = formData.Get("ElectronicsType")
		so.BatteryType = formData.Get("BatteryType")
		so.NumBattery = formData.GetInt("NumBattery")
		so.ExternalBatteryPack = formData.Get("ExternalBatteryPack")
		so.CableLength = formData.Get("CableLength")
		so.InternalMemory = formData.Get("InternalMemory")
		so.InternalCompass = formData.Get("InternalCompass")
		so.DeckBox = formData.Get("DeckBox")
		so.PulseVersion = formData.Get("PulseVersion")
		so.UserVersion = formData.Get("UserVersion")
		so.ThirdParty = formData.Get("ThirdParty")
		so.Notes = formData.Get("Notes")
		so.Modified = time.Now().Local()

		fmt.Printf("Sales Order Update: %s\n", so.SalesOrderNumber)

		// Update the sales order in DB
		updateSalesOrder(so)

		// Go to the list of ADCP
		http.Redirect(w, r, "/so", http.StatusFound)
	}
}
Esempio n. 12
0
// Add the RMA.
func rmaAddHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		// Display blank form
		rmaData := &RmaUpdate{}
		rmaData.ProductList = *getProductList()
		rmaData.StatusList = getStatusList("Reported")
		rmaData.BillableList = getBillableList("Warranty")
		rmaData.RmaTypeList = getRmaTypeList("290")
		rmaData.RMA.RmaNumber = getNewRmaNumber()

		displayRmaTemplate(w, rmaData)
	} else {
		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// // Validate data
		// val := formData.Validator()
		// val.Require("Company")
		// val.Require("ContactName")
		// val.Require("ContactEmail")
		// val.Require("ContactPhone")
		// val.Require("SerialNumber")
		// val.Require("ReasonReturn")

		// Use data to create a user object
		rma := &RMA{
			RmaType:                    formData.Get("RmaType"),
			RmaNumber:                  formData.Get("RmaNumber"),
			OrigSalesOrder:             formData.Get("OrigSalesOrder"),
			Company:                    formData.Get("Company"),
			ContactName:                formData.Get("ContactName"),
			ContactEmail:               formData.Get("ContactEmail"),
			ContactPhone:               formData.Get("ContactPhone"),
			ContactAddress:             formData.Get("ContactAddress"),
			ContactAddress2:            formData.Get("ContactAddress2"),
			ContactAddressCityStateZip: formData.Get("ContactAddressCityStateZip"),
			ContactAddressCountry:      formData.Get("ContactAddressCountry"),
			ProductDesc:                formData.Get("ProductDesc"),
			ReasonReturn:               formData.Get("ReasonReturn"),
			ReturnCompany:              formData.Get("ReturnCompany"),
			ReturnContact:              formData.Get("ReturnContact"),
			ReturnAddress:              formData.Get("ReturnAddress"),
			ReturnAddressCont:          formData.Get("ReturnAddressCont"),
			ReturnAddressCityStateZip:  formData.Get("ReturnAddressCityStateZip"),
			ReturnAddressCountry:       formData.Get("ReturnAddressCountry"),
			ReturnPhone:                formData.Get("ReturnPhone"),
			ReturnEmail:                formData.Get("ReturnEmail"),
			ReceiveInfo:                formData.Get("ReceiveInfo"),
			ReceiveUser:                formData.Get("ReceiveUser"),
			InspectionInfo:             formData.Get("InspectionInfo"),
			InspectionUser:             formData.Get("InspectionUser"),
			RepairInfo:                 formData.Get("RepairInfo"),
			RepairUser:                 formData.Get("RepairUser"),
			RepairEstHours:             formData.GetInt("RepairEstHours"),
			Billable:                   formData.Get("Billable"),
			QuoteNum:                   formData.Get("QuoteNum"),
			OriginalRmaNum:             formData.Get("OriginalRmaNum"),
			SerialNumber:               formData.Get("SerialNumber"),
			Notes:                      formData.Get("Notes"),
			RmaDate:                    formData.Get("RmaDate"),
			Created:                    time.Now().Local(),
			Modified:                   time.Now().Local(),
			InspectionDate:             formData.Get("InspectionDate"),
			ReceiveDate:                formData.Get("ReceiveDate"),
			RepairDate:                 formData.Get("RepairDate"),
			ShipDate:                   formData.Get("ShipDate"),
			Status:                     formData.Get("Status"),
		}

		fmt.Printf("Submit Button: %s\n", formData.Get("SubmitButton"))

		// Add the new product to the RMA
		if formData.Get("SubmitButton") == "ADD" {
			//if !val.HasErrors() {
			fmt.Printf("Add product to RMA: %s\n", rma.RmaNumber)

			// Add the product to the list
			rmaProduct := &RmaProduct{}
			rmaProduct.PartNumber = formData.Get("AddProductPartNumber")
			rmaProduct.Qty = formData.GetInt("AddProductQty")
			rmaProduct.SerialNumber = formData.Get("AddProductSerialNumber")
			product := getProductPartNumber(rmaProduct.PartNumber)
			if product != nil {
				rma.Products = append(rma.Products, *rmaProduct)
			}

			rmaData := &RmaUpdate{}
			rmaData.ProductList = *getProductList()
			rmaData.StatusList = getStatusList(rma.Status)
			rmaData.BillableList = getBillableList(rma.Billable)
			rmaData.RmaTypeList = getRmaTypeList(rma.RmaType)
			rmaData.RMA = *rma

			displayRmaTemplate(w, rmaData)
		} else if formData.Get("SubmitButton") == "ADD REPAIR" {
			//if !val.HasErrors() {
			fmt.Printf("Add repair product to RMA: %s\n", rma.RmaNumber)

			// Add the product to the repair list
			rmaProduct := &RmaProduct{}
			rmaProduct.PartNumber = formData.Get("AddRepairProductPartNumber")
			rmaProduct.Qty = formData.GetInt("AddRepairProductQty")
			rmaProduct.SerialNumber = formData.Get("AddRepairProductSerialNumber")
			product := getProductPartNumber(rmaProduct.PartNumber)
			if product != nil {
				rma.RepairProducts = append(rma.Products, *rmaProduct)
			}

			rmaData := &RmaUpdate{}
			rmaData.ProductList = *getProductList()
			rmaData.StatusList = getStatusList(rma.Status)
			rmaData.BillableList = getBillableList(rma.Billable)
			rmaData.RmaTypeList = getRmaTypeList(rma.RmaType)
			rmaData.RMA = *rma

			displayRmaTemplate(w, rmaData)
		} else {
			fmt.Printf("RMA Add: %s\n", rma.RmaNumber)

			// Accumulate the Products
			for i := range rma.Products {
				rma.Products[i].PartNumber = r.Form["ProductPartNumber"][i]
				rma.Products[i].SerialNumber = r.Form["ProductSerialNumber"][i]

				qty, err1 := strconv.Atoi(r.Form["ProductQty"][i])
				if err1 == nil {
					rma.Products[i].Qty = qty
				}
			}

			// Accumulate the Repair Products
			for i := range rma.RepairProducts {
				rma.RepairProducts[i].PartNumber = r.Form["RepairProductPartNumber"][i]
				rma.RepairProducts[i].SerialNumber = r.Form["RepairProductSerialNumber"][i]

				qty, err2 := strconv.Atoi(r.Form["RepairProductQty"][i])
				if err2 == nil {
					rma.RepairProducts[i].Qty = qty
				}
			}

			// Add the RMAs to the DB
			err = Vault.Mongo.C("RMAs").Insert(rma)
			CheckError(err)

			// Go to the list of RMAs
			http.Redirect(w, r, "/rma", http.StatusFound)
		}
	}
}
Esempio n. 13
0
func adcpAddHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method adcpAddHander:", r.Method) // get request method
	if r.Method == "GET" {

		// Init data
		adcp := &Adcp{}
		adcpData := &AdcpDataUpdate{Adcp: *adcp}

		displayTemplate(w, adcpData)
	} else {
		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// Validate data
		val := formData.Validator()
		val.Require("SerialNumber")
		val.LengthRange("SerialNumber", 16, 16)

		// Use data to create a user object
		adcp := &Adcp{
			SerialNumber:          formData.Get("SerialNumber"),
			Frequency:             formData.Get("Frequency"),
			Customer:              formData.Get("Customer"),
			OrderNumber:           formData.Get("OrderNumber"),
			Application:           formData.Get("Application"),
			ConnectorType:         formData.Get("ConnectorType"),
			DepthRating:           formData.Get("DepthRating"),
			Firmware:              formData.Get("Firmware"),
			Hardware:              formData.Get("Hardware"),
			HeadType:              formData.Get("HeadType"),
			Modified:              time.Now(),
			Created:               time.Now(),
			PressureSensorPresent: formData.GetBool("PressureSensorPresent"),
			PressureSensorRating:  formData.Get("PressureSensorRating"),
			RecorderFormatted:     formData.GetBool("RecorderFormatted"),
			RecorderSize:          formData.Get("RecorderSize"),
			Software:              formData.Get("Software"),
			SystemType:            formData.Get("SystemType"),
			TemperaturePresent:    formData.GetBool("TemperaturePresent"),
		}
		adcpData := &AdcpDataUpdate{
			Adcp: *adcp,
		}

		// Check for errors and print the error message
		if val.HasErrors() {
			fmt.Println("Error with value:")
			for err := range val.ErrorMap() {
				fmt.Print(err)
				fmt.Print(":")
				fmt.Println(val.ErrorMap()[err])
			}

			// Set the error values
			adcpData.Errors.SerialNumber = val.ErrorMap()["SerialNumber"][0]

			// Display the template
			displayTemplate(w, adcpData)
		} else if checkSerialNumber(adcp.SerialNumber) {
			adcpData.Errors.SerialNumber = "Serial Number already used."
			// Display template
			displayTemplate(w, adcpData)

		} else {
			fmt.Println("SerialNumber:", adcpData.Adcp.SerialNumber)
			fmt.Println("Customer:", adcpData.Adcp.Customer)

			// Add the ADCP to the DB
			err := Vault.Mongo.C("adcps").Insert(adcpData.Adcp)
			CheckError(err)

			// Add the ADCP checklist to the DB
			checklist := &AdcpChecklist{
				SerialNumber: adcpData.Adcp.SerialNumber,
				Modified:     time.Now(),
				Created:      time.Now(),
			}
			err = Vault.Mongo.C("AdcpChecklists").Insert(checklist)
			CheckError(err)

			// Go to the list of ADCP
			http.Redirect(w, r, "/adcp", http.StatusFound)
		}
	}
}
Esempio n. 14
0
func adcpChecklistUpdateHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method:", r.Method) // get request method

	if r.Method == "GET" {

		// Get the value of the "id" parameters.
		val := bone.GetValue(r, "id")

		// Check if the checklist exist, if it does not, add it
		CheckAdcpChecklist(val)

		// Get the checklist from the DB
		checklist := getAdcpChecklist(val)

		// Generate a token
		token := genToken()

		adcpChecklist := &AdcpChecklistUpdate{ADCP: *checklist, Token: token}
		adcpChecklist.OringStatusList = getChecklistStatusList(checklist.Oring.Status)
		adcpChecklist.UrethaneStatusList = getChecklistStatusList(checklist.Urethane.Status)
		adcpChecklist.StandoffsStatusList = getChecklistStatusList(checklist.Standoffs.Status)
		adcpChecklist.ScrewsStatusList = getChecklistStatusList(checklist.Standoffs.Status)
		adcpChecklist.NotchStatusList = getChecklistStatusList(checklist.Notch.Status)
		adcpChecklist.PhotoBoardStackStatusList = getChecklistStatusList(checklist.PhotoBoardStack.Status)
		adcpChecklist.FirmwareStatusList = getChecklistStatusList(checklist.Firmware.Status)
		adcpChecklist.FinalCheckLakeStatusList = getChecklistStatusList(checklist.FinalCheckLake.Status)
		adcpChecklist.FinalCheckShippingStatusList = getChecklistStatusList(checklist.FinalCheckShipping.Status)
		adcpChecklist.BeamWiresStatusList = getChecklistStatusList(checklist.BeamWires.Status)
		adcpChecklist.ThermistorStrandedStatusList = getChecklistStatusList(checklist.ThermistorStranded.Status)
		adcpChecklist.TemperatureStatusList = getChecklistStatusList(checklist.Temperature.Status)
		adcpChecklist.PressureStatusList = getChecklistStatusList(checklist.Pressure.Status)
		adcpChecklist.VaccumTestStatusList = getChecklistStatusList(checklist.VaccumTest.Status)
		adcpChecklist.VibeTestStatusList = getChecklistStatusList(checklist.VibeTest.Status)
		adcpChecklist.LakeTestStatusList = getChecklistStatusList(checklist.LakeTest.Status)
		adcpChecklist.ReviewLakeTestDataStatusList = getChecklistStatusList(checklist.ReviewLakeTestData.Status)
		adcpChecklist.TankTestStatusList = getChecklistStatusList(checklist.TankTest.Status)
		adcpChecklist.ReviewTankTestDataStatusList = getChecklistStatusList(checklist.ReviewTankTestData.Status)
		adcpChecklist.BurnInTestBoardStackStatusList = getChecklistStatusList(checklist.BurnInTestBoardStack.Status)
		adcpChecklist.BurnInTestSystemStatusList = getChecklistStatusList(checklist.BurnInTestSystem.Status)
		adcpChecklist.AccuracyJumperStatusList = getChecklistStatusList(checklist.AccuracyJumper.Status)
		adcpChecklist.AccuracyShortStatusList = getChecklistStatusList(checklist.AccuracyShort.Status)
		adcpChecklist.CompassCalStatusList = getChecklistStatusList(checklist.CompassCal.Status)
		adcpChecklist.BeamOrientationStatusList = getChecklistStatusList(checklist.BeamOrientation.Status)
		adcpChecklist.PressureTestSystemStatusList = getChecklistStatusList(checklist.PressureTestSystem.Status)
		adcpChecklist.Battery1StatusList = getChecklistStatusList(checklist.Battery1.Status)
		adcpChecklist.Battery2StatusList = getChecklistStatusList(checklist.Battery2.Status)

		t, _ := template.ParseFiles("header.html", "adcp_checklist_update.html", "footer.html")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", adcpChecklist)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, adcpChecklist)

	} else {
		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		fmt.Println("Update the ADCP Checklist")

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// Update the checklist in the DB
		if updateAdcpChecklistForm(formData) > 0 {
			// Go to the list of ADCP
			http.Redirect(w, r, "/adcp", http.StatusFound)
		}
	}
}
Esempio n. 15
0
// Add the SalesOrder.
func salesOrderAddHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		soData := &SalesOrderUpdate{}

		displaySalesOrderTemplate(w, soData)
	} else {
		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// Validate data
		val := formData.Validator()
		val.Require("SalesOrderNumber")

		// Use data to create a user object
		so := &SalesOrder{
			SalesOrderNumber: formData.Get("SalesOrderNumber"),
			IsSelected:       formData.GetBool("IsSelected"),
			UserName:         formData.Get("UserName"),
			SalesPerson:      formData.Get("SalesPerson"),
			POReference:      formData.Get("POReference"),
			//PODateIssued:             formData.get("PODateIssued"),
			//PODateReceived:           formData.Get("PODateReceived"),
			//DueDate:                  formData.Get("DueDate"),
			//EstShipDate:              formData.Get("EstShipDate"),
			Qty:                      formData.GetInt("Qty"),
			UnitPrice:                formData.Get("UnitPrice"),
			TotalPrice:               formData.Get("TotalPrice"),
			EUS:                      formData.Get("EUS"),
			BuildStatusPurchase:      formData.Get("BuildStatusPurchase"),
			BuildStatusPurchaseNotes: formData.Get("BuildStatusPurchaseNotes"),
			BuildStatusXdcr:          formData.Get("BuildStatusXdcr"),
			BuildStatusXdcrNotes:     formData.Get("BuildStatusXdcrNotes"),
			BuildStatusAssembly:      formData.Get("BuildStatusAssembly"),
			BuildStatusAssemblyNotes: formData.Get("BuildStatusAssemblyNotes"),
			BuildStatusTesting:       formData.Get("BuildStatusTesting"),
			BuildStatusTestingNotes:  formData.Get("BuildStatusTestingNotes"),
			//DateShiped:               formData.Get("DateShiped"),
			SerialNumber: formData.Get("SerialNumber"),
			//DeliveryDate:             formData.Get("DeliveryDate"),
			Region:              formData.Get("Region"),
			BeamAngle:           formData.Get("BeamAngle"),
			ElectronicsType:     formData.Get("ElectronicsType"),
			BatteryType:         formData.Get("BatteryType"),
			NumBattery:          formData.GetInt("NumBattery"),
			ExternalBatteryPack: formData.Get("ExternalBatteryPack"),
			CableLength:         formData.Get("CableLength"),
			InternalMemory:      formData.Get("InternalMemory"),
			InternalCompass:     formData.Get("InternalCompass"),
			DeckBox:             formData.Get("DeckBox"),
			PulseVersion:        formData.Get("PulseVersion"),
			UserVersion:         formData.Get("UserVersion"),
			ThirdParty:          formData.Get("ThirdParty"),
			Notes:               formData.Get("Notes"),
			Created:             time.Now().Local(),
		}

		// Add the SalesOrders to the DB
		err = Vault.Mongo.C("SalesOrders").Insert(so)
		CheckError(err)

		// Go to the list of SalesOrders
		http.Redirect(w, r, "/so", http.StatusFound)
	}
}
Esempio n. 16
0
// Add the Water Test.
func watertestAddHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Printf("method watertestAddHandler: %s\n", r.Method) // get request method
	if r.Method == "GET" {
		wtData := &WaterTestUpdate{}

		displayWaterTestTemplate(w, wtData)
	} else {
		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// Validate data
		val := formData.Validator()
		val.Require("SerialNumber")

		// Use data to create a WaterTestResults
		wt := &WaterTestResults{
			SerialNumber:              formData.Get("SerialNumber"),
			TestOrientation:           formData.GetInt("TestOrientation"),
			Beam0NoiseFloor:           formData.GetFloat("Beam0NoiseFloor"),
			Beam1NoiseFloor:           formData.GetFloat("Beam1NoiseFloor"),
			Beam2NoiseFloor:           formData.GetFloat("Beam2NoiseFloor"),
			Beam3NoiseFloor:           formData.GetFloat("Beam3NoiseFloor"),
			Beam0SignalLake:           formData.GetFloat("Beam0SignalLake"),
			Beam1SignalLake:           formData.GetFloat("Beam1SignalLake"),
			Beam2SignalLake:           formData.GetFloat("Beam2SignalLake"),
			Beam3SignalLake:           formData.GetFloat("Beam3SignalLake"),
			Beam0SignalOcean:          formData.GetFloat("Beam0SignalOcean"),
			Beam1SignalOcean:          formData.GetFloat("Beam1SignalOcean"),
			Beam2SignalOcean:          formData.GetFloat("Beam2SignalOcean"),
			Beam3SignalOcean:          formData.GetFloat("Beam3SignalOcean"),
			Beam0SnrLake:              formData.GetFloat("Beam0SnrLake"),
			Beam1SnrLake:              formData.GetFloat("Beam1SnrLake"),
			Beam2SnrLake:              formData.GetFloat("Beam2SnrLake"),
			Beam3SnrLake:              formData.GetFloat("Beam3SnrLake"),
			Beam0SnrOcean:             formData.GetFloat("Beam0SnrOcean"),
			Beam1SnrOcean:             formData.GetFloat("Beam1SnrOcean"),
			Beam2SnrOcean:             formData.GetFloat("Beam2SnrOcean"),
			Beam3SnrOcean:             formData.GetFloat("Beam3SnrOcean"),
			GpsDistance:               formData.Get("GpsDistance"),
			GpsDirection:              formData.Get("GpsDirection"),
			BtDistance:                formData.Get("BtDistance"),
			BtDirection:               formData.Get("BtDirection"),
			DistanceError:             formData.Get("DistanceError"),
			DirectionError:            formData.Get("DirectionError"),
			ProfileRangeBeam0:         formData.GetFloat("ProfileRangeBeam0"),
			ProfileRangeBeam1:         formData.GetFloat("ProfileRangeBeam1"),
			ProfileRangeBeam2:         formData.GetFloat("ProfileRangeBeam2"),
			ProfileRangeBeam3:         formData.GetFloat("ProfileRangeBeam3"),
			GlitchCountBeam0:          formData.GetFloat("GlitchCountBeam0"),
			GlitchCountBeam1:          formData.GetFloat("GlitchCountBeam1"),
			GlitchCountBeam2:          formData.GetFloat("GlitchCountBeam2"),
			GlitchCountBeam3:          formData.GetFloat("GlitchCountBeam3"),
			BottomTrackAmplitudeBeam0: formData.GetFloat("BottomTrackAmplitudeBeam0"),
			BottomTrackAmplitudeBeam1: formData.GetFloat("BottomTrackAmplitudeBeam1"),
			BottomTrackAmplitudeBeam2: formData.GetFloat("BottomTrackAmplitudeBeam2"),
			BottomTrackAmplitudeBeam3: formData.GetFloat("BottomTrackAmplitudeBeam3"),
			PlotReport:                formData.Get("PlotReport"),
			Notes:                     formData.Get("Notes"),
			Created:                   time.Now().Local(),
		}

		// Add the WaterTestResults to the DB
		err = Vault.Mongo.C("WaterTestResults").Insert(wt)
		CheckError(err)

		// Go to the list of WaterTests
		http.Redirect(w, r, "/adcp/wt", http.StatusFound)
	}
}
Esempio n. 17
0
// Add the Product.
func adcpChecklistAddHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		// Display blank form
		data := &AdcpChecklistUpdate{}
		displayAdcpChecklistAddTemplate(w, data)
	} else {
		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// Validate data
		val := formData.Validator()
		val.Require("SerialNumber")

		// Use data to create a user object
		adcp := &AdcpChecklist{
			SerialNumber: formData.Get("SerialNumber"),
			Modified:     time.Now().Local(),
			Created:      time.Now().Local(),
		}
		oring := &CheckListItem{
			Status: formData.Get("OringStatus"),
			Date:   formData.Get("OringDate"),
			User:   formData.Get("OringUser"),
		}
		adcp.Oring = *oring

		urethane := &CheckListItem{
			Status: formData.Get("UrethaneStatus"),
			Date:   formData.Get("UrethaneDate"),
			User:   formData.Get("UrethaneUser"),
		}
		adcp.Urethane = *urethane

		standoff := &CheckListItem{
			Status: formData.Get("StandoffsStatus"),
			Date:   formData.Get("StandoffsDate"),
			User:   formData.Get("StandoffsUser"),
		}
		adcp.Standoffs = *standoff

		screws := &CheckListItem{
			Status: formData.Get("ScrewsStatus"),
			Date:   formData.Get("ScrewsDate"),
			User:   formData.Get("ScrewsUser"),
		}
		adcp.Screws = *screws

		notch := &CheckListItem{
			Status: formData.Get("NotchStatus"),
			Date:   formData.Get("NotchDate"),
			User:   formData.Get("NotchUser"),
		}
		adcp.Notch = *notch

		photoBoardStack := &CheckListItem{
			Status: formData.Get("PhotoBoardStackStatus"),
			Date:   formData.Get("PhotoBoardStackDate"),
			User:   formData.Get("PhotoBoardStackUser"),
		}
		adcp.PhotoBoardStack = *photoBoardStack

		firmware := &CheckListItem{
			Status: formData.Get("FirmwareStatus"),
			Date:   formData.Get("FirmwareDate"),
			User:   formData.Get("FirmwareUser"),
		}
		adcp.Firmware = *firmware
		adcp.FirmwareVersion = formData.Get("FirmwareVersion")

		finalCheckLake := &CheckListItem{
			Status: formData.Get("FinalCheckLakeStatus"),
			Date:   formData.Get("FinalCheckLakeDate"),
			User:   formData.Get("FinalCheckLakeUser"),
		}
		adcp.FinalCheckLake = *finalCheckLake

		finalCheckShipping := &CheckListItem{
			Status: formData.Get("FinalCheckShippingStatus"),
			Date:   formData.Get("FinalCheckShippingDate"),
			User:   formData.Get("FinalCheckShippingUser"),
		}
		adcp.FinalCheckShipping = *finalCheckShipping

		beamWires := &CheckListItem{
			Status: formData.Get("BeamWiresStatus"),
			Date:   formData.Get("BeamWiresDate"),
			User:   formData.Get("BeamWiresUser"),
		}
		adcp.BeamWires = *beamWires

		thermistorStranded := &CheckListItem{
			Status: formData.Get("ThermistorStrandedStatus"),
			Date:   formData.Get("ThermistorStrandedDate"),
			User:   formData.Get("ThermistorStrandedUser"),
		}
		adcp.ThermistorStranded = *thermistorStranded

		temperature := &CheckListItem{
			Status: formData.Get("TemperatureStatus"),
			Date:   formData.Get("TemperatureDate"),
			User:   formData.Get("TemperatureUser"),
		}
		adcp.Temperature = *temperature

		pressure := &CheckListItem{
			Status: formData.Get("PressureStatus"),
			Date:   formData.Get("PressureDate"),
			User:   formData.Get("PressureUser"),
		}
		adcp.Pressure = *pressure
		adcp.PressureSensorSize = formData.Get("PressureSensorSize")

		vaccumTest := &CheckListItem{
			Status: formData.Get("VaccumTestStatus"),
			Date:   formData.Get("VaccumTestDate"),
			User:   formData.Get("VaccumTestUser"),
		}
		adcp.VaccumTest = *vaccumTest

		vibeTest := &CheckListItem{
			Status: formData.Get("VibeTestStatus"),
			Date:   formData.Get("VibeTestDate"),
			User:   formData.Get("VibeTestUser"),
		}
		adcp.VibeTest = *vibeTest

		lakeTest := &CheckListItem{
			Status: formData.Get("LakeTestStatus"),
			Date:   formData.Get("LakeTestDate"),
			User:   formData.Get("LakeTestUser"),
		}
		adcp.LakeTest = *lakeTest

		reviewLakeTestData := &CheckListItem{
			Status: formData.Get("ReviewLakeTestDataStatus"),
			Date:   formData.Get("ReviewLakeTestDataDate"),
			User:   formData.Get("ReviewLakeTestDataUser"),
		}
		adcp.ReviewLakeTestData = *reviewLakeTestData
		adcp.ReviewLakeTestNotes = formData.Get("ReviewLakeTestNotes")

		tankTest := &CheckListItem{
			Status: formData.Get("TankTestStatus"),
			Date:   formData.Get("TankTestDate"),
			User:   formData.Get("TankTestUser"),
		}
		adcp.TankTest = *tankTest

		reviewTankTestData := &CheckListItem{
			Status: formData.Get("ReviewTankTestDataStatus"),
			Date:   formData.Get("ReviewTankTestDataDate"),
			User:   formData.Get("ReviewTankTestDataUser"),
		}
		adcp.ReviewTankTestData = *reviewTankTestData
		adcp.ReviewTankTestNotes = formData.Get("ReviewTankTestNotes")

		burnInTestBoardStack := &CheckListItem{
			Status: formData.Get("BurnInTestBoardStackStatus"),
			Date:   formData.Get("BurnInTestBoardStackDate"),
			User:   formData.Get("BurnInTestBoardStackUser"),
		}
		adcp.BurnInTestBoardStack = *burnInTestBoardStack

		burnInTestSystem := &CheckListItem{
			Status: formData.Get("BurnInTestSystemStatus"),
			Date:   formData.Get("BurnInTestSystemDate"),
			User:   formData.Get("BurnInTestSystemUser"),
		}
		adcp.BurnInTestSystem = *burnInTestSystem

		accuracyShort := &CheckListItem{
			Status: formData.Get("AccuracyShortStatus"),
			Date:   formData.Get("AccuracyShortDate"),
			User:   formData.Get("AccuracyShortUser"),
		}
		adcp.AccuracyShort = *accuracyShort

		accuracyJumper := &CheckListItem{
			Status: formData.Get("AccuracyJumperStatus"),
			Date:   formData.Get("AccuracyJumperDate"),
			User:   formData.Get("AccuracyJumperUser"),
		}
		adcp.AccuracyJumper = *accuracyJumper

		compassCal := &CheckListItem{
			Status: formData.Get("CompassCalStatus"),
			Date:   formData.Get("CompassCalDate"),
			User:   formData.Get("CompassCalUser"),
		}
		adcp.CompassCal = *compassCal

		beamOrientation := &CheckListItem{
			Status: formData.Get("BeamOrientationStatus"),
			Date:   formData.Get("BeamOrientationDate"),
			User:   formData.Get("BeamOrientationUser"),
		}
		adcp.BeamOrientation = *beamOrientation

		pressureTestSystem := &CheckListItem{
			Status: formData.Get("PressureTestSystemStatus"),
			Date:   formData.Get("PressureTestSystemDate"),
			User:   formData.Get("PressureTestSystemUser"),
		}
		adcp.PressureTestSystem = *pressureTestSystem

		battery1 := &CheckListItem{
			Status: formData.Get("Battery1Status"),
			Date:   formData.Get("Battery1Date"),
			User:   formData.Get("Battery1User"),
		}
		adcp.Battery1 = *battery1
		adcp.Battery1Voltage = formData.Get("Battery1Voltage")
		adcp.Battery1LoadVoltage = formData.Get("Battery1LoadVoltage")
		adcp.Battery1LotNum = formData.Get("Battery1LotNum")
		adcp.Battery1PartNum = formData.Get("Battery1PartNum")
		adcp.Battery1Rev = formData.Get("Battery1Rev")
		adcp.Battery1SerialNumber = formData.Get("Battery1SerialNumber")

		battery2 := &CheckListItem{
			Status: formData.Get("Battery2Status"),
			Date:   formData.Get("Battery2Date"),
			User:   formData.Get("Battery2User"),
		}
		adcp.Battery2 = *battery2
		adcp.Battery2Voltage = formData.Get("Battery2Voltage")
		adcp.Battery2LoadVoltage = formData.Get("Battery2LoadVoltage")
		adcp.Battery2LotNum = formData.Get("Battery2LotNum")
		adcp.Battery2PartNum = formData.Get("Battery2PartNum")
		adcp.Battery2Rev = formData.Get("Battery2Rev")
		adcp.Battery2SerialNumber = formData.Get("Battery2SerialNumber")

		checklist := AdcpChecklistUpdate{}
		checklist.ADCP = *adcp

		// Add the Products to the DB
		err = Vault.Mongo.C("AdcpChecklist").Insert(checklist)
		CheckError(err)

		// Go to the list of products
		http.Redirect(w, r, "/adcp", http.StatusFound)
	}
}
Esempio n. 18
0
// Update the RMA.
func rmaUpdateHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {

		// Get the value of the "id" parameters.
		rmaNum := bone.GetValue(r, "id")
		rma := getRma(rmaNum)
		rmaData := &RmaUpdate{}
		rmaData.RMA = *rma
		rmaData.ProductList = *getProductList()
		rmaData.StatusList = getStatusList(rma.Status)
		rmaData.BillableList = getBillableList(rma.Billable)
		rmaData.RmaTypeList = getRmaTypeList(rma.RmaType)

		if len(rmaData.RMA.Notes) > 50000 {
			rmaData.RMA.Notes = rmaData.RMA.Notes[0:50000]
		}

		displayRmaUpdateTemplate(w, rmaData)
	} else {
		fmt.Printf("Request: %v", r)

		// Parse the form
		formData, err := forms.Parse(r)
		CheckError(err)

		fmt.Printf("Button clicked: %s\n", formData.Get("SubmitButton"))
		fmt.Printf("Selected Product: %s\n", bson.ObjectId(formData.Get("AddProduct")))
		//fmt.Printf("Selected Product: %s\n", formData.Get("AddProduct"))

		// Check token
		token := r.Form.Get("token")
		if token != "" {
			// check token validity
			fmt.Println("Good token")
		} else {
			// give error if no token
			fmt.Println("Bad token")
		}

		// Validate data
		val := formData.Validator()
		val.Require("RmaNumber")

		fmt.Printf("FormData %v\n", formData)

		// Use data to create a user object
		rma := getRma(formData.Get("OriginalRmaNumber"))
		fmt.Printf("Set RMA %s Orignal RMA Num %s\n", formData.Get("RmaNumber"), formData.Get("OriginalRmaNumber"))
		rma.RmaNumber = formData.Get("RmaNumber")
		rma.RmaType = formData.Get("RmaType")
		rma.OrigSalesOrder = formData.Get("OrigSalesOrder")
		rma.Company = formData.Get("Company")
		rma.ContactName = formData.Get("ContactName")
		rma.ContactEmail = formData.Get("ContactEmail")
		rma.ContactPhone = formData.Get("ContactPhone")
		rma.ContactAddress = formData.Get("ContactAddress")
		rma.ContactAddress2 = formData.Get("ContactAddress2")
		rma.ContactAddressCityStateZip = formData.Get("ContactAddressCityStateZip")
		rma.ContactAddressCountry = formData.Get("ContactAddressCountry")
		rma.ProductDesc = formData.Get("ProductDesc")
		rma.ReasonReturn = formData.Get("ReasonReturn")
		rma.ReturnCompany = formData.Get("ReturnCompany")
		rma.ReturnContact = formData.Get("ReturnContact")
		rma.ReturnAddress = formData.Get("ReturnAddress")
		rma.ReturnAddressCont = formData.Get("ReturnAddressCont")
		rma.ReturnAddressCityStateZip = formData.Get("ReturnAddressCityStateZip")
		rma.ReturnAddressCountry = formData.Get("ReturnAddressCountry")
		rma.ReturnPhone = formData.Get("ReturnPhone")
		rma.ReturnEmail = formData.Get("ReturnEmail")
		rma.ReceiveInfo = formData.Get("ReceiveInfo")
		rma.ReceiveUser = formData.Get("ReceiveUser")
		rma.InspectionInfo = formData.Get("InspectionInfo")
		rma.InspectionUser = formData.Get("InspectionUser")
		rma.RepairInfo = formData.Get("RepairInfo")
		rma.RepairUser = formData.Get("RepairUser")
		rma.RepairEstHours = formData.GetInt("RepairEstHours")
		rma.Billable = formData.Get("Billable")
		rma.QuoteNum = formData.Get("QuoteNum")
		rma.OriginalRmaNum = formData.Get("OriginalRmaNum")
		rma.SerialNumber = formData.Get("SerialNumber")
		rma.Notes = formData.Get("Notes")
		rma.Modified = time.Now().Local()
		rma.InspectionDate = formData.Get("InspectionDate")
		rma.ReceiveDate = formData.Get("ReceiveDate")
		rma.RepairDate = formData.Get("RepairDate")
		rma.RmaDate = formData.Get("RmaDate")
		rma.ShipDate = formData.Get("ShipDate")
		rma.Status = formData.Get("Status")

		// Accumulate the Products
		for i := range rma.Products {
			rma.Products[i].PartNumber = r.Form["ProductPartNumber"][i]
			rma.Products[i].SerialNumber = r.Form["ProductSerialNumber"][i]

			qty, err := strconv.Atoi(r.Form["ProductQty"][i])
			if err == nil {
				rma.Products[i].Qty = qty
			}
		}

		// Accumulate the RepairProducts
		for i := range rma.RepairProducts {
			rma.RepairProducts[i].PartNumber = r.Form["ProductPartNumber"][i]
			rma.RepairProducts[i].SerialNumber = r.Form["ProductSerialNumber"][i]

			qty, err := strconv.Atoi(r.Form["ProductQty"][i])
			if err == nil {
				rma.RepairProducts[i].Qty = qty
			}
		}

		// Add the new product to the RMA
		if formData.Get("SubmitButton") == "ADD" {
			fmt.Printf("Add product to RMA: %s\n", rma.RmaNumber)
			//
			// // Add the product to the list
			// rmaProduct := &RmaProduct{}
			// rmaProduct.PartNumber = formData.Get("AddProductPartNumber")
			// rmaProduct.Qty = formData.GetInt("AddProductQty")
			// rmaProduct.SerialNumber = formData.Get("AddProductSerialNumber")
			// product := getProductPartNumber(rmaProduct.PartNumber)
			// if product != nil {
			// 	rma.Products = append(rma.Products, *rmaProduct)
			// }
			// // Update the RMA in DB
			// updateRma(rma)
			addRmaProduct(formData.Get("AddProductPartNumber"),
				formData.GetInt("AddProductQty"),
				formData.Get("AddProductSerialNumber"),
				rma)

			// Go back to the update page
			http.Redirect(w, r, "/rma/update/"+rma.RmaNumber, http.StatusFound)
		} else if formData.Get("SubmitButton") == "ADD REPAIR" {
			fmt.Printf("Add Repair product to RMA: %s\n", rma.RmaNumber)
			//
			// Add the repair to the list
			addRmaRepairProduct(formData.Get("AddRepairProductPartNumber"),
				formData.GetInt("AddRepairProductQty"),
				formData.Get("AddRepairProductSerialNumber"),
				rma)

			// Go back to the update page
			http.Redirect(w, r, "/rma/update/"+rma.RmaNumber, http.StatusFound)
		} else {

			fmt.Printf("RMA Update: %s\n", rma.RmaNumber)

			// Update the RMA in DB
			updateRma(rma)

			// Go to the list of RMA
			http.Redirect(w, r, "/rma", http.StatusFound)
		}

	}
}