Example #1
0
def tambah():
    if request.method == 'POST':
        kode = request.form['kode']
        qrc = pyqrcode.create(kode)
        qrcd = kode + '.svg'
        qrc.svg(qrcd, scale=7)
        cwd = os.getcwd()
        print(cwd + '\lol.svg')
        shutil.move(cwd + '/' + qrcd, cwd + '/Web/static/images/' + qrcd)
        print('QRCODE generated')
        nama = request.form['nama']
        satuan = request.form['satuan']
        harga = request.form['harga']
        db = get_db()
        jmbl = db.execute("SELECT COUNT(*) FROM Barang").fetchone()
        bukti = 'M' + thn + '/' + bln + '/' + kode
        # bukti = jmbl
        merk = request.form['merk']
        gambar = request.form['gambar']
        db = get_db()
        error = None
        if error is None:
            db.execute(
                'INSERT INTO Barang (kodeBarang,namaBarang,satuan,hargaSatuan,Tanggal,Merk,gambar,Qrcode) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
                (kode, nama, satuan, harga, bukti, merk, gambar, qrcd))
            db.commit()
            return redirect(url_for('auth.barang'))

        flash(error)

    return render_template('auth/tambah.html')
Example #2
0
def load_logged_in_user():
    user_id = session.get('user_id')

    if user_id is None:
        g.user = None
    else:
        g.user = get_db().execute('SELECT * FROM user WHERE id = ?',
                                  (user_id, )).fetchone()
Example #3
0
def ubah(ide):
    db = get_db()
    brng = db.execute('SELECT * FROM Barang WHERE kodeBarang=?',
                      (ide, )).fetchone()

    if request.method == 'POST':
        kode = request.form['kode']
        nama = request.form['nama']
        satuan = int(request.form['satuan'])
        harga = int(request.form['harga'])
        merk = request.form['merk']
        gambar = request.form['gambar']
        db = get_db()
        error = None
        if error is None:
            db.execute(
                ''' UPDATE Barang SET namaBarang = ?,satuan = ?,hargaSatuan = ?,Merk =?,gambar =? WHERE kodeBarang = ? ''',
                (nama, satuan, harga, merk, gambar, ide))
            db.commit()
            return redirect(url_for('auth.barang'))

        flash(error)

    return render_template('auth/edit.html', data=brng)
Example #4
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None
        user = db.execute('SELECT * FROM user WHERE username = ?',
                          (username, )).fetchone()

        if user is None:
            error = 'Incorrect username.'
        elif not check_password_hash(user['password'], password):
            error = 'Incorrect password.'

        if error is None:
            session.clear()
            session['user_id'] = user['id']
            return redirect(url_for('auth.Home'))

        flash(error)

    return render_template('auth/login.html')
Example #5
0
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None

        if not username:
            error = 'Username is required.'
        elif not password:
            error = 'Password is required.'
        elif db.execute('SELECT id FROM user WHERE username = ?',
                        (username, )).fetchone() is not None:
            error = 'User {} is already registered.'.format(username)

        if error is None:
            db.execute('INSERT INTO user (username, password) VALUES (?, ?)',
                       (username, generate_password_hash(password)))
            db.commit()
            return redirect(url_for('auth.login'))

        flash(error)

    return render_template('auth/register.html')
Example #6
0
def index():
    db = get_db()
    # container = []
    # for kodeBarang,namaBarang,satuan,hargaSatuan,Merk,gambar in db.execute('SELECT * FROM Barang'):
    #     container.append((ids,nama,satuan,harga,Merk,gambar))
    return 'hello'
Example #7
0
def ambilbarang():
    db = get_db()
    brng = db.execute('SELECT * FROM Barang')
    # db.commit()
    return render_template('auth/ambilbarang.html', container=brng)
Example #8
0
def Hapus(ide):
    db = get_db()
    db.execute('DELETE FROM Barang WHERE kodeBarang=?', (ide, ))
    db.commit()
    return redirect(url_for('auth.barang'))