[production] update planned and produced ty
diff --git a/patches/december_2012/repost_ordered_qty.py b/patches/december_2012/repost_ordered_qty.py
index e73b726..4c1d11d 100644
--- a/patches/december_2012/repost_ordered_qty.py
+++ b/patches/december_2012/repost_ordered_qty.py
@@ -3,19 +3,9 @@
 
 def execute():
 	import webnotes
-	from webnotes.utils import flt
-
-	for d in webnotes.conn.sql("select name, item_code, warehouse, ordered_qty from tabBin", 
-			as_dict=1):
-		ordered_qty = webnotes.conn.sql("""
-			select sum((po_item.qty - po_item.received_qty)*po_item.conversion_factor)
-			from `tabPurchase Order Item` po_item, `tabPurchase Order` po
-			where po_item.item_code=%s and po_item.warehouse=%s 
-			and po_item.qty > po_item.received_qty and po_item.parent=po.name 
-			and po.status!='Stopped' and po.docstatus=1""", (d.item_code, d.warehouse))
+	from utilities.repost_stock import get_ordered_qty, update_bin
 			
-		if flt(d.ordered_qty) != flt(ordered_qty[0][0]):
-			webnotes.conn.set_value("Bin", d.name, "ordered_qty", flt(ordered_qty[0][0]))
-			
-			webnotes.conn.sql("""update tabBin set projected_qty = actual_qty + planned_qty + 
-				indented_qty + ordered_qty - reserved_qty where name = %s""", d.name)
\ No newline at end of file
+	for d in webnotes.conn.sql("select item_code, warehouse from tabBin"):
+		update_bin(d[0], d[1], {
+			"ordered_qty": get_ordered_qty(d[0], d[1])
+		})
\ No newline at end of file
diff --git a/patches/february_2013/repost_reserved_qty.py b/patches/february_2013/repost_reserved_qty.py
index 3a3353f..5c41266 100644
--- a/patches/february_2013/repost_reserved_qty.py
+++ b/patches/february_2013/repost_reserved_qty.py
@@ -4,54 +4,10 @@
 import webnotes
 def execute():
 	webnotes.conn.auto_commit_on_many_writes = 1
-	repost_reserved_qty()
-	webnotes.conn.auto_commit_on_many_writes = 0
+	from utilities.repost_stock import get_reserved_qty, update_bin
 	
-def repost_reserved_qty():
-	from webnotes.utils import flt
-	bins = webnotes.conn.sql("select item_code, warehouse, name, reserved_qty from `tabBin`")
-	i = 0
-	for d in bins:
-		i += 1
-		reserved_qty = webnotes.conn.sql("""
-			select 
-				sum((dnpi_qty / so_item_qty) * (so_item_qty - so_item_delivered_qty))
-			from 
-				(
-					(select
-						qty as dnpi_qty,
-						(
-							select qty from `tabSales Order Item`
-							where name = dnpi.parent_detail_docname
-						) as so_item_qty,
-						(
-							select ifnull(delivered_qty, 0) from `tabSales Order Item`
-							where name = dnpi.parent_detail_docname
-						) as so_item_delivered_qty, 
-						parent, name
-					from 
-					(
-						select qty, parent_detail_docname, parent, name
-						from `tabDelivery Note Packing Item` dnpi_in
-						where item_code = %s and warehouse = %s
-						and parenttype="Sales Order"
-					and item_code != parent_item
-						and exists (select * from `tabSales Order` so
-						where name = dnpi_in.parent and docstatus = 1 and status != 'Stopped')
-					) dnpi)
-				union
-					(select qty as dnpi_qty, qty as so_item_qty,
-						ifnull(delivered_qty, 0) as so_item_delivered_qty, parent, name
-					from `tabSales Order Item` so_item
-					where item_code = %s and reserved_warehouse = %s 
-					and exists(select * from `tabSales Order` so
-						where so.name = so_item.parent and so.docstatus = 1 
-						and so.status != 'Stopped'))
-				) tab
-			where 
-				so_item_qty >= so_item_delivered_qty
-		""", (d[0], d[1], d[0], d[1]))
-		
-		if flt(d[3]) != flt(reserved_qty[0][0]):
-			webnotes.conn.sql("""update `tabBin` set reserved_qty = %s where name = %s""",
-				(reserved_qty and reserved_qty[0][0] or 0, d[2]))
\ No newline at end of file
+	for d in webnotes.conn.sql("select item_code, warehouse from tabBin"):
+		update_bin(d[0], d[1], {
+			"reserved_qty": get_reserved_qty(d[0], d[1])
+		})
+	webnotes.conn.auto_commit_on_many_writes = 0
\ No newline at end of file
diff --git a/patches/october_2013/repost_planned_qty.py b/patches/october_2013/repost_planned_qty.py
new file mode 100644
index 0000000..cfe47ca
--- /dev/null
+++ b/patches/october_2013/repost_planned_qty.py
@@ -0,0 +1,11 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+def execute():
+	import webnotes
+	from utilities.repost_stock import get_planned_qty, update_bin
+	
+	for d in webnotes.conn.sql("select item_code, warehouse from tabBin"):
+		update_bin(d[0], d[1], {
+			"planned_qty": get_planned_qty(d[0], d[1])
+		})
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 6a5d0f4..59e0b0c 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -221,4 +221,5 @@
 	"patches.september_2013.p05_fix_customer_in_pos",
 	"patches.october_2013.fix_is_cancelled_in_sle",
 	"patches.october_2013.repost_ordered_qty",
+	"patches.october_2013.repost_planned_qty",
 ]
\ No newline at end of file