コード例 #1
0
ファイル: binList.py プロジェクト: lezzgiles/esp
        if foundQty < totalToMove:
           raise ValueError, "<p class=error>Didn't find enough items to move</p>"

        cursor.execute('DELETE FROM binItems WHERE binId = ? and itemId = ?',(delBin,delItem))

        for (binId,binQty) in moveDetails:
            cursor.execute('INSERT INTO binItems (binId,itemId,quantity) VALUES (?,?,?)',(binId,delItem,binQty))

        if foundQty > totalToMove:
            cursor.execute('INSERT INTO binItems (binId,itemId,quantity) VALUES (?,?,?)',(delBin,delItem,foundQty-totalToMove))
            
        cursor.execute('''INSERT INTO history (historyDate,body) VALUES (DATETIME('now'),?)''',(history,))
        c.commit()
        # Redirect to same page, so page reload doesn't re-add move
        printRedirect('Move completed','binList.py',0)
        sys.exit()

    except Exception,e:
        c.rollback()
        errorString = "<p class=error>Problem with database update:</p><pre>%s</pre>"%str(sys.exc_info())
    
printHeader2('Bin/stock list',errorString)

#########################################    
cursor.execute('''
SELECT
    binId,itemId,Bin.name,Item.manufacturer,Item.brand,Item.name,SUM(quantity)
FROM
    Bin
    INNER JOIN BinItems using (binId)
コード例 #2
0
ファイル: sales.py プロジェクト: lezzgiles/esp
                
            cursor.execute('INSERT INTO TransItem (tranId,itemId,quantity,pricePerItem) VALUES (?,?,?,?)',
                           (tranId,itemId,totalQuantity,pricePerItem))

        for (kitId,qty) in kitSales:
            cursor.execute("SELECT quantity FROM Kit WHERE kitId = ?",(kitId,))
            (foundQty,) = cursor.fetchone()
            foundQty = int(foundQty)
            if foundQty < qty:
                raise ValueError,'<p class=error>Database changed - needed %s kit %s but only found %d - aborting sale</p>'%(qty,kitId,foundQty)
            cursor.execute('UPDATE Kit SET quantity = ? WHERE kitId = ?',(foundQty-qty,kitId))
                
        cursor.execute('''INSERT INTO history (historyDate,body) VALUES (DATETIME('now'),?)''',(history,))
        c.commit()
        # Redirect to same page, so page reload doesn't re-add sale
        printRedirect('Added Sale','sales.py',0)
        sys.exit()

    except Exception,e:
        c.rollback()
        errorString = "<p class=error>Problem with database update:</p><pre>%s</pre>"%str(sys.exc_info())

printHeader2('Sales',errorString)
    
################
# Get list of items for add sale form

cursor.execute("SELECT itemId,manufacturer,brand,name FROM item INNER JOIN binItems USING (itemId) WHERE quantity > 0 GROUP BY manufacturer,brand,name ORDER BY manufacturer,brand,name")
itemOptions = []
for (itemId,manufacturer,brand,name) in cursor:
    itemOptions.append('<OPTION VALUE=Item%s>%s</OPTION>'%(itemId,getItemName(manufacturer,brand,name)))
コード例 #3
0
ファイル: kits.py プロジェクト: lezzgiles/esp
        maxItemIdx = form['addLastItem'].value
        cursor.execute('BEGIN IMMEDIATE TRANSACTION')
        cursor.execute("INSERT INTO Kit (name) VALUES (?)",(name,))
        kitId = cursor.lastrowid

        for i in range(1,int(maxItemIdx)+1):
            if form.has_key('addItem-'+str(i)):
                itemId = form['addItem-'+str(i)].value
                quantity = form['quantity-'+str(i)].value
                if int(quantity) == 0: continue
                cursor.execute('INSERT INTO KitItem (kitId,itemId,quantity) VALUES (?,?,?)',
                               (kitId,itemId,quantity))

        c.commit()
        # redirect to same page, so reload doesn't re-add purchase
        printRedirect('Added kit','kits.py',0)
        sys.exit()

    except Exception,e:
        c.rollback()
        errorString = "<p class=error>Problem with database update:</p><pre>%s</pre>"%str(sys.exc_info())


##################
# Handle delete kit request
if form.has_key('delId'):
    try:
        delId = form['delId'].value
        cursor.execute('BEGIN IMMEDIATE TRANSACTION')
        cursor.execute("DELETE FROM Kit WHERE kitId = ?",(delId,))
        cursor.execute("DELETE FROM KitItem WHERE kitId = ?",(delId,))
コード例 #4
0
ファイル: expenses.py プロジェクト: lezzgiles/esp
form = cgi.FieldStorage()

printHeader1('Expenses & Fees')

errorString = None

######################
# Handle delete
if form.has_key('deleteId'):
    try:
        deleteId = int(form['deleteId'].value)

        cursor.execute('BEGIN IMMEDIATE TRANSACTION')
        cursor.execute('DELETE FROM expense WHERE expenseId = ?',(deleteId,))
        c.commit()
        printRedirect('Deleted expense','expenses.py',0)
        sys.exit()

    except Exception,e:
        c.rollback()
        errorString = "<p class=error>Problem with database update:</p><pre>%s</pre>"%str(sys.exc_info())

######################
# Handle add
addManufacturer = None
addBrand = None
if form.has_key('add'):
    try:
        addDate = form['date'].value
        addDesc = form['description'].value
        addAmt  = form['amount'].value
コード例 #5
0
ファイル: saleDetails.py プロジェクト: lezzgiles/esp
printHeader1('Sale Details')

errorString = None

tranId = form['tranId'].value

if form.has_key('tracking'):
    try:
        tracking = form['tracking'].value
        actualShipping = dollarStringToCents(form['actualShipping'].value)
        cursor.execute('BEGIN IMMEDIATE TRANSACTION')
        cursor.execute('UPDATE Trans SET tracking=?, actualShipping=? WHERE tranId = ?',(tracking,actualShipping,tranId))
        c.commit()
        # redirect to page, so page reload doesn't re-add change
        printRedirect('Updating Sale','sales.py',0)
        sys.exit()
    except Exception,e:
        c.rollback()
        errorString = "<p class=error>Problem with database updte:</p><pre></pre>"%str(sys.exc_info())

printHeader2('Sale Details',errorString)

cursor.execute('SELECT type,direction,tranDate,description,shipping,actualShipping,tracking FROM Trans where tranId = ?',(tranId,))
(type,direction,tranDate,description,shipping,actualShipping,tracking) = cursor.fetchone()


mytype = getTranType(type,direction)

print '<H2>Details for %s: %s</H2>'%(mytype,description)
print '<p>Date: %s</p>'%tranDate
コード例 #6
0
ファイル: purchases.py プロジェクト: lezzgiles/esp
                name = form['addName-'+str(i)].value.strip()
                quantity = int(form['quantity-'+str(i)].value)
                if quantity == 0: continue
                if not name: raise ValError,"Empty item type name"
                cursor.execute("INSERT INTO item (manufacturer,brand,name) VALUES (?,?,?)",(mfr,brand,name))
                itemId = cursor.lastrowid
                history += " %s OF %s TO 1"%(quantity,itemId)    # binId 1 - unstocked - is hard-coded
                pricePerItem = dollarStringToCents(form['pricePerItem-'+str(i)].value)
                cursor.execute('INSERT INTO TransItem (tranId,itemId,quantity,pricePerItem) VALUES (?,?,?,?)',
                               (tranId,itemId,quantity,pricePerItem))
                cursor.execute('INSERT INTO binItems (binId,itemId,quantity) VALUES (1,?,?)',(itemId,quantity))

        cursor.execute('''INSERT INTO history (historyDate,body) VALUES (DATETIME('now'),?)''',(history,))
        c.commit()
        # redirect to same page, so reload doesn't re-add purchase
        printRedirect('Added purchase','purchases.py',0)
        sys.exit()

    except Exception,e:
        c.rollback()
        errorString = "<p class=error>Problem with database updte:</p><pre>%s</pre>"%str(sys.exc_info())

printHeader2('Purchases',errorString)

################
# Get list of items for add purchase form

cursor.execute("SELECT itemId,manufacturer,brand,name FROM item ORDER BY manufacturer,brand,name")
itemOptions = []
for (itemId,manufacturer,brand,name) in cursor:
    itemOptions.append('<OPTION VALUE=%s>%s</OPTION>'%(itemId,getItemName(manufacturer,brand,name)))