incubus - an obsession in computing
  • rss
  • Home
  • Linux Apps
    • C&G 4250 Linux Extension
  • C&G 4240
    • Overview
    • Validate Program
    • Sort Program
    • Update / Merge Program
    • Report Program
    • Downloads
  • C&G 4250
    • Overview
    • Data Entry Program
    • Validate Program
    • Sort Program
    • Customer Update / Merge Program
    • Customer Report Program
    • Stock Update / Merge Program
    • Stock Report Program
    • Downloads
  • About
  • Contact

Stock Report Program

Program Overview:

The contents of the newly updated (created) stock master file produced by the Stock Update Program (494792P5.exe) are now to be printed under suitable headings. Stock records that have free stock levels below their minimum stock level are highlighted on the report. Also stock records that have a zero free stock level are highlighted on the report.

The binary file which contains the updated stock records must be named STCKMAST.DAT, and must be located in the same directory from where the report program is located and executed from. The updated stock index file must be named STCKMAST.IDX, and must be located in the same directory from where the report program is located and executed from. This is unless the user changes these default file names by entering additional program parameters at the command line. Below describes how the default file names may be overridden: -

494792P6.exe <stock master file> <stock index file> <printer>

The defaults file names are as follows: -

Stock Master file – STCKMAST.DAT
Stock Index file – STCKMAST.IDX
Printer – PRN

If the user wishes to override one of these files they must also enter the file names of all the files preceding it. For example to override the printer to a text file named test.txt, they must enter the following command: -

494792P6.exe STCKMAST.DAT STCKMAST.IDX test.txt

However if the user only wishes to change the name of the stock master file, they may enter the following command: -

494792P6.exe NEWSTCK.DAT

The overriding of the default file names is mainly for test purposes or where there is a need to do so. Such a need may arise when there is a need to produce a report for an old stock master file, where maybe the old report had been accidentally destroyed. The everyday users of this program need not even have to be aware of this overriding feature.

Report:

When the program is first started it checks to see if there was a command-line argument given. If there was then the argument is taken to be the name of the stock master file, and an attempt at opening this file is made. If the attempt fails then the program reverts to using the default file name (STCKMAST.DAT). An attempt at opening the default named file is now made, if this also fails an error message informing the user that the file could not be opened is displayed and the program exits returning the user back to the operating system.

If there was another command-line argument given this is taken to be the name of the stock index file. An attempt at opening this file is made. If the attempt fails then the program reverts to using the default file name (STCKMAST.IDX). An attempt at opening the default named file is now made, if this also fails an error message informing the user that the file could not be opened is displayed and the program exits returning the user back to the operating system.

If there was another command-line argument given this is taken to be the name of the printer file (where the output from this program is printed to). An attempt at opening this file is made. If the attempt fails then the program reverts to using the default file name (PRN). An attempt at opening the default named file is now made, if this also fails an error message informing the user that the file could not be opened is displayed and the program exits returning the user back to the operating system.

If no command-line arguments were given then all default file names are used.

Once the required files have been opened, the printer is reset to its default settings, and then placed in landscape mode. A page header is now printed at the top of the first page. This page header contains the following information: -

Page title – Zenith Paints Master Stock File Report.
Current system date, in the format DD/MM/YYYY.
Current page number, Page #.
Column headings for the following: -

Part Number
Part Description
Supplier Code
Free Stock
Minimum Stock Level
Selling Price
Last Movement date

A message is now displayed to the user informing them that the Stock Master file is about to be printed (the names of the two files are also displayed so that the user knows where the input is coming from and the output is going to).

The main processing loop is now entered; a stock record is read from the master file. There is a detail description below on how a stock record is read from the master file.

Get Stock Record:

The getStockRec function is a very important function within this program, because of this here is a detailed description of the functions actions.

If this is the very first time this function has been called then the following actions occur. It is known as to whether this is the first time calling this function as the static variable idxList will equal NULL (the index list has not been created).

Firstly a calculation is made to determine how many records are stored in the index file. This is achieved by going to the end of the index file and then calculating how many big the file. Next we divide the size of the file by the size of an index record. This will leave us the exact number of records that are stored in the index file.

/*– Calculate the number of record entries –*/
fseek(index,0L,SEEK_END);
count = ftell(index) / IDX_SIZE;

When we have determined how many records there are in the index file, we then attempt to allocate enough memory to store the entire contents of the index file in memory. If the memory allocation fails we report this error to the user by way of an error message on the screen. The program is also exited, returning a value that indicates program failure to the operating system. The user is then returned to the operating system.

/*– Create a list to hold the contents of the index file –*/
if (!(idxList = (STOCK_IDX *) malloc(count * IDX_SIZE)))
{ printf(“Error allocating memory for INDEX LIST\n”);
exit(EXIT_FAILURE);
}

Next we keep track of the allocated memory, for when we are in a position to free it later. The index file pointer is moved back to point to the start of the index file. The complete contents of the index file now read from disk and stored in the allocated memory. The index list now stored in memory is sorted into ascending part number (key) using the standard sort utility qsort.

/*– Keep track of the start of the allocated memory –*/
start = idxList;

/*– Go back to the start of the index file –*/
rewind(index);
/*– Read the complete list from the index file –*/
fread(idxList, IDX_SIZE * count, 1, index);
/*– Sort the index list into ascending part number order –*/
qsort(idxList, count, IDX_SIZE, compare);

The above actions are only performed the very first time this function is called. The remaining actions occur when ever the function is called, as this part of the function returns the next available record from the stock master file. By next available I mean the next master stock record as read in ascending part number sequence.

We move to the correct position in the stock master file, this is known by multiplying the value stored in the current index records record number field by the size of a master stock record. The correct stock master record is then read from the stock master file.

If the record was read successfully, we move to the next index record in the index list (idxList++), and return to the calling function that the operation succeeded.

If the record was not successfully read then a check is made to see if we are at the end of the stock master file. If we have reached the end of the stock master file the memory allocated to store the index list is not freed as it is no longer required. The idxList pointer is also set to point to NULL (having no value). We then return to the calling function that the operation failed.

If the stock record was not successfully read and we have not yet reached the end of the master file, then an error is generated and displayed on screen to the user. The program is also exited, returning a value that indicates program failure to the operating system. The user is then returned to the operating system.

Once a stock record has been successfully read from the master stock file its contents are displayed under the correct page headings.

A check is now made to ensure the stock records stock level has not reached zero. If it has reached a zero stock level then the stock level is underlined with asterisks and a message printed indicating that this item is totally out of stock. A count is kept as to how many stock records have a zero stock level.

A check is now made to ensure the stock records stock level is not below its minimum stock level. If it is currently below its minimum level then the stock level is underlined with asterisks and a message printed indicating that this item is currently below its minimum stock level by the correct number it is below that level. A count is kept as to how many stock records are below their minimum stock level.

When all the stock records have been processed we print our report totals. The report totals include how many stock items are below their minimum stock levels, how many stock items that are totally out of stack and how many stock items have been processed.

Finally the program tidies up after its self by closing all open files and returns a value that indicates program success to the operating system. The user is then returned back to the operating system.

Design decisions:

There were no major design decisions as this was a quite straight forward program to design. It opens the stock master file and the printer, then simply reads each record from the master file and prints these details to the printer. The printout is in landscape so that all the stock records’ details are printed on a single line under appropriate headings.

To start with the file names were hard coded within the program; if any of them were not found then the program would exit. This was changed quite late in the program development, as it would be more practical to allow the user to override the name of any file at the command line (as a command line argument). This way the file names are not hard coded into the program, which makes the program much more flexible. If however a file name is not provided on the command line or there was an error trying to open the given file name then the default file names are used.

Limitations:

There are no real limitations to this program, as all it’s purpose in life is to produce a formatted report. There may be a problem if the stock index file ever exceeds the amount of memory that can be allocated. As the entire contents of the index are read into memory and sorted, the program can not do any printing if the list can not be created.

All of the programs are limited to using a Hewlett Packard printer as all printouts use Hewlett Packard specific escape codes to format the output. If the printer is changed for a different make then this program will need modification and recompilation. The modifications are all contained within the printer.h header file and so should not cause any problems if this task is required.

Comments rss
Comments rss
Trackback
Trackback

Leave a Reply

Click here to cancel reply.

You must be logged in to post a comment.

Search @incubus

Recent Posts

  • Compressed Hard Disk Image
  • It’s been along time …
  • T209 ECA Result
  • Old Linux Discs…
  • Panasonic CF-U1 / 2D Barcode Imager
  • Useful Gentoo Aliases
  • Hosting Provider Changed.
  • Linux – Merge AVI Files
  • Coders at Work
  • Remove OGA Office Not Genuine Notifications (KB949810)

Links

  • Demonoid
  • Engadget
  • Gentoo Linux
  • Gentoo Planet
  • Gentoo Universe
  • GNOME
  • GNOME Planet
  • ISO Hunt
  • OS News
  • Piratebay

Navigation

  • Register
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Archives

  • May 2010 (1)
  • February 2010 (1)
  • December 2009 (3)
  • November 2009 (2)
  • September 2009 (4)
  • August 2009 (1)
  • July 2009 (1)
  • May 2009 (2)
  • April 2009 (1)
  • February 2009 (2)
  • January 2009 (1)
  • December 2008 (1)
  • November 2008 (1)
  • October 2008 (3)
  • September 2008 (7)
  • August 2008 (16)

Categories

  • 4240 (1)
  • 4250 (1)
  • Code (8)
  • Linux (29)
  • ODB2 (2)
  • Open University (6)
  • Tips & Tricks (13)
  • Uncategorized (5)

Stats

Visits Today: 6
rss Comments rss design by jide powered by Wordpress get firefox
© Copyright 1999-2010 @incubus. All Rights Reserved. All trademarks acknowledged.
incubus.co.uk || incubus.mobi || rankinstine.co.uk