Allow users update their tax details
This commit is contained in:
parent
798289bc8e
commit
57d5137913
|
@ -29,8 +29,8 @@ create table company (
|
|||
created_at timestamptz not null default current_timestamp
|
||||
);
|
||||
|
||||
grant select on table company to invoicer;
|
||||
grant select on table company to admin;
|
||||
grant select, update on table company to invoicer;
|
||||
grant select, update on table company to admin;
|
||||
|
||||
|
||||
commit;
|
||||
|
|
|
@ -88,12 +88,29 @@ func CompanyTaxDetailsHandler() http.Handler {
|
|||
}
|
||||
company := mustGetCompany(r)
|
||||
conn := getConn(r)
|
||||
err := conn.QueryRow(r.Context(), "select business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country from company where company_id = $1", company.Id).Scan(&page.BusinessName, &page.VATIN, &page.TradeName, &page.Phone, &page.Email, &page.Web, &page.Address, &page.City, &page.Province, &page.PostalCode, &page.Country);
|
||||
if r.Method == "POST" {
|
||||
r.ParseForm()
|
||||
page.BusinessName = r.FormValue("business_name")
|
||||
page.VATIN = r.FormValue("vatin")
|
||||
page.TradeName = r.FormValue("trade_name")
|
||||
page.Phone = r.FormValue("phone")
|
||||
page.Email = r.FormValue("email")
|
||||
page.Web = r.FormValue("web")
|
||||
page.Address = r.FormValue("address")
|
||||
page.City = r.FormValue("city")
|
||||
page.Province = r.FormValue("province")
|
||||
page.PostalCode = r.FormValue("postal_code")
|
||||
page.Country = r.FormValue("country")
|
||||
conn.MustExec(r.Context(), "update company set business_name = $1, vatin = $2, trade_name = $3, phone = $4, email = $5, web = $6, address = $7, city = $8, province = $9, postal_code = $10, country = $11 where company_id = $12", page.BusinessName, page.VATIN, page.TradeName, page.Phone, page.Email, page.Web, page.Address, page.City, page.Province, page.PostalCode, page.Country, company.Id)
|
||||
http.Redirect(w, r, "/company/"+company.Slug+"/tax-details", http.StatusSeeOther)
|
||||
} else {
|
||||
err := conn.QueryRow(r.Context(), "select business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country from company where company_id = $1", company.Id).Scan(&page.BusinessName, &page.VATIN, &page.TradeName, &page.Phone, &page.Email, &page.Web, &page.Address, &page.City, &page.Province, &page.PostalCode, &page.Country)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
mustRenderAppTemplate(w, r, "tax-details.html", page)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
func mustGetCompany(r *http.Request) *Company {
|
||||
|
@ -101,5 +118,5 @@ func mustGetCompany(r *http.Request) *Company {
|
|||
if company == nil {
|
||||
panic(errors.New("company: required but not found"))
|
||||
}
|
||||
return company;
|
||||
return company
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ set search_path to numerus, auth, public;
|
|||
select has_table('company');
|
||||
select has_pk('company');
|
||||
select table_privs_are('company', 'guest', array []::text[]);
|
||||
select table_privs_are('company', 'invoicer', array ['SELECT']);
|
||||
select table_privs_are('company', 'admin', array ['SELECT']);
|
||||
select table_privs_are('company', 'invoicer', array ['SELECT', 'UPDATE']);
|
||||
select table_privs_are('company', 'admin', array ['SELECT', 'UPDATE']);
|
||||
select table_privs_are('company', 'authenticator', array []::text[]);
|
||||
|
||||
select has_column('company', 'company_id');
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
<input type="text" name="country" id="country" required="required" value="{{ .Country }}" placeholder="{{( pgettext "Country" "input" )}}">
|
||||
<label for="country">{{( pgettext "Country" "input" )}}</label>
|
||||
</div>
|
||||
<button type="submit">{{( pgettext "Save changes" "action" )}}</button>
|
||||
</form>
|
||||
</section>
|
||||
{{- end }}
|
||||
|
|
Loading…
Reference in New Issue