<?php include "required/connection.php"; if ($_FILES[csvData][size] > 0) { //get the csv file $file = $_FILES[csvData][tmp_name]; $handle = fopen($file, "r"); $x = 0; //loop through the csv file and insert into database while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if ($x > 0) { $ExDate = explode("/", $data[0]); $FormattedDate = $ExDate[2] . "-" . $ExDate[0] . "-" . $ExDate[1]; mysql_query("INSERT INTO lot_details(date_of_lot, lot_category, lot_title, lot_location, lot_condition, pre_tax_amount, tax_name, tax_amount) VALUES \n ( \n '" . mysql_escape_string(addslashes($FormattedDate)) . "', \n '" . mysql_escape_string(addslashes($data[1])) . "', \n '" . mysql_escape_string(addslashes($data[2])) . "',\n\t\t\t\t\t'" . mysql_escape_string(addslashes($data[3])) . "', \n\t\t\t\t\t'" . mysql_escape_string(addslashes($data[4])) . "', \n\t\t\t\t\t'" . mysql_escape_string(addslashes($data[5])) . "', \n\t\t\t\t\t'" . mysql_escape_string(addslashes($data[6])) . "', \n\t\t\t\t\t'" . mysql_escape_string(addslashes($data[7])) . "'\t\t\t\t\t\n ) \n ") or die(myswl_error()); } $x = $x + 1; } $RecordSet = mysql_query("select date_of_lot, lot_category, lot_title, lot_location, lot_condition, pre_tax_amount, tax_name, tax_amount from lot_details order by date_of_lot "); } //Result is returned to index page $Rs = mysql_query("SELECT *, sum(`pre_tax_amount`+`tax_amount`) as total_spendings,year(date_of_lot) as year, monthname(date_of_lot) as month FROM `lot_details` group by month(`date_of_lot`),lot_category"); echo "<div style='color:gray;font-weight:bold'>Report Generated</div>"; echo "<table class='table-striped table-hover table-bordered' width='100%' cellpadding='20px' cellspacing='10'>"; echo "<tr style='background-color:gray;'><td style='background-color:gray;color:#ffffff;padding-left:5px;'>Year</td><td style='background-color:gray;color:#ffffff;padding-left:5px;'>Month</td><td style='background-color:gray;color:#ffffff;padding-left:5px;'>Category</td><td style='background-color:gray;color:#ffffff;padding-left:5px;'>Total Spendings</td></tr>"; echo "<tr><td> </td><td></td><td></td><td></td></tr>"; while ($row = mysql_fetch_object($Rs)) { echo "<tr><td style='padding-left:5px'>" . $row->year . "</td><td style='padding-left:5px'>" . $row->month . "</td><td style='padding-left:5px'>" . $row->lot_category . "</td><td style='padding-left:5px'>" . sprintf("%.2f", $row->total_spendings) . "</td></tr>"; } echo "</table>";
# jika timbangan pembeli maka sum(kgpembeli) dari kg timbangan dari tanggal s/d tanggal dari table pabrik timbangan if ($biaya == 'Uang Muka') { $s_qtykontrak = "select kuantitaskontrak from " . $dbname . ".pmn_kontrakjual\r\n where nokontrak='" . $kontrak . "' "; $q_qtykontrak = mysql_query($s_qtykontrak) or die(mysql_error($conn)); $r_qtykontrak = mysql_fetch_assoc($q_qtykontrak); $vol = $r_qtykontrak['kuantitaskontrak']; } else { if ($timbangan == 'Sendiri') { $s_wb = "select sum(a.beratbersih) as total from " . $dbname . ".pabrik_timbangan a\r\n left join " . $dbname . ".pmn_4customer b on a.kodecustomer=b.kodetimbangan\r\n where a.kodebarang = '" . $komoditi . "' and b.kodecustomer='" . $customer . "'\r\n and b.kodetimbangan = '" . $kodetimbangan . "'\r\n and substr(a.tanggal,1,10) between '" . $dari . "' and '" . $sd . "' "; // exit("error: ".$s_wb); $q_wb = mysql_query($s_wb) or die(myswl_error($conn)); $r_wb = mysql_fetch_assoc($q_wb); $vol = $r_wb['total']; } else { $s_wb = "select sum(a.kgpembeli) as total from " . $dbname . ".pabrik_timbangan a\r\n left join " . $dbname . ".pmn_4customer b on a.kodecustomer=b.kodetimbangan\r\n where a.kodebarang = '" . $komoditi . "' and b.kodecustomer='" . $customer . "'\r\n and b.kodetimbangan = '" . $kodetimbangan . "'\r\n and substr(a.tanggal,1,10) between '" . $dari . "' and '" . $sd . "' "; $q_wb = mysql_query($s_wb) or die(myswl_error($conn)); $r_wb = mysql_fetch_assoc($q_wb); $vol = $r_wb['total']; } } #Jumlah Rp: # jika mata uang asing maka valas kali kurs, # jika RP maka diisi dari harga satuan kontrak dikali volume if ($curr != 'IDR') { $jml = $valas * $kurs; } else { $s_harga = "select hargasatuan from " . $dbname . ".pmn_kontrakjual where nokontrak='" . $kontrak . "'"; $q_harga = mysql_query($s_harga) or die(mysql_error($conn)); $r_harga = mysql_fetch_assoc($q_harga); $harga = $r_harga['hargasatuan']; $jml = $harga * $vol;