Added in house invoice numbering to database triggers IO-460

This commit is contained in:
Patrick Fic
2020-12-23 08:44:18 -08:00
parent a0d90d2b1f
commit c8532f668b
31 changed files with 354 additions and 3 deletions

View File

@@ -117,13 +117,14 @@ export function PartsOrderModalContainer({
let invoiceToPost = {
vendorid: bodyshop.inhousevendorid,
isinhouse: true,
jobid: jobId,
total: 0,
invoice_number: `${jobId}`,
invoice_number: "ih",
federal_tax_rate: bodyshop.bill_tax_rates.federal_tax_rate || 0,
state_tax_rate: bodyshop.bill_tax_rates.state_tax_rate || 0,
local_tax_rate: bodyshop.bill_tax_rates.local_tax_rate || 0,
invoicelines: {
billlines: {
data: values.parts_order_lines.data.map((p) => {
return {
joblineid: p.job_line_id,

View File

@@ -1,2 +1,2 @@
endpoint: https://bodyshop-dev-db.herokuapp.com
#endpoint: https://db.imex.online
admin_secret: Dev-BodyShopAppBySnaptSoftware!

View File

@@ -0,0 +1,5 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."bills" DROP COLUMN "isinhouse";
type: run_sql

View File

@@ -0,0 +1,6 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."bills" ADD COLUMN "isinhouse" boolean NOT NULL DEFAULT
false;
type: run_sql

View File

@@ -0,0 +1,40 @@
- args:
role: user
table:
name: bills
schema: public
type: drop_insert_permission
- args:
permission:
check:
job:
bodyshop:
associations:
_and:
- user:
authid:
_eq: X-Hasura-User-Id
- active:
_eq: true
columns:
- created_at
- date
- due_date
- exported
- exported_at
- federal_tax_rate
- id
- invoice_number
- is_credit_memo
- jobid
- local_tax_rate
- state_tax_rate
- total
- updated_at
- vendorid
set: {}
role: user
table:
name: bills
schema: public
type: create_insert_permission

View File

@@ -0,0 +1,41 @@
- args:
role: user
table:
name: bills
schema: public
type: drop_insert_permission
- args:
permission:
check:
job:
bodyshop:
associations:
_and:
- user:
authid:
_eq: X-Hasura-User-Id
- active:
_eq: true
columns:
- created_at
- date
- due_date
- exported
- exported_at
- federal_tax_rate
- id
- invoice_number
- is_credit_memo
- isinhouse
- jobid
- local_tax_rate
- state_tax_rate
- total
- updated_at
- vendorid
set: {}
role: user
table:
name: bills
schema: public
type: create_insert_permission

View File

@@ -0,0 +1,41 @@
- args:
role: user
table:
name: bills
schema: public
type: drop_select_permission
- args:
permission:
allow_aggregations: true
columns:
- created_at
- date
- due_date
- exported
- exported_at
- federal_tax_rate
- id
- invoice_number
- is_credit_memo
- jobid
- local_tax_rate
- state_tax_rate
- total
- updated_at
- vendorid
computed_fields: []
filter:
job:
bodyshop:
associations:
_and:
- user:
authid:
_eq: X-Hasura-User-Id
- active:
_eq: true
role: user
table:
name: bills
schema: public
type: create_select_permission

View File

@@ -0,0 +1,42 @@
- args:
role: user
table:
name: bills
schema: public
type: drop_select_permission
- args:
permission:
allow_aggregations: true
columns:
- created_at
- date
- due_date
- exported
- exported_at
- federal_tax_rate
- id
- invoice_number
- is_credit_memo
- isinhouse
- jobid
- local_tax_rate
- state_tax_rate
- total
- updated_at
- vendorid
computed_fields: []
filter:
job:
bodyshop:
associations:
_and:
- user:
authid:
_eq: X-Hasura-User-Id
- active:
_eq: true
role: user
table:
name: bills
schema: public
type: create_select_permission

View File

@@ -0,0 +1,40 @@
- args:
role: user
table:
name: bills
schema: public
type: drop_update_permission
- args:
permission:
columns:
- created_at
- date
- due_date
- exported
- exported_at
- federal_tax_rate
- id
- invoice_number
- is_credit_memo
- jobid
- local_tax_rate
- state_tax_rate
- total
- updated_at
- vendorid
filter:
job:
bodyshop:
associations:
_and:
- user:
authid:
_eq: X-Hasura-User-Id
- active:
_eq: true
set: {}
role: user
table:
name: bills
schema: public
type: create_update_permission

View File

@@ -0,0 +1,41 @@
- args:
role: user
table:
name: bills
schema: public
type: drop_update_permission
- args:
permission:
columns:
- created_at
- date
- due_date
- exported
- exported_at
- federal_tax_rate
- id
- invoice_number
- is_credit_memo
- isinhouse
- jobid
- local_tax_rate
- state_tax_rate
- total
- updated_at
- vendorid
filter:
job:
bodyshop:
associations:
_and:
- user:
authid:
_eq: X-Hasura-User-Id
- active:
_eq: true
set: {}
role: user
table:
name: bills
schema: public
type: create_update_permission

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1,10 @@
- args:
cascade: true
read_only: false
sql: "CREATE OR REPLACE FUNCTION public.assign_ibh_number()\r\n RETURNS trigger\r\n
LANGUAGE plpgsql\r\nAS $function$\r\n begin\r\n IF NEW.isinhouse
= true and (new.invoice_number is null or new.invoice_number = '') THEN\r\n
\ UPDATE counters\r\n\tSET count = count + 1 where shopid=new.shopid
AND countertype = 'ihbnum'\r\n\tRETURNING concat(prefix,count) into new.invoice_number;\r\n\r\n
\ END IF;\r\n RETURN NEW;\r\n END;\r\n $function$\r\n;"
type: run_sql

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1,6 @@
- args:
cascade: true
read_only: false
sql: "create trigger bills_assign_ihb_num before\r\nupdate\r\n on\r\n public.bills
for each row execute procedure assign_ibh_number();"
type: run_sql

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1,10 @@
- args:
cascade: true
read_only: false
sql: "CREATE OR REPLACE FUNCTION public.assign_ibh_number()\r\n RETURNS trigger\r\n
LANGUAGE plpgsql\r\nAS $function$\r\n begin\r\n IF NEW.isinhouse
= true and (new.invoice_number is null or new.invoice_number = 'ih') THEN\r\n
\ UPDATE counters\r\n\tSET count = count + 1 where shopid=new.shopid
AND countertype = 'ihbnum'\r\n\tRETURNING concat(prefix,count) into new.invoice_number;\r\n\r\n
\ END IF;\r\n RETURN NEW;\r\n END;\r\n $function$\r\n;"
type: run_sql

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1,5 @@
- args:
cascade: true
read_only: false
sql: drop trigger if exists bills_assign_ihb_num on bills;
type: run_sql

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1,6 @@
- args:
cascade: true
read_only: false
sql: "create trigger bills_assign_ihbnum before\r\ninsert\r\n on\r\n public.jobs
for each row execute procedure assign_ibh_number();"
type: run_sql

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1,6 @@
- args:
cascade: true
read_only: false
sql: "create trigger bills_assign_ihbnum before\r\ninsert\r\n on\r\n public.bills
for each row execute procedure assign_ibh_number();"
type: run_sql

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1,5 @@
- args:
cascade: true
read_only: false
sql: drop trigger if exists bills_assign_ihbnum on jobs;
type: run_sql

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1,11 @@
- args:
cascade: true
read_only: false
sql: "CREATE OR REPLACE FUNCTION public.assign_ibh_number()\r\n RETURNS trigger\r\n
LANGUAGE plpgsql\r\nAS $function$\r\n begin\r\n IF NEW.isinhouse
= true and (new.invoice_number is null or new.invoice_number = '') THEN\r\n
\ UPDATE counters\r\n\tSET count = count + 1\r\n\tfrom jobs\r\n\twhere
jobs.id=new.jobid and counters.shopid = jobs.shopid AND countertype = 'ihbnum'\r\n\tRETURNING
concat(prefix,count) into new.invoice_number;\r\n\r\n END IF;\r\n RETURN
NEW;\r\n END;\r\n $function$\r\n;"
type: run_sql

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1,11 @@
- args:
cascade: true
read_only: false
sql: "CREATE OR REPLACE FUNCTION public.assign_ibh_number()\r\n RETURNS trigger\r\n
LANGUAGE plpgsql\r\nAS $function$\r\n begin\r\n IF NEW.isinhouse
= true and (new.invoice_number is null or new.invoice_number = '') THEN\r\n
\ UPDATE counters\r\n\tSET count = count + 1\r\n\tfrom bodyshops \r\n\twhere
bodyshops.id = (select shopid from jobs where jobs.id = new.jobid)\r\n\tAND
countertype = 'ihbnum'\r\n\tRETURNING concat(prefix,count) into new.invoice_number;\r\n\r\n
\ END IF;\r\n RETURN NEW;\r\n END;\r\n $function$\r\n;"
type: run_sql

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1,11 @@
- args:
cascade: true
read_only: false
sql: "CREATE OR REPLACE FUNCTION public.assign_ibh_number()\r\n RETURNS trigger\r\n
LANGUAGE plpgsql\r\nAS $function$\r\n begin\r\n IF NEW.isinhouse
= true and (new.invoice_number is null or new.invoice_number = 'ih') THEN\r\n
\ UPDATE counters\r\n\tSET count = count + 1\r\n\tfrom bodyshops \r\n\twhere
bodyshops.id = (select shopid from jobs where jobs.id = new.jobid)\r\n\tAND
countertype = 'ihbnum'\r\n\tRETURNING concat(prefix,count) into new.invoice_number;\r\n\r\n
\ END IF;\r\n RETURN NEW;\r\n END;\r\n $function$\r\n;"
type: run_sql

View File

@@ -509,6 +509,7 @@ tables:
- id
- invoice_number
- is_credit_memo
- isinhouse
- jobid
- local_tax_rate
- state_tax_rate
@@ -528,6 +529,7 @@ tables:
- id
- invoice_number
- is_credit_memo
- isinhouse
- jobid
- local_tax_rate
- state_tax_rate
@@ -558,6 +560,7 @@ tables:
- id
- invoice_number
- is_credit_memo
- isinhouse
- jobid
- local_tax_rate
- state_tax_rate