Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PHP, HTML5 Accounting Import The Mammoth Island Tourism Company is undergoing a

ID: 3845982 • Letter: P

Question

PHP, HTML5

Accounting Import

The Mammoth Island Tourism Company is undergoing a project to digitize a large quantity of paper documents, sales records going back 100 years.
They’ve already commissioned a company to digitize the documents into a text format, but now they require an application to extract a small amount of useful information from the documents.
Unfortunately, their accounting format changed several times over the course of business, so the application must be intelligent enough to find the data.
For this application, the client would pay $490.

Interface

Provide an interface where the user can upload a document of any text or csv file type. Three sample datasets are provided for you.

When the file is uploaded, check that it contains the proper type of information – text. Other types, such as images, should not be allowed.

Once the file is uploaded, store the file in a secure location.

File Parsing

Use any methods at your disposal to read the contents of the document
Certain types of information should be gathered and stored for output.

Phone Number – any data that resembles a phone number (with or without area code) should be extracted for the data.B3.

Account Number – The client uses a specific format to record account numbers. This format is two letters followed by eight numbers
(prior to 1920 they used two letters followed by four numbers).

Sales amount – the amount of each sale should be extracted if known.

data_1914.txt

data_1938.csv

data_1952.csv

Output

Provide simple information about the data file: filename and record count

List all records with corresponding account, phone, and amount.
(Leave blank if some information cannot be determined.)

Provide the total sale amount from the entire document.

Sample Output

  

Customer ActRef tele Total Date Becker KW37749876 433-3431 $1.79 11/17/38 Ferris PS75344973 838-9495 $74.29 3/5/38 Alonzo YB22356502 633-8635 $171.73 3/30/38 Fultz VS12702734 968-7651 $8.51 4/13/38 Estrada NG57202870 909-2601 $28.40 7/18/38 Christian PW26261775 336-7487 $62.29 3/30/38 Gilchrist DG74291195 569-3558 $67.73 6/15/38 Andrade DP88009441 110-6774 $168.94 7/13/38 Culpepper VW26510507 870-6483 $32.31 8/23/38 Bollinger AU52849187 316-4614 $125.13 2/3/38 Forbes CV99714005 359-7954 $115.82 11/8/38 Frantz IL87423619 424-6335 $67.23 10/13/38 Barrera MD77991820 312-2671 $55.75 12/1/38 Brunson JQ10021685 333-2355 $129.24 8/15/38 Burrell JV19475662 280-1447 $159.74 5/15/38 Ely BO26578567 611-3813 $67.79 3/7/38 Beard PX17737465 272-8510 $108.70 12/15/38 Grayson GH35585663 119-8614 $18.40 4/6/38 Dupree FW48708763 400-7324 $89.12 6/21/38 Beaty IG18365372 652-9484 $182.58 7/31/38 Castillo ZX35309452 587-3079 $107.22 3/24/38 Brewer VH68557195 765-6322 $175.87 12/20/38 Atwood KM36381396 893-8443 $190.71 3/15/38 Childers SL95951973 885-1774 $162.10 1/27/38 Bravo BP48706583 641-3583 $7.43 3/5/38 Bassett XR35526858 558-8701 $49.60 12/3/38 Bullock ZK29459849 224-1429 $52.57 5/22/38 Delvalle SF27056636 145-1627 $169.53 6/10/38 Bryson HE60283997 644-4631 $67.49 9/4/38 Crocker QI11130784 791-1154 $156.12 10/2/38 Gaye ZX89555454 400-6030 $47.12 7/1/38 Buford QC18450718 704-3688 $185.77 4/17/38 Easter HB76267072 641-2625 $165.10 6/19/38 Carpenter NJ47701986 746-1477 $36.27 9/29/38 Flanagan QL40119055 987-6896 $30.90 3/9/38 Conner AZ75193831 372-2482 $171.68 11/14/38 Downey AV96350502 938-3724 $63.73 1/27/38 Field GV88902011 456-4180 $111.26 1/8/38 Benavidez GN58258130 735-9624 $90.36 4/3/38 Daley CA88215077 746-7540 $75.48 2/17/38 Fournier HR57654575 706-1542 $160.61 3/1/38 Crow NI98289769 873-7585 $19.60 8/20/38 Dent HH82555104 673-4005 $39.93 9/4/38 Graf BU44705117 318-1473 $120.53 12/14/38 Cabrera UT14179947 939-1345 $86.38 3/23/38 Chappell BM55779074 920-4068 $132.66 7/25/38 Cornelius BU22686515 770-3456 $100.58 9/24/38

Explanation / Answer

<html>
<body>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="sel_file" id="fileToUpload">
<input type="submit" value="submit" name="submit">
</form>

<?php
$servername = "localhost";
$username = "root";
$password = "";
$db="test";
// Create connection
$conn = new mysqli($servername, $username, $password,$db);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$count=0;
echo "Connected successfully";
   if(isset($_POST['submit']))
   {
       $fname=$_FILES['sel_file']['name'];
       echo 'upload file : '.$fname;
       $chk_ext=explode(".",$fname);

       if(strtolower(end($chk_ext))=="csv")
       {
           $filename=$_FILES['sel_file']['tmp_name'];
           $handle=fopen($filename,"r");
           while(($data=fgetcsv($handle,1000,","))!==FALSE)
           {
               $sql="INSERT INTO student(Customer,ActRef,tele,Total,Date)values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";

               mysql_query($sql)or die(mysql_error());

               $count++;
           }
           fclose($handle);
           echo "imported";
       }
       else
       {
           echo"invalid file";
       }
   }
?>
</body>
</html>