Postingan lainnya
Alert double input menggunakan jquery
Bagaimana caranya agar Item yang di masukan tidak boleh sama ? Harusnya bila item yg di add sama muncul alert 'Item already input'. Alert pada saat klik save dan otomatis data tidak tersimpan atau update.
CODING JQUERY ADD ITEM
function addMaterialItem()
{
var vHTML = '';
vHTML = '<div class="materialItem add">';
i += 1;
vHTML += '<div>';
vHTML += '<div style="float:left; width:195px;"><input type="text" id="item_' + i + '" name="item_' + i + '" title="Item" class="formElement items" style="width:190px;" value="" /><input type="text" id="items_id_' + i + '" name="items_id_' + i + '" class="formElement items_id" value="" /><input type="text" class="formElement rows" id="rows_' + i + '" name="rows[]" value="' + i + '" /></div>';
vHTML += '<div style="float:left; margin-left:2px; width:40px;"><input type="text" id="item_satuan_' + i + '" name="item_satuan_' + i + '" title="Satuan" class="formElement item_satuan" style="width:35px;" onFocus="$(this).removeClass(\'missingInfo\')" value="" readonly /></div>';
vHTML += '<div style="float:left; margin-left:2px; width:50px;"><input type="text" id="qty_' + i + '" name="qty_' + i + '" title="Quantity" class="formElement qty" style="width:45px; text-align:center;" value="" onChange="CekStock(this);" /><input type="hidden" id="stok_' + i + '" name="stok_' + i + '" class="formElement stok" value=""/></div>';
vHTML += '<div style="float:left; margin-left:2px; width:400px;"><input type="text" id="remark_' + i + '" name="remark_' + i + '" title="Remark" class="formElement remark" style="width:395px; text-align:center;" onChange="sumTotal(this); updatePETotals();" value=""/><input type="hidden" id="total_wo_tax_' + i + '" name="total_wo_tax_' + i + '" title="Total WO/ Tax" class="formElement total_wo_tax" value="" /><input type="hidden" id="total_' + i + '" name="total_' + i + '" title="Total W/ Tax" class="formElement total" value="" /></div>';
vHTML += '<div style="float:right; margin-top:2px; margin-right:1px;"><img src="../../images/delete_12.png" style="cursor:pointer;" width="12" height="12" border="0" title="Remove this item" onClick="removeMaterialItem(this);" /></div>';
vHTML += '<div style="clear:both;"></div>';
vHTML += '</div>';
vHTML += '</div>';
vObj = $(vHTML);
$('#materialList').append(vObj).scrollTop($('#materialList').scrollTop()+30);
//Autocompletes
itemAutocomplete(vObj);
updatePETotals();
return true;
}
CODING FILTER SAVE JQUERY (YANG MAU DI EDIT)
function preSubmit()
{
if (!confirm('Do you really want to continue?'))
return false;
if ($('.items_id').val() != $('.items_id').val())
{
alert('Item already input.');
return false;
}
if(!$('.qty').val())
{
alert('- Quantity field is mandatory.');
return false;
}
//Disable buttons
$('input.button').prop('disabled',true);
}
CODING INSERT/UPDATE
<?php
session_start();
//koneksi database
include "../../inc/inc.koneksi.php";
include "../../inc/fungsi_tanggal.php";
$Code = $_POST['code'];
$description = $_POST['description'];
$RequestBy = $_POST['request_by_id'];
$Request2By = $_POST['request2_by_id'];
$Date = jin_date_sql($_POST['date']);
$users = $_SESSION[namalengkap];
$text = "SELECT max(Code) as noakhir FROM outbound_code";
$sql = mysql_query($text);
$row = mysql_num_rows($sql);
if ($row>0){
$r=mysql_fetch_array($sql);
$noakhir = $r[noakhir];
$no = (int) substr($noakhir,0,7);
$no++;
$kode = sprintf("%07s",$no);
$data['kode'] = $kode;
}else{
$data['kode'] = '0000001';
}
if(!empty($RequestBy)){
$Request2By=$RequestBy;
}else{
$RequestBy=$Request2By;}
$tgl = date("y");
$VoucherNo="OUT-".$tgl."1-".$kode;
// ---------------------Update baru------------------
//Input Staff
$sql = mysql_query("SELECT Code
FROM outbound
WHERE Code='$Code'");
$row = mysql_num_rows($sql);
if ($row>0){
$input = "UPDATE outbound SET
outbound_date = '$Date',
RequestBy = '$RequestBy'
WHERE Code='$Code'";
mysql_query($input);
foreach ($_POST['rows'] as $key => $count ){
$RowID = $_POST['rows_id_'.$count];
$Items = $_POST['items_id_'.$count];
$Satuan = $_POST['item_satuan_'.$count];
$Qty = $_POST['qty_'.$count];
$Price = $_POST['price_'.$count];
$Remark = $_POST['remark_'.$count];
$Total = $_POST['total_'.$count];
$TotalWOTax = $_POST['total_wo_tax_'.$count];
$sqlD = mysql_query("SELECT ID
FROM outbound_detail
WHERE ID='$RowID'");
$rowD = mysql_num_rows($sqlD);
$sqlE = mysql_query("SELECT qty
FROM outbound_detail
WHERE ID='$RowID'");
$rowE = mysql_fetch_array($sqlE);
if ($rowD>0){
$input = "UPDATE outbound_detail SET
ID_Product = '$Items',
Satuan = '$Satuan',
qty = '$Qty',
remark = '$Remark'
WHERE ID='$RowID'";
mysql_query($input);
$queryS = "UPDATE stok_barang SET
qty = qty+'$rowE[qty]'-'$Qty'
WHERE ID_Product='$Items'";
mysql_query($queryS);
}else{
if(!empty($Items)){
$queryH = "INSERT INTO outbound_detail
(Code, ID_Product, Satuan, qty, remark)
VALUES
('$Code', '$Items', '$Satuan', '$Qty', '$Remark')";
mysql_query($queryH);
}
$queryS = "UPDATE stok_barang SET
qty = qty-'$Qty'
WHERE ID_Product='$Items'";
mysql_query($queryS);
}
}
$sqlH = mysql_query("SELECT ID
FROM outbound_history
WHERE Code='$Code' AND Activity='Edited'");
$rowH = mysql_num_rows($sqlH);
if ($rowH>0){
$input = "UPDATE outbound_history SET
LoggedBy = '$users',
Date = Now()
WHERE Code='$Code' AND Activity='Edited'";
mysql_query($input);
}else{
$queryH = "INSERT INTO outbound_history
(Code, LoggedBy, Activity, Date)
VALUES
('$Code', '$users', 'Edited', Now())";
mysql_query($queryH);
}
echo "<script language='javascript' type='text/javascript'>
window.parent.location.reload();
</script>";
}else{
// --------------------Insert baru-------------------
$query = "INSERT INTO outbound
(Code, outbound_date, status, pic, RequestBy, remark)
VALUES
('$VoucherNo', NOW(), 'New', '$users', '$RequestBy','$remark')";
mysql_query($query);
$queryC = "INSERT INTO outbound_code (Code)
VALUES
('$kode')";
mysql_query($queryC);
foreach ($_POST['rows'] as $key => $count ){
$Items = $_POST['items_id_'.$count];
$Satuan = $_POST['item_satuan_'.$count];
$Qty = $_POST['qty_'.$count];
$remark = $_POST['remark_'.$count];
$Total = $_POST['total_'.$count];
$TotalWOTax = $_POST['total_wo_tax_'.$count];
/*$sqlC = mysql_query("SELECT qty as qty
FROM stok_barang
WHERE nama_barang='$Items'");
$rowC = mysql_fetch_array($sqlC);
*/
if(!empty($Items)){
$queryH = "INSERT INTO outbound_detail
(Code, ID_Product, Satuan, qty, remark)
VALUES
('$VoucherNo', '$Items', '$Satuan', '$Qty', '$remark')";
mysql_query($queryH);
$queryS = "UPDATE stok_barang SET
qty = qty-'$Qty'
WHERE ID_Product='$Items'";
mysql_query($queryS);
}
}
$sqlH = mysql_query("SELECT ID
FROM outbound_history
WHERE Code='$Code' AND Activity='Created'");
$rowH = mysql_num_rows($sqlH);
if ($rowH>0){
$input = "UPDATE outbound_history SET
LoggedBy = '$users',
LoggedDate = Now()
WHERE Code='$Code' AND Activity='Created'";
mysql_query($input);
}else{
$queryH = "INSERT INTO outbound_history (Code, LoggedBy, Activity, Date)
VALUES
('$VoucherNo', '$users', 'Created', Now())";
mysql_query($queryH);
}
echo "<script language='javascript' type='text/javascript'>
top.openDialog('/stationary/jkt/webui/outbound/outbound_show.php?Code=$VoucherNo', 800, 470, 'Opening...', 'webui_outbound_outbound_show_$VoucherNo', 0, 'material_18.png', 0, 0);
top.closeDialogOperations('#webui_outbound_outbound_request1');
</script>";
//echo "<script language='javascript' type='text/javascript'>
// alert('Stok tidak ada');
//top.closeDialogOperations('#webui_outbound_outbound_request1');
//</script>";
}
?>
0