Project

General

Profile

Actions

Feature #118

closed

DP Profit Batch File

Added by Chooi-Mey about 13 years ago. Updated over 12 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Chee-Hoong
Category:
Batch
Target version:
Start date:
08/03/2011
Due date:
11/04/2011
% Done:

100%

Estimated time:
Resolution:
Fixed

Description

Requirement:

  1. Construct Currency Hashtable:
    • Query all latest currency info from Mend_CurrConv table, into a hashtable based on below query:
      SELECT CTRY_CODE, CURR_CODE, CURR_EXCH_RATE FROM MEND_CURRCONV A WHERE A.EFFECTIVE_DATE = (SELECT MAX(B.EFFECTIVE_DATE) 
      FROM MEND_CURRCONV B 
      GROUP BY B.CTRY_CODE HAVING B.CTRY_CODE = A.CTRY_CODE) AND A.STATUS = 'A'
      
    • Populate the return query result into hashtable, with "CTRY_CODE" as key, while "CURR_CODE|CURR_EXCH_RATE" as value.
  2. Retrieve Member DP Records:
    • Query member's earned DP Profit from VIP_Stat and Member_stat table with below query logic:
      SELECT VIP.VIP_ID AS MEMBER_ID, VIP.DP_EARNED AS DP_EARNED, VIP.COUNTRY_CODE AS COUNTRY_CODE FROM VIP_STAT VIP WHERE VIP.DATA_MONTH = '2011-05-31' AND VIP.DP_EARNED <> 0 
      
  3. COUNTRY (pos 41-43) field:
    If the retrieval country_code = 156 (CHINA), 344 (HK) or 446 (MACAU), COUNTRY field mapped to 344 (HK).
    The rest as it is.
  4. TRAN_TYPE (pos 135-139) field:
    If the retrieval dp_earned value < 0, set it to "20501";
    If the retrieval dp_earned value > 0, set it to "20101"
  5. TRAN_AMT (pos 160-172) field:
    If the retrieval dp_earned value < 0, remove the negative sign.
  6. CURRENCY_FROM (pos 462-464) field:
    Set it default to "USD"
  7. CURRENCY_TO (pos 465-467) field:
    Based on the COUNTRY field value (item 3 above) as key, get the CURRENCY_TO from Currency Hashtable.
  8. EXCHG_RATE (pos 466-474) field:
    Based on the COUNTRY field value (item 3 above) as key, get the EXCHG_RATE from Currency Hashtable.
  9. FINGERPRINT (pos 475-506) field:
    Hashed the message of "CODE^MBR_ID^PIN^TRAN_AMT" by using the HmacMD5 hashing method as below:
    //Constants
    String transactionKey    = "cosway88";
    
    KeyGenerator kg = KeyGenerator.getInstance("HmacMD5");
    SecretKey key = new SecretKeySpec(transactionKey.getBytes(), "HmacMD5");
    // A MAC object is created to generate the hash using the HmacMD5 algorithm
    Mac mac = Mac.getInstance("HmacMD5");
    mac.init(key);
    
    //Pass in method argument
    String inputstring = "CEN001^MEM001^182838^10.50";
    byte[] result = mac.doFinal(inputstring.getBytes());
    // Convert the result from byte[] to hexadecimal format
    StringBuffer strbuf = new StringBuffer(result.length * 2);
    
    for(int i=0; i< result.length; i++)
    {
        if(((int) result[i] & 0xff) < 0x10)
            strbuf.append("0");
        strbuf.append(Long.toString((int) result[i] & 0xff, 16));
    }
    
    String fingerprint = strbuf.toString().toUpperCase();
    

Fixed length File Format. Refer to the DP_Batch_File_Format_PA5.xls in DP Batch File Format, column "Profit" for details of field.


Files

DP_PROFIT_FINANCE_REFERENCE_072011_Sample.xls (102 KB) DP_PROFIT_FINANCE_REFERENCE_072011_Sample.xls Finance Reference Report Sample Chooi-Mey, 09/05/2011 11:22 AM
nicholasClass.sh (297 Bytes) nicholasClass.sh Chee-Hoong, 09/19/2011 12:38 PM
poi-3.7-20101029.jar (1.6 MB) poi-3.7-20101029.jar Chee-Hoong, 09/19/2011 12:39 PM
Actions #1

Updated by Chooi-Mey about 13 years ago

  • Assignee set to Chee-Hoong
Actions #2

Updated by Chooi-Mey about 13 years ago

Amendment on item (5) TRAN_AMT:

TRAN_AMT = dp_earned (retrieval) * EXCHG_RATE

Note: dp_earned is in USD currency value. Take the absolute value via Math.abs method.

Actions #3

Updated by Chee-Hoong about 13 years ago

planning program flow soon

Actions #4

Updated by Chooi-Mey about 13 years ago

Add in:

item 11) TRAN_ID, set it to 'PROFITmmyyyy', where mmyyyy is the profit month.

Actions #5

Updated by Chooi-Mey about 13 years ago

  • File DP_Batch_File_Format_PA3.xls added
Actions #6

Updated by Chooi-Mey about 13 years ago

For the batch file format, please refer to DP Batch File Format, for the latest version.

Actions #7

Updated by chin-yeh about 13 years ago

removed all old attachments. refer to the DP Batch File Format for the latest documents.

Actions #8

Updated by chin-yeh about 13 years ago

  • File deleted (DP_Batch_File_Format_PA3.xls)
Actions #9

Updated by chin-yeh about 13 years ago

  • File deleted (DP_Batch_File_Format_PA3.xls)
Actions #10

Updated by chin-yeh about 13 years ago

  • Target version set to 0.1
Actions #11

Updated by Chooi-Mey about 13 years ago

Changes:
Do not need to retrieve records from MEMBER_STAT, as BO earned DP profit has already been converted into cash pay out via eAccount, therefore BO will not able to utilize DP during purchase.
Only need to retrieve data from VIP_STAT.

Actions #12

Updated by Chee-Hoong about 13 years ago

means the the SQL to retrive VIP_STAT and MEMBER_STAT table did not need to execute? ty

Actions #13

Updated by Chee-Hoong about 13 years ago

or remove the UNION SELECT MEMBER_STAT?

Actions #14

Updated by Chooi-Mey about 13 years ago

Only remove the UNION SELECT MEMBER_STAT from SQL query.

Actions #15

Updated by chin-yeh about 13 years ago

refer to the issue description for the latest data retrievin SQL

Actions #16

Updated by Chee-Hoong about 13 years ago

ok ty

Actions #17

Updated by chin-yeh about 13 years ago

Please send the sample generated file to Benny Kuok Chan Weng [] by today, do CC me and chooi-mey. If there's any issue, do update here. Thanks.

Actions #18

Updated by Chee-Hoong about 13 years ago

to chin yeh, the sample file is gen-ed.
u wan to hav a look first or i direct email to the receipient?

Actions #19

Updated by chin-yeh about 13 years ago

work with Benny to make sure the system can process the generated file.

do update the issue to reflect the current progress.

Actions #20

Updated by chin-yeh about 13 years ago

There's some changes:
  • TRAN_ID column - the data month will be the previous month of the report generation date
    • e.g. if report generation month is August 2011, then the value of the column would be PROFIT072011
  • able to accept input parameter to generate batch file for different month, for example, 092011, 102011
Actions #21

Updated by Chooi-Mey about 13 years ago

Need to apply the logic (same as bank file generation checking) that check whether is ready to generate not.
Refer to GenProfitPaymentForUkBank, method "getUserInputOrSystemParam" logic checking, to check whether is the publish flag (MEND_PROC_IND) is set to 'Y' in table MTH_END_CALC, based on pass in month and year param/sys date.

Actions #22

Updated by Chee-Hoong about 13 years ago

to chooi mey, is it if date not null then READY_TO_GENERATE set to true value in hashtable?

Actions #23

Updated by Chee-Hoong about 13 years ago

sample file sent to benny and waiting for feedback

Actions #24

Updated by chin-yeh about 13 years ago

As request by Benny, you need to provide him the batch file that contains:
  • The Profit from member of country Taiwan which belongs to Foreigner.
  • The Profit from member of country Taiwan which not belongs to Foreigner.
  • The Profit from member of country apart from Taiwan.

Remember to refer to the latest batch file format, DP Batch File Format

Suggestion:
  • populate the data to a new table, vip_stat_dummy and point your batch program to the new table
  • below is the sample SQL you could use to populate part of the table's columns:
    select a.sacntry, b.shlogid from shaddr a,shopper b 
        where b.shrfnbr=a.sashnbr
         and b.shshtyp = 'S' and b.shopper_grp = '9' 
         and b.status ='A' and a.saadrflg='P' 
         and a.sacntry in ('036')
    
    • replace the sacntry with the country code you want to query
  • populate the dp_earned column with dummy values
  • populate the table with at least 5-7 country codes, each country code has 15-20 member ID
  • try to only populate the columns that needed by batch file, e.g. dp_earned
  • assume all Taiwan ID is not foreigner
Actions #25

Updated by chin-yeh about 13 years ago

Updates:
  • output filename convention is DP_PROFITMMyyyy.txt
    • MMyyyy - profit month, e.g. 092011 for September 2011
    • Example: DP_PROFIT092011.txt, DP_PROFIT102011.txt
  • output folder is

/usr/ecosway/offlinefiles/etransfer

  • no need to specify any value for the IS_FORE column. Just leave it blank
Actions #26

Updated by Chee-Hoong about 13 years ago

ok

Actions #27

Updated by chin-yeh about 13 years ago

Could you prepare the following guide:
  • how to deploy the batch program
  • how to execute the batch program
  • how to configure the application properties if any

It would be great if the guides are written in wiki so everyone can view or edit it when necessary.

Actions #28

Updated by Chee-Hoong about 13 years ago

•how to deploy the batch program
•how to execute the batch program
•how to configure the application properties if any

for these purposes
is it different from other batch program as need to be planned?

Actions #29

Updated by chin-yeh about 13 years ago

Just prepare for the profit batch program first.

Besides that, here are the latest changes needed:
  • change the PRO_CODE for profit to Profit, originally is Bonus
Actions #30

Updated by Chee-Hoong about 13 years ago

neeed to gen and send sample file again?

Actions #31

Updated by chin-yeh about 13 years ago

yes, please generate again and send to Benny.

Actions #32

Updated by Chooi-Mey about 13 years ago

Bugs:
1) Those VIP residing in China, Macau and Hong Kong, should mapped into HKD currency (Currency_To), instead of RMB/MC.

Actions #33

Updated by Chee-Hoong about 13 years ago

the macau and china residing country is mapped to hong kong residing country in program and file generated.
only data inside database not changed.

Actions #34

Updated by Chooi-Mey about 13 years ago

The Currency_to should mapped to HKD as well, besides the residing country. Same to exchange rate.
It means when system detect the actual residing country of the VIP is 156/446, when generate the profit batch file, system need to treat them based at HK, instead of their originated country. This is because those VIP is actually earned profit/utilized DP balance in HKD currency, instead of RMB/MC.

Actions #35

Updated by Chee-Hoong about 13 years ago

ok i get wat u mean. now the file regenerated

Actions #36

Updated by Chooi-Mey about 13 years ago

  • Status changed from New to Feedback

Ok. Verified.

Actions #37

Updated by Chooi-Mey about 13 years ago

For DP Amount in profit file, the value need to be in Local currency of the mapped country.
The retrieval value from VIP_STAT is defaulted in USD value. So need to perform currency conversion based on the latest exchange rate (from MEND_CURRCONV table) and its mapped country/currency.
DP AMOUNT = dp_earned * exchange rate (based on its mapped currency)
For example, for China VIP, the dp_earned need to be converted into HKD currency as the DP amount in profit file.

Actions #38

Updated by Chooi-Mey about 13 years ago

Add requirements:
1) Finance Report
- Filename Format: DP_PROFIT_FINANCE_REFERENCE_MMyyyy.csv
- File Encoding: ISO-8859-1
- Comma Delimited
- Header: MEMBER ID,COUNTRY CODE,MAPPED COUNTRY CODE,DP EARNED (USD),DP EARNED,EXCHANGE RATE
- Details: Example
VP123456,156,344,2.00(USD),15.60(HKD),7.80
VP123457,826,826,-1.00(USD),-0.62(GBP),0.62

2) Exception Report
- Filename Format: DP_PROFIT_EXCEPTION_MMyyyy.csv
- File Encoding: ISO-8859-1
- Comma Delimited
- Header: MEMBER ID,DP EARNED (USD),REASON
- Details: Example
VP123456,2.00,EXCHANGE RATE OF 344 NOT FOUND
VP123457,-1.00,EXCHANGE RATE OF 826 NOT FOUND
- Exception is catch when hashExchangeRateValue is null (due to fail get the match record from MEND_CURRCONV by country code), and skipped the record to be written into profit file.

Actions #39

Updated by chin-yeh about 13 years ago

Important notes:
  • Refer to the format2Decimal method in my.com.eCosway.util.MyUtil class in usa-mall repository about how to round the monetary value such as DP amount. This is the common method we use to round the value to 2 decimal places.
Actions #40

Updated by chin-yeh about 13 years ago

The file encoding of the profit batch file will be UTF-8.

FYI, the file encoding for all of the VP/DP batch files will be UTF-8 as well.

Actions #41

Updated by Chee-Hoong about 13 years ago

format dp earned to 2 decimal is after currency conversion? for calculation purpose?

Actions #42

Updated by chin-yeh about 13 years ago

Use the util to format all monetary value to 2 decimal places after calculation

Actions #43

Updated by Chee-Hoong about 13 years ago

ok i get it

Actions #44

Updated by Chee-Hoong about 13 years ago

wat is the formula or how to calculate the dp that need to convert 2 decimal?

Actions #45

Updated by chin-yeh about 13 years ago

I've imported the live VIP_STAT & mend_currconv tables into development STORE db. Can you generate a copy and pass it to Ting-Ting for verification asap?

As per discussion, this batch program will be deployed to production by tomorrow morning. After deployed, we will generate the batch file and pass it to Benny for final verification.

Actions #46

Updated by Chee-Hoong about 13 years ago

i just gen the file and send to ting ting?

Actions #47

Updated by chin-yeh about 13 years ago

As discussed, do provide the profit batch file, which generated in live environment, to Ting-Ting & Benny for final verification.

After that, try to fix all of the bug(s) you have encountered by today.

Actions #48

Updated by Chee-Hoong about 13 years ago

production generated file sent to ting ting and benny.
bug fixed

Actions #49

Updated by Chooi-Mey about 13 years ago

Changes:

1) Add in USD_DP_AMT field at last column (position 531-543), with length 13N (13,2). Pass the DP amount in USD currency (before convert) into the field.

2) For INV_NO field (position 140-159), put in value "BONUSyyyyMM" to show the profit month remarks. For example: BONUS201107.

This changes will only take effect for next month profit run. The updated batch file format will be uploaded later.

Actions #50

Updated by Chee-Hoong about 13 years ago

adding

Actions #51

Updated by Chee-Hoong about 13 years ago

INV_NO field refers to current date time?

Actions #52

Updated by Chooi-Mey about 13 years ago

INV_NO field refer to profit month, for example, if you are generating for May 2011 profit, then it will be BONUS201105. Not the generated date time. Same as the filename MMyyyy logic.

Actions #53

Updated by Chee-Hoong about 13 years ago

finding test data to enable verification

Actions #54

Updated by Chooi-Mey about 13 years ago

Changes:
1) Generate the Finance Reference Report into excel(xls) format, with VIP records group by country as tab(sheet) and show the total amount (USD) and total amount (local currency) as footer. Refer to attached sample format (DP_PROFIT_FINANCE_REFERENCE_072011_Sample.xls).
2) Perform load test on it, to evaluate the impact on memory usage.

Actions #55

Updated by chin-yeh about 13 years ago

Use the Apache POI to generate the excel file.

Regarding to the load test, I would suggest you to capture the result as:
  • memory usage on writing 1 million records to excel file
  • memory usage on writing 100,000 records to excel file
  • memory usage on writing 5 millions records (5 mapped country code in total, each contains 1 million) to excel file
  • memory usage on writing 500,000 records (5 mapped country code in total, each contains 100,000) to excel file

Also, do update the Due date when this changes are ready to be deployed to production environment for final testing.

Actions #56

Updated by Chee-Hoong about 13 years ago

is the excel API (APACHE POI) already exist in our eclipse or need to download?

Actions #57

Updated by chin-yeh about 13 years ago

get the latest stable version from the official website

Actions #58

Updated by chin-yeh about 13 years ago

In excel, there's a limit on number of rows & columns per sheet.
  • prior office 2007 - 65,536 rows by 256 columns
  • office 2007 or above - 1,048,576 rows by 16,384 columns

Click here to see the more details of the excel specification.

Because of this, your program must be able to split out the record to different sheets when reach the limit. However, the size of the workbook is limited by the available memory resource on the client machine.

At the moment, we will use xls format to have better compatibility.

Actions #59

Updated by chin-yeh about 13 years ago

you could use this code snippet to capture the memory usage:

long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();

Actions #60

Updated by Chee-Hoong about 13 years ago

is the Runtime under java.lang? if is i try it now

Actions #61

Updated by chin-yeh about 13 years ago

Just a reminder. The total amount in the sheet's footer is referring to total amount (USD & local currency) on the particular sheet, not mapped country code.

Besides that, do update the Due Date.

Actions #62

Updated by Chee-Hoong about 13 years ago

load test still in progress
latest code commited to CVS

Actions #63

Updated by chin-yeh about 13 years ago

  • Due date changed from 08/12/2011 to 09/15/2011

The load test result and the changes should be ready by this Thursday as we will calculate profit next week.

Actions #64

Updated by Chee-Hoong about 13 years ago

• memory usage on writing 100,000 records to excel file - 144212200 bytes (144MB)

• memory usage on writing 500,000 records (5 mapped country code in total, each contains 100,000) to excel file - 759753320 bytes (759MB)

• memory usage on writing 1 million records to excel file - 1385801560 bytes (1.39GB)

Actions #65

Updated by Chee-Hoong about 13 years ago

the following is settings for JVM arg
100 k and 500 k use default (no need to set)
for 1m record with arg -Xmx1536m

Actions #66

Updated by chin-yeh about 13 years ago

Attach the latest shell scripts and the required libraries here

Actions #67

Updated by Chee-Hoong about 13 years ago

here is the new script file to run the program.
and only 1 new library added

Actions #68

Updated by Chee-Hoong about 13 years ago

Actions #69

Updated by chin-yeh almost 13 years ago

This batch program has already been scheduled to run daily since yesterday.

Since this is a new program, you are required to enter the details of the program into the runHK.txt sheet of DailyBatchNew.xls, the file are located at:

<<src shared folder>>/schedule batch

Actions #70

Updated by Chee-Hoong almost 13 years ago

i take a look

Actions #71

Updated by Chee-Hoong almost 13 years ago

direct profit details added into into the runHK.txt sheet of DailyBatchNew.xls

Actions #72

Updated by Chooi-Mey almost 13 years ago

Pls provide guideline to Chee Wei on how to manual run the DP Profit program.

Actions #73

Updated by Chee-Hoong almost 13 years ago

i've added in the param needed in the force run column

Actions #74

Updated by chin-yeh almost 13 years ago

Please fill up the related info. for Date Generated and Data Date columns in the excel file.

Actions #75

Updated by Chee-Hoong almost 13 years ago

Date Generated and Date Date is refer to date of?

Actions #76

Updated by Chee-Hoong almost 13 years ago

Date Generated and Data Date filled

Actions #77

Updated by Chooi-Mey almost 13 years ago

[Changes]
1) Change the Finance Reference Report Excel sheet(tab) from country code to country name (with max length 20 chars).
2) Add new param argument to allow pre-run without checking on the publish flag.

Actions #78

Updated by Chooi-Mey almost 13 years ago

Both items (country name & force run) tested.

Actions #79

Updated by Chee-Hoong almost 13 years ago

ok

Actions #80

Updated by chin-yeh almost 13 years ago

do update the DailyBatchNew.xls if there's any changes made.

Actions #81

Updated by Chee-Hoong almost 13 years ago

DailyBatchNew.xls updated

Actions #82

Updated by Chooi-Mey almost 13 years ago

[Changes]
- Remove the 2 columns: Country Code and Mapped Country Code, from displaying on sheet.
Note: Comment out the code with remarks, for future enable back if need to.

Actions #83

Updated by Chee-Hoong almost 13 years ago

changes deployed to live and code commited into CVS

Actions #84

Updated by Chooi-Mey almost 13 years ago

  • Due date changed from 09/15/2011 to 11/04/2011

[Changes/Bug]
1) In DP_Profit_Finance_Reference, show the value of the amount, include the minus sign, - if < 0.
2) Total is wrongly calculated due to - value of the amount is not being take into calculation. Total is sum of amount (with 2 decimal point).

Actions #85

Updated by Chooi-Mey almost 13 years ago

Chooi-Mey wrote:

[Changes/Bug]
  1. In DP_Profit_Finance_Reference, show the value of the amount, include the negative sign if < 0.
  2. Total is wrongly calculated due to negative value of the amount is not being take into calculation. Total is sum of amount (with 2 decimal point).
Actions #86

Updated by Chee-Hoong almost 13 years ago

calculation corrected and deployed to production env

Actions #87

Updated by chin-yeh over 12 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 0 to 100
  • Resolution set to Fixed

fixed and deployed

Actions

Also available in: Atom PDF