Ejemplo n.º 1
0
form = cgi.FieldStorage()

printHeader1('Sales')

errorString = None

#cgi.print_form(form)

################
# Handle add sale

if form.has_key('addSale'):
    try:
        #cgi.print_form(form)
        buyer = form['buyer'].value
        shipping = dollarStringToCents(form['shipping'].value)
        if form.has_key('reconcile'):
            tranType = 'RECONCILE'
        else:
            tranType = 'REAL'
        cursor.execute('BEGIN IMMEDIATE TRANSACTION')
        cursor.execute("INSERT INTO Trans (type,direction,tranDate,description,shipping) VALUES (?,'DEL',DATE('now'),?,?)",
                       (tranType,buyer,shipping))
        tranId = cursor.lastrowid

        history = "SELL %d"%tranId

        numberOfBins = {}
        kitSales = []

        for field in form.keys():
Ejemplo n.º 2
0
    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
        cursor.execute('BEGIN IMMEDIATE TRANSACTION')
        cursor.execute('INSERT INTO Expense (expDate,description,amount) VALUES (?,?,?)',(addDate,addDesc,dollarStringToCents(addAmt)))
        c.commit()
        printRedirect('Added 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())

#######################3
# Handle edit
if form.has_key('edit'):
    try:
        editDate = form['date'].value
        editDesc = form['description'].value
        editAmt  = form['amount'].value
Ejemplo n.º 3
0
cgitb.enable()

form = cgi.FieldStorage()

printHeader1('Purchases')

errorString = None

#cgi.print_form(form)

##################
# Handle add purchase request
if form.has_key('AddPurchase'):
    try:
        seller = form['seller'].value
        shipping = dollarStringToCents(form['shipping'].value)
        if form.has_key('reconcile'):
            tranType = 'RECONCILE'
        else:
            tranType = 'REAL'
        maxItemIdx = form['addLastItem'].value
        cursor.execute('BEGIN IMMEDIATE TRANSACTION')
        cursor.execute("INSERT INTO Trans (type,direction,tranDate,description,shipping) VALUES (?,'ADD',DATE('now'),?,?)",
                       (tranType,seller,shipping))
        tranId = cursor.lastrowid

        history = "BUY %d"%tranId

        for i in range(1,int(maxItemIdx)+1):
            if form.has_key('addItem-'+str(i)):
                itemId = form['addItem-'+str(i)].value
Ejemplo n.º 4
0
from myutils import c,cursor,sql, printRedirect,printHeader1,printHeader2, printFooter, gotoButton, centsToDollarString, centsToString,dollarStringToCents,cell,moneyCell,getTranType,getItemName

cgitb.enable()

form = cgi.FieldStorage()

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()
Ejemplo n.º 5
0
print '<INPUT TYPE=HIDDEN NAME=buyer VALUE="%s" />'%buyer
print '<INPUT TYPE=HIDDEN NAME=shipping VALUE="%s" />'%shipping
if form.has_key('reconcile'):
    print '<INPUT TYPE=HIDDEN NAME=reconcile VALUE=1 />'

salesItems = []
salesKits = []
    
# Now print move table for each item
for i in range(1,int(maxItemIdx)+1):
    if form.has_key('addItem-'+str(i)):
        itemId = form['addItem-'+str(i)].value
        if itemId.startswith('Item'):
            # item is an item
            itemId = itemId.replace('Item','')
            salesItems.append((itemId,form['quantity-'+str(i)].value,dollarStringToCents(form['pricePerItem-'+str(i)].value)))
        else:
            # item is a kit
            kitId = itemId.replace('Kit','')
            quantity = int(form['quantity-'+str(i)].value)
            pricePerKit = int(dollarStringToCents(form['pricePerItem-'+str(i)].value))
            cursor.execute('SELECT itemId,quantity FROM KitItem WHERE kitId = ?',(kitId,))
            itemList = []
            for (itemId,itemQty) in cursor:
                itemList.append((itemId,int(itemQty)))
            itemCount = len(itemList)*quantity
            for (itemId,itemQty) in itemList:
                salesItems.append((itemId,itemQty*quantity,pricePerKit/itemCount))
            salesKits.append((kitId,quantity))

for (itemId,quantity,pricePerItem) in salesItems: