package com.aka.telkom;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Login extends Activity {
String xml="";
EditText txtpassword,txtusername,txtnamapemesan;
Spinner mySpin;
String kode_pegawai="";
String nama_pegawai="";
String no_meja="",nama_pemesan="";
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private static final String TAG_SUKSES = "sukses";
private static final String TAG_record = "record";
String ip="";
String username,password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
ip=jsonParser.getIP();
txtusername=(EditText)findViewById(R.id.txtusername);
txtpassword=(EditText)findViewById(R.id.txtpassword);
txtnamapemesan=(EditText)findViewById(R.id.txtnamapemesan);
mySpin=(Spinner)findViewById(R.id.mySpin);
String[]pilihan={"Meja No1","Meja No2","Meja No3","Meja No4","Meja No5"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, pilihan);
mySpin.setAdapter(adapter);
Button btnLogin=(Button)findViewById(R.id.btnlogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
username=txtusername.getText().toString().trim();
password=txtpassword.getText().toString().trim();
if(username.length()<1){lengkapi("username");}
else if(password.length()<1){lengkapi("password");}
else {
new login().execute();
}
}});
Button btndaftar=(Button)findViewById(R.id.btndaftar);
btndaftar.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
finish();
}});
}
class login extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Login.this);
pDialog.setMessage("Proses Login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... params) {
int sukses;
try {
List<NameValuePair> myparams = new ArrayList<NameValuePair>();
myparams.add(new BasicNameValuePair("username", username));
myparams.add(new BasicNameValuePair("password", password));
String url=ip+"pegawai/pegawai_login.php";
Log.v("detail",url);
JSONObject json = jsonParser.makeHttpRequest(url, "GET", myparams);
Log.d("detail", json.toString());
sukses = json.getInt(TAG_SUKSES);
if (sukses == 1) {
JSONArray myObj = json.getJSONArray(TAG_record); // JSON Array
final JSONObject myJSON = myObj.getJSONObject(0);
runOnUiThread(new Runnable() {
public void run() {
try {
kode_pegawai=myJSON.getString("kode_pegawai");
nama_pegawai=myJSON.getString("nama_pegawai");
no_meja=mySpin.getSelectedItem().toString();
nama_pemesan=txtnamapemesan.getText().toString();
}
catch (JSONException e) {e.printStackTrace();}
}});
}
else{
// jika id tidak ditemukan
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@SuppressLint("NewApi")
protected void onPostExecute(String file_url) {pDialog.dismiss();
final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Login.this);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putBoolean("Registered", true);
editor.putString("kode_pegawai", kode_pegawai);
editor.putString("nama_pegawai", nama_pegawai);
editor.putString("no_meja", no_meja);
editor.putString("nama_pemesan", nama_pemesan);
editor.apply();
Intent i = new Intent(getApplicationContext(),Menuutama.class);
// i.putExtra("kode_pegawai", kode_pegawai);
// i.putExtra("nama_pegawai", nama_pegawai);
// i.putExtra("no_meja", no_meja);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
}
public void lengkapi(String item){
new AlertDialog.Builder(this)
.setTitle("Lengkapi Data")
.setMessage("Silakan lengkapi data "+item)
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}})
.show();
}
public void gagal(String item){
new AlertDialog.Builder(this)
.setTitle("Gagal Login")
.setMessage("Login "+item+" ,, Gagal")
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}})
.show();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
===================================================
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dip" >
<!-- View Title Label -->
<TextView
android:id="@+id/txtMarquee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="14sp"
android:typeface="sans"
android:textColor="#ffffff"
android:background="#000000"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever">
</TextView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Nama Pemesan"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"/>
<!-- telepon TextField -->
<EditText
android:id="@+id/txtnamapemesan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="No Meja"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"/>
<Spinner android:id="@+id/mySpin" android:drawSelectorOnTop="true" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView
android:layout_width="fill_parent"
android:layout_marginTop="70dip"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<!-- telepon TextField -->
<EditText
android:id="@+id/txtusername"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000" />
<!-- Name Label -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Password"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"/>
<!-- telepon TextField -->
<EditText
android:id="@+id/txtpassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textColor="#000000" />
<!-- Link to Login Screen -->
<Button
android:id="@+id/btnlogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:text="Login"
android:textColor="#000000"
android:textStyle="bold" />
<Button
android:id="@+id/btndaftar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Keluar"
android:textColor="#000000"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DI menu Makanan Order:
package com.aka.telkom;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
@SuppressLint("NewApi")
public class Menumakanan extends Activity {
String ip="",no_meja="",gambarq="avatar.jpg";
String kode_menu,nama_pemesan;
String kode_menu0="";
String kode_pegawai="";
String nama_pegawai="";
EditText txtkode_menu;
EditText txtnama_menu;
EditText txtKategori;
EditText txtDeskripsi;
EditText txtStatus;
EditText txtHarga;
EditText txtJumlah;
EditText txtCatatan;
Button btnProses;
Button btnHapus;
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
SharedPreferences sharedPref ;
private static final String TAG_SUKSES = "sukses";
private static final String TAG_record = "record";
static final String TAG_kode_menu = "kode_menu";
private static final String TAG_nama_menu = "nama_menu";
private static final String TAG_kategori= "kategori";
private static final String TAG_deskripsi= "deskripsi";
private static final String TAG_status= "status";
private static final String TAG_harga = "harga";
private static final String TAG_gambar = "gambar";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menumakanan);
ip=jsonParser.getIP();
callMarquee();
sharedPref= PreferenceManager.getDefaultSharedPreferences(Menumakanan.this);
txtkode_menu= (EditText) findViewById(R.id.txtkode_menu);txtkode_menu.setEnabled(false);
txtnama_menu= (EditText) findViewById(R.id.txtnama_menu);txtnama_menu.setEnabled(false);
txtKategori= (EditText) findViewById(R.id.txtkategori);txtKategori.setEnabled(false);
txtDeskripsi = (EditText) findViewById(R.id.txtdeskripsi);txtDeskripsi.setEnabled(false);
txtStatus= (EditText) findViewById(R.id.txtstatus);txtStatus.setEnabled(false);
txtHarga= (EditText) findViewById(R.id.txtharga);txtHarga.setEnabled(false);
txtJumlah= (EditText) findViewById(R.id.txtJumlah);txtJumlah.setEnabled(true);txtJumlah.setText("1");
txtCatatan= (EditText) findViewById(R.id.txtCatatan);txtCatatan.setEnabled(true);
txtCatatan.setText("GPL");
btnProses= (Button) findViewById(R.id.btnproses);
btnHapus = (Button) findViewById(R.id.btnhapus);
btnHapus.setText("Kembali");
Intent i = getIntent();
kode_menu0 = i.getStringExtra("pk");
// kode_pegawai = i.getStringExtra("kode_pegawai");
// nama_pegawai = i.getStringExtra("nama_pegawai");
// no_meja = i.getStringExtra("no_meja");
// nama_pemesan = i.getStringExtra("nama_pemesan");
Boolean Registered = sharedPref.getBoolean("Registered", false);
if (!Registered){
finish();
}else {
kode_pegawai = sharedPref.getString("kode_pegawai", "");
nama_pegawai = sharedPref.getString("nama_pegawai", "");
no_meja = sharedPref.getString("no_meja", "");
nama_pemesan=sharedPref.getString("nama_pemesan", "");
}
new get().execute();
btnProses.setText("Order Now");
btnProses.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
kode_menu= txtkode_menu.getText().toString();
String lnama_menu= txtnama_menu.getText().toString();
String lkategori= txtKategori.getText().toString();
String ldeskripsi= txtDeskripsi.getText().toString();
String lstatus= txtStatus.getText().toString();
String lharga= txtHarga.getText().toString();
String ljumlah= txtJumlah.getText().toString();
if(kode_menu.length()<1){lengkapi("kode_menu");}
else if(lnama_menu.length()<1){lengkapi("nama_menu");}
else if(lkategori.length()<1){lengkapi("kategori");}
else if(ldeskripsi.length()<1){lengkapi("deskripsi");}
else if(lstatus.length()<1){lengkapi("status");}
else if(lharga.length()<1){lengkapi("harga");}
else if(ljumlah.length()<1){lengkapi("Jumlah");}
else{
new save().execute();
}//else
}});
btnHapus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}});
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
}
catch (Exception e) {Log.e("Error", e.getMessage());e.printStackTrace();}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {bmImage.setImageBitmap(result); }
}
class get extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Menumakanan.this);
pDialog.setMessage("Load data detail. Silahkan tunggu...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... params) {
int sukses;
try {
List<NameValuePair> params1 = new ArrayList<NameValuePair>();
params1.add(new BasicNameValuePair("kode_menu", kode_menu0));
String url=ip+"menu/menu_detail.php";
Log.v("detail",url);
JSONObject json = jsonParser.makeHttpRequest(url, "GET", params1);
Log.d("detail", json.toString());
sukses = json.getInt(TAG_SUKSES);
if (sukses == 1) {
JSONArray myObj = json.getJSONArray(TAG_record); // JSON Array
final JSONObject myJSON = myObj.getJSONObject(0);
runOnUiThread(new Runnable() {
public void run() {
try {
txtkode_menu.setText(kode_menu0);
txtnama_menu.setText(myJSON.getString(TAG_nama_menu));
txtKategori.setText(myJSON.getString(TAG_kategori));
txtDeskripsi.setText(myJSON.getString(TAG_deskripsi));
txtStatus.setText(myJSON.getString(TAG_status));
txtHarga.setText(myJSON.getString(TAG_harga));
gambarq=myJSON.getString("gambar");
}
catch (JSONException e) {e.printStackTrace();}
}});
}
else{
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {pDialog.dismiss();
String arUrlFoto=ip+"ypathfile/"+gambarq;
new DownloadImageTask((ImageView) findViewById(R.id.myGambar)).execute(arUrlFoto);
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class save extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Menumakanan.this);
pDialog.setMessage("Menyimpan data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
kode_menu = txtkode_menu.getText().toString();
String lcatatan= txtCatatan.getText().toString();
String ljumlah= txtJumlah.getText().toString();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("kode_menu", kode_menu0));
params.add(new BasicNameValuePair("jumlah", ljumlah));
params.add(new BasicNameValuePair("catatan", lcatatan));
params.add(new BasicNameValuePair("no_meja", no_meja));
params.add(new BasicNameValuePair("nama_pemesan", nama_pemesan));
params.add(new BasicNameValuePair("kode_pegawai", kode_pegawai));
Boolean First = sharedPref.getBoolean("First", true);
String kode_pemesanan= sharedPref.getString("kode_pemesanan", "");
Log.v("kode_pemesanan","APA?"+kode_pemesanan);
if (First){
Log.v("FIRST","FIRST ORDER");
params.add(new BasicNameValuePair("status", "Save"));
params.add(new BasicNameValuePair("kode_pemesanan", "-"));
SharedPreferences.Editor editor = sharedPref.edit();
editor.putBoolean("First", false);
editor.apply();
}else {
Log.v("SECOND","SECOND AND NEXT ORDER");
params.add(new BasicNameValuePair("status", "Update"));
params.add(new BasicNameValuePair("kode_pemesanan", kode_pemesanan));
}
//http://localhost/bimbel2017/bimbelTelkom/NaeliMenuMakanan/pemesanan/pemesanan_add.php?
//status=Save&no_meja=1&nama_pemesan=joko&kode_petugas=PTG001
//&jumlah=3&catatan=-&kode_menu=MNU001
String url=ip+"pemesanan/pemesanan_add.php";
Log.v("add",url);
JSONObject json = jsonParser.makeHttpRequest(url,"GET", params);
Log.d("add", json.toString());
try {
int sukses = json.getInt(TAG_SUKSES);
if (sukses == 1) {
if (First){
JSONArray myJSON = json.getJSONArray(TAG_record);
JSONObject c = myJSON.getJSONObject(0);
kode_pemesanan= c.getString("kode_pemesanan");
Log.v("SAVE","SAVE SESSIOON="+kode_pemesanan);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("kode_pemesanan", kode_pemesanan);
editor.apply();
}
Intent i = getIntent();
setResult(100, i);
finish();
} else {
// gagal update data
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {pDialog.dismiss();
}
}
public void gagal(String item){
new AlertDialog.Builder(this)
.setTitle("Gagal Proses")
.setMessage("Maaf Order "+item +" ada kegagalan baca data")
.setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}}).show();
}
public void lengkapi(String item){
new AlertDialog.Builder(this)
.setTitle("Lengkapi Data")
.setMessage("Silakan lengkapi data "+item +" !")
.setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
finish();
}}).show();
}
void callMarquee(){
Calendar cal = Calendar.getInstance();
int jam = cal.get(Calendar.HOUR);
int menit= cal.get(Calendar.MINUTE);
int detik= cal.get(Calendar.SECOND);
int tgl= cal.get(Calendar.DATE);
int bln= cal.get(Calendar.MONTH)+1;
int thn= cal.get(Calendar.YEAR);
String stgl=String.valueOf(tgl)+"-"+String.valueOf(bln)+"-"+String.valueOf(thn);
String sjam=String.valueOf(jam)+":"+String.valueOf(menit)+":"+String.valueOf(detik);
TextView txtMarquee=(TextView)findViewById(R.id.txtMarquee);
txtMarquee.setSelected(true);
String kata="Selamat Datang di Aplikasi Android "+stgl+"/"+sjam+" #";
String kalimat=String.format("%1$s",TextUtils.htmlEncode(kata));
txtMarquee.setText(Html.fromHtml(kalimat+kalimat+kalimat));
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
======================
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ScrollView
android:layout_marginBottom="50dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#999999"
>
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff">
<TextView
android:id="@+id/txtMarquee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="14sp"
android:typeface="sans"
android:textColor="#ffffff"
android:background="#000000"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever">
</TextView>
<ImageView
android:id="@+id/myGambar" android:layout_centerHorizontal="true"
android:src="@drawable/admin"
android:layout_width="100dp"
android:layout_height="100dp"
/>
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="kode_menu"
android:textColor="#000000" />
<EditText
android:id="@+id/txtkode_menu"
android:textColor="#000000"
android:hint="kode_menu" />
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="nama_menu" />
<EditText android:id="@+id/txtnama_menu"
android:textColor="#000000"
android:hint="nama_menu" />
</TableRow>
<TableRow android:id="@+id/TableRow03" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="kategori" />
<EditText android:id="@+id/txtkategori"
android:textColor="#000000"
android:hint="kategori"
/>
</TableRow>
<TableRow android:id="@+id/TableddRow04" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="deskripsi" />
<TextView android:text="" />
</TableRow>
<EditText android:id="@+id/txtdeskripsi"
android:textColor="#000000"
android:hint="deskripsi" />
<TableRow android:id="@+id/TableRowx04" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="harga" />
<EditText android:id="@+id/txtharga"
android:textColor="#000000"
android:hint="harga"
/>
</TableRow>
<TableRow android:id="@+id/TableRow05" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="status" />
<EditText android:id="@+id/txtstatus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="2"
android:textColor="#000000"
android:hint="status"
android:gravity="top"/>
</TableRow>
<TableRow android:id="@+id/TablxxedRow04" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Jumlah" />
<EditText android:id="@+id/txtJumlah"
android:textColor="#000000"
android:hint="jumlah"
/>
</TableRow>
<TableRow android:id="@+id/TableaaRow04" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Catatan" />
<TextView android:text="" />
</TableRow>
<EditText android:id="@+id/txtCatatan"
android:textColor="#000000"
android:hint="catatan"
/>
<Button android:id="@+id/btnproses"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Proses"
android:layout_weight="1"/>
<Button android:id="@+id/btnhapus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hapus"
android:layout_weight="1"/>
</TableLayout>
</ScrollView>
</RelativeLayout>
++++++++++++++++++++++++++++++++++++++++++++++
PHP
<?php
require_once"../konmysqli.php";
error_reporting(0);
$respon = array();
if (isset($_GET['status'])) {
$status=$_GET['status'];
if($status=="Save"){
$sql="select `kode_pemesanan` from `$tbpemesanan` order by `kode_pemesanan` desc";
$q=mysqli_query($conn, $sql);
$jum=mysqli_num_rows($q);
$th=date("y");
$bl=date("m")+0;if($bl<10){$bl="0".$bl;}
$kd="PMS".$th.$bl;//KEG1610001
if($jum > 0){
$d=mysqli_fetch_array($q);
$idmax=$d["kode_pemesanan"];
$bul=substr($idmax,5,2);
$tah=substr($idmax,3,2);
if($bul==$bl && $tah==$th){
$urut=substr($idmax,7,3)+1;
if($urut<10){$idmax="$kd"."00".$urut;}
else if($urut<100){$idmax="$kd"."0".$urut;}
else{$idmax="$kd".$urut;}
}//==
else{
$idmax="$kd"."001";
}
}//jum>0
else{$idmax="$kd"."001";}
$kode_pemesanan=$idmax;
$tanggal_pemesanan =date("Y-m-d");
$jam_pemesanan = date("H:i:s");;
$no_meja = $_GET['no_meja'];
$nama_pemesan = $_GET['nama_pemesan'];
$keterangan = "";
$kode_pegawai= $_GET['kode_pegawai'];
$status = "Order";
//http://localhost/bimbel2017/bimbelTelkom/NaeliMenuMakanan/pemesanan/pemesanan_add.php?status=Save&no_meja=1&nama_pemesan=joko&kode_petugas=PTG001&jumlah=3&catatan=-&kode_menu=MNU001
//pemesanan/pemesanan_add.php?status=Save&no_meja=1&nama_pemesan=joko&kode_petugas=PTG001&jumlah=3&catatan=-&kode_menu=MNU001
$sql="INSERT INTO `$tbpemesanan`
(`kode_pemesanan`, `tanggal_pemesanan`, `jam_pemesanan`, `no_meja`, `nama_pemesan`, `keterangan`, `status`,`kode_pegawai`) VALUES
('$kode_pemesanan', '$tanggal_pemesanan', '$jam_pemesanan', '$no_meja', '$nama_pemesan', '$keterangan', '$status','$kode_pegawai')";
$simpan=process($conn,$sql);
}
if(isset($_GET['kode_pemesanan']) && strlen($_GET['kode_pemesanan'])>3){
$kode_pemesanan = $_GET['kode_pemesanan'];
}
$jumlah = $_GET['jumlah'];
$catatan = $_GET['catatan'];
$kode_menu = $_GET['kode_menu'];
$sqlc="SELECT * FROM `$tbmenu` WHERE `kode_menu` = '$kode_menu'";
$dc=getField($conn,$sqlc);
$hargamenu =$dc["harga"];
$subtotal=$hargamenu * $jumlah;
$sql="INSERT INTO `$tbpemesanandetail`
(`id_pemesanan`, `kode_pemesanan`, `kode_menu`, `jumlah`,`harga`,`subtotal`,`catatan`, `status`) VALUES
('', '$kode_pemesanan', '$kode_menu', '$jumlah', '$hargamenu', '$subtotal', '$catatan', 'Proses')";
$simpan=process($conn,$sql);
$record["kode_pemesanan"] = $kode_pemesanan;
$respon["record"] = array();
array_push($respon["record"], $record);
$respon["sukses"] = 1;
$respon["pesan"] = "1 sukses tambah.";
echo json_encode($respon);
} else {
$respon["sukses"] = 0;
$respon["pesan"] = "? lengkapi data";
echo json_encode($respon);
}
?>
<?php
function getField($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$d= $rs->fetch_assoc();
$rs->free();
return $d;
}
function process($conn,$sql){
$s=false;
$conn->autocommit(FALSE);
try {
$rs = $conn->query($sql);
if($rs){
$conn->commit();
$last_inserted_id = $conn->insert_id;
$affected_rows = $conn->affected_rows;
$s=true;
}
}
catch (Exception $e) {
echo 'fail: ' . $e->getMessage();
$conn->rollback();
}
$conn->autocommit(TRUE);
return $s;
}
?>
konmsyqi.php
<?php
require_once"koneksivar.php";
date_default_timezone_set("Asia/Jakarta");
$conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
if ($conn->connect_error) {
trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
?>
<?php function RPM($rupiah){return number_format($rupiah,"2",",",".");}?>
<?php
function WKTM($sekarang){
$tanggal = substr($sekarang,8,2)+0;
$bulan = substr($sekarang,5,2);
$tahun = substr($sekarang,0,4);
$judul_bln=array(1=> "Januari", "Februari", "Maret", "April", "Mei","Juni", "Juli", "Agustus", "September","Oktober", "November", "Desember");
$wk=$tanggal." ".$judul_bln[(int)$bulan]." ".$tahun;
return $wk;
}
?>
Tidak ada komentar:
Posting Komentar