File manager - Edit - /home/autoph/public_html/voc/home/import_vehicle_inventory.php
Back
<?php $uploadCount = 0; include 'core/database/connect.php'; //$conn = mysqli_connect("localhost", "autoph_arnel", "Hke@2001", "autoph_connec"); //$conn = mysqli_connect("localhost", "root", "aee10244", "db_vts"); $toDate = date_create() ->format("Y/m/d"); error_reporting(0); //echo "Active ID :".$activeID; //$ext = explode('.', $_FILES['file']['name']); //$allow_ext = array('PNG','png','JPG' ,'jpg','GIF', 'gif'); //$target_path = basename( $_FILES['file']['name']); //$target_path = mysql_real_escape_string($target_path); //$filename = $_FILES['file']['name']; //$fext = pathinfo($filename, PATHINFO_EXTENSION); //$itemCode = $_POST['custID']; $checkIfExist=0; if (isset($_POST["import"])) { $fileName = $_FILES["file"]["tmp_name"]; if ($_FILES["file"]["size"] > 0) { $ext = explode('.', $_FILES['file']['name']); $allow_ext = array('CSV','csv'); $target_path = basename( $_FILES['file']['name']); $target_path = mysql_real_escape_string($target_path); $filename = $_FILES['file']['name']; $fext = pathinfo($filename, PATHINFO_EXTENSION); $itemCode = $_POST['custID']; $duplicate=0; $fileTotal=0; if(!in_array($fext,$allow_ext)){ echo '<script>alert("Problem Importing File. Plaase make sure you are using correct CSV Type Inventory Template. Import ABORTED...")</script>'; }else { $file = fopen($fileName, "r"); while (($column = fgetcsv($file, 5000, ",")) !== FALSE) { if($column[0] === 'BRAND' || $column[1]==='MODEL'){ }else{ $fileTotal = $fileTotal + 1; //$chkStatus = $column[2]; //if($chkStatus == 'Incoming'){ // $incoming = 1 ; //}else { // $incoming = 0 ; //} $chkStatus = $column[2]; $chkStatusNew = "Available"; if($chkStatus === 'DEMO' || $chkStatus === 'Demo' || $chkStatus === 'demo'){ $ZeorOrOne = 0; $chkStatusNew = "Demo"; }else { $chkOneOrZero = $column[10]; if($chkOneOrZero == '1'){ $chkStatusNew = "Incoming"; $ZeorOrOne = 1; }else { $ZeorOrOne = 0; } } if(TRIM($column[16]== 1)){ $chkStatusNew = "Reserved"; } if(TRIM($column[7]!='')){ $inventoryDate=$column[7]; $invDate = date("Y/m/d", strtotime($inventoryDate)); }else{ $invDate = $toDate; } $chkBrand = TRIM($column[0]);//NISSAN $chkModel = TRIM($column[1]);//ALMERA $chkColor = TRIM($column[6]);//ALPINE WHITE $chkBrandIfExist = mysql_result(mysql_query("SELECT COUNT('b_id') FROM `vts_brands` WHERE `b_name` LIKE '%$chkBrand%'"),0); $chkModelIfExist = mysql_result(mysql_query("SELECT COUNT('m_id') FROM `vts_model` WHERE `m_name` LIKE '%$chkModel%'"),0); $chkColorIfExist = mysql_result(mysql_query("SELECT COUNT('c_id') FROM `vts_colors` WHERE `c_name` LIKE '%$chkColor%'"),0); if($chkBrandIfExist === '0'){ $sqlInsertB = "INSERT into vts_brands(`b_name`, `b_desc`, `b_status`, `date`, `group_brand`) values ('".TRIM($column[0])."','ALL ".$column[0]." PRODUCTS','1','".$toDate ."', 'Yes')"; mysqli_query($conn, $sqlInsertB); } if($chkModelIfExist == 0){ $brandID = mysql_result(mysql_query("SELECT `b_id` FROM `vts_brands` WHERE `b_name`='$chkBrand'"),0); $sqlInsertM = "INSERT into vts_model(`m_name`, `m_desc`, `b_id`, `m_status`, `date`,`brand_id`) values ('".TRIM($column[1])."','ALL ".$column[1]." VARIANT','".$brandID."','1','".$toDate ."', '".$brandID."')"; mysqli_query($conn, $sqlInsertM); } if($chkColorIfExist == 0){ $sqlInsertC = "INSERT into vts_colors(`C_name`, `C_desc`, `C_status`, `date`) values ('".TRIM($column[6])."','".$column[6]."','1','".$toDate ."')"; mysqli_query($conn, $sqlInsertC); } $srpPrice = str_replace(',', '', $column[11]); $disPrice = str_replace(',', '', $column[12]); $comPrice = str_replace(',', '', $column[13]); $myCSNumber = TRIM($column[3]); $myBrand = TRIM($column[0]); $checkIfExist = mysql_result(mysql_query("SELECT COUNT(id) FROM `db_vehicle_inventory` WHERE `cs_number` LIKE '%$myCSNumber%' AND `returned` = 0 AND `brand`='$myBrand'"),0); if($checkIfExist > 0 ){ $duplicate = $duplicate + 1; }else{ mysql_query("INSERT into db_vehicle_inventory(`brand`, `brand_code`, `status`, `cs_number`, `year_model`, `description`, `color`, `date_received`, `selling_dealer`, `remarks`, `incoming_unit`, `price`, `discount`, `commission`,`company`,`dealer`, `reserved`) values ('".TRIM($column[0])."','".TRIM($column[1])."','".$chkStatusNew."','".TRIM($column[3])."','".TRIM($column[4])."','".TRIM($column[5])."','".TRIM($column[6])."','".$invDate."','".$column[8]."','".$column[9]."','".$ZeorOrOne."','".$srpPrice."','".$disPrice."','".$comPrice."','".$column[14]."','".$column[15]."','".$column[16]."')"); //$result = mysqli_query($conn, $sqlInsert); } //echo "<script>alert('Duplicate Count: ".$checkIfExist."')</script>"; } } $AddedFile = $fileTotal - $duplicate; // if($type === 'success'){ echo '<script>alert("You have uploaded a total of '.$fileTotal.' records. '.$AddedFile.' has been added to database and '.$duplicate.' possible duplicate CS NUMBER")</script>'; //}else{ // echo '<script>alert("Problem in Importing CSV Data. please make sure to follow the provided format and there is no duplicate Plate/CSNumber in record")</script>'; //} } } } ?> <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="wait" style="display:none;width:69px;height:89px;border:0px solid red;position:absolute;top:50%;left:50%;padding:2px;"> <img src='images/demo_wait.gif' width="64" height="64" /><br>Loading..</div> <script src="js/jquery-3.2.1.min.js"></script> <script type="text/javascript"> function ShowUploadBar() { var div = document.getElementById("uploading"); if (div.style.display == 'none') { div.style.display = ''; } else { div.style.display = 'none' } } $(document).ready(function() { $("#frmCSVImport").on("submit", function () { ShowUploadBar(); $("#response").attr("class", ""); $("#response").html(""); var fileType = ".csv"; var regex = new RegExp("([a-zA-Z0-9\s_\\.\-:])+(" + fileType + ")$"); if (!regex.test($("#file").val().toLowerCase())) { $("#response").addClass("error"); $("#response").addClass("display-block"); $("#response").html("Invalid File. Upload : <b>" + fileType + "</b> Files."); return false; } return true; }); }); </script> </head> <body> <h2 onclick="ShowUploadBar()" style="padding:10px;font-family:Aria;font-size:16px"></h2> <div id="uploading" style="display:none;position:absolute;top:43%;left:00%;width:480px;height:300px;background:transparent;z-index:9999;border:0px solid gray;z-index:999999999999999999"> <div id="uploadBar" style="font-family:Calibri;font-size:14px;color:red;text-align:center;margin-top:0px;background:white;display:block;width:100%;height:30px;border:0px solid red;position:relative;left:5px;padding:5px;z-index:999999999999999999"> <img src='images/ajaxLoader.gif' width="100%" height="20px" /><br><center>UPLOADING FILES. PLEASE WAIT...<center></div> </div> <div id="response" class="<?php if(!empty($type)) { echo $type . " display-block"; } ?>"><?php if(!empty($message)) { echo $message; } ?></div> <div class="outer-scontainer"> <div class="row" style='text-align:center'> <form class="form-horizontal" action="" method="post" name="frmCSVImport" id="frmCSVImport" enctype="multipart/form-data"><br> <div class="input-row" style='border:0px solid red;text-align:left;width:100%;padding-left:20px;background:#ffffff '> <label class="col-md-4 control-label">Choose CSV File</label> <input type="file" name="file" id="file" required accept=".csv"> </div> <div class="input-row" style='border:0px solid red;text-align:center;width:100%;padding:25px;background:#transparent'> <button type="submit" id="submit" name="import" class="btn-submit" style='margin-top:25px;padding:4px;border-radius:3px;border:border:1px solid gray;width:100px'>Import</button> <br><?php echo $message;?> <br /> </div> </form> <?php if($uploadCount > 1 && $upLoad==1){echo "<p style='text-align:center;margin:20px;'>".$uploadCount." Records has been uploaded</p>";}else{}?> </div> </div> </body> </html>
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings