IF (fetchMetricText('QUNumberGeneration') IN ('A','O')) THEN
--- clear the number from the issue cache
PERFORM clearNumberIssue('QuNumber', NEW.quhead_number);
IF (fetchMetricText('QUNumberGeneration') IN ('A','O')) THEN
--- clear the number from the issue cache
PERFORM clearNumberIssue('QuNumber', NEW.quhead_number);
--- clear the number from the issue cache
PERFORM clearNumberIssue('SoNumber', NEW.quhead_number);
END IF;
--- clear the number from the issue cache
PERFORM clearNumberIssue('SoNumber', NEW.quhead_number);
END IF;
IF (FOUND) THEN
NEW.quhead_warehous_id := COALESCE(NEW.quhead_warehous_id,_w.warehous_id);
NEW.quhead_fob := COALESCE(NEW.quhead_fob,_w.warehous_fob);
END IF;
END IF;
END IF;
IF (FOUND) THEN
NEW.quhead_warehous_id := COALESCE(NEW.quhead_warehous_id,_w.warehous_id);
NEW.quhead_fob := COALESCE(NEW.quhead_fob,_w.warehous_fob);
END IF;
END IF;
END IF;
--Auto create project if applicable
IF ((TG_OP = 'INSERT') AND (COALESCE(NEW.quhead_prj_id,-1)=-1)) THEN
SELECT fetchMetricBool('AutoCreateProjectsForOrders') INTO _check;
--Auto create project if applicable
IF ((TG_OP = 'INSERT') AND (COALESCE(NEW.quhead_prj_id,-1)=-1)) THEN
SELECT fetchMetricBool('AutoCreateProjectsForOrders') INTO _check;
NEW.quhead_billtoname=COALESCE(NEW.quhead_billtoname,_p.cust_name,'');
NEW.quhead_billtoaddress1=COALESCE(NEW.quhead_billtoaddress1,_p.addr_line1,'');
NEW.quhead_billtoaddress2=COALESCE(NEW.quhead_billtoaddress2,_p.addr_line2,'');
NEW.quhead_billtoname=COALESCE(NEW.quhead_billtoname,_p.cust_name,'');
NEW.quhead_billtoaddress1=COALESCE(NEW.quhead_billtoaddress1,_p.addr_line1,'');
NEW.quhead_billtoaddress2=COALESCE(NEW.quhead_billtoaddress2,_p.addr_line2,'');
- NEW.quhead_billtoaddress3=COALESCE(NEW.quhead_billtoaddress3,_p.addr_line3,'');
- NEW.quhead_billtocity=COALESCE(NEW.quhead_billtocity,_p.addr_city,'');
+ NEW.quhead_billtoaddress3=COALESCE(NEW.quhead_billtoaddress3,_p.addr_line3,'');
+ NEW.quhead_billtocity=COALESCE(NEW.quhead_billtocity,_p.addr_city,'');
NEW.quhead_billtostate=COALESCE(NEW.quhead_billtostate,_p.addr_state,'');
NEW.quhead_billtozip=COALESCE(NEW.quhead_billtozip,_p.addr_postalcode,'');
NEW.quhead_billtostate=COALESCE(NEW.quhead_billtostate,_p.addr_state,'');
NEW.quhead_billtozip=COALESCE(NEW.quhead_billtozip,_p.addr_postalcode,'');
ELSE
-- Free form not allowed, we're going to put in the address regardless
NEW.quhead_billtoname=COALESCE(_p.cust_name,'');
NEW.quhead_billtoaddress1=COALESCE(_p.addr_line1,'');
NEW.quhead_billtoaddress2=COALESCE(_p.addr_line2,'');
ELSE
-- Free form not allowed, we're going to put in the address regardless
NEW.quhead_billtoname=COALESCE(_p.cust_name,'');
NEW.quhead_billtoaddress1=COALESCE(_p.addr_line1,'');
NEW.quhead_billtoaddress2=COALESCE(_p.addr_line2,'');
- NEW.quhead_billtoaddress3=COALESCE(_p.addr_line3,'');
- NEW.quhead_billtocity=COALESCE(_p.addr_city,'');
+ NEW.quhead_billtoaddress3=COALESCE(_p.addr_line3,'');
+ NEW.quhead_billtocity=COALESCE(_p.addr_city,'');
NEW.quhead_billtostate=COALESCE(_p.addr_state,'');
NEW.quhead_billtozip=COALESCE(_p.addr_postalcode,'');
NEW.quhead_billtocountry=COALESCE(_p.addr_country,'');
NEW.quhead_billtostate=COALESCE(_p.addr_state,'');
NEW.quhead_billtozip=COALESCE(_p.addr_postalcode,'');
NEW.quhead_billtocountry=COALESCE(_p.addr_country,'');
AND NOT ((NEW.quhead_shipto_id IS NULL) AND NOT _p.cust_ffshipto)
AND (NEW.quhead_shiptoname IS NULL)
AND (NEW.quhead_shiptoaddress1 IS NULL)
AND NOT ((NEW.quhead_shipto_id IS NULL) AND NOT _p.cust_ffshipto)
AND (NEW.quhead_shiptoname IS NULL)
AND (NEW.quhead_shiptoaddress1 IS NULL)
WHERE ((shipto_id=_shiptoId)
AND (addr_id=shipto_addr_id));
NEW.quhead_shiptoname := COALESCE(_p.shipto_name,'');
NEW.quhead_shiptoaddress1 := COALESCE(_a.addr_line1,'');
NEW.quhead_shiptoaddress2 := COALESCE(_a.addr_line2,'');
WHERE ((shipto_id=_shiptoId)
AND (addr_id=shipto_addr_id));
NEW.quhead_shiptoname := COALESCE(_p.shipto_name,'');
NEW.quhead_shiptoaddress1 := COALESCE(_a.addr_line1,'');
NEW.quhead_shiptoaddress2 := COALESCE(_a.addr_line2,'');
- NEW.quhead_shiptoaddress3 := COALESCE(_a.addr_line3,'');
- NEW.quhead_shiptocity := COALESCE(_a.addr_city,'');
+ NEW.quhead_shiptoaddress3 := COALESCE(_a.addr_line3,'');
+ NEW.quhead_shiptocity := COALESCE(_a.addr_city,'');
NEW.quhead_shiptostate := COALESCE(_a.addr_state,'');
NEW.quhead_shiptozipcode := COALESCE(_a.addr_postalcode,'');
NEW.quhead_shiptocountry := COALESCE(_a.addr_country,'');
NEW.quhead_shiptostate := COALESCE(_a.addr_state,'');
NEW.quhead_shiptozipcode := COALESCE(_a.addr_postalcode,'');
NEW.quhead_shiptocountry := COALESCE(_a.addr_country,'');
SELECT quhead_shipto_id INTO _shiptoid FROM quhead WHERE (quhead_id=NEW.quhead_id);
-- Get the shipto address
IF (COALESCE(NEW.quhead_shipto_id,-1) <> COALESCE(_shiptoid,-1)) THEN
SELECT quhead_shipto_id INTO _shiptoid FROM quhead WHERE (quhead_id=NEW.quhead_id);
-- Get the shipto address
IF (COALESCE(NEW.quhead_shipto_id,-1) <> COALESCE(_shiptoid,-1)) THEN
NEW.quhead_shiptophone := COALESCE(_a.cntct_phone,'');
NEW.quhead_shiptoaddress1 := COALESCE(_a.addr_line1,'');
NEW.quhead_shiptoaddress2 := COALESCE(_a.addr_line2,'');
NEW.quhead_shiptophone := COALESCE(_a.cntct_phone,'');
NEW.quhead_shiptoaddress1 := COALESCE(_a.addr_line1,'');
NEW.quhead_shiptoaddress2 := COALESCE(_a.addr_line2,'');
- NEW.quhead_shiptoaddress3 := COALESCE(_a.addr_line3,'');
- NEW.quhead_shiptocity := COALESCE(_a.addr_city,'');
+ NEW.quhead_shiptoaddress3 := COALESCE(_a.addr_line3,'');
+ NEW.quhead_shiptocity := COALESCE(_a.addr_city,'');
NEW.quhead_shiptostate := COALESCE(_a.addr_state,'');
NEW.quhead_shiptozipcode := COALESCE(_a.addr_postalcode,'');
NEW.quhead_shiptostate := COALESCE(_a.addr_state,'');
NEW.quhead_shiptozipcode := COALESCE(_a.addr_postalcode,'');
ELSE
-- If no shipto data and free form not allowed, this won't work
RAISE EXCEPTION 'Free form Shipto is not allowed on this Customer. You must supply a valid Shipto ID.';
ELSE
-- If no shipto data and free form not allowed, this won't work
RAISE EXCEPTION 'Free form Shipto is not allowed on this Customer. You must supply a valid Shipto ID.';