Dumped on 2004-08-27
address Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('address_id_seq'::text)
|
|
name_prefix |
character(16) |
|
|
name_first |
character(255) |
|
|
name_middle |
character(255) |
|
|
name_last |
character(255) |
NOT NULL
|
|
name_suffix |
character(16) |
|
|
company |
character(255) |
|
|
street1 |
character(255) |
|
|
street2 |
character(255) |
|
|
street3 |
character(255) |
|
|
city |
character(255) |
NOT NULL
|
|
stateprov |
character(255) |
NOT NULL
|
|
postalcode |
character(255) |
NOT NULL
|
|
countrycode |
character(2) |
|
|
phone1 |
character(32) |
|
|
phone2 |
character(32) |
|
|
fax |
character(32) |
|
|
email |
character(255) |
NOT NULL
|
|
optin |
character(1) |
|
address Constraints
Name |
Constraint |
address_optin |
CHECK (((optin = 'Y'::bpchar) OR (optin = 'N'::bpchar))) |
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
affiliate Structure
F-Key |
Name |
Type |
Description |
ftuser.id
|
ftuser |
integer |
PRIMARY KEY
|
|
active |
boolean |
NOT NULL
DEFAULT true
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
affiliate_global Structure
F-Key |
Name |
Type |
Description |
|
cookiedays |
integer |
NOT NULL
DEFAULT 30
|
|
returnperiod |
interval |
NOT NULL
DEFAULT '30 days'::interval
|
|
commissionrate |
numeric(5,5) |
NOT NULL
DEFAULT 0.15
|
Index -
Schema public
affiliate_numbers Structure
F-Key |
Name |
Type |
Description |
ftuser.id
|
ftuser |
integer |
PRIMARY KEY
|
|
months |
date |
PRIMARY KEY
DEFAULT date_trunc('month'::text, (('now'::text)::date)::timestamp with time zone)
|
|
commissiondate |
date |
|
|
commission |
numeric(11,2) |
NOT NULL
|
|
referrals |
integer |
NOT NULL
|
|
sales |
integer |
NOT NULL
|
|
salestotal |
numeric(11,2) |
NOT NULL
|
|
returns |
integer |
NOT NULL
|
|
returnstotal |
numeric(11,2) |
NOT NULL
|
affiliate_numbers Constraints
Name |
Constraint |
affiliate_numbers_referrals |
CHECK ((referrals >= 0)) |
affiliate_numbers_returns |
CHECK (("returns" >= 0)) |
affiliate_numbers_returnstotal |
CHECK ((returnstotal >= (0)::numeric)) |
affiliate_numbers_sales |
CHECK ((sales >= 0)) |
affiliate_numbers_salestotal |
CHECK ((salestotal >= (0)::numeric)) |
Index -
Schema public
affiliate_unpaid_commission Structure
F-Key |
Name |
Type |
Description |
|
ftuser |
integer |
|
|
sales |
integer |
|
|
salestotal |
numeric(11,2) |
|
|
returns |
integer |
|
|
returnstotal |
numeric(11,2) |
|
|
netsales |
numeric |
|
|
commission |
numeric(11,2) |
|
|
months |
date |
|
SELECT an.ftuser
, an.sales
, an.salestotal
, an."returns"
, an.returnstotal
, (an.salestotal - an.returnstotal) AS netsales
, an.commission
, an.months
FROM affiliate_numbers an
WHERE (
(an.commissiondate IS NULL)
AND is_commission_mature
(
(an.months)::timestamp without time zone
)
);
Index -
Schema public
affiliates_commission Structure
F-Key |
Name |
Type |
Description |
|
affiliate |
integer |
|
|
login |
character(32) |
|
|
sales |
bigint |
|
|
salestotal |
numeric |
|
|
returns |
bigint |
|
|
returnstotal |
numeric |
|
|
netsales |
numeric |
|
|
commission |
numeric |
|
|
enddate |
date |
|
SELECT a.ftuser AS affiliate
, u.login
, sum
(COALESCE
(auc.sales
, 0
)
) AS sales
, sum
(COALESCE
(auc.salestotal
, (0)::numeric
)
) AS salestotal
, sum
(COALESCE
(auc."returns"
, 0
)
) AS "returns"
, sum
(COALESCE
(auc.returnstotal
, (0)::numeric
)
) AS returnstotal
, sum
(
(COALESCE
(auc.salestotal
, (0)::numeric
) - COALESCE
(auc.returnstotal
, (0)::numeric
)
)
) AS netsales
, sum
(COALESCE
(commission
, (0)::numeric
)
) AS commission
, max
(months) AS enddate
FROM (affiliate a
LEFT JOIN affiliate_unpaid_commission auc
ON (
(a.ftuser = auc.ftuser)
)
)
, ftuser u
WHERE (u.id = a.ftuser)
GROUP BY a.ftuser
, u.login;
Index -
Schema public
attribute Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('attribute_id_seq'::text)
|
|
name |
character(64) |
NOT NULL
|
|
graphic |
character(255) |
|
|
displayprecedence |
integer |
NOT NULL
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
billing Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('billing_id_seq'::text)
|
|
name |
character(64) |
NOT NULL
|
|
displayprecedence |
integer |
NOT NULL
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
coupon Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('coupon_id_seq'::text)
|
|
name |
character(32) |
NOT NULL
|
|
dollaroff |
numeric(5,2) |
|
|
percentageoff |
numeric(5,2) |
|
|
minamountpurchased |
numeric(5,2) |
|
|
startdate |
timestamp without time zone |
|
|
enddate |
timestamp without time zone |
|
|
neverexpires |
character(1) |
NOT NULL
DEFAULT 'N'::bpchar
|
|
combineable |
character(1) |
NOT NULL
DEFAULT 'N'::bpchar
|
|
displayprecedence |
integer |
|
coupon Constraints
Name |
Constraint |
coupon_combineable |
CHECK (((combineable = 'Y'::bpchar) OR (combineable = 'N'::bpchar))) |
coupon_neverexpires |
CHECK (((neverexpires = 'Y'::bpchar) OR (neverexpires = 'N'::bpchar))) |
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
coupon_user Structure
F-Key |
Name |
Type |
Description |
coupon.id
|
coupon |
integer |
PRIMARY KEY
|
ftuser.id
|
ftuser |
integer |
PRIMARY KEY
|
Index -
Schema public
credit Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('credit_id_seq'::text)
|
|
externalid |
character(32) |
NOT NULL
|
ftuser.id
|
purchaser |
integer |
NOT NULL
|
|
purchased |
timestamp without time zone |
|
|
expires |
timestamp without time zone |
|
|
initialvalue |
numeric(11,2) |
NOT NULL
|
|
remainingvalue |
numeric(11,2) |
NOT NULL
|
Index -
Schema public
department Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('department_id_seq'::text)
|
|
name |
character(64) |
NOT NULL
|
|
graphic |
character(255) |
|
department.id
|
parent |
integer |
|
|
description |
text |
|
|
displayprecedence |
integer |
NOT NULL
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
department_item Structure
F-Key |
Name |
Type |
Description |
department.id
|
department |
integer |
PRIMARY KEY
|
item.id
|
item |
integer |
PRIMARY KEY
|
Index -
Schema public
Table:
fee
fee Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('fee_id_seq'::text)
|
|
name |
character(64) |
NOT NULL
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
ftuser Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('ftuser_id_seq'::text)
|
|
login |
character(32) |
NOT NULL
|
|
password |
character(32) |
NOT NULL
|
address.id
|
address |
integer |
NOT NULL
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
inventory_log Structure
F-Key |
Name |
Type |
Description |
|
filename |
character varying(255) |
PRIMARY KEY
|
|
processed |
timestamp without time zone |
|
Index -
Schema public
invoice Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('invoice_id_seq'::text)
|
|
externalid |
integer |
|
|
ftuser |
integer |
NOT NULL
|
|
active |
character(1) |
NOT NULL
DEFAULT 'N'::bpchar
|
|
created |
timestamp without time zone |
NOT NULL
|
invoice Constraints
Name |
Constraint |
invoice_active |
CHECK (((active = 'Y'::bpchar) OR (active = 'N'::bpchar))) |
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
invoice_billing Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('invoice_billing_id_seq'::text)
|
invoice.id
|
invoice |
integer |
NOT NULL
|
billing.id
|
billing |
integer |
NOT NULL
|
address.id
|
address |
integer |
NOT NULL
|
affiliate.ftuser
|
affiliate |
integer |
|
|
creditcardowner |
character(64) |
NOT NULL
|
|
creditcardnumber |
bytea |
NOT NULL
|
|
creditcardexpiration |
timestamp without time zone |
NOT NULL
|
|
creditcardverification |
character(4) |
|
|
charge |
numeric(11,2) |
|
Index -
Schema public
invoice_coupon Structure
F-Key |
Name |
Type |
Description |
invoice.id
|
invoice |
integer |
PRIMARY KEY
|
coupon.id
|
coupon |
integer |
PRIMARY KEY
|
Index -
Schema public
invoice_fee Structure
F-Key |
Name |
Type |
Description |
invoice.id
|
invoice |
integer |
NOT NULL
|
fee.id
|
fee |
integer |
NOT NULL
|
|
value |
numeric(11,2) |
NOT NULL
|
Index -
Schema public
invoice_log Structure
F-Key |
Name |
Type |
Description |
|
filename |
character varying(255) |
PRIMARY KEY
|
|
processed |
timestamp without time zone |
|
Index -
Schema public
invoice_shipping Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('invoice_shipping_id_seq'::text)
|
invoice.id
|
invoice |
integer |
NOT NULL
|
address.id
|
address |
integer |
NOT NULL
|
shipping.id
|
shipping |
integer |
NOT NULL
|
|
message |
character(255) |
|
Index -
Schema public
invoice_sku Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('invoice_sku_id_seq'::text)
|
invoice.id
|
invoice |
integer |
NOT NULL
|
sku.id
|
sku |
integer |
NOT NULL
|
|
quantity |
integer |
NOT NULL
|
|
externalsku |
character(64) |
NOT NULL
|
|
name |
character(64) |
NOT NULL
|
|
listprice |
numeric(11,2) |
NOT NULL
|
|
saleprice |
numeric(11,2) |
NOT NULL
|
|
additionalshipping |
numeric(11,2) |
NOT NULL
|
|
shipping |
integer |
NOT NULL
|
invoice_sku Constraints
Name |
Constraint |
invoice_sku_quantity |
CHECK ((quantity > 0)) |
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
invoice_sku_variation Structure
F-Key |
Name |
Type |
Description |
|
invoicesku |
integer |
PRIMARY KEY
|
|
variation |
integer |
PRIMARY KEY
|
|
qualifier |
character(255) |
|
|
price |
numeric(11,2) |
NOT NULL
|
Index -
Schema public
invoice_status Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('invoice_status_id_seq'::text)
|
invoice.id
|
invoice |
integer |
NOT NULL
|
status.id
|
status |
integer |
NOT NULL
|
|
created |
timestamp without time zone |
NOT NULL
|
|
description |
character(255) |
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
item Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('item_id_seq'::text)
|
|
name |
character(64) |
NOT NULL
|
|
description |
text |
|
|
keywords |
character varying(255) |
|
|
thumbnail |
character varying(255) |
|
|
graphic |
character varying(255) |
|
|
largegraphic |
character varying(255) |
|
|
displayprecedence |
integer |
|
|
active |
character(1) |
NOT NULL
DEFAULT 'N'::bpchar
|
item Constraints
Name |
Constraint |
item_active |
CHECK (((active = 'Y'::bpchar) OR (active = 'N'::bpchar))) |
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
item_item Structure
F-Key |
Name |
Type |
Description |
item.id
|
item |
integer |
PRIMARY KEY
|
item.id
|
related_item |
integer |
PRIMARY KEY
|
relationship.id
|
relationship |
integer |
PRIMARY KEY
|
Index -
Schema public
localize Structure
F-Key |
Name |
Type |
Description |
|
id |
character(32) |
PRIMARY KEY
|
|
target |
character(2) |
PRIMARY KEY
|
|
translation |
character varying |
|
Index -
Schema public
news Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('news_id_seq'::text)
|
|
headline |
character varying(255) |
NOT NULL
DEFAULT ''::character varying
|
|
summary |
character varying(255) |
|
|
body |
text |
|
|
location |
character varying(255) |
|
|
expires |
timestamp without time zone |
NOT NULL
|
|
displayprecedence |
integer |
NOT NULL
|
Index -
Schema public
permission Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('permission_id_seq'::text)
|
|
name |
character(255) |
NOT NULL
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
recdmaterial Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('recdmaterial_id_seq'::text)
|
rma_invoice_sku.id
|
rmainvoicesku |
integer |
NOT NULL
|
invoice_status.id
|
invoicestatus |
integer |
NOT NULL
|
|
quantity |
integer |
NOT NULL
|
recdmaterial Constraints
Name |
Constraint |
recdmaterial_quantity |
CHECK ((quantity > 0)) |
Index -
Schema public
relationship Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('relationship_id_seq'::text)
|
|
name |
character(255) |
NOT NULL
|
|
displayprecedence |
integer |
NOT NULL
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
Table:
rma
rma Constraints
Name |
Constraint |
$1 |
CHECK (((completed IS NULL) OR (revoked IS NULL))) |
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
rma_invoice_sku Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('rma_invoice_sku_id_seq'::text)
|
rma.id
|
rma |
integer |
NOT NULL
|
invoice_sku.id
|
invoicesku |
integer |
NOT NULL
|
|
quantity |
integer |
NOT NULL
|
|
received |
timestamp without time zone |
|
rma_invoice_sku Constraints
Name |
Constraint |
rma_invoice_sku_quantity |
CHECK ((quantity > 0)) |
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
rma_invoice_status Structure
F-Key |
Name |
Type |
Description |
|
rma |
integer |
|
|
invoicestatus |
integer |
|
(
(
(
(
SELECT rma
, invoicestatus
FROM (recdmaterial m
JOIN (
SELECT rma_invoice_sku.rma
, rma_invoice_sku.id
FROM rma_invoice_sku
) y
ON (
(m.rmainvoicesku = y.id)
)
)
GROUP BY rma
, invoicestatus
)
UNION (
SELECT rma.id AS rma
, rma.issued AS invoicestatus
FROM rma
)
)
)
UNION (
SELECT rma.id AS rma
, COALESCE
(rma.completed
, rma.revoked
) AS invoicestatus
FROM rma
)
);
Index -
Schema public
rma_status Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
|
|
rma |
integer |
|
|
invoice |
integer |
|
|
status |
integer |
|
|
created |
timestamp without time zone |
|
|
description |
character(255) |
|
SELECT i.id
, rma
, invoice
, status
, created
, description
FROM (rma_invoice_status r
JOIN invoice_status i
ON (
(r.invoicestatus = i.id)
)
);
Index -
Schema public
seed Structure
F-Key |
Name |
Type |
Description |
|
seed |
integer |
NOT NULL
DEFAULT 314
|
Index -
Schema public
session Structure
F-Key |
Name |
Type |
Description |
|
id |
character(16) |
PRIMARY KEY
|
ftuser.id
|
ftuser |
integer |
|
|
lastaction |
timestamp without time zone |
|
|
invoice |
integer |
|
|
phpdata |
text |
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
session_sku Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('session_sku_id_seq'::text)
|
session.id
|
session |
character(24) |
NOT NULL
|
sku.id
|
sku |
integer |
NOT NULL
|
|
quantity |
integer |
NOT NULL
|
session_sku Constraints
Name |
Constraint |
session_sku_quantity |
CHECK ((quantity > 0)) |
Index -
Schema public
session_sku_variation Structure
F-Key |
Name |
Type |
Description |
|
sessionsku |
integer |
PRIMARY KEY
|
|
variation |
integer |
PRIMARY KEY
|
|
qualifier |
character(255) |
|
Index -
Schema public
shipping Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('shipping_id_seq'::text)
|
|
name |
character(255) |
NOT NULL
|
|
displayprecedence |
integer |
NOT NULL
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
Table:
sku
sku Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('sku_id_seq'::text)
|
item.id
|
item |
integer |
NOT NULL
|
|
externalsku |
character(64) |
NOT NULL
|
|
name |
character(64) |
NOT NULL
|
|
listprice |
numeric(11,2) |
NOT NULL
|
|
saleprice |
numeric(11,2) |
NOT NULL
|
|
additionalshipping |
numeric(11,2) |
NOT NULL
|
|
weight |
numeric(11,2) |
NOT NULL
|
|
displayprecedence |
integer |
NOT NULL
|
|
active |
character(1) |
NOT NULL
DEFAULT 'N'::bpchar
|
|
inventoryavailable |
integer |
NOT NULL
|
|
reserve |
integer |
NOT NULL
|
|
canbackorder |
character(1) |
NOT NULL
DEFAULT 'N'::bpchar
|
sku Constraints
Name |
Constraint |
sku_active |
CHECK (((active = 'Y'::bpchar) OR (active = 'N'::bpchar))) |
sku_canbackorder |
CHECK (((canbackorder = 'Y'::bpchar) OR (canbackorder = 'N'::bpchar))) |
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
sku_variation Structure
F-Key |
Name |
Type |
Description |
sku.id
|
sku |
integer |
PRIMARY KEY
|
variation.id
|
variation |
integer |
PRIMARY KEY
|
Index -
Schema public
status Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('status_id_seq'::text)
|
|
name |
character(64) |
NOT NULL
|
|
type |
text |
NOT NULL
|
status Constraints
Name |
Constraint |
status_type |
CHECK ((("type" = 'Invoice'::text) OR ("type" = 'RMA'::text))) |
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
status_log Structure
F-Key |
Name |
Type |
Description |
|
filename |
character varying(255) |
PRIMARY KEY
|
|
processed |
timestamp without time zone |
|
Index -
Schema public
store Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('store_id_seq'::text)
|
|
address |
integer |
NOT NULL
|
|
description |
text |
|
|
image |
character varying(255) |
|
Index -
Schema public
Table:
tax
tax Structure
F-Key |
Name |
Type |
Description |
|
state |
character(2) |
PRIMARY KEY
|
|
rate |
numeric(5,5) |
NOT NULL
|
|
taxshipping |
character(1) |
NOT NULL
DEFAULT 'N'::bpchar
|
tax Constraints
Name |
Constraint |
tax_taxshipping |
CHECK (((taxshipping = 'Y'::bpchar) OR (taxshipping = 'N'::bpchar))) |
Index -
Schema public
user_permission Structure
F-Key |
Name |
Type |
Description |
ftuser.id
|
ftuser |
integer |
PRIMARY KEY
|
permission.id
|
permission |
integer |
PRIMARY KEY
|
Index -
Schema public
user_sku Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('user_sku_id_seq'::text)
|
ftuser.id
|
ftuser |
integer |
NOT NULL
|
sku.id
|
sku |
integer |
NOT NULL
|
|
quantity |
integer |
NOT NULL
|
user_sku Constraints
Name |
Constraint |
user_sku_quantity |
CHECK ((quantity > 0)) |
Index -
Schema public
user_sku_variation Structure
F-Key |
Name |
Type |
Description |
|
usersku |
integer |
PRIMARY KEY
|
|
variation |
integer |
PRIMARY KEY
|
|
qualifier |
character(255) |
|
Index -
Schema public
variation Structure
F-Key |
Name |
Type |
Description |
|
id |
integer |
PRIMARY KEY
DEFAULT nextval('variation_id_seq'::text)
|
|
name |
character(64) |
NOT NULL
|
attribute.id
|
attribute |
integer |
NOT NULL
|
|
description |
character(64) |
|
|
graphic |
character(255) |
|
|
displayprecedence |
integer |
NOT NULL
|
|
price |
numeric(11,2) |
NOT NULL
|
Tables referencing this one via Foreign Key Constraints:
Index -
Schema public
Returns: boolean
Language: PLPGSQL
BEGIN
IF (SELECT COUNT(*)
FROM affiliate_numbers
WHERE Months = date_trunc('Month', NOW()) AND
FTUser = $1) = 0 THEN
INSERT INTO affiliate_numbers VALUES($1);
END IF;
RETURN TRUE;
END;
Returns: timestamp without time zone
Language: SQL
SELECT (NOW() - ReturnPeriod)::TIMESTAMP
FROM affiliate_global;
Returns: abstime
Language: SQL
select $1::ABSTIME;
Returns: boolean
Language: SQL
SELECT (NOW() - (SELECT ReturnPeriod FROM affiliate_global)) >
(SELECT date_trunc('Month', $1) + '1 Month'::INTERVAL -
'1 Day'::INTERVAL);
Returns: "trigger"
Language: PLPGSQL
DECLARE
affiliateID INTEGER;
sku RECORD;
total DECIMAL(11,2);
BEGIN
-- Work only on revoked RMAs and no change if ship date is older than
-- configured interval.
IF (OLD.Revoked IS NOT NULL) OR (NEW.Revoked IS NULL) OR
(ship_date(NEW.Invoice) < commission_end_date()) THEN
RETURN NULL;
END IF;
-- Initialize.
SELECT INTO affiliateID Affiliate
FROM invoice_billing
WHERE Invoice = NEW.Invoice;
-- Verify a record exists in affiliate_numbers before update.
PERFORM check_affiliate_numbers(affiliateID);
-- Update return count within affiliate_numbers.
UPDATE affiliate_numbers
SET Returns = Returns - 1
WHERE Months = date_trunc('Month', NOW()) AND
FTUser = affiliateID;
FOR sku IN SELECT * FROM rma_invoice_sku WHERE RMA = NEW.ID LOOP
-- Determine the total.
SELECT INTO total (isk.SalePrice * sku.Quantity)
FROM invoice_sku isk
WHERE isk.ID = sku.InvoiceSKU;
-- Update return total within affiliate_numbers.
UPDATE affiliate_numbers
SET ReturnsTotal = ReturnsTotal - total,
Commission = Commission + (total *
(SELECT CommissionRate FROM affiliate_global))
WHERE Months = date_trunc('Month', NOW()) AND
FTUser = affiliateID;
END LOOP;
RETURN NULL;
END;
Returns: "trigger"
Language: PLPGSQL
DECLARE
affiliateID INTEGER;
invoiceID INTEGER;
total DECIMAL(11,2);
BEGIN
-- No change if ship date is older than configured interval.
IF ship_date((SELECT rma
FROM rma_invoice_sku
WHERE ID = New.InvoiceSKU)) < commission_end_date() THEN
RETURN NULL;
END IF;
-- Initialize.
SELECT INTO invoiceID Invoice
FROM rma r, rma_invoice_sku ris
WHERE r.ID = ris.RMA AND ris.ID = NEW.ID;
SELECT INTO affiliateID Affiliate
FROM invoice_billing
WHERE Invoice = invoiceID;
-- Verify a record exists in affiliate_numbers before update.
PERFORM check_affiliate_numbers(affiliateID);
-- Determine the total.
SELECT INTO total (isk.SalePrice * NEW.Quantity)
FROM invoice_sku isk
WHERE isk.ID = NEW.InvoiceSKU;
-- Update return total within affiliate_numbers.
UPDATE affiliate_numbers
SET ReturnsTotal = ReturnsTotal + total,
Commission = Commission - (total *
(SELECT CommissionRate FROM affiliate_global))
WHERE Months = date_trunc('Month', NOW()) AND
FTUser = affiliateID;
RETURN NULL;
END;
Returns: "trigger"
Language: PLPGSQL
DECLARE
affiliateID INTEGER;
BEGIN
-- No change if ship date is older than configured interval.
IF ship_date(NEW.Invoice) < commission_end_date() THEN
RETURN NULL;
END IF;
-- Initialize.
SELECT INTO affiliateID Affiliate
FROM invoice_billing
WHERE Invoice = NEW.Invoice;
-- Verify a record exists in affiliate_numbers before update.
PERFORM check_affiliate_numbers(affiliateID);
-- Update return count within affiliate_numbers.
UPDATE affiliate_numbers
SET Returns = Returns + 1
WHERE Months = date_trunc('Month', NOW()) AND
FTUser = affiliateID;
RETURN NULL;
END;
Returns: "trigger"
Language: PLPGSQL
DECLARE
affiliateID INTEGER;
total DECIMAL(11,2);
BEGIN
-- Configure on whether to add or subtract from sales.
IF NEW.Status = (SELECT ID FROM status WHERE name = 'Shipped') THEN
-- Determine the total.
SELECT INTO total SUM(SalePrice * Quantity)
FROM invoice_sku
WHERE Invoice = NEW.Invoice;
-- Initialize.
SELECT INTO affiliateID Affiliate
FROM invoice_billing
WHERE Invoice = NEW.Invoice;
-- Verify a record exists in affiliate_numbers before update.
PERFORM check_affiliate_numbers(affiliateID);
-- Update sales count and total within affiliate_numbers.
UPDATE affiliate_numbers
SET Sales = Sales + 1,
SalesTotal = SalesTotal + total,
Commission = Commission + (total *
(SELECT CommissionRate FROM affiliate_global))
WHERE Months = date_trunc('Month', NEW.Created) AND
FTUser = affiliateID;
END IF;
RETURN NULL;
END;
Returns: timestamp without time zone
Language: SQL
SELECT date_trunc('Month', Created)
FROM invoice_status
WHERE Invoice = $1 AND
Status = (SELECT ID
FROM status
WHERE name = 'Shipped');
Returns: integer
Language: SQL
select date_part('epoch', $1)::INT4;
Generated by PostgreSQL Autodoc
W3C HTML 4.01 Strict