! -> Note
$ -> Affected files
+30-Jun-2009 Joe Hunt
++ Implemented automatic price calculation of items from std. cost.
+$ /admin/company_preferences.php
+ /admin/db/company_db.inc
+ /doc/calculate_price.txt (new file)
+ /sales/includes/sales_db.inc
+ /sql/alter2.2.sql
+
29-Jun-2009 Joe Hunt
! Small layout improments in Customer Payments
$ /sales/customer_payments.php
$_POST['coy_logo'] = "";
}
}
+ if ($_POST['add_pct'] == "")
+ $_POST['add_pct'] = -1;
if ($input_error != 1)
{
update_company_setup($_POST['coy_name'], $_POST['coy_no'],
$_POST['email'], $_POST['coy_logo'], $_POST['domicile'],
$_POST['use_dimension'], $_POST['curr_default'], $_POST['f_year'],
check_value('no_item_list'), check_value('no_customer_list'),
- check_value('no_supplier_list'), $_POST['base_sales'], check_value('time_zone'));
+ check_value('no_supplier_list'), $_POST['base_sales'], check_value('time_zone'), $_POST['add_pct'], $_POST['round_to']);
display_notification_centered(_("Company setup has been updated."));
}
$_POST['f_year'] = $myrow["f_year"];
$_POST['time_zone'] = $myrow["time_zone"];
$_POST['version_id'] = $myrow["version_id"];
+$_POST['add_pct'] = $myrow['add_pct'];
+if ($_POST['add_pct'] == -1)
+ $_POST['add_pct'] = "";
+$_POST['round_to'] = $myrow['round_to'];
$_POST['del_coy_logo'] = 0;
start_outer_table($table_style2);
text_row_ex(_("Name (to appear on reports):"), 'coy_name', 42, 50);
textarea_row(_("Address:"), 'postal_address', $_POST['postal_address'], 35, 6);
+text_row_ex(_("Domicile:"), 'domicile', 25, 55);
text_row_ex(_("Phone Number:"), 'phone', 25, 55);
text_row_ex(_("Fax Number:"), 'fax', 25);
label_row(_("Company Logo:"), $_POST['coy_logo']);
label_row(_("New Company Logo (.jpg)") . ":", "<input type='file' id='pic' name='pic'>");
check_row(_("Delete Company Logo:"), 'del_coy_logo', $_POST['del_coy_logo']);
-text_row_ex(_("Domicile:"), 'domicile', 25, 55);
number_list_row(_("Use Dimensions:"), 'use_dimension', null, 0, 2);
sales_types_list_row(_("Base for auto price calculations:"), 'base_sales', $_POST['base_sales'], false,
_('No base price list') );
+text_row_ex(_("Add Price from Std Cost:"), 'add_pct', 10, 10, '', null, null, "%");
+$curr = get_currency($_POST['curr_default']);
+text_row_ex(_("Round to nearest:"), 'round_to', 10, 10, '', null, null, $curr['hundreds_name']);
check_row(_("Search Item List"), 'no_item_list', null);
check_row(_("Search Customer List"), 'no_customer_list', null);
function update_company_setup($coy_name, $coy_no, $gst_no, $tax_prd, $tax_last,
$postal_address, $phone, $fax, $email, $coy_logo, $domicile, $Dimension,
$curr_default, $f_year, $no_item_list, $no_customer_list, $no_supplier_list,
- $base_sales, $time_zone)
+ $base_sales, $time_zone, $add_pct, $round_to)
{
if ($f_year == null)
$f_year = 0;
curr_default=".db_escape($curr_default).",
f_year=$f_year,
base_sales=$base_sales,
- time_zone=$time_zone
+ time_zone=$time_zone,
+ add_pct=$add_pct,
+ round_to=$round_to
WHERE coy_code=1";
db_query($sql, "The company setup could not be updated ");
--- /dev/null
+Calculate sales price from standard cost
+----------------------------------------
+
+You can have automatic sales price calculation from items that do not have any prices in Sales Prices entered. This works
+independently from Base Price factor, but if Base Price is set it works together with it.
+
+Preparing and operation
+-----------------------
+
+Go into Setup tab - Company Setup.
+
+In the field, Add Price from Std cost, enter the % that you want to increase from the average standard costs for the items not.
+listed in the Item Price List. If this value is empty there are no automatic price calculations. BE aware that an increase value of 0 will
+calculate the price to be the same as the Std cost. So to remove the calculation, just empty the field. It will then get an internal value of -1.
+If the average standard costs is 0, the calculation would result in 0 as well.
+
+The field, Round to nearest xxx Cents, will round the calculated result to the nearest Cent entered. If you have 2 decimals in the amounts
+the value 100 would be divided by the xxx value. If you have 3 dicimans in the amounts the value 1000 will be divided by the xxx value.
+If there is no fraction, the value will be rounded up to the nearest xxx value. If there is a fraction, the value xxx will be subtracted from
+the value (100-xxx) or (1000-xxx).
+
+Let us take an example:
+----------------------
+
+Item standard cost = 20.77
+Decimals = 2
+Value to increase the items with = 70 (%)
+Round to nearest value = 5
+
+the pow(10, 2) = 100. 100 divided by 5 = 20 and no fraction. Price after increase = 20.77 * (1 + 70 / 100) = 35.309.
+Rounded to nearest 5 cent value = 35.35;
+
+Let us set the Round to nearest value = 95.
+
+The value 100 / 95 = 1 and a fraction of 95. The Price will still be calculated to 35.309. Now the value will be rounded to 36.00
+and subtracted by (100 - 95) = 35.95.
+
+So you see it is very flexible. If you have larger prices you can even round up to nearest 10, 100 by setting the rounding to
+nearest value = 1000 or 10000. But take care if you have different prices, large prices and small prices. It might not be a good idea to
+round a value of 10.77 to 100.
+
+If there is a base price list set and for instance a factor 0.7 the price list in foreign currencies are calculated as well.
+And again, if a 'Round to nearest' value is set to other than 1 the foreign prices are rounded in the same way as explained above.
+
+This new price calculaton should work with sales kits too.
+
//----------------------------------------------------------------------------------------
+function get_calculated_price($stock_id, $add_pct)
+{
+ $avg = get_standard_cost($stock_id);
+ if ($avg == 0)
+ return 0;
+ return round2($avg * (1 + $add_pct / 100), user_price_dec());
+}
+
+function round_to_nearest($price, $round_to)
+{
+ if ($price == 0)
+ return 0;
+ $pow = pow(10, user_price_dec());
+ if ($pow >= $round_to)
+ $mod = ($pow % $round_to);
+ else
+ $mod = ($round_to % $pow);
+ if ($mod != 0)
+ $price = ceil($price) - ($pow - $round_to) / $pow;
+ else
+ $price = ceil($price * ($pow / $round_to)) / ($pow / $round_to);
+ return $price;
+
+}
+
function get_price ($stock_id, $currency, $sales_type_id, $factor=null, $date=null)
{
if ($date == null)
$msg = "There was a problem retrieving the pricing information for the part $stock_id for customer";
$result = db_query($sql, $msg);
+ $add_pct = get_company_pref('add_pct');
+ $round_to = get_company_pref('round_to');
+ $home_curr = get_company_currency();
+
if (db_num_rows($result) != 0)
{
$myrow = db_fetch_row($result);
return $myrow[0];
}
+ elseif ($add_pct != -1)
+ {
+ $price = get_calculated_price($stock_id, $add_pct);
+ if ($currency == $home_curr)
+ return round_to_nearest($price, $round_to);
+ }
if ($factor == 0) return false; // auto price calculations off
$base_id = get_base_sales_type();
if ($base_id <= 0) return 0; // auto price calculations off
- $home_curr = get_company_currency();
-
// get all prices which we can use to guess the price.
// alternative is make up to 2 additional sql queries
$sql = "SELECT price, curr_abrev, sales_type_id
{
$prices[$myrow['sales_type_id']][$myrow['curr_abrev']] = $myrow['price'];
}
-
$rate = round(get_exchange_rate_from_home_currency($currency, $date),
user_exrate_dec());
- $price = false;
+ if (db_num_rows($result) == 0 && $add_pct != -1)
+ {
+ if ($factor != 0)
+ $price = $price * $factor / $rate;
+ else
+ $price /= $rate;
+ return round_to_nearest($price, $round_to);
+ }
+ $price = false;
if (isset($prices[$sales_type_id][$home_curr]))
{
$price = $prices[$sales_type_id][$home_curr] / $rate;
{
$price = $prices[$base_id][$home_curr] * $factor / $rate;
}
-
- return $price === false ? false : round($price, user_price_dec());
+ if ($price === false)
+ return false;
+ else if ($round_to != 1)
+ return round_to_nearest($price, $round_to);
+ else
+ return round2($price, user_price_dec());
}
//----------------------------------------------------------------------------------------
//
ALTER TABLE `0_company` DROP COLUMN `purch_exchange_diff_act`;
ALTER TABLE `0_company` ADD COLUMN`profit_loss_year_act` VARCHAR(11) NOT NULL DEFAULT '' AFTER `exchange_diff_act`;
ALTER TABLE `0_company` ADD COLUMN `time_zone` TINYINT(1) NOT NULL DEFAULT '0';
+ALTER TABLE `0_company` ADD COLUMN `add_pct` INT(5) NOT NULL DEFAULT '-1';
+ALTER TABLE `0_company` ADD COLUMN `round_to` INT(5) NOT NULL DEFAULT '1';
ALTER TABLE `0_company` CHANGE `grn_act` `bank_charge_act` VARCHAR(11) NOT NULL DEFAULT '';
#INSERT INTO `0_chart_master` VALUES ('9990', '', 'Profit and Loss this year', '52', '0');
UPDATE `0_company` SET `profit_loss_year_act`='9990', `version_id`='2.2' WHERE `coy_code`=1;