Added in house invoice numbering to database triggers IO-460
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
endpoint: https://bodyshop-dev-db.herokuapp.com
|
||||
#endpoint: https://db.imex.online
|
||||
admin_secret: Dev-BodyShopAppBySnaptSoftware!
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: ALTER TABLE "public"."bills" DROP COLUMN "isinhouse";
|
||||
type: run_sql
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
10
hasura/migrations/1608740480171_run_sql_migration/up.yaml
Normal file
10
hasura/migrations/1608740480171_run_sql_migration/up.yaml
Normal 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
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
10
hasura/migrations/1608740773551_run_sql_migration/up.yaml
Normal file
10
hasura/migrations/1608740773551_run_sql_migration/up.yaml
Normal 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
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: drop trigger if exists bills_assign_ihb_num on bills;
|
||||
type: run_sql
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: drop trigger if exists bills_assign_ihbnum on jobs;
|
||||
type: run_sql
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
11
hasura/migrations/1608741387779_run_sql_migration/up.yaml
Normal file
11
hasura/migrations/1608741387779_run_sql_migration/up.yaml
Normal 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
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
11
hasura/migrations/1608741701614_run_sql_migration/up.yaml
Normal file
11
hasura/migrations/1608741701614_run_sql_migration/up.yaml
Normal 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
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
11
hasura/migrations/1608741738380_run_sql_migration/up.yaml
Normal file
11
hasura/migrations/1608741738380_run_sql_migration/up.yaml
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user