This project is for a shipping calculator script.
Given the following array of products to be packaged:
// measures = milimeters
// weight = kilograms
$products[] = array('quantity' => 2, 'height' => 140, 'width' => 80, 'length' => 80, 'weight' => 0.200, 'type' => 'square', 'loadingAllowed' => array('h', 'l', 'w'));
$products[] = array('quantity' => 4, 'height' => 50, 'width' => 60, 'length' => 60, 'weight' => 0.100, 'type' => 'circle', 'loadingAllowed' => array('h'));
$products[] = array('quantity' => 30, 'height' => 100, 'width' => 100, 'length' => 100, 'weight' => 0.100, 'type' => 'circle', 'loadingAllowed' => array('l'));
$products[] = array('quantity' => 5, 'height' => 80, 'width' => 80, 'length' => 80, 'weight' => 0.100, 'type' => 'square', 'loadingAllowed' => array('h', 'l', 'w'));
And the following array of boxes:
// max_weight = 30 kilograms
// quantity = is how many boxes we have available in stock to package the customer goods
// If there is no box available, try the next box (with quantity)
$boxes[] = array('type' => 'Box 1', 'width' => 110, 'height' => 20, 'length' => 160, 'quantity' => 100, 'max_weight' => 30);
$boxes[] = array('type' => 'Box 2', 'width' => 180, 'height' => 90, 'length' => 270, 'quantity' => 100, 'max_weight' => 30);
$boxes[] = array('type' => 'Box 3', 'width' => 270, 'height' => 180, 'length' => 360, 'quantity' => 100, 'max_weight' => 30);
$boxes[] = array('type' => 'Box 4', 'width' => 270, 'height' => 270, 'length' => 360, 'quantity' => 100, 'max_weight' => 30);
$boxes[] = array('type' => 'Box 5', 'width' => 360, 'height' => 270, 'length' => 540, 'quantity' => 100, 'max_weight' => 30);
With that, we start to test which box is needed to fit all products (starting with the product that has the largest weight)
If all products fit Box 1, good, return the box.
If not all products fit Box 1, try Box 2.
If not all products fit Box 2, try Box 3 and so on.
If all products doesn't fit any box, split the products between the boxes starting with the largest box.
e.g
Box 5 doesn't have enough space to fit all 4 products, now we start with Box 5 (because it's the largest box available) and see how many items fit Box 5, if half of the products fit Box 5, start again with the remaning products (but now with Box 1, doing the loop again).
If the box max_weight has been reached, start a new box.
If product 1 fit box 1, try to fit product 2 in box 1 too, if product 2 doesn't fit box 1, try to fit product 3 in box 1, if product 3 doesn't fit in box 1, try product 4 and so on until no products remain left.
This is exactly what I need, but without having to the user do step by step:
[login to view URL]
The 'type' and 'loadingAllowed' is to create the loading steps that you can see at the end of this page:
[login to view URL]
Let me know if you need anymore details.