예제 #1
0
def print_multi_add():
    print '''<div class="fixed">'''

    print '''<select class="multi_dist" id="multi_dist">'''
    for dist in db.get_distributors():
        print '''<option class="%d_dist_option" value="%d"> %s </option>''' % (dist.get_id(),dist.get_id(),dist)
    print '''</select>'''
    print '''<button type="button" onClick="multiAddDist()">Add Dist</button>'''
    print '''<button type="button" onClick="multiRemoveDist()">Remove Dist</button>'''

    print '''<select class="multi_category" id="multi_category">'''
    for cat in db.get_categories():
        print '''<option class="%d_cat_option" value="%d"> %s </option>''' % (cat.get_id(),cat.get_id(),cat)
    print '''</select>'''
    print '''<button type="button" onClick="multiAddCategory()">Add Category</button>'''
    print '''<button type="button" onClick="multiRemoveCategory()">Remove Category</button>'''
    
    print '''<select class="addTaxCat" id="multi_tax_category">'''
    for taxcat in db.get_tax_categories():
        print '''<option class="%d_taxcat_option" value="%d"> %s </option>''' % (taxcat.get_id(),taxcat.get_id(),taxcat)
    print '''</select>'''
    print '''<button type="button" onClick="multiSetTaxCategory()">Set TaxCat</button>'''

    print '''<button type="button" onClick="uncheckAllMulti()">Uncheck All Items </button>'''
    print '''</div>'''
예제 #2
0
def print_distributors():
    print '''<br/><br/>Select distributors to display:'''
    if "allDists" in input_form:
        print '''<input name="allDists" type="checkbox" onClick="allDistributors(this)" value="True" checked>All </input><br/>'''
    else:
        print '''<input name="allDists" type="checkbox" onClick="allDistributors(this)" value="True">All </input><br/>'''
    dists = []

    print '''<table cellspacing=0 cellpadding=2 style="border-top: 1px solid #999; border-left: 1px solid #999;">'''
    
    for i,dist in enumerate(db.get_distributors()):
        if i % 5 == 0:
            if i> 0:
                print '''</tr>'''
            print '''<tr>'''
        test_str = "dist_%s" % str(dist)
        if test_str in input_form:
            dists.append(dist)
            print '''<td>%s</td> <td style="border-right: 1px solid #999"><input class="distributorbox" type="checkbox" name="dist_%s" value="True" checked/></td>''' % (dist,dist)
        else:
            print '''<td>%s</td><td  style="border-right: 1px solid #999"> <input class="distributorbox" type="checkbox" name="dist_%s" value="True"/> </td>''' % (dist,dist)

    if (i+1) % 5 == 0:
        print '''</tr><tr>'''
    test_str = "dist_No Distributor"
    if test_str in input_form:
        print '''<td>%s</td> <td style="border-right: 1px solid #999"><input class="distributorbox" type="checkbox" name="dist_%s" value="True" checked/></td>''' % ("No Distributor", "No Distributor")
        hide_distributorless = False
    else:
        print '''<td>%s</td> <td style="border-right: 1px solid #999"><input class="distributorbox" type="checkbox" name="dist_%s" value="True"/></td>''' % ("No Distributor", "No Distributor")
        hide_distributorless = True
    print '</tr></table><br />'
    
    return dists, hide_distributorless
예제 #3
0
def print_distributor_items(item,key_handlers,select_handlers):
    print '''<table id="distributors">
                 <thead>
                 <th>Distributor</th>
                 <th>Dist Item ID</th>
                 <th>Case Size</th>
                 <th>Case Units</th>
                 <th>Case Price</th>
                 <th>Each Price</th>
                 <th>Margin</th>
                 <th>Remove</th>
                 </thead>'''
    for ditem in item.get_distributor_items():
        print '''<tr id="%d_dist_tr">''' % (ditem.get_id(),)
        dist = db.get_distributor(ditem.get_dist_id())
        print '''<td> %s</td><td> <input type="text" class="%s" id="%d_ditemid" value="%s" size="16" /></td>''' % (dist,key_handlers['ditemid'].element,ditem.get_id(),ditem.get_dist_item_id())
        print '''<td><input type="text" class="%s" id="%d_casesize" value="%.2f" size="4" /> </td>''' % (key_handlers['casesize'].element,ditem.get_id(), ditem.get_case_size())
        print '''<td><select class="%s" id="%d_caseunits">''' % (select_handlers['caseunit'].element,ditem.get_id())
        print_unit_options(ditem.get_case_unit_id())
        print '''</select></td>'''
        print '''<td>$<input type="text" class="%s" id="%d_caseprice" value="%.2f" size="5" /></td>''' % (key_handlers['caseprice'].element,ditem.get_id(), ditem.get_wholesale_price())

        each_cost = ditem.get_each_cost()
        op_price = item.get_price()
        tax = item.get_tax_value()

        if op_price - tax > 0:
            margin = (1.0 - each_cost/(op_price - tax)) * 100
        else:
            margin = 100

	print '''<td width="80" id="%d_each">$%.2f </td>''' % (ditem.get_id(),each_cost)
        if margin <= 20:
            print '''<td width="80" class="bad" id="%d_margin"> %.0f%% &nbsp;</td>''' % (ditem.get_id(), margin)
        elif margin <= 30:
            print '''<td width="80" class="mid" id="%d_margin"> %.0f%% &nbsp; </td>''' % (ditem.get_id(), margin)
        else:
            print '''<td width="80" class="good" id="%d_margin"> %.0f%% &nbsp; </td>''' % (ditem.get_id(), margin)

        print '''<td><button type="button" onClick="removeDistributor(%d)">remove</button></td>''' % (ditem.get_id(),)

        print '</tr>'
    print '</table>'
    print '''<select id="new_distributor">'''
    for dist in db.get_distributors():
        print '''<option value="%d"> %s </option>''' % (dist.get_id(), dist)
    print '''</select>'''
    print '''<button type="button" onClick="addDistributor()"> Add Distributor</button>'''
예제 #4
0
print 'Content-type: text/plain\n'
action = form.getvalue('action')
if action == 'add':
    if 'name' in form:
        distname = form.getvalue('name')
        if db.is_distributor_byname(distname):
            raise Exception ('distributor already exists')
        else:
            db.add_distributor(distname)
            dist = db.get_distributor_byname(distname)
            print '%d,%s' % (dist.get_id(),distname)
    else:
        raise Exception ('no distributor name given')
elif action == 'remove':
    distid = int(form.getvalue('id'))
    if not db.is_distributor(distid):
        raise Exception ('distributor not in database')
    else:
        dist = db.get_distributor(distid)
        print dist.get_name()
        db.remove_distributor(dist)
        
elif action == 'query':
    dist_list = [dist.get_name() for dist in db.get_distributors()]
    print ','.join(dist_list)
elif action == 'query-name':
    dist_list = [str(dist.get_id())+','+dist.get_name() for dist in db.get_distributors()]
    print '\n'.join(dist_list);
else:
    raise Exception ('invalid action')
예제 #5
0
print '''PLU : <input type="text" name="plu" size="10" />'''
print '''count*: <input type="text" name="count" size="3" /> <br />'''
print '''price: $<input type="text" name="price" size="5"/>'''
print '''price unit: <select name="price_unit">'''
for unit in db.get_units():
    print '''<option> %s </option> ''' % unit
print '''</select>'''
print '''price id: <input type="text" name="price_id" size="4" />'''
print '''tax category*: <select name="taxcat">'''
for taxcat in db.get_tax_categories():
    print '''<option> %s </option> ''' % taxcat
print '''</select> <br />'''

print '''distributor: <select name="distributor" /> '''
print '''<option></option>'''
for dist in db.get_distributors():
    print '''<option> %s </option> ''' % dist
print '''</select>'''
print '''distributor item id: <input type="text" name="dist_item_id" size=10" /> '''
print '''case price: <input type="text" name="wholesale_price" size="5" /> '''
print '''case size: <input type="text" name="case_size" size=5" /> '''
print '''case unit: <select name="case_unit"> '''
for unit in db.get_units():           
    print '''<option> %s </option> ''' % unit
print '''</select> <br />'''

print ''' <input type="submit" value="Add Item" /> </form>'''
print '''Starred fields are required <br />'''
print '''Input either a price AND a price unit OR a price id'''
print '''</body></html>'''
예제 #6
0
def main():
    form = cgi.FieldStorage()
    idf.init(form,discontinued=True,distributors=True,categories=True)
    print_headers()
    print '''
<body>
<div class="key">
         Key:
	      <span class="na"> very negative (produce, etc.) </span>
	      <span class="bad"> slightly negative (counting error?) </span>
	      <span class="out"> out (0 in stock) </span>
              <span class="low"> &lt;14 day supply in stock </span>
         </div>
         <div>Click table headers to sort</div>
         <div>Click distributor to change</div>
         <div>Type and hit ENTER to change item number or to adjust quantity</div>
         <div>Boxes will be grayed out until the update happens to the database.  If a box doesn't become normal after a few seconds, then likely something is wrong with the database or the server</div>
         <div>The Out in column estimates the number of days of stock left in store.  It uses the average # units sold per day for the last 14 days to get its estimate</div>
         <div>The Spec column shows the estimated stock count for 'Speculate stock for date:' day.  Speculation is based on average # units sold per day for the last 14 days. The default date is for the next Thursday</div>
         <div>The New count field is meant to change an item's count after doing a manual count.  Deliveries should be logged under manage_prices.  Type a new count and press ENTER </div>
         <div style="clear: both; height: 15px;"> </div>'''
    
    print '''<form name="options" action="catalog.py" method="get">'''
    options = idf.print_form()    # prints out all of the options for item displaying

    print '''Speculate stock for date'''
    if "exp_date" in form:
        speculate_date = datetime.datetime.strptime(form.getvalue("exp_date"), spec_date_format)
        days_to_speculate = (speculate_date - datetime.datetime.now()).days
        print_dates(14, speculate_date)
    else:
        today = datetime.datetime.now()
        days_to_speculate = (6 - today.weekday() + 4) % 7  # weekday goes Monday=0, Sunday=6 so: 6-today = days to next sunday
        print_dates(14, today+datetime.timedelta(days=days_to_speculate))
    print ''' <br /><input type="submit" value="Change options" /> </form>'''
    print '''<br /><br />'''
    print '''<table border=0 class="sortable" cellspacing=2 cellpadding=0>
             <thead class="col-header"><tr>
             <th class="th">dist (case size/units/price)</th>
             <th class="th">d item id</th>
             <th class="th">name</th>
             <th class="th">size</th>
             <th class="th">price</th>
             <th class="th">7d</th>
             <th class="th">14d</th>
             <th class="th">30d</th>
             <th class="th" class="sorttable_numeric">Out in</th>
             <th class="th">Spec</th>
             <th class="th">#stocked</th>
             <th class="th">New count</th>
             <th class="th">OP SKU</th>
             <th class="th">barcodes</th>
             <th class="th">Stocked</th>
             </thead><tbody id="item-stats">\n'''

    distributors = dict([(d.get_id(), d) for d in db.get_distributors()])
    for item in db.get_items(**options):
        # Need to make these floats b/c comparison b/t Decimal and float work strangely
        count = float(item.get_count())
        item_id = item.get_id()
        day7, day14, day30 = db.get_sales_in_multi_range(item_id,7,14,30)
        stock_strings = ['%.2f'%day7,'%.2f'%day14,'%.2f'%day30]
        dist_list = item.get_distributors()     
        dist_count = len(dist_list)
        
        for i in range(max(1,dist_count)):   # need the max in case the item has no distributors            
            row_color = ""
            if count < -10.0:
                row_color = "na"
            elif count < 0.0:
                row_color = "bad"
            elif count < 1.0:
                row_color = "out"
            elif count < day14:
                row_color = "low"
            print '<tr id="tr_%d_%.2f" class="%s">' % (item_id, day14,row_color)
            
            print '<div class="div_%d">' % (item_id)
        
            if dist_count == 0:  # don't have any distributors so we just print blanks in first two spots
                print '''<td> - &nbsp; </td> <td> - &nbsp; </td>'''
            else:
                d_i = dist_list[i]
                dist = distributors[d_i.get_dist_id()]
                case_str = '''%.2f''' % d_i.get_case_size()
                price_str = '''$%.2f''' % d_i.get_wholesale_price()
                print '''<td>''',str(dist),'(',case_str,' ',d_i.get_case_unit(),' ',price_str,') </td> <td>',d_i.get_dist_item_id(),' </td>'''
        
            print '''<td style='padding-left: 1em;'>''',str(item),'</td>'''
            print '''<td>''',item.get_size_str(),'''</td>'''
            print '''<td>''',item.get_price_str(),'''</td>'''
            print '<td>',stock_strings[0],'</td><td>',stock_strings[1],'</td><td>',stock_strings[2],'</td>'
            if count > 0:
                if float(day14) > 0:
                    days_of_stock = float(count) *14.0/ float(day14)
                    print '<td>','%.0f'%days_of_stock,' days</td>'
                else:
                    print '''<td>No sales</td>'''
            else:
                print '''<td>0 days</td>'''

            speculated = count - day14/14*days_to_speculate   # days_to_speculate determined outside of loop
            print '''<td id="%d_spec_%d" class="spec">''' % (item_id,i)
            print '%d'%speculated,'''</td>'''
            print '''<td id="%d_amt_%d" style="border-left: 1px solid #999; padding-left: 1em;">''' % (item_id, i)
            print int(count),'''</td>'''
            print '''<td><input class="count default" id="%d_count_%d" size="3" /></td>''' % (item_id,i)
            print '''<td style='text-align: center;'> <a href="''',db.get_item_info_page_link(item_id),'''" target="_blank">''',str(item_id),'''</a> </td>'''
            print '''<td>''',item.get_barcodes_str(),'''&nbsp;</td>'''
            if not item.get_is_discontinued():
                print '''<td><input type="checkbox" id="%d_isStocked" onClick="discontinueItem(this)" checked /> </td>''' % (item_id,)
            else:
                print '''<td><input type="checkbox" id="%d_isStocked"  onClick="discontinueItem(this)"/> </td>''' % (item_id,)                                             
            print '''</div>'''
            print '''</tr>\n'''
    print '''</tbody></table>\n'''
    print '''</body></html>'''