Exemple #1
0
// Modifica si hay, Crea si no hay
// Requiere IdEmp. IdSuc es opcional, si no hay lo crea, si hay modifica
func SucMod(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	c.Errorf("R-EMP: %v", r.FormValue("IdEmp"))
	if s, ok := sess.IsSess(w, r, c); ok {
		u, _ := model.GetCta(c, s.User)
		tc := make(map[string]interface{})
		tc["Sess"] = s
		fd, valid := sucForm(w, r, true)
		empresa, err := u.GetEmpresa(c, r.FormValue("IdEmp"))
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		sucursal := sucFill(r)
		if valid {
			if empresa != nil {
				newsuc, err := empresa.PutSuc(c, u, &sucursal, r.FormValue("IdEmp"))
				//fmt.Fprintf(w, "IdSuc: %s", newsuc.IdSuc);
				if err != nil {
					http.Error(w, err.Error(), http.StatusInternalServerError)
					return
				}
				fd = sucToForm(*newsuc)
				fd.Ackn = "Ok"
			}
		}
		fd.Entidades = model.ListEnt(c, strings.TrimSpace(r.FormValue("DirEnt")))
		tc["Empresa"] = empresa
		tc["FormDataSuc"] = fd
		sucadmTpl.ExecuteTemplate(w, "sucursal", tc)
	} else {
		http.Redirect(w, r, "/r/registro", http.StatusFound)
	}
}
Exemple #2
0
func formEmp(c appengine.Context, w http.ResponseWriter, s *sess.Sess, e *model.Empresa) {
	fd := empresaToForm(*e)
	fd.Entidades = model.ListEnt(c, e.DirEnt)
	fd.Organismos = ListOrg(c, e.OrgEmp)
	tc := make(map[string]interface{})
	tc["Sess"] = s
	tc["FormDataEmp"] = fd
	empadmTpl.ExecuteTemplate(w, "empresa", tc)
	return
}
Exemple #3
0
func SucShow(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	if s, ok := sess.IsSess(w, r, c); ok {
		u, _ := model.GetCta(c, s.User)
		tc := make(map[string]interface{})
		tc["Sess"] = s
		empresa, err := u.GetEmpresa(c, r.FormValue("IdEmp"))
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		sucursal := model.GetSuc(c, u, r.FormValue("IdSuc"), r.FormValue("IdEmp"))
		if sucursal == nil {
			sucursal.IdEmp = empresa.IdEmp
		}
		tc["Empresa"] = empresa
		fd := sucToForm(*sucursal)
		fd.Entidades = model.ListEnt(c, sucursal.DirEnt)
		tc["FormDataSuc"] = fd
		sucadmTpl.ExecuteTemplate(w, "sucursal", tc)
	} else {
		http.Redirect(w, r, "/r/registro", http.StatusFound)
	}
}
Exemple #4
0
func formatoEmp(w http.ResponseWriter, r *http.Request, s sess.Sess, valida bool) (FormDataEmp, bool) {
	c := appengine.NewContext(r)
	filter := strings.NewReplacer("\n", " ", "\r", " ", "\t", " ")
	partlinea, _ := strconv.Atoi(r.FormValue("PartLinea"))
	expcomer, _ := strconv.Atoi(r.FormValue("ExpComer"))
	fd := FormDataEmp{
		IdEmp:         strings.TrimSpace(r.FormValue("IdEmp")),
		RFC:           strings.TrimSpace(r.FormValue("RFC")),
		ErrRFC:        "",
		Nombre:        strings.TrimSpace(r.FormValue("Nombre")),
		ErrNombre:     "",
		RazonSoc:      strings.TrimSpace(r.FormValue("RazonSoc")),
		ErrRazonSoc:   "",
		DirCalle:      strings.TrimSpace(r.FormValue("DirCalle")),
		ErrDirCalle:   "",
		DirCol:        strings.TrimSpace(r.FormValue("DirCol")),
		ErrDirCol:     "",
		DirEnt:        strings.TrimSpace(r.FormValue("DirEnt")),
		ErrDirEnt:     "",
		DirMun:        strings.TrimSpace(r.FormValue("DirMun")),
		ErrDirMun:     "",
		DirCp:         strings.TrimSpace(r.FormValue("DirCp")),
		ErrDirCp:      "",
		NumSuc:        strings.TrimSpace(r.FormValue("NumSuc")),
		ErrNumSuc:     "",
		OrgEmp:        strings.TrimSpace(r.FormValue("OrgEmp")),
		ErrOrgEmp:     "",
		OrgEmpOtro:    strings.TrimSpace(r.FormValue("OrgEmpOtro")),
		ErrOrgEmpOtro: "",
		OrgEmpReg:     strings.TrimSpace(r.FormValue("OrgEmpReg")),
		ErrOrgEmpReg:  "",
		Url:           strings.TrimSpace(r.FormValue("Url")),
		ErrUrl:        "",
		PartLinea:     partlinea,
		ExpComer:      expcomer,
		Desc:          strings.TrimSpace(filter.Replace(r.FormValue("Desc"))),
	}
	if valida {
		var ef bool
		ef = false
		if fd.RFC == "" || !model.ValidRfc.MatchString(fd.RFC) {
			fd.ErrRFC = "invalid"
			ef = true
		}
		if fd.Nombre == "" || !model.ValidSimpleText.MatchString(fd.Nombre) {
			fd.ErrNombre = "invalid"
			ef = true
		}
		if fd.RazonSoc == "" || !model.ValidSimpleText.MatchString(fd.RazonSoc) {
			fd.ErrRazonSoc = "invalid"
			ef = true
		}
		if fd.DirEnt == "" || !model.ValidSimpleText.MatchString(fd.DirEnt) {
			fd.ErrDirEnt = "invalid"
			ef = true
		}
		if fd.DirMun == "" || !model.ValidSimpleText.MatchString(fd.DirMun) {
			fd.ErrDirMun = "invalid"
			ef = true
		}
		if fd.DirCalle == "" || !model.ValidSimpleText.MatchString(fd.DirCalle) {
			fd.ErrDirCalle = "invalid"
			ef = true
		}
		if fd.DirCol == "" || !model.ValidSimpleText.MatchString(fd.DirCol) {
			fd.ErrDirCol = "invalid"
			ef = true
		}
		if fd.DirCp == "" || !model.ValidCP.MatchString(fd.DirCp) {
			fd.ErrDirCp = "invalid"
			ef = true
		}
		if fd.NumSuc != "" && !model.ValidNum.MatchString(fd.NumSuc) {
			fd.ErrNumSuc = "invalid"
			ef = true
		}
		if fd.OrgEmp != "" && !model.ValidSimpleText.MatchString(fd.OrgEmp) {
			fd.ErrOrgEmp = "invalid"
			ef = true
		}
		if fd.OrgEmpOtro != "" && !model.ValidSimpleText.MatchString(fd.OrgEmpOtro) {
			fd.ErrOrgEmpOtro = "invalid"
			ef = true
		}
		if fd.OrgEmpReg != "" && !model.ValidSimpleText.MatchString(fd.OrgEmpReg) {
			fd.ErrOrgEmpReg = "invalid"
			ef = true
		}
		if fd.Url != "" && !model.ValidUrl.MatchString(fd.Url) {
			fd.ErrUrl = "invalid"
			ef = true
		}
		/*
			if fd.Desc != "" && !validSimpleText.MatchString(fd.Desc) {
				fd.ErrDesc = "invalid"
				ef = true
			}
		*/

		if ef {
			fd.Entidades = model.ListEnt(c, strings.TrimSpace(r.FormValue("DirEnt")))
			fd.Organismos = ListOrg(c, fd.OrgEmp)
			tc := make(map[string]interface{})
			tc["Sess"] = s
			tc["FormDataEmp"] = fd
			empadmTpl.ExecuteTemplate(w, "empresa", tc)
			return fd, false
		}
	}
	return fd, true
}