Melayani Dengan Nurani

IA

9 September 2016

Listing Program Master Detail / Transaksi Pemrograman PHP Mysql + Javascript



<?php require_once('../../Connections/conn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_conn, $conn);
$query_r1 = "SELECT no_reg_item, name_item, harga_jual FROM masterbarang";
$r1 = mysql_query($query_r1, $conn) or die(mysql_error());
$row_r1 = mysql_fetch_assoc($r1);
$totalRows_r1 = mysql_num_rows($r1);

$colname_rj = "-1";
if (isset($_GET['kodesales'])) {
  $colname_rj = $_GET['kodesales'];
}
mysql_select_db($database_conn, $conn);
$query_rj = sprintf("SELECT * FROM salesroute WHERE kodesales = %s", GetSQLValueString($colname_rj, "text"));
$rj = mysql_query($query_rj, $conn) or die(mysql_error());
$row_rj = mysql_fetch_assoc($rj);
$totalRows_rj = mysql_num_rows($rj);

$colname_ro = "-1";
if (isset($_GET['kodesales'])) {
  $colname_ro = $_GET['kodesales'];
}
mysql_select_db($database_conn, $conn);
$query_ro = sprintf("SELECT * FROM `counter` WHERE kodesales = %s ORDER BY counter_name ASC", GetSQLValueString($colname_ro, "text"));
$ro = mysql_query($query_ro, $conn) or die(mysql_error());
$row_ro = mysql_fetch_assoc($ro);
$totalRows_ro = mysql_num_rows($ro);

//  buat nomor faktur otomatis
    $tmptgl=date('d-m-Y'); $tgj=date('d')+13 ; $blj=date('m'); $thj=date('Y');
    $query = "SELECT max(no_reg_in) AS akhir FROM  master_in" ;
    $hasil = mysql_query($query);
    $data = mysql_fetch_array($hasil);
    $lastNo = $data['akhir'];
    // baca nomor urut transaksi dari id transaksi terakhir
    $lastNoUrut = $lastNo;
    // nomor urut ditambah 1
    $nextNoUrut = $lastNoUrut + 1;
    // membuat format nomor transaksi berikutnya
    $nextNo = "FB"."-".$thj."-".$blj."-".sprintf('%06s', $nextNoUrut);
   
?>

<html>
<head>
<script  language="javascript" >
function cek(){
if(form.jumlah[].value == "" ){
alert("Jumlah kosong"); //jika angka kosong maka pesan akan tampil
exit;
}
}
function kali() {
cek();
a=eval(form.jumlah[].value);
b=eval(form.angka2.value);
c=a*b
form.total.value = c;
}
</script>

<script language="javascript1.5" >
var idrow = 6;
var i = 1;
var j = 0;
function tambah(){ i++;
    var x=document.getElementById('datatable').insertRow(idrow);
    var td1=x.insertCell(0);
    var td2=x.insertCell(1);
    var td3=x.insertCell(2);
    var td4=x.insertCell(3);

    td1.innerHTML="<div align='center'> <input type='text' name='no[]' size=4 readonly=true value = "+i+">  </div>";
    td2.innerHTML="<select name='no_reg_item[]'> "+"<?php do {  ?>"+
    "<option value=<?php echo $row_r1['no_reg_item']?>><?php echo $row_r1['name_item']; echo "------> Harga :Rp."; echo $row_r1['harga_jual'];?></option>"+
 "<?php } while ($row_r1 = mysql_fetch_assoc($r1)); $rows = mysql_num_rows($r1);  if($rows > 0) { mysql_data_seek($r1, 0); ?>"+
 "<?php  $row_r1= mysql_fetch_assoc($r1);  }?>"+"</select> ";
    td3.innerHTML="<input type='text' name='jumlah[]' size=15 >";
    td4.innerHTML="<div align='center'> <input type ='text' name='diskon[]' size=5 > </div> ";
    idrow++;
}

function hapus(){
    if(idrow>6){
        var x=document.getElementById('datatable').deleteRow(idrow-1);
        idrow--;
        i--;
    }
}
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('Ada kesalahan, tak boleh kosong :\n'+errors);
    document.MM_returnValue = (errors == '');
} }
</script>
<title>Faktur per Sales</title>
<script type="text/javascript" src="../../stok/calendar.js"></script>
<!-- language for the calendar -->
<script type="text/javascript" src="../../stok/calendar-en.js"></script>
<script type="text/javascript" src="../../stok/calendar-setup.js"></script>

<link href="../../transaksi/calendar-win2k-1.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {font-size: 12}
.style2 {font-size: 18px}
.style3 {font-size: 24px}
-->
</style>
</head>

<body>
<form action=../../transaksi/fakturcetak.php method=post>
<table width="772" border=0 align="center" cellpadding="0" cellspacing="0" id=datatable>
  <tr bgcolor=#ababab>
    <td colspan="4" align="left" valign="top" nowrap background="../../images/ltrfrm.png" bgcolor="#FFFFFF"><span class="style3">PT BEJANA MAS</span></td>
    </tr>
  <tr bgcolor=#ababab>
    <td width="113" align="left" valign="top" nowrap background="../../images/ltrfrm.png" bgcolor="#FFFFFF"><img src="../../images/icon/icons/checkout.png" alt="a" width="46" height="31">No Faktur</td>
    <td background="../../images/ltrfrm.png" bgcolor="#FFFFFF"><input name="no_faktur" type="text" id="no_faktur" size="17" value="<?php echo $nextNo ;?>"></td>
    <td background="../../images/ltrfrm.png" bgcolor="#FFFFFF">No Order/PO</td>
    <td nowrap background="../../images/ltrfrm.png" bgcolor="#FFFFFF"><input name="no_order" type="text" id="no_order" size="17"></td>
    </tr>
  <tr bgcolor=#ababab>
    <td nowrap background="../../images/ltrfrm.png" bgcolor="#FFFFFF"><div align="right">Kd Jalur</div></td>
    <td background="../../images/ltrfrm.png" bgcolor="#FFFFFF"><select name="koderoute" id="koderoute">
      <?php
do { 
?>
      <option value="<?php echo $row_rj['koderoute']?>"><?php echo $row_rj['mingguke']; echo "-".$row_rj['hari']; echo "-".$row_rj['kecamatan'] ?></option>
      <?php
} while ($row_rj = mysql_fetch_assoc($rj));
  $rows = mysql_num_rows($rj);
  if($rows > 0) {
      mysql_data_seek($rj, 0);
      $row_rj = mysql_fetch_assoc($rj);
  }
?>
    </select></td>
    <td background="../../images/ltrfrm.png" bgcolor="#FFFFFF">Tanggal Faktur</td>
    <td nowrap background="../../images/ltrfrm.png" bgcolor="#FFFFFF"><?php $tmptgl=date('d-m-Y'); $tgj=date('d')+13 ; $blj=date('m'); $thj=date('Y'); ?>
      <input name="date_in" type="text" id="f_date_b" value="<?php echo $tmptgl ; ?>" size="12">
      <button type="reset" id="f_trigger_b">...</button></td>
    </tr>
  <tr bgcolor=#ababab>
    <td nowrap background="../../images/ltrfrm.png" bgcolor="#FFFFFF"> <div align="right">Outlet</div></td>
    <td background="../../images/ltrfrm.png" bgcolor="#FFFFFF"><select name="outlet" id="outlet">
      <?php
do { 
?>
      <option value="<?php echo $row_ro['no_reg_konter']?>"<?php if (!(strcmp($row_ro['no_reg_konter'], $row_ro['no_reg_konter']))) {echo "selected=\"selected\"";} ?>><?php echo $row_ro['counter_name']; echo "->"; echo $row_ro['address']?></option>
      <?php
} while ($row_ro = mysql_fetch_assoc($ro));
  $rows = mysql_num_rows($ro);
  if($rows > 0) {
      mysql_data_seek($ro, 0);
      $row_ro = mysql_fetch_assoc($ro);
  }
?>
    </select></td>
    <td background="../../images/ltrfrm.png" bgcolor="#FFFFFF">Tgl Jth. Tempo</td>
    <td nowrap background="../../images/ltrfrm.png" bgcolor="#FFFFFF"><input name="tgljttempo" type="text" id="tgljttempo" value="<?php echo $tgj."-".$blj."-".$thj ; ?>" size="12"></td>
    </tr>
  <tr background="../../images/tblheder.png">
    <td nowrap>
        <p class="style2">No Urut</p></td>
    <td width="425">        <p align="left" class="style2">Jenis Produk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Harga </p></td>
    <td width="109"><div align="center" class="style1">
     
       
          <p align="left" class="style2">Jumlah/pieces</p>
    </div></td>
    <td width="125" nowrap><div align="left" class="style1">
     
          <p class="style2">Diskon</p>
    </div></td>
    </tr>
  <tr>
    <td nowrap background="../../images/ltrfrm.png">  <div align="center">
      <input name="no[]" type="text" id="no[]" value="1" size="4" readonly="true">   
    </div></td>
    <td background="../../images/ltrfrm.png"><select name='no_reg_item[]'>
      <?php do {  ?>
      <option value="<?php echo $row_r1['no_reg_item']?>"><?php echo $row_r1['name_item']; echo "------> Harga :Rp."; echo $row_r1['harga_jual']; ?></option>
      <?php
} while ($row_r1 = mysql_fetch_assoc($r1));
  $rows = mysql_num_rows($r1);
  if($rows > 0) {
      mysql_data_seek($r1, 0);
      $row_r1 = mysql_fetch_assoc($r1);
  }
?>
    </select></td>
    <td background="../../images/ltrfrm.png"><input name='jumlah[]' type='text' id="jumlah[]" size="15" ></td>
    <td nowrap background="../../images/ltrfrm.png">
     
        <div align="center">
          <input name='diskon[]' type ='text' size="5">
          </div></td>
    </tr>
  <tr>
    <td nowrap background="../../images/tblheder.png">Kode Sales  </td>
    <td background="../../images/tblheder.png"> <?php echo $_GET['kodesales']?><?php echo "->".$_GET['namasales']; ?><input name="kodesales" type="hidden" value="<?php echo $_GET['kodesales']?>"></td>
    <td background="../../images/tblheder.png">&nbsp;</td>
    <td nowrap background="../../images/tblheder.png">&nbsp;</td>
  </tr>
</table>
<p align="center">
  <input name="mundur" type=button id="mundur" onClick=history.go(-1); VALUE=Back/mundur>
  <input type=button value="Tambah Data" onClick=tambah()>
  <input type=button value="Hapus" onClick=hapus() >
  <input type=submit onClick="MM_validateForm('no_faktur','','R','no_order','','R','jumlah[]','','RisNum');return document.MM_returnValue" value="Checkout">
  <input   name=reset type="reset" value=Reset>
</p>
</form>
<script type="text/javascript">
    Calendar.setup({
        inputField     :    "f_date_b",      // id of the input field
        ifFormat       :    "%d-%m-%Y",       // format of the input field
        showsTime      :    true,            // will display a time selector
        button         :    "f_trigger_b",   // trigger for the calendar (button ID)
        singleClick    :    false,           // double-click mode
        step           :    1                // show all years in drop-down boxes (instead of every other year as default)
    });
</script>
</body>
</html>
<?php
mysql_free_result($r1);

mysql_free_result($rj);

mysql_free_result($ro);
?>
Reactions:

0 comments:

Posting Komentar

Nuhun sudah komentar