mirror of
https://github.com/itflow-org/itflow
synced 2026-11-23 12:57:24 +00:00
Quotes: a line can carry its cost each and a markup, margin or set price in the Edit Line window, with quick-pick percentages and what the line makes, a line added from a product takes the product's cost, the cost shows under the line while the quote can be changed and the quote's Margin counts each line's own cost, all for agents only; Admin Settings Quotes sets the starting method, percent and quick picks; Copy Quote keeps each line's product; database 3.8.7 adds quote_items.item_cost, item_price_method and item_price_percent and the pricing settings; 26.11.9 changelog entries
This commit is contained in:
46
admin/database_updates/3.8.7.php
Normal file
46
admin/database_updates/3.8.7.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Database update to version 3.8.7 (from 3.8.6)
|
||||
* Included by admin/database_updates.php - do not access directly
|
||||
*
|
||||
* Quote line pricing (functions/quote_pricing.php) - the same columns, with the
|
||||
* same meanings, as MountaineerIT's build, so their quotes carry straight over:
|
||||
* quote_items.item_cost - what the line costs you, each; NULL is not entered.
|
||||
* quote_items.item_price_method - how its price came from the cost: markup,
|
||||
* margin or price (set by hand); NULL with no cost.
|
||||
* quote_items.item_price_percent - the markup or margin %; NULL for a set price.
|
||||
* settings.config_quote_price_method - what a new line is priced by (markup or margin).
|
||||
* settings.config_quote_price_percent - its % to start with.
|
||||
* settings.config_quote_price_presets - the % buttons offered, comma separated.
|
||||
*
|
||||
* Re-runnable: each column is added only where it isn't there yet.
|
||||
*/
|
||||
|
||||
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
||||
|
||||
$itflow_column = function ($table, $column) use ($mysqli) {
|
||||
$result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$table' AND COLUMN_NAME = '$column' LIMIT 1");
|
||||
return $result && mysqli_num_rows($result) > 0;
|
||||
};
|
||||
|
||||
if (!$itflow_column('quote_items', 'item_cost')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `quote_items` ADD `item_cost` decimal(15,2) DEFAULT NULL AFTER `item_price`");
|
||||
}
|
||||
if (!$itflow_column('quote_items', 'item_price_method')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `quote_items` ADD `item_price_method` varchar(10) DEFAULT NULL AFTER `item_cost`");
|
||||
}
|
||||
if (!$itflow_column('quote_items', 'item_price_percent')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `quote_items` ADD `item_price_percent` decimal(7,2) DEFAULT NULL AFTER `item_price_method`");
|
||||
}
|
||||
|
||||
if (!$itflow_column('settings', 'config_quote_price_method')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_quote_price_method` varchar(10) NOT NULL DEFAULT 'markup' AFTER `config_quote_notification_email`");
|
||||
}
|
||||
if (!$itflow_column('settings', 'config_quote_price_percent')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_quote_price_percent` decimal(7,2) NOT NULL DEFAULT 20.00 AFTER `config_quote_price_method`");
|
||||
}
|
||||
if (!$itflow_column('settings', 'config_quote_price_presets')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_quote_price_presets` varchar(100) NOT NULL DEFAULT '15,20,25,35' AFTER `config_quote_price_percent`");
|
||||
}
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
/*
|
||||
* Admin > Settings > Quotes (admin/settings_quote.php):
|
||||
* edit_quote_settings saves the numbering, the footer and who is emailed a
|
||||
* client's answer. A next number already in use, or an email address that
|
||||
* isn't one, comes back to the page saying so - nothing is saved.
|
||||
* edit_quote_settings saves the numbering, the footer, who is emailed a
|
||||
* client's answer and the pricing a line starts with. A next number already
|
||||
* in use, an email address that isn't one, or a % that can't be used, comes
|
||||
* back to the page saying so - nothing is saved.
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
@@ -13,7 +14,8 @@ if (isset($_POST['edit_quote_settings'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$before = settingsCurrent(['config_quote_prefix', 'config_quote_next_number', 'config_quote_footer', 'config_quote_notification_email']);
|
||||
$pricing_columns = quotePricingReady() ? ['config_quote_price_method', 'config_quote_price_percent', 'config_quote_price_presets'] : [];
|
||||
$before = settingsCurrent(array_merge(['config_quote_prefix', 'config_quote_next_number', 'config_quote_footer', 'config_quote_notification_email'], $pricing_columns));
|
||||
|
||||
// What was sent, and what is saved for anything that wasn't
|
||||
$in = $_POST + array_map(function ($value) { return (string) $value; }, $before);
|
||||
@@ -28,6 +30,23 @@ if (isset($_POST['edit_quote_settings'])) {
|
||||
if ($problem = settingsEmailProblem($after['config_quote_notification_email'])) {
|
||||
$errors['config_quote_notification_email'] = $problem;
|
||||
}
|
||||
// How a line's price comes from its cost (functions/quote_pricing.php)
|
||||
if ($pricing_columns) {
|
||||
$method = quotePriceMethod($in['config_quote_price_method']);
|
||||
$percent = quotePricingNumber($in['config_quote_price_percent']);
|
||||
$presets = quotePricePresets($in['config_quote_price_presets']);
|
||||
$after['config_quote_price_method'] = in_array($method, ['markup', 'margin'], true) ? $method : 'markup';
|
||||
$after['config_quote_price_percent'] = $percent === null ? '' : number_format($percent, 2, '.', '');
|
||||
$after['config_quote_price_presets'] = implode(',', array_map('quotePricePercentText', $presets));
|
||||
if ($percent === null || $percent < 0 || $percent >= 1000) {
|
||||
$errors['config_quote_price_percent'] = 'A number from 0 to 999.';
|
||||
} elseif ($after['config_quote_price_method'] === 'margin' && $percent >= 100) {
|
||||
$errors['config_quote_price_percent'] = 'A margin has to be under 100%.';
|
||||
}
|
||||
if (!$presets) {
|
||||
$errors['config_quote_price_presets'] = 'At least one %, such as 15, 20, 25.';
|
||||
}
|
||||
}
|
||||
if ($errors) {
|
||||
settingsRefuse('quote', $errors);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
/*
|
||||
* Admin > Settings > Quotes - how quotes are numbered, the footer under each
|
||||
* one, and who hears when a client accepts or declines one online. Saved by
|
||||
* one, who hears when a client accepts or declines one online, and how a
|
||||
* line's price comes from its cost (functions/quote_pricing.php). Saved by
|
||||
* edit_quote_settings (admin/post/settings_quote.php).
|
||||
*/
|
||||
|
||||
@@ -31,6 +32,18 @@ echo settingsPageStart('quote');
|
||||
'placeholder' => 'sales@company.com', 'help' => 'A shared mailbox or list works best. Empty, nobody is emailed - the quote still shows the answer.']) ?>
|
||||
<?= settingsSectionEnd() ?>
|
||||
|
||||
<?php if (quotePricingReady()) {
|
||||
$pricing = quotePricingSettings(); ?>
|
||||
<?= settingsSectionStart('pricing', 'Pricing', 'A quote line can carry what it costs you, and its price can come from that cost - a markup or a margin. Only agents see the cost, in a line\'s Edit window and the quote\'s Margin - never the PDF, the guest link or the portal.') ?>
|
||||
<?= settingsSelect('config_quote_price_method', $pricing['method'], ['markup' => 'Markup - a % added to the cost', 'margin' => 'Margin - a % of the price'], ['icon' => 'fa-calculator',
|
||||
'help' => 'What a line is priced by when a cost is typed in. Markup 25% on a cost of 80.00 is 100.00; margin 25% on 80.00 is 106.67.']) ?>
|
||||
<?= settingsInput('config_quote_price_percent', quotePricePercentText($pricing['percent']), ['icon' => 'fa-percent', 'inputmode' => 'decimal', 'maxlength' => 8,
|
||||
'help' => 'The % a line starts with.']) ?>
|
||||
<?= settingsInput('config_quote_price_presets', implode(', ', array_map('quotePricePercentText', $pricing['presets'])), ['icon' => 'fa-hand-pointer', 'maxlength' => 100,
|
||||
'placeholder' => '15, 20, 25, 35', 'help' => 'The % buttons in a quote line\'s Edit window, to pick one in a click - up to eight, separated by commas.']) ?>
|
||||
<?= settingsSectionEnd() ?>
|
||||
<?php } ?>
|
||||
|
||||
<?= settingsSaveBar('edit_quote_settings') ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user