def main():
    print_headers()
    form = cgi.FieldStorage()
    if 'old' not in form or 'into' not in form:
        print 'Error: You need to include the OLD item id and the item id it is being merged INTO'
        print '''Use the interface on <a href='item_info.py'>item_info.py</a> to do this'''
    else:
        old_item_id = int(form.getvalue('old'))
        into_item_id = int(form.getvalue('into'))
        if not db.is_item(old_item_id):
            print 'Item %d not found.' % (old_item_id)
            sys.exit(0)
        if not db.is_item(into_item_id):
            print 'Item %d not found.' % (into_item_id)
            sys.exit(0)
        old_item = db.get_item(old_item_id)
        into_item = db.get_item(into_item_id)
        old_name = old_item.get_name()
        into_name = into_item.get_name()
        print '''<b>%s</b> (SKU: %d) will be REMOVED from the database.<br />''' % (old_item,old_item_id)
        print '''It will be merged INTO <b>%s</b> (SKU: %d).<br />''' % (into_item, into_item_id)
        print '''Note: There is currently no way to undo the merge operation.<br />'''
        print '''Additonally, if the merge results in the item having multiple entries for a given distributor the display in catalog.py will be wonky.  This will be corrected soon. Everything will display correctly in the item's item_info.py page so use that instead.<br /><br />'''

        print '''<u>Current Barcodes:</u>'''
        print_tables(old_name, old_item.get_barcodes(), into_name, into_item.get_barcodes())
        print '<br />'
        print '''<u>Current Distributor Item Info:</u>'''
        print_tables(old_name, old_item.get_distributor_items(), into_name, into_item.get_distributor_items())
        print '<br />'

        print '''The following options control whether certain data about <b>%s</b> will be ADDED to <b>%s</b> <br />''' % (old_name, into_name)

        print '''Merge barcodes: <input type="checkbox" id="m_barcodes" /> <br />'''
        print '''Merge delivery records: <input type="checkbox" id="m_deliveries" checked /><br />'''
        print '''Merge distributor item info: <input type="checkbox" id="m_dist_items" checked /><br />'''
        print '''Merge sales data (Only Steven should change this option!): <input type="checkbox" id="m_sales" checked /><br />'''
        print '''<br />'''
        print '''The count and last_manual_count for the old item will disappear and not affect the count/last_manual_count of the item it is being merged into.  However, the count of the merged item may change due to the sales/deliveries from the old item.'''
        print '''<br />'''
        print '''<button type="button" onClick="merge(%d,%d)">Merge</button> ''' % (old_item_id, into_item_id)
    print '''
def main():
    print_headers()
    print '''<body>'''
    print '''<form name="item" action="inventory_history.py" method="get">'''
    print '''Input an item SKU:'''
    print '''<input type="text" name="itemid" size="4" /> <input type="submit" value="Display" />'''
    print '''</form>'''
    form = cgi.FieldStorage()
    if "itemid" in form:
        itemid = int(form.getvalue("itemid"))
        item = db.get_item(itemid)
        print '''<br /> <b>30 day history for item %d (%s) </b><br />''' % (itemid, item)
        total_sales,total_deliveries,total_slush,history = db.get_item_history(itemid,30)
        print '<b>Total sales: %d <br />' % (total_sales,)
        print 'Total deliveries: %d <br />' % (total_deliveries,)
        print 'Total slushfunded: %d <br /></b>' % (total_slush,)
        print '''<table><thead><th>Date</th><th>+/-</th><th>Type</th></thead>'''
        for ttp in history:
            print '''<tr><td>%s</td><td>%.2f</td><td>%s</td></tr>''' % ttp
        print '''</table>'''
    print '''</body></html>'''
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import cgi
import op_db_library as db

form = cgi.FieldStorage()
print 'Content-type: text/plain\n'

itemid = int(form.getvalue('item'))
item = db.get_item(itemid)
dist = None
if 'distname' in form:
    distname = form.getvalue('distname')
    if db.is_distributor_byname(distname):
        dist = db.get_distributor_byname(distname)
elif 'distid' in form:
    distid = int(form.getvalue('distid'))
    if db.is_distributor(distid):
        dist = db.get_distributor(distid)

if dist != None:
    dist_item = db.get_distributor_item(item,dist)
    print '%s,%d,%s,%.2f,%.2f,%s' % (dist.get_name(), dist.get_id(),dist_item.get_dist_item_id(), dist_item.get_wholesale_price(), dist_item.get_case_size(), dist_item.get_case_unit())

        if 'caseunit' in form:
            case_unit_id = int(form.getvalue('caseunit'))

        db.update_distributor_item(dist_item, dist_item_id, wholesale_price, case_size, case_unit_id)        
    else:
        raise Exception ('no distributor_item id given')
elif action == 'remove_byid':  # temporary hack until things get sorted out with item_info (should only need this)
    if "dist_item_id" in form:
        db.remove_distributor_item_byid(int(form.getvalue('dist_item_id')))
    else:
        raise Exception ('no distributor_item id given')
elif action == 'query-margin':  # temporary hack until things get sorted out with item_info (should only need this)
    if "dist_item_id" in form:
        dist_item = db.get_distributor_item_byid(int(form.getvalue('dist_item_id')))
        each_cost = dist_item.get_each_cost()
        item = db.get_item(dist_item.get_item_id())
        dist = db.get_distributor(dist_item.get_dist_id())
        margin = db.get_distributor_item_margin(item,dist,dist_item)
        print '%.2f, %d' % (each_cost, margin)
    else:
        raise Exception ('no distributor_item id given')
elif 'item' in form:
    itemid = int(form.getvalue('item'))
    if action == 'query':                       # get a list of all distributors for a given item
        item = db.get_item(itemid)
        print item.get_distributors_str()
    elif action == 'query-id':    # get a string of all distributor ids for a given item
        item = db.get_item(itemid)
        print item.get_distributor_ids_str()
    else:
        if 'distname' not in form and 'distid' not in form:
Example #5
0
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import op_db_library as db
import smtplib
import cgi

print '''Content-type: text/plain\n'''
form = cgi.FieldStorage()
if 'old' not in form or 'into' not in form or 'barcodes' not in form or 'deliveries' not in form or 'dist_items' not in form or 'sales' not in form:
    print 'Error: invalid arguments.'
else:
    old_item_id = int(form.getvalue('old'))
    into_item_id = int(form.getvalue('into'))
    old_item = db.get_item(old_item_id)
    into_item = db.get_item(into_item_id)
    merge_barcodes = form.getvalue('barcodes') == 'true'
    merge_deliveries = form.getvalue('deliveries') == 'true'
    merge_dist_items = form.getvalue('dist_items') == 'true'
    merge_sales = form.getvalue('sales') == 'true'
    db.merge_items(old_item, into_item, merge_barcodes = merge_barcodes, merge_deliveries=merge_deliveries,merge_dist_items=merge_dist_items,merge_sales=merge_sales)
    SERVER = "localhost"

    FROM = "*****@*****.**"
    TO = ["*****@*****.**"]
    
    SUBJECT = 'Item merger notification'
    
    TEXT = '''Item %s was merged into %s (%s). '%s' no longer exists in the database.''' % (old_item.id, into_item.id, into_item, old_item)
    
Example #6
0
import datetime


def log_exception(*args):
    print "Error: %s" % (args[1],)


sys.excepthook = log_exception

form = cgi.FieldStorage()
print "Content-type: text/plain\n"

action = form.getvalue("action")
if action == "count":
    if "id" in form and "count" in form:
        item = db.get_item(int(form.getvalue("id")))
        item.set_count(int(form.getvalue("count")))
        if "exp_date" in form:
            speculate_date = datetime.datetime.strptime(form.getvalue("exp_date"), "%A %m/%d/%y")
            days_to_speculate = (speculate_date - datetime.datetime.now()).days
            count = item.get_count()
            day14 = db.get_sales_in_range(int(form.getvalue("id")), 14)
            speculated = count - day14 / 14 * days_to_speculate  # days_to_speculate determined outside of loop
            print "%d,%d" % (speculated, count)
        else:
            print item.get_count()
elif action == "status":
    if "id" in form and "stocked" in form:
        item = db.get_item(int(form.getvalue("id")))
        if form.getvalue("stocked") == "true":
            db.set_item_discontinued(item, 0)
Example #7
0
action = form.getvalue("action")
if action == 'price':
    if "price_id" in form and "price" in form:
        price = db.get_price(int(form.getvalue("price_id")))
        db.set_price(price, float(form.getvalue("price")))
    else:
        raise Exception ('invalid arguments. need price_id and price.  given %s' % form.keys())
elif action == 'group':
    if "price_id" in form and "item_id" in form:
        newid = form.getvalue('price_id')
        itemid = form.getvalue('item_id')
        if newid.isdigit() and itemid.isdigit():
            newid = int(newid)
            itemid = int(itemid)
            if db.is_price(newid):
                item = db.get_item(itemid)
                old = item.get_price_id()
                db.set_item_price(item,newid)
                price = db.get_price(newid)
                sale_unit = db.get_unit(price.get_sale_unit_id())
                print '%d,%d,%.2f,%d,%s' % (old,db.price_item_count(old),price.get_unit_cost(), price.get_id(),sale_unit) 
            else:
                raise Exception ('price_id %d not currently in database' % (newid))
        else:
            raise Exception ('invalid price_id or item_id')
    else:
        raise Exception ('invalid arguments. need price_id and item_id. given %s' % (form.keys()))
elif action == 'query':
    # returns a string containing information about all (item,distributor) pairs with the given price_id
    # prints the string as info about one item per line (separated with '\n')
    # prints out the following for each item: "id,dist_id,each_cost,margin"
Example #8
0
def main():
    form = cgi.FieldStorage()
    if "itemid" in form:
        itemid = int(form.getvalue("itemid"))
    else:
        itemid = 0
    # The index ito this dict is used in other parts of the python code for when we print out html elements,
    # we index into the key_handlers list to add the appropriate key handler to that object
    key_handlers = {'ditemid' : KeyHandler('handleDistItemIdChange','changes the distributor_item.dist_item_id field',ENTER_KEY,
                                           'update_distributor_item.py',{'action':'update_byid','dist_item_id':TEXTBOX_ID,'distitemid':TEXTBOX_VALUE},'','ditemid'),
                    
                    'casesize' : KeyHandler('handleCaseSizeChange','changes the case size of a distributor_item',ENTER_KEY,
                                            'update_distributor_item.py',{'action':'update_byid','dist_item_id':TEXTBOX_ID,'casesize':TEXTBOX_VALUE},
                                            'updateMargin(id)','casesize'),

                    'caseprice' : KeyHandler('handleCasePriceChange','changes the wholesale_price of a distributor_item',ENTER_KEY,
                                             'update_distributor_item.py',{'action':'update_byid','dist_item_id':TEXTBOX_ID,'caseprice':TEXTBOX_VALUE},
                                             'updateMargin(id)','caseprice'),
                    'name' : KeyHandler('handleItemNameChange','changes the name of a given item', ENTER_KEY,
                                        'update_item.py',{'action':'name','id' : str(itemid), 'name':TEXTBOX_VALUE},
                                        'updateItemString();', 'item_name'),
                    'itemsize' : KeyHandler('handleItemSizeChange','changes the size of a given item', ENTER_KEY,
                                            'update_item.py',{'action':'size','id':str(itemid),'size':TEXTBOX_VALUE},
                                            'updateItemString();', 'item_string'),

                    'barcode' : KeyHandler('handleBarcodeChange','changes the barcode of an item', ENTER_KEY,
                                           'update_item.py',{'action':'barcode_byid', 'barcode_id':TEXTBOX_ID, 'new_barcode':TEXTBOX_VALUE}, '','barcode'),


                    }
    select_handlers = {'taxcat' : SelectHandler('setTaxCategory','changes the tax category of the item','update_tax_categories.py',
                                                {'action':'set-item','item_id':str(itemid),'taxcatid':SELECT_VALUE}, '','tax_category'),

                       'itemsize' : SelectHandler('setItemSizeUnit','changes the size of the item','update_item.py',
                                                  {'action':'sizeunit_byid','id':str(itemid), 'sizeunit':SELECT_VALUE}, 'updateItemString();','item_size_unit'),

                       'caseunit' : SelectHandler('setCaseUnits','changes the units of the distributor_item', 'update_distributor_item.py',
                                                  {'action':'update_byid', 'dist_item_id' : SELECT_ID , 'caseunit':SELECT_VALUE},
                                                  '', 'dist_item_id')
                       }

    print_headers(key_handlers,select_handlers,itemid)

    print '''<form name="item" action="item_info.py" method="get">'''
    print '''Input an item SKU'''
    print '''<input type="text" name="itemid" size="4" /> <input type="submit" value="Display" />'''
    print '''</form>'''

    if "itemid" in form:
        itemid = int(form.getvalue("itemid"))
        if not db.is_item(itemid):
            print '''Item %d not found''' % itemid
            sys.exit(0)
        item = db.get_item(itemid)
        print '''<b><div id="item_string">OP SKU  %d: %s</div></b><br />''' % (itemid, item)
        print '''Name: <input type="text" size="40" class="%s" value="%s" /> <br />''' % (key_handlers['name'].element, item.get_name())
        print '''Item size: <input type="text" size="5" class="%s" value="%.2f" /> &nbsp;''' % (key_handlers['itemsize'].element, item.get_unit_size())
        print ''' <select class="%s">''' % (select_handlers['itemsize'].element)
        print_unit_options(item.get_size_unit_id())
        print '''</select> <br />'''
        print '''Tax category:''' 
        print_tax_categories(item,select_handlers)
        print '''<br />'''
        print '''OP Price: $<input type="text" size="5" class="op_price" value="%.2f" id="%d_op_price" />''' % (item.get_price(),item.get_id())
        print '''<br />'''
#        print '''OP in store count: %d''' % (item.get_count())
        print '''OP in store count: <input type="text" size="5" class="count" value="%d" id="%d_count" />''' % (item.get_count(),item.get_id())
        print '''<br />'''
        print '''Stocked:'''
        if not item.get_is_discontinued():
            print '''<input type="checkbox" id="%d_isStocked" onClick="discontinueItem(this)" checked />''' % (itemid,)
        else:
            print '''<input type="checkbox" id="%d_isStocked"  onClick="discontinueItem(this)"/>''' % (itemid,)
 
        print '''<br />'''*2
        print_barcodes(item,key_handlers)
        print_categories(item)
        print_distributor_items(item,key_handlers,select_handlers)
        print '''<br /> <br />'''
        print '''Merge this item into item with OP SKU:'''
        print '''<input type="text" id="merge" size="4" />'''
        print '''<button type="button" id="merge_btn" onClick="mergeItem()"> Merge </button><br /><br />'''
        print '''Notes: <br /><textarea id="notes" cols="40" rows="4">%s</textarea><br />''' % (item.get_notes())
        print '''<button type="button" onClick="updateNotes()">Update Notes</button><br />'''
        print '''<br /> <br /><button type="button" id="history_button" onClick="toggleHistory()"> Show History </button>'''
        print '''<br />'''
        print '''<div id="history" style="display: none">'''
        print_item_history(item)
        print '''</div>'''
        print '''<br /><button type="button" id="graph_button" onClick="toggleGraph()"> Show Graph </button>'''
        print '''<div id="graph" style="display: none">'''
        print '''<img src="item_graphs.py?itemid=%d&graph=sales" alt="%d_sales">''' % (itemid,itemid)
        print '''<img src="item_graphs.py?itemid=%d&graph=prices" alt=%d_prices">''' % (itemid, itemid)
        print '''</div>'''

    print '''</body></html>'''