def customer(request,customer_id): data=False data2=False try: # int or not customer_id=int(customer_id) except ValueError: raise Http404() data=True customer_id=str(customer_id) query="SELECT type FROM customers WHERE customer_id="+customer_id+";" dat=util.fetchone_from_sql(query) element=dat[0] infoheader1=['Номер','Имя/Название','Адрес','Телефон','Факс','Электронная почта'] if element: # if it is natural person query2 ="SELECT customer_id,name,address,phone,fax,email " query2+=" FROM customers WHERE customer_id="+customer_id+";" else: data2=True infoheader2=['Название банка','Счёт','БИК','ИНН','ОКОНХ','ОКПО'] query2 ="SELECT a.customer_id,a.name,a.address,a.phone,a.fax,a.email," query2+="b.bank,b.account,b.bik,b.inn,b.okonh,b.okpo " query2+=" FROM customers a RIGHT JOIN customers_lp b" query2+=" on(a.customer_id=b.customer_id) " query2+=" WHERE a.customer_id="+customer_id+";" customerdata=util.fetchone_from_sql(query2) customerdata1=customerdata[0:6] customerdata2=customerdata[6:12] return render_to_response('customer.html',locals())
def order(request,order_id): data=False try: # int or not order_id=int(order_id) except ValueError: raise Http404() data=True order_id=str(order_id) query ="select a.order_id,a.customer_id,a.responsible,a.order_date,a.order_amount,a.order_total, " query+=" b.diagram_id,b.vehicle,b.agent,b.plan_date,b.status,b.fact_date, " query+=" c.delpoint_id,c.del_address,c.zone,c.floor,c.elevator,c.entrance,c.code " query+=" from orders a left join delivery_diagrams b on (a.diagram_id=b.diagram_id) " query+=" left join delpoints c on (a.delpoint_id=c.delpoint_id) " query+=" where order_id="+order_id+";" infoheader1=['Номер','Клиент','Ответственный менеджер','Дата заказа','Цена без скидки','Цена со скидкой'] infoheader2=['Номер графика доставки','Транспортное средство','Агент','Планируемая дата доставки', 'Статус доставки','Фактическая дата доставки'] infoheader3=['Номер пункта доставки','Адрес','Зона','Этаж','Наличие лифта','Номер парадной','Входной код'] orderdata=util.fetchone_from_sql(query) orderdata=list(orderdata) if orderdata[10] == True: orderdata[10]='Доставлен' elif orderdata[10] == False: orderdata[10]='Не доставлен' if orderdata[16] == True: orderdata[16]='Есть' elif orderdata[16] == False: orderdata[16]='Нет' orderdata1=orderdata[0:6] orderdata2=orderdata[6:12] orderdata3=orderdata[12:19] return render_to_response('order.html',locals())
def addcustomer(request): if request.method == 'POST': form = AddCustomerForm(request.POST) if form.is_valid(): cd = form.cleaned_data name = cd['name'] address = cd['address'] phone = cd['phone'] fax = cd['fax'] email = cd['email'] type = int(cd['type']) if type ==2: bank = cd['bank'] account = str(cd['account']) bik = str(cd['bik']) inn = str(cd['inn']) okonh = str(cd['okonh']) okpo = str(cd['okpo']) type="False" elif type==1: type="True" query="INSERT INTO customers (name,address,phone,fax,email,type) " query+=" VALUES ('"+name+"','"+address+"','"+phone+"','"+fax+"','"+email+"',"+type+");" if util.simpleSqlCheck(query): util.execute_sql(query) else: return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request') if type=="False": dat=util.fetchone_from_sql("SELECT max(customer_id) FROM customers;") new_customer_id=dat[0] query2 ="INSERT INTO customers_lp (customer_id,bank,account,bik,inn,okonh,okpo) " query2+=" VALUES ("+str(new_customer_id)+",'"+bank+"',"+account+","+bik+","+inn+","+okonh+","+okpo+");" if util.simpleSqlCheck(query2): util.execute_sql(query2) else: return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request') return HttpResponseRedirect('thanks') return render_to_response('addcustomer.html',locals()) else: form = AddCustomerForm() return render_to_response('addcustomer.html',locals())
def addorder(request): if request.method == 'POST': form = AddOrderForm(request.POST) form.updateNonStaticFields() if form.is_valid(): # getting data from forms cd = form.cleaned_data customer_id =str(cd['customer_id']) delpoint_id =str(cd['delpoint_id']) responsible =cd['responsible'] vehicle =cd['vehicle'] agent =cd['agent'] plan_date =str(cd['plan_date']) output_id1 = str(cd['output_id1']) output_id1q = int(cd['output_id1q']) output_id1d = int(cd['output_id1d']) # calculating order_amount and order_total squery="SELECT output_price FROM outputs " squery+=" WHERE output_id="+output_id1+";" info=util.fetchone_from_sql(squery) order_amount=str(int(info[0])*output_id1q) order_total=str(int(order_amount)*(100-output_id1d)/100) # calculating current date info=util.fetchone_from_sql("SELECT CURRENT_DATE;") order_date=str(info[0]) # inserting new delivery_diagram row query= " INSERT into delivery_diagrams (vehicle,agent,plan_date,status) " query+=" VALUES ('"+vehicle+"','"+agent+"','"+plan_date+"',False);" if util.simpleSqlCheck(query): util.execute_sql(query) else: return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request') # getting new diagram_id from delivery_diagrams dat=util.fetchone_from_sql("SELECT max(diagram_id) FROM delivery_diagrams;") diagram_id=str(dat[0]) # inserting new order row query2="INSERT into orders(diagram_id,customer_id,delpoint_id," query2+="responsible,order_date,order_amount,order_total) " query2+=" VALUES("+diagram_id+","+customer_id+","+delpoint_id query2+=",\'"+responsible+"\','"+order_date+"',"+order_amount+","+order_total+");" if util.simpleSqlCheck(query2): util.execute_sql(query2) else: return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request') # getting new order_id from orders dat=util.fetchone_from_sql("SELECT max(order_id) FROM orders;") oid=dat[0] # inserting new order_output row discount=int(order_amount)-int(order_total) query3="INSERT into orders_outputs(order_id,output_id,quantity,discount) values" query3+=" ("+str(oid)+","+str(output_id1)+","+str(output_id1q)+","+str(discount)+");" if util.simpleSqlCheck(query3): util.execute_sql(query3) else: return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request') return HttpResponseRedirect('thanks') return render_to_response('addorder.html',locals()) else: form = AddOrderForm() form.updateNonStaticFields() return render_to_response('addorder.html',locals())