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(): 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" /> ''' % (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>'''