Generation and restoration of a transaction number

Source: Internet
Author: User
Tags addall

The requirement is given by a student. I will help him finish it and record it.

The requirements are as follows:

Business change content and needs confirmation:

1. original transaction sequence number --> algorithm --> disrupt transaction sequence number

2. The disrupted transaction sequence number corresponds to the original transaction sequence number to ensure that the customer can return the goods according to the disrupted transaction sequence number.

3. the cashier's invoice only displays the transaction number that has been disrupted.

4. The correct transaction serial number is still displayed on the top of the POs screen to facilitate routine operations by the cashier.

System Change description:

Add a Field automatically generated when a disordered ticket is added to the previous POS invoice. the disordered serial number is displayed in the customer ticket, query the original correct transaction sequence number from the table during return.

Algorithm Implementation: Shift algorithm. For example, a normal transaction sequence number is 1 2 3 4 5 6 (A, B, C, D, E, F, G, d, C, F, E) and sort again, then the disordered sequence number becomes: (2 1 4 3 6 5)

 

1. Set whether system parameters disrupt the transaction sequence number confusetrannumber = yes;

2. If the transaction sequence number needs to be disrupted, the program will disrupt the original transaction sequence number and store it in memory variable A. If the transaction sequence number does not need to be disrupted, the correct transaction sequence number will be stored in memory variable;

3. Read transaction number a during printing;

4. During return, enter the transaction sequence number after disruption and use the algorithm to calculate the normal transaction sequence number. Then, retrieve the content of the normal transaction sequence number on the interface for return;

5. algorithm parsing:

Ø transaction serial number calculated during sales:

Disrupt the passed transaction sequence number. If the length of the transaction sequence number is less than 8 digits, use "0" to fill it up. The sum of the numbers above and 10 is equal to that of 10, the remainder may be 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. There are different ways to arrange the remainder: 56204173, 20417365, 41736520, 73652041, 65412073, 20736541, 65204173, 20417365, 41736520, 73652041

For example, if the transaction number is 12345678, and the sum of 36 and 10 is 6, the sixth type of disruption method is 65204173, and the transaction number after the disruption is 76315284.

Transaction number during return:

Returns the transaction sequence number after the input is disrupted. If the transaction sequence number is less than 8 characters long, use "0" to fill it up, the remainder may be 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. There are different ways to disrupt the remainder: 35274016, 13052764, 71630542, 57416320, 53472106, 17036542, 35274106, 13052764, 71630542, 57416320

For example, if the return transaction number is 76315284, and the sum of 36 and 10 is 6, the sixth type of disruption method is 35274106, and the normal transaction number is 12345678.

 

Directly add the code and comment out everything:

 

Code

 1 #-*-coding: GBK -*-
2
3 ''' transaction code decoding '''
4 # sales number Arrangement
5 saleorder = ['123', '123', '123', '123', '123 ',\
6 '123', '123', '123', '123', '123']
7 # How to arrange return numbers
8 sendbackorder = ['20160301', '20160301', '20160301', '20160301 ',\
9 '123', '123', '123', '123', '123']
10 def addall (TID ):
11 '''calculate the sum of the numbers '''
12 Total = 0
13 For N in TID:
14 total + = int (N)
15 return total
16
17 def selectorder (total, flag ):
18 ''' select the Arrangement Method
19 Total: Sum of Values
20 flag: sale Sales No. is disrupted; sendback return No. is restored
21 '''
22 if flag = 'sale ':
23 return saleorder [Total % 10]
24 else:
25 return sendbackorder [Total % 10]
26
27 def showresult (TID, flag ):
28''' return the decoding or encoding result
29 TID: Sales No. Or return no.
30 flag: sale Sales No. is disrupted; sendback return No. is restored
31 '''
32 order = selectorder (addall (TID), flag)
33 res =''
34 For index in order:
35 res + = TID [int (INDEX)]
36 return res
37
38 def formatid (TID ):
'''Formatting removes spaces and line breaks to create an 8-bit length '''
40 tid = tid. Strip ()
41 tid = TID [: 8]
42 tid = tid. zfill (8)
43 # tid = '% 08d' % tid
44 return tid
45
46
47 def main ():
48 '''test function '''
49 while (true ):
50 tid = raw_input ('\ N input number: \ n ')
51 flag = raw_input ('input number type: sale or sendback: \ n ')
52 tid = formatid (TID)
53 print showresult (TID, flag)
54 if _ name _ = '_ main __':
55 main ()

 

 

Several other functions are used:

Strip ([chars])
Return a copy of the string with Trailing characters removed.
Returns a copy of a string that removes extra characters.
The chars argument is a string specifying the set of characters to be removed.
The chars parameter is a specified character set to be deleted.
If omitted or none, the Chars argument defaults to removing whitespace.
If this parameter is set to political or none, the Chars parameter Deletes white space characters by default.
The chars argument is not a suffix; rather, all combinations of its values are stripped:
The Char parameter is not a suffix. In fact, all combinations of their values will be deleted.

 

Lstrip ([chars])
Return a copy of the string with leading characters removed. the chars argument is a string specifying the set of characters to be removed. if omitted or none, the Chars argument defaults to removing whitespace. the chars argument is not a prefix; rather, all combinations of its values are stripped:

Rstrip ([chars])
Return a copy of the string with Trailing characters removed. the chars argument is a string specifying the set of characters to be removed. if omitted or none, the Chars argument defaults to removing whitespace. the chars argument is not a suffix; rather, all combinations of its values are stripped:

Ljust (width [, fillchar])
Return the string left justified in a string of length width. Padding is done using the specified fillchar (default is a space ).
Returns a left-side typographical string with a string length of width. It is filled with the specified (specific, clear) parameter fillchar (filling string). The default value is space.
The original string is returned if width is less than Len (s). Changed in version 2.4: Support for the fillchar argument.
If wdith is less than the string length, the original string is returned. Change in version 2.4: The fillchar parameter is supported.

Must ust (width [, fillchar])
Return the string right justified in a string of length width. Padding is done using the specified fillchar (default is a space ).
The original string is returned if width is less than Len (s). Changed in version 2.4: Support for the fillchar argument.

Zfill (width)
Return the numeric string left filled with zeros in a string of length width.
Returns a string with a length of width filled with 0 on the left.
The original string is returned if width is less than Len (s). New in version 2.2.2.
If width is less than the string length, the original string is returned. Version 2.2.2 is added.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.