예제 #1
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>'''
예제 #2
0
# 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())

            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:
            raise Exception ('no distributor given')
예제 #4
0
                    margin,
                    cost,
                    db.get_unit(item_price.get_sale_unit_id()),
                    db.get_item_info_page_link(itemid),
                )

    else:
        raise Exception("incorrect arguments. given %s" % (form.keys()))
elif action == "get-string":
    if "id" in form:
        item = db.get_item(int(form.getvalue("id")))
        print item
    else:
        raise Exception("incorrect arguments. need id. given %s" % (form.keys()))
elif action == "get-margin":
    if "item_id" in form and "dist_id" in form:
        item = db.get_item(int(form.getvalue("item_id")))
        distributor = db.get_distributor(int(form.getvalue("dist_id")))
        margin = db.get_distributor_item_margin(item, distributor)
        print margin
    else:
        raise Exception("invlaid arguments. need item_id, distid. given %s" % (form.keys()))
elif action == "update-notes":
    if "item_id" in form and "notes" in form:
        item = db.get_item(int(form.getvalue("item_id")))
        item.set_notes(form.getvalue("notes"))
    else:
        raise Exception("invalid arguments. need item_id, notes. given %s" % (form.keys()))
else:
    raise Exception("invalid action")