diff --git a/CHANGELOG.md b/CHANGELOG.md
index f3dc6da2a..92d9a4861 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,9 +6,9 @@ This file documents all notable changes made to ITFlow.
### Upgrading to 26.11
-Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's database changes (2.7.9 to 2.9.5) in the same pass. Nothing else is required.
+Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's database changes (2.7.9 to 2.9.6) in the same pass. Nothing else is required.
-This is a big release, with sixteen database steps in one go, so take a backup before you update.
+This is a big release, with seventeen database steps in one go, so take a backup before you update.
The update also clears out data that deletes in older versions left behind, all of it pointing at something that no longer exists:
@@ -17,7 +17,7 @@ The update also clears out data that deletes in older versions left behind, all
- the tasks, approvals and history of deleted tickets, the projects of deleted clients, and tickets still pointing at a deleted project
- project template entries whose ticket template is gone, and the same service link saved twice
-It also gives every existing network a type (LAN, WAN, Guest and so on) guessed from its name or description, which you can change afterwards, and fills in the issue date, names covered and fingerprint of every certificate already on file. Invoices made from a quote before the update are linked to that quote, so each one shows where it came from. Products that ever had stock added keep tracking their stock, and the rest are set to ordered as needed (see Breaking Changes, Products). Their past stock changes are sorted into received, sold and returned from their notes, and linked to the invoice they name.
+It also gives every existing network a type (LAN, WAN, Guest and so on) guessed from its name or description, which you can change afterwards, and fills in the issue date, names covered and fingerprint of every certificate already on file. Invoices made from a quote before the update are linked to that quote, so each one shows where it came from. Products that ever had stock added keep tracking their stock, and the rest are set to ordered as needed (see Breaking Changes, Products). Their past stock changes are sorted into received, sold and returned from their notes, and linked to the invoice they name. No product becomes a client asset when it is sold until you give it an asset type (see New Features, Products).
If you are coming from 26.08 or earlier, the database update still has to be run from the command line one time, exactly as described under Upgrading to 26.09 below.
@@ -124,7 +124,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- **Dashboard** (rebuilt)
- Needs attention along the top:
- tickets past their SLA, unassigned tickets and overdue projects
- - overdue and draft invoices, resolved tickets not invoiced yet, and stock to reorder
+ - overdue and draft invoices, resolved tickets not invoiced yet, stock to reorder, and hardware sold in the last 90 days that isn't on the client's assets yet
- domains, certificates, licenses and warranties expiring in the next 30 days
- services needing attention and service reviews due
@@ -263,8 +263,17 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- One Stock window to Receive (at a unit cost, which can become the product's cost, linked to an expense from the last year, the vendor's first), Count (type what is on the shelf and the difference is recorded) or Write off (damaged, lost or stolen, used by us, or sent back to the vendor). It shows what will be on the shelf as you type.
- Reorder at and Order on each product. Products at or under their level show on the To reorder tab, with a badge on the list, on Products in the menu and in Needs attention on the dashboard. A Low Stock notification goes out when stock drops to the level or runs out, saying how many to order and from whom.
- Count Stock lists every tracked product, or one location's, with what ITFlow has and a box for what you counted. The difference shows as you type, Enter moves to the next box, and blank ones are left alone. Print it as a count sheet to take to the shelf.
- - Import takes every field, including Reorder At and Order. Categories, taxes and vendors are matched by name. A new price list can update products by their code, and a file with only Code and Price will do. Download the template for the layout.
- - Export adds cost, margin, how it is billed, vendor, part number, stock and its value, and the reorder level, and can export just what is to reorder.
+ - Hardware becomes client assets:
+ - Give a product the asset it becomes - a laptop, a switch, an access point and so on - with its make, model and warranty in months.
+ - An invoice with hardware on it has a Hardware card: each line, how many of it are on the client's assets, and which ones with their serial numbers.
+ - Add to Assets has a row for each one still to add, named from the model, for its serial number and who has it. Enter after a serial, or a barcode scan, moves to the next one. The make, model and warranty (counted from the invoice date) come from the product and can be changed, and the status and location are set for all of them. A row can be linked to an asset the client already has instead, or taken out and left for later.
+ - Each asset made this way is bought on the invoice date with the invoice number as its order reference, and its page links to the invoice and the product.
+ - The product's page shows the asset it becomes and how many are in use, with an Assets tab listing each one with its client, serial number, warranty and invoice.
+ - Products has a Hardware tab, and each row says the asset it becomes.
+ - The packing slip lists the serial numbers under each line.
+ - The starter catalog's hardware comes with its asset type and warranty, and so does the demo data's.
+ - Import takes every field, including Reorder At, Order, Asset Type, Make, Model and Warranty. Categories, taxes and vendors are matched by name. A new price list can update products by their code, and a file with only Code and Price will do. Download the template for the layout.
+ - Export adds cost, margin, how it is billed, vendor, part number, stock and its value, the reorder level, and the asset it becomes with its make, model and warranty. It can export just what is to reorder, or just hardware.
- Invoices, quotes and recurring invoices show agents their margin on lines from products with a cost, at today's cost. A quote shows it up front and each month.
- Our vendors' pages have a Products tab listing what we buy from them.
- Search finds products by part number and opens their page.
@@ -511,6 +520,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- 2.9.3: `quote_items.item_frequency` (NULL for one time, or `month`, `quarter` or `year`), `quotes.quote_monthly_amount`, `invoices.invoice_quote_id` and `recurring_invoices.recurring_invoice_quote_id`. Invoices are linked to their quote from the "Invoice created from quote QUO-n" history the old Make Invoice wrote, matched on the client too.
- 2.9.4: `products.product_cost`, `product_vendor_id`, `product_vendor_part`, `product_notes`, `product_frequency` (NULL once, or `month`, `quarter`, `year`), `product_seat_source` (NULL, `contacts` or `assets`) and `product_track_stock`, set for products with any `product_stock` rows. Keys on `item_product_id` in `invoice_items`, `quote_items` and `recurring_invoice_items`, and on `product_stock.stock_product_id`.
- 2.9.5: `product_stock.stock_qty` becomes `decimal(15,2)`, with `stock_type` (`received`, `sold`, `returned`, `adjusted` or `written_off`, default `adjusted`), `stock_unit_cost`, `stock_invoice_id` (keyed) and `stock_user_id`. Existing rows take their invoice from a note ending "Invoice n" and their type from the sign and the note. `products.product_reorder_level` and `product_reorder_qty`.
+ - 2.9.6: `products.product_asset_type` (one of the asset types, NULL for none), `product_make`, `product_model` and `product_warranty_months`. `assets.asset_product_id`, `asset_invoice_id` and `asset_invoice_item_id`, keyed on the product and the invoice.
- New shared function files, loaded by `functions.php`: `functions/asset.php`, `asset_interface.php`, `certificate.php`, `client_overview.php`, `contact.php`, `credential.php`, `dashboard.php`, `links.php`, `location.php`, `notifications.php`, `project.php`, `rack.php`, `search.php`, `service.php`, `software.php`, `tags.php`, `ticket.php`, `ticket_fields.php`, `user.php` and `vendor.php`. They hold the queries and rules, so the pages, the API and cron share one definition.
- Removed post models: `agent/post/{asset_interface,certificate,credential,domain,event,location,network_ip,network,recurring_ticket,vendor}_model.php`, `admin/post/user_model.php` and `api/v1/certificates/certificate_model.php`. Their handlers call the shared functions above. Interface handlers moved to `agent/post/asset_interface.php`.
- New scripts: `js/itflow_select.js`, `quick_pick.js`, `tag_picker.js`, `global_search.js`, `notifications.js`, `dashboard.js`, `client_overview.js`, `client_switcher.js`, `credentials.js` and `autosubmit.js`, and `agent/js/calendar.js`, `calendar_event_modal.js`, `files.js`, `interface_form.js`, `network_form.js`, `project_modal.js` and `ticket_schedule_modal.js`.
@@ -631,6 +641,9 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- Handlers: `product_stock_save` (POST `product_id`, `mode` and `note`, with `qty`, `unit_cost`, `update_cost` and `expense` to receive, `counted` to count, or `qty` and `reason` to write off) from `agent/modals/product/product_stock.php?id=&mode=`, and `product_stock_count` (POST `counted[product_id]` and `note`) from the new page `agent/products_count.php`. Removed: `agent/modals/product/product_stock_add.php` and `add_product_stock`.
- `productSave()` and `productCopy()` take `reorder_level` and `reorder_qty`, with import aliases and export columns for them and the stock value. The products list and export take `type=reorder`.
- `$num_products_reorder` in `agent/includes/get_side_nav_counts.php`, `Stock to reorder` in `dashboardAttention()`, and `inventory` in `reportCatalog()` (Sales & Billing, `module_sales`, accounting) for `agent/reports/inventory.php`.
+ - Sold hardware, in `functions/products.php`: `productAssetTypes()` (the `$asset_types_array` list), `productAssetType()`, `productAssetIcon()`, `productHardwareSql()`, `productHardwareUnits()` (a line's quantity rounded up, none for a credit), `productWarrantyUntil()`, `productHardwareInvoiceSql()` (not drafts or cancelled, not made by a recurring invoice), `productHardwareShortSql()`, `productHardwarePending($days)`, `productInvoiceHardware($invoice_id)`, `productAssets($product_id)` and `productAssetCandidates()`. `productSaleAssets($invoice_id, $lines, $units, $shared, &$error)` checks every row first, then adds or links them in one transaction, each new one with its primary interface, and each with a history line and an audit log entry.
+ - Handler `invoice_assets_save` (POST `invoice_id`, `status`, `location`, `lines[item_id][make|model|warranty]` and `units[item_id][n][name|serial|contact|existing]`; needs Sales, and Support at edit) from `agent/modals/invoice/invoice_assets.php?invoice_id=`. `billingItemDelete()` clears `asset_invoice_item_id` on the line's assets and `delete_invoice` clears both invoice links - the assets stay.
+ - `productSave()` and `productCopy()` take `asset_type`, `make`, `model` and `warranty_months`, with import aliases and export columns for them. The products list and export take `type=hardware`, and `invoices.php` takes `hardware=1`. `dashboardAttention()` adds Hardware not on assets for agents with Support access, `billingPdfRender()` reads the serials for the packing slip, and the asset page joins the invoice and the product. Seeds: columns 12 to 15 on `demoDataProducts()` and an eighth and ninth on `starterContentProducts()`. CSS: `.itflow-hw-*`.
- The billing helpers (`billingTimeInvoice()`, `quoteConvert()`, `recurringInvoiceGenerate()` and the rest) take the agent's name as plain text. Their handlers now pass `stripslashes($session_name)`, so a name with an apostrophe no longer shows a backslash in history and the audit log.
- Sidebar brand: `agent/css/sidebar_brand_fix.css` and `agent/js/sidebar_brand_fix.js` from 26.10 are replaced by CSS in `css/itflow_custom.css`. `includes/load_company_settings.php` now sets `$session_company_logo`.
- `alertMessageHtml()` no longer double-encodes, and save messages built from `escapeSql()` values use `stripslashes()` at the flash.
diff --git a/admin/database_updates/2.9.6.php b/admin/database_updates/2.9.6.php
new file mode 100644
index 000000000..d265eeae1
--- /dev/null
+++ b/admin/database_updates/2.9.6.php
@@ -0,0 +1,27 @@
+ $product[5],
'product_currency_code' => $session_company_currency ?? '',
'product_tax_id' => 0,
- ] + ($frequency !== '' ? ['product_frequency' => $frequency] : []) + ($seat !== '' ? ['product_seat_source' => $seat] : []));
+ ] + ($frequency !== '' ? ['product_frequency' => $frequency] : []) + ($seat !== '' ? ['product_seat_source' => $seat] : [])
+ + (!empty($product[7]) ? ['product_asset_type' => $product[7], 'product_warranty_months' => intval($product[8] ?? 0)] : []));
}
return $added;
@@ -1146,7 +1147,8 @@ function starterContentDocumentTemplates() {
// ------------------------------
// starterContentProducts
// name, type, code, price, income category, description, billed (a frequency,
-// or frequency:contacts per user / frequency:assets per device, empty once).
+// or frequency:contacts per user / frequency:assets per device, empty once),
+// and for hardware the client asset it becomes and its warranty in months.
// Hardware and resold SKUs come in at zero - they are quoted per deal or move
// with the vendor price list.
// ------------------------------
@@ -1224,25 +1226,25 @@ function starterContentProducts() {
['Equipment Disposal', 'service', 'PRJ-DISP', '25.00', 'Projects', 'Per device. Secure data destruction and certified recycling.', ''],
// Hardware - quoted per deal, seeded at zero
- ['Desktop', 'product', 'HW-DSK', '0.00', 'Hardware Sales', 'Business class desktop. Priced per quote.', ''],
- ['Laptop', 'product', 'HW-LAP', '0.00', 'Hardware Sales', 'Business class laptop. Priced per quote.', ''],
+ ['Desktop', 'product', 'HW-DSK', '0.00', 'Hardware Sales', 'Business class desktop. Priced per quote.', '', 'Desktop', 36],
+ ['Laptop', 'product', 'HW-LAP', '0.00', 'Hardware Sales', 'Business class laptop. Priced per quote.', '', 'Laptop', 36],
['Docking Station', 'product', 'HW-DOCK', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
- ['Monitor', 'product', 'HW-MON', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
- ['Server', 'product', 'HW-SRV', '0.00', 'Hardware Sales', 'Rack or tower server. Priced per quote.', ''],
- ['Network Attached Storage', 'product', 'HW-NAS', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
- ['Firewall Appliance', 'product', 'HW-FW', '0.00', 'Hardware Sales', 'Priced per quote, excludes subscription.', ''],
- ['Switch - 24 Port', 'product', 'HW-SW24', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
- ['Switch - 48 Port', 'product', 'HW-SW48', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
- ['Wireless Access Point', 'product', 'HW-AP', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
- ['Uninterruptible Power Supply', 'product', 'HW-UPS', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
+ ['Monitor', 'product', 'HW-MON', '0.00', 'Hardware Sales', 'Priced per quote.', '', 'Display', 36],
+ ['Server', 'product', 'HW-SRV', '0.00', 'Hardware Sales', 'Rack or tower server. Priced per quote.', '', 'Server', 36],
+ ['Network Attached Storage', 'product', 'HW-NAS', '0.00', 'Hardware Sales', 'Priced per quote.', '', 'Server', 36],
+ ['Firewall Appliance', 'product', 'HW-FW', '0.00', 'Hardware Sales', 'Priced per quote, excludes subscription.', '', 'Firewall/Router', 12],
+ ['Switch - 24 Port', 'product', 'HW-SW24', '0.00', 'Hardware Sales', 'Priced per quote.', '', 'Switch', 12],
+ ['Switch - 48 Port', 'product', 'HW-SW48', '0.00', 'Hardware Sales', 'Priced per quote.', '', 'Switch', 12],
+ ['Wireless Access Point', 'product', 'HW-AP', '0.00', 'Hardware Sales', 'Priced per quote.', '', 'Access Point', 12],
+ ['Uninterruptible Power Supply', 'product', 'HW-UPS', '0.00', 'Hardware Sales', 'Priced per quote.', '', 'Other', 24],
['Solid State Drive', 'product', 'HW-SSD', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
['Memory Upgrade', 'product', 'HW-RAM', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
['Keyboard and Mouse', 'product', 'HW-KBM', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
['Headset', 'product', 'HW-HS', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
['Webcam', 'product', 'HW-CAM', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
- ['Printer', 'product', 'HW-PRT', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
+ ['Printer', 'product', 'HW-PRT', '0.00', 'Hardware Sales', 'Priced per quote.', '', 'Printer', 12],
['Toner Cartridge', 'product', 'HW-TON', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
- ['VoIP Handset', 'product', 'HW-PHONE', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
+ ['VoIP Handset', 'product', 'HW-PHONE', '0.00', 'Hardware Sales', 'Priced per quote.', '', 'Phone', 12],
['Patch Cable', 'product', 'HW-CBL', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
['Rack Cabinet', 'product', 'HW-RACK', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
['Power Distribution Unit', 'product', 'HW-PDU', '0.00', 'Hardware Sales', 'Priced per quote.', ''],
diff --git a/agent/asset.php b/agent/asset.php
index 94331899d..e35225a14 100644
--- a/agent/asset.php
+++ b/agent/asset.php
@@ -37,13 +37,16 @@ $sql = mysqli_query($mysqli, "SELECT asset_archived_at, asset_client_id, asset_c
contact_archived_at, contact_email, contact_extension, contact_mobile,
contact_mobile_country_code, contact_name, contact_phone, contact_phone_country_code, contact_photo,
interface_ip, interface_ipv6, interface_mac, interface_nat_ip, interface_network_id,
- location_archived_at, location_name, network_name, network_type, network_description, vendor_name FROM assets
+ location_archived_at, location_name, network_name, network_type, network_description, vendor_name,
+ asset_product_id, asset_invoice_id, invoice_prefix, invoice_number, invoice_date, product_name FROM assets
LEFT JOIN clients ON client_id = asset_client_id
LEFT JOIN contacts ON asset_contact_id = contact_id
LEFT JOIN locations ON asset_location_id = location_id
LEFT JOIN vendors ON asset_vendor_id = vendor_id
LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1
LEFT JOIN networks ON network_id = interface_network_id
+ LEFT JOIN invoices ON invoice_id = asset_invoice_id AND asset_invoice_id > 0
+ LEFT JOIN products ON product_id = asset_product_id AND asset_product_id > 0
WHERE asset_id = $asset_id
" . clientScopeSql('asset_client_id') . "
$client_query
@@ -85,6 +88,13 @@ if (mysqli_num_rows($sql) == 0) {
$asset_vendor_id = intval($row['asset_vendor_id']);
$asset_contact_id = intval($row['asset_contact_id']);
$asset_tone = assetTypeTone($row['asset_type']);
+ // Sold to the client on one of our invoices, from a catalog product
+ $can_sales = lookupUserPermission('module_sales') >= 1;
+ $asset_invoice_id = intval($row['asset_invoice_id']);
+ $asset_sold_number = $row['invoice_number'] !== null ? escapeHtml($row['invoice_prefix'] . $row['invoice_number']) : '';
+ $asset_sold_date = escapeHtml((string) $row['invoice_date']);
+ $asset_product_id = intval($row['asset_product_id']);
+ $asset_product_name = escapeHtml((string) $row['product_name']);
$device_icon = getAssetIcon($row['asset_type']);
$asset_ip = escapeHtml($row['interface_ip']);
@@ -434,7 +444,17 @@ if (mysqli_num_rows($sql) == 0) {
diff --git a/agent/invoice.php b/agent/invoice.php
index 41ff80952..0959153cc 100644
--- a/agent/invoice.php
+++ b/agent/invoice.php
@@ -8,6 +8,7 @@
* take a payment on one that is owed. The invoice itself is on the left,
* as the client sees it, with its lines edited in place while it is open.
* On the right: what has been paid and what is left, the payments, the
+ * hardware sold on it and whether it is on the client's assets yet, the
* tickets billed on it and its history.
*/
@@ -59,6 +60,12 @@ $mail_ready = !empty($config_smtp_provider) && billingEmailableContacts('invoice
$saved_card = $can_take_payment && in_array($status, ['Sent', 'Viewed'], true) && invoiceHasSavedCard($client_id);
$unbilled_tickets = $can_edit && $can_edit_lines && $config_module_enable_ticketing ? count(billingUnbilledTickets($client_id)) : 0;
$guest_url = billingGuestUrl('invoice', $invoice);
+// Hardware sold on it, and how much of it is on the client's assets (functions/products.php)
+$can_see_assets = lookupUserPermission('module_support') >= 1;
+$hardware = $can_see_assets ? productInvoiceHardware($invoice_id) : [];
+$hardware_units = array_sum(array_column($hardware, 'units'));
+$hardware_to_add = $status === 'Cancelled' ? 0 : array_sum(array_column($hardware, 'to_add'));
+$can_add_assets = $hardware_to_add > 0 && lookupUserPermission('module_support') >= 2;
$csrf = $_SESSION['csrf_token'];
// Made by a recurring invoice?
@@ -331,6 +338,60 @@ $paper = [
+
+
When it is sold, the invoice offers to add each one to the client's assets with its serial number, this make and model, and the warranty counted from the invoice date.
+
Pick an asset type for hardware the client keeps - a laptop, a switch, a firewall - and selling it offers to add it to their assets.
+
+
@@ -246,6 +292,7 @@ if ($form_vendor_id && !isset($form_vendors[$form_vendor_id]) && $form_value('ve
var frequency = form.querySelector('[data-product-frequency]');
var counted = form.querySelector('[data-product-counted]');
var track = form.querySelector('[data-product-track]');
+ var assetType = form.querySelector('[data-product-asset-type]');
function number(value) {
var text = String(value || '').replace(/[\s,$€£]/g, '');
@@ -269,6 +316,11 @@ if ($form_vendor_id && !isset($form_vendors[$form_vendor_id]) && $form_value('ve
});
form.querySelector('[data-product-track-on]').hidden = !track.checked;
form.querySelector('[data-product-track-off]').hidden = track.checked;
+ form.querySelectorAll('[data-product-asset]').forEach(function (el) {
+ el.hidden = assetType.value === '';
+ });
+ form.querySelector('[data-product-asset-on]').hidden = assetType.value === '';
+ form.querySelector('[data-product-asset-off]').hidden = assetType.value !== '';
}
counted.hidden = frequency.value === '';
diff --git a/agent/modals/product/product_import.php b/agent/modals/product/product_import.php
index a2df5a648..a2916404e 100644
--- a/agent/modals/product/product_import.php
+++ b/agent/modals/product/product_import.php
@@ -21,7 +21,8 @@ ob_start();
A CSV with a heading row. Columns can be in any order, and only Name is needed:
Name, Type (Service or Product), Code, Category, Description, Price, Cost, Tax, Billed (One time, Monthly, Quarterly, Yearly),
- Counted (Per user, Per device), Vendor, Part Number, Track Stock (Yes or No), Reorder At, Order, Location, Notes.
+ Counted (Per user, Per device), Vendor, Part Number, Track Stock (Yes or No), Reorder At, Order, Location,
+ Asset Type (Laptop, Switch, Access Point and so on), Make, Model, Warranty (in months), Notes.
Categories, taxes and vendors are matched by name to the ones you have.
diff --git a/agent/post/invoice.php b/agent/post/invoice.php
index 5a272603a..755b07015 100644
--- a/agent/post/invoice.php
+++ b/agent/post/invoice.php
@@ -305,6 +305,9 @@ if (isset($_GET['delete_invoice'])) {
//unlink tickets from invoice
mysqli_query($mysqli,"UPDATE tickets SET ticket_invoice_id = 0 WHERE ticket_invoice_id = $invoice_id");
+ // Assets made from its hardware stay on the client's assets, unlinked
+ mysqli_query($mysqli, "UPDATE assets SET asset_invoice_id = 0, asset_invoice_item_id = 0 WHERE asset_invoice_id = $invoice_id");
+
logAudit("Invoice", "Delete", "$session_name deleted invoice $invoice_prefix$invoice_number", $client_id);
flashAlert("Invoice $invoice_prefix$invoice_number deleted", 'error');
@@ -895,6 +898,46 @@ if (isset($_GET['remove_ticket_from_invoice'])) {
}
+if (isset($_POST['invoice_assets_save'])) {
+
+ validateCSRFToken();
+
+ enforceUserPermission('module_sales');
+ enforceUserPermission('module_support', 2);
+
+ $invoice = billingRow('invoice', intval($_POST['invoice_id'] ?? 0));
+ if (!$invoice) {
+ flashAlert('That invoice no longer exists.', 'error');
+ redirect('invoices.php');
+ }
+ $invoice_id = intval($invoice['invoice_id']);
+ $client_id = intval($invoice['client_id']);
+
+ enforceClientAccess();
+
+ // functions/products.php - checks every row before it adds or links any
+ $done = productSaleAssets($invoice_id, (array) ($_POST['lines'] ?? []), (array) ($_POST['units'] ?? []), [
+ 'status' => (string) ($_POST['status'] ?? ''),
+ 'location' => intval($_POST['location'] ?? 0),
+ ], $error);
+ if ($done === null) {
+ flashAlert(escapeHtml($error), 'error');
+ redirect();
+ }
+
+ $parts = [];
+ if ($done['added']) {
+ $parts[] = "{$done['added']} added";
+ }
+ if ($done['linked']) {
+ $parts[] = "{$done['linked']} linked";
+ }
+ flashAlert(escapeHtml(billingNumber('invoice', $invoice)) . " hardware on " . escapeHtml($invoice['client_name']) . "'s assets - " . implode(', ', $parts));
+
+ redirect();
+
+}
+
if (isset($_GET['export_invoice_pdf'])) {
validateCSRFToken();
diff --git a/agent/post/product.php b/agent/post/product.php
index 9e342227b..dbb26f856 100644
--- a/agent/post/product.php
+++ b/agent/post/product.php
@@ -12,7 +12,8 @@ defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
/** The product fields from a posted form, raw. */
function productFormInput() {
$in = [];
- foreach (['name', 'type', 'category', 'price', 'cost', 'tax', 'frequency', 'seat_source', 'code', 'vendor', 'vendor_part', 'reorder_level', 'reorder_qty', 'location', 'description', 'notes'] as $key) {
+ foreach (['name', 'type', 'category', 'price', 'cost', 'tax', 'frequency', 'seat_source', 'code', 'vendor', 'vendor_part', 'reorder_level', 'reorder_qty', 'location',
+ 'asset_type', 'make', 'model', 'warranty_months', 'description', 'notes'] as $key) {
if (array_key_exists($key, $_POST)) {
$in[$key] = (string) $_POST[$key];
}
@@ -317,6 +318,7 @@ if (isExportRequest('export_products')) {
'recurring' => ["AND product_frequency IS NOT NULL", 'Billed each month, quarter or year'],
'stocked' => ["AND product_track_stock = 1", 'Stock tracked'],
'reorder' => ["AND " . productReorderSql(), 'To reorder'],
+ 'hardware' => ["AND " . productHardwareSql(), 'Become client assets'],
];
$type_query = '';
if (isset($type_queries[$type_filter])) {
@@ -383,6 +385,7 @@ if (isExportRequest('export_products')) {
$row['product_reorder_display'] = intval($row['product_track_stock']) && floatval($row['product_reorder_level']) > 0 ? billingQuantity($row['product_reorder_level']) : '';
$row['product_order_display'] = intval($row['product_track_stock']) && floatval($row['product_reorder_qty']) > 0 ? billingQuantity($row['product_reorder_qty']) : '';
$row['product_stock_value'] = intval($row['product_track_stock']) && floatval($row['product_stock']) > 0 ? round(floatval($row['product_stock']) * floatval($row['product_cost']), 2) : '';
+ $row['product_warranty_display'] = intval($row['product_warranty_months']) > 0 ? intval($row['product_warranty_months']) : '';
addExportRow($export, $row);
}
@@ -592,6 +595,10 @@ if (isset($_POST["import_products_csv"])) {
'reorder_level' => ['reorder at', 'reorder level', 'reorder point', 'minimum stock'],
'reorder_qty' => ['order', 'order qty', 'reorder qty', 'reorder quantity'],
'location' => ['location'],
+ 'asset_type' => ['asset type', 'asset', 'client asset'],
+ 'make' => ['make', 'manufacturer', 'brand'],
+ 'model' => ['model'],
+ 'warranty_months' => ['warranty', 'warranty months', 'warranty (months)'],
'notes' => ['notes', 'internal notes'],
];
$columns = [];
@@ -708,9 +715,9 @@ if (isset($_POST["import_products_csv"])) {
if (isset($_GET['download_products_csv_template'])) {
$f = fopen('php://memory', 'w');
- fputcsv($f, ['Name', 'Type', 'Code', 'Category', 'Description', 'Price', 'Cost', 'Tax', 'Billed', 'Counted', 'Vendor', 'Part Number', 'Track Stock', 'Reorder At', 'Order', 'Location', 'Notes'], ',', '"', '\\');
- fputcsv($f, ['Managed Workstation', 'Service', 'MS-WKS', 'Managed Services', 'Per workstation, per month. Monitoring, patching and support.', '65.00', '18.00', '', 'Monthly', 'Per device', '', '', '', '', '', '', ''], ',', '"', '\\');
- fputcsv($f, ['24 Port PoE Switch', 'Product', 'HW-SW24', 'Hardware Sales', '24 port managed PoE switch.', '785.00', '520.00', '', 'One time', '', '', 'USW-PRO-24-POE', 'Yes', '2', '5', 'Shelf B2', 'Order from the distributor, 2 day lead time'], ',', '"', '\\');
+ fputcsv($f, ['Name', 'Type', 'Code', 'Category', 'Description', 'Price', 'Cost', 'Tax', 'Billed', 'Counted', 'Vendor', 'Part Number', 'Track Stock', 'Reorder At', 'Order', 'Location', 'Asset Type', 'Make', 'Model', 'Warranty', 'Notes'], ',', '"', '\\');
+ fputcsv($f, ['Managed Workstation', 'Service', 'MS-WKS', 'Managed Services', 'Per workstation, per month. Monitoring, patching and support.', '65.00', '18.00', '', 'Monthly', 'Per device', '', '', '', '', '', '', '', '', '', '', ''], ',', '"', '\\');
+ fputcsv($f, ['24 Port PoE Switch', 'Product', 'HW-SW24', 'Hardware Sales', '24 port managed PoE switch.', '785.00', '520.00', '', 'One time', '', '', 'USW-PRO-24-POE', 'Yes', '2', '5', 'Shelf B2', 'Switch', 'Ubiquiti', 'USW-Pro-24-PoE', '12', 'Order from the distributor, 2 day lead time'], ',', '"', '\\');
fseek($f, 0);
header('Content-Type: text/csv');
diff --git a/agent/product.php b/agent/product.php
index d2ad7ad86..05e7ebf89 100644
--- a/agent/product.php
+++ b/agent/product.php
@@ -6,11 +6,13 @@
* What it sells for and costs us, so its margin; how it is billed by default;
* who we buy it from and their part number; for a product, its stock - on the
* shelf, where, what that is worth and when to reorder - or that it is
- * ordered as needed. Internal notes save as you click away.
+ * ordered as needed, and for hardware the client asset it becomes. Internal
+ * notes save as you click away.
*
* Then in tabs with counts: its stock moves with what was on the shelf after
* each, the recurring invoices it is on (what that brings in a month), open
- * quotes, the invoices it was sold on, and its history. Figures are for the clients the agent can see.
+ * quotes, the invoices it was sold on, the client assets made from it, and
+ * its history. Figures are for the clients the agent can see.
*/
require_once "includes/inc_all.php";
@@ -46,6 +48,13 @@ if (!$product) {
$can_delete = lookupUserPermission('module_sales') >= 3 && !empty($config_destructive_deletes_enable);
$csrf = $_SESSION['csrf_token'];
+ // Hardware - the client asset it becomes when sold, and the ones it became
+ $asset_type = $type === 'product' ? (string) $product['product_asset_type'] : '';
+ $warranty_months = intval($product['product_warranty_months']);
+ $can_see_assets = lookupUserPermission('module_support') >= 1;
+ $assets = $can_see_assets ? productAssets($product_id, 200) : [];
+ $asset_clients = count(array_unique(array_column($assets, 'client_id')));
+
$usage = productUsage($product_id);
$moves = $type === 'product' ? productStockMoves($product_id, 200) : [];
$history = productHistory($product_id, 100);
@@ -61,6 +70,17 @@ if (!$product) {
if (!$product['product_frequency']) {
$tabs = ['invoices' => $tabs['invoices'], 'quotes' => $tabs['quotes'], 'recurring' => $tabs['recurring'], 'history' => $tabs['history']];
}
+ // The client assets made from it, after the invoices it was sold on
+ if ($can_see_assets && ($asset_type !== '' || $assets)) {
+ $with_assets = [];
+ foreach ($tabs as $tab_key => $tab) {
+ $with_assets[$tab_key] = $tab;
+ if ($tab_key === 'invoices') {
+ $with_assets['assets'] = ['label' => 'Assets', 'icon' => 'fa-laptop', 'count' => count($assets)];
+ }
+ }
+ $tabs = $with_assets;
+ }
// Its stock moves - first for a product that tracks stock
if ($tracked || $moves) {
$stock_tab = ['stock' => ['label' => 'Stock', 'icon' => 'fa-warehouse', 'count' => count($moves)]];
@@ -291,6 +311,33 @@ if (!$product) {
+ Sold as goods - it doesn't go on the client's assets.
+ Pick an asset type in Edit for hardware the client keeps, and selling it offers to add it to their assets.
+