Invoice line items, n-n relation, and item quantity
- Single Page
Posted 04 July 2012 - 19:29 PM
I have all the usual suspects as tables: Customers, Orders, Products
I have then used a table to make an n-n relationship between orders and products: OrdersProducts
[b]Customers:[/b]
CustomerID, CustomerName
[b]Orders:[/b]
OrderID, CustomerID, OrderDate
[b]Products:[/b]
ProductID, ProductsName, ProductPrice
[b]OrdersProducts:[/b]
OrderID, ProductID, Quantity
Finally here's my code:
[font=courier new,courier,monospace]function Orders()[/font]
[font=courier new,courier,monospace]{[/font]
[font=courier new,courier,monospace]$crud = new grocery_CRUD();[/font]
[font=courier new,courier,monospace]$crud->set_table('Orders');[/font]
[font=courier new,courier,monospace]$crud->set_subject('Order');[/font]
[font=courier new,courier,monospace]$crud->set_relation_n_n('Products', 'OrdersProducts', 'Products', 'OrderID', 'ProductID', 'ProductName');[/font]
[font=courier new,courier,monospace]$output = $crud->render();[/font]
[font=courier new,courier,monospace]$this->_mgm_output($output);[/font]
[font=courier new,courier,monospace]} [/font]
It works fine and I can add Products to Orders.
However I also need to be able to set the quantity of each Product for this order when I add them.... how can this be done?
Thank you
Posted 19 January 2013 - 19:31 PM
Posted 20 January 2013 - 15:30 PM
http://www.grocerycrud.com/documentation/options_functions/callback_field
It gonna be a hard-work though
You might probably want set_relation_1_n if it is exists. But since it is not, you might be interested on this:
/topic/1260-no-cms-and-grocery-crud-master-detail-form/#entry5168
You will still need some custom code, but I hope it can reduce your pain