1/*
2 * Legal Notice
3 *
4 * This document and associated source code (the "Work") is a part of a
5 * benchmark specification maintained by the TPC.
6 *
7 * The TPC reserves all right, title, and interest to the Work as provided
8 * under U.S. and international laws, including without limitation all patent
9 * and trademark rights therein.
10 *
11 * No Warranty
12 *
13 * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION
14 * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE
15 * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER
16 * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
17 * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES,
18 * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR
19 * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF
20 * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE.
21 * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT,
22 * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT
23 * WITH REGARD TO THE WORK.
24 * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO
25 * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE
26 * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS
27 * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT,
28 * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY,
29 * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT
30 * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD
31 * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * Contributors:
34 * Gradient Systems
35 */
36#include "config.h"
37#include "porting.h"
38#include <stdio.h>
39#include "pricing.h"
40#include "w_web_returns.h"
41#include "w_web_sales.h"
42#include "date.h"
43#include "decimal.h"
44#include "genrand.h"
45#include "build_support.h"
46#include "misc.h"
47#include "error_msg.h"
48#include "tables.h"
49#include "nulls.h"
50#include "tdefs.h"
51
52struct W_WEB_RETURNS_TBL g_w_web_returns;
53extern struct W_WEB_SALES_TBL g_w_web_sales;
54
55/*
56 * Routine: mk_web_returns()
57 * Purpose: populate a return fact *sync'd with a sales fact*
58 * Algorithm: Since the returns need to be in line with a prior sale, they are
59 *built by a call from the mk_catalog_sales() routine, and then add
60 *return-related information Data Structures:
61 *
62 * Params:
63 * Returns:
64 * Called By:
65 * Calls:
66 * Assumptions:
67 * Side Effects:
68 * TODO: None
69 */
70int mk_w_web_returns(void *row, ds_key_t index) {
71 int res = 0;
72
73 static decimal_t dMin, dMax;
74 static struct W_WEB_SALES_TBL *sale;
75 static int bInit = 0;
76 struct W_WEB_RETURNS_TBL *r;
77 tdef *pT = getSimpleTdefsByNumber(WEB_RETURNS);
78
79 if (row == NULL)
80 r = &g_w_web_returns;
81 else
82 r = row;
83
84 if (!bInit) {
85 strtodec(&dMin, "1.00");
86 strtodec(&dMax, "100000.00");
87 bInit = 1;
88 }
89
90 nullSet(&pT->kNullBitMap, WR_NULLS);
91
92 /*
93 * Some of the information in the return is taken from the original sale
94 * which has been regenerated
95 */
96 sale = &g_w_web_sales;
97 r->wr_item_sk = sale->ws_item_sk;
98 r->wr_order_number = sale->ws_order_number;
99 memcpy((void *)&r->wr_pricing, (void *)&sale->ws_pricing, sizeof(ds_pricing_t));
100 r->wr_web_page_sk = sale->ws_web_page_sk;
101
102 /*
103 * the rest of the columns are generated for this specific return
104 */
105 /* the items cannot be returned until they are shipped; offset is handled in
106 * mk_join, based on sales date */
107 r->wr_returned_date_sk = mk_join(WR_RETURNED_DATE_SK, DATET, sale->ws_ship_date_sk);
108 r->wr_returned_time_sk = mk_join(WR_RETURNED_TIME_SK, TIME, 1);
109
110 /* most items are returned by the people they were shipped to, but some are
111 * returned by other folks
112 */
113 r->wr_refunded_customer_sk = mk_join(WR_REFUNDED_CUSTOMER_SK, CUSTOMER, 1);
114 r->wr_refunded_cdemo_sk = mk_join(WR_REFUNDED_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1);
115 r->wr_refunded_hdemo_sk = mk_join(WR_REFUNDED_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1);
116 r->wr_refunded_addr_sk = mk_join(WR_REFUNDED_ADDR_SK, CUSTOMER_ADDRESS, 1);
117 if (genrand_integer(NULL, DIST_UNIFORM, 0, 99, 0, WR_RETURNING_CUSTOMER_SK) < WS_GIFT_PCT) {
118 r->wr_refunded_customer_sk = sale->ws_ship_customer_sk;
119 r->wr_refunded_cdemo_sk = sale->ws_ship_cdemo_sk;
120 r->wr_refunded_hdemo_sk = sale->ws_ship_hdemo_sk;
121 r->wr_refunded_addr_sk = sale->ws_ship_addr_sk;
122 }
123 r->wr_returning_customer_sk = r->wr_refunded_customer_sk;
124 r->wr_returning_cdemo_sk = r->wr_refunded_cdemo_sk;
125 r->wr_returning_hdemo_sk = r->wr_refunded_hdemo_sk;
126 r->wr_returning_addr_sk = r->wr_refunded_addr_sk;
127
128 r->wr_reason_sk = mk_join(WR_REASON_SK, REASON, 1);
129 genrand_integer(&r->wr_pricing.quantity, DIST_UNIFORM, 1, sale->ws_pricing.quantity, 0, WR_PRICING);
130 set_pricing(WR_PRICING, &r->wr_pricing);
131
132 return (res);
133}
134