Hi there,
I've been having problems with the automatic cost
calculation due to different units given to ingredients
and used for recipes (for eg: you can buy flour by 1kg
packages, however if you need just 30 decagram, you
don't specify it at 0.3 kg).
As cost is an approx anyways, I decided to let ppl
specify it manually. This was much less time consuming
as it would not worth programming the whole calculation
between all measurements to get an approximate cost.
To do this, you'll need to patch 2 files.
1) /modules/recipes/addedit.php:
$> diff addedit.php addedit_patched.php
52a53
> $recipe["recipe_cost"] = $_POST["recipe_cost"];
63a65,66
> // added to set cost manually - check if
numeric, else set to 0
> if (!is_numeric($recipe["recipe_cost"]))
$recipe["recipe_cost"]="0";
76a80
> $recipe["recipe_cost"] =
$rc->fields["recipe_cost"];
184a189,194
> <? php //4 lines below added to set the recipe cost
by the user ?>
> <tr>
> <td><?php echo $LangUI->_('Approximate
Cost');?>:<?php echo getHelpLink("cost");?></td>
> <td><input type="text" name="recipe_cost"
size="5" value="<?php echo $recipe["recipe_cost"];?>"> Ft
> </td>
> </tr>
2) /modules/recipes/update.php:
$> diff update.php update_patched.php
21c21,24
< $recipe_cost = 0;
---
> //removed $recipe_cost = 0; not to zero cost by default
> $recipe_cost = ($_POST['recipe_cost'] != "" ) ?
$_POST['recipe_cost'] : '0';
> // added to set cost manually - check if numeric,
else set to 0
> if (!is_numeric($recipe["recipe_cost"]))
$recipe["recipe_cost"]="0";
97c100,101
< $recipe_cost +=
$ingObj->computePrice(); // Add the cost of this item
to the total cost
---
> // commented this below
not to compute price as it's set manually
> // $recipe_cost +=
$ingObj->computePrice(); // Add the cost of this item
to the total cost
112c116,117
<
---
> // added to validate numeric field (cost)
> if (!is_numeric($recipe_cost)) $recipe_cost="0";
I'll be attaching a .tar.gz file with the 2 patched
phps to save time to whoever finds this useful :-)
Cheers,
MBJr.
Users to edit Approximate Cost Patch for phprecipebook v2.32
Logged In: YES
user_id=599321
I will look into this one more carefully in a little bit.
Right now the problem would be that the user entered cost
will get overwritten if it is resubmitted (the cost is
computed on each update). So either a config option to
allow editing, or a recipe by recipe db field is needed....
Todd