Files
PowderCoatingLogix/src/PowderCoating.Web/Views/Expenses/Create.cshtml
T
spouliot 4ec55e7290 Restore all zeroed views + add bulk gift certificate creation
The HTML entity sweep script had a bug where it wrote empty files for any
view that contained no target Unicode characters, zeroing out 215 view files.
All views restored from the pre-sweep commit (cefdf3e).

Bulk gift certificate feature:
- BulkCreateGiftCertificateDto with Quantity (1-500), Amount, Reason, Expiry, Notes
- GenerateBulkGiftCertificatePdfAsync on IPdfService / PdfService: one Letter page
  per cert, reusing the same purple/gold branded ComposeGiftCertificateContent helper
- GiftCertificatesController: BulkCreate GET/POST, BulkResult GET, BulkDownloadPdf POST
- Views: BulkCreate.cshtml (form with live total preview), BulkResult.cshtml (table +
  Download All PDF button that POSTs cert IDs to avoid URL length limits)
- gift-certificate-bulk.js: live preview + spinner/disable on submit
- Index.cshtml: Bulk Create button added alongside New Certificate

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 20:09:22 -04:00

204 lines
13 KiB
Plaintext

@model PowderCoating.Application.DTOs.Accounting.CreateExpenseDto
@{
ViewData["Title"] = "New Expense";
ViewData["PageIcon"] = "bi-receipt";
ViewData["PageHelpTitle"] = "New Expense";
ViewData["PageHelpContent"] = "Use this for purchases paid immediately — credit card swipes, cash payments, debit transactions. For vendor invoices paid later, use Bills instead. Select the expense account (what was bought) and the payment account (where the money came from).";
}
<div class="d-flex justify-content-start mb-4">
<a asp-action="Index" class="btn btn-sm btn-outline-secondary"><i class="bi bi-arrow-left"></i></a>
</div>
<div class="row justify-content-center">
<div class="col-lg-7">
<div class="card shadow-sm">
<div class="card-body">
<form asp-action="Create" method="post" enctype="multipart/form-data">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="alert alert-danger alert-permanent mb-3"></div>
<div class="row g-3">
<div class="col-sm-6">
<label asp-for="Date" class="form-label fw-medium">Date <span class="text-danger">*</span></label>
<input asp-for="Date" type="date" class="form-control" />
<span asp-validation-for="Date" class="text-danger small"></span>
</div>
<div class="col-sm-6">
<label asp-for="Amount" class="form-label fw-medium">Amount <span class="text-danger">*</span></label>
<div class="input-group">
<span class="input-group-text">$</span>
<input asp-for="Amount" type="number" step="0.01" min="0.01" class="form-control" />
</div>
<span asp-validation-for="Amount" class="text-danger small"></span>
</div>
<div class="col-12">
<div class="d-flex align-items-center gap-1 mb-1">
<label asp-for="ExpenseAccountId" class="form-label fw-medium mb-0">Expense Account <span class="text-danger">*</span></label>
<a tabindex="0" class="help-icon" role="button"
data-bs-toggle="popover" data-bs-placement="right" data-bs-trigger="focus"
data-bs-title="Expense Account"
data-bs-content="The expense category this purchase belongs to — e.g. Supplies, Materials, Utilities, Fuel. This account is debited when the expense is saved. Choose the most specific account that fits to keep your reports accurate.">
<i class="bi bi-question-circle"></i>
</a>
</div>
<div class="d-flex gap-2 align-items-center">
<select asp-for="ExpenseAccountId" asp-items="ViewBag.ExpenseAccounts" class="form-select" id="expenseAccountSelect">
<option value="">— Select Account —</option>
</select>
<button type="button" class="btn btn-sm btn-outline-primary text-nowrap" id="expAiSuggestBtn" title="AI-suggest expense account">
<i class="bi bi-stars me-1"></i>AI Suggest
</button>
</div>
<span asp-validation-for="ExpenseAccountId" class="text-danger small"></span>
<div id="expAiSuggestionBadge" class="mt-2 d-none">
<span class="badge bg-info text-dark me-2" id="expAiSuggestionText"></span>
<button type="button" class="btn btn-xs btn-success btn-sm py-0 px-2" id="expAiSuggestionUseBtn">Use This</button>
<button type="button" class="btn btn-xs btn-outline-secondary btn-sm py-0 px-2 ms-1" onclick="document.getElementById('expAiSuggestionBadge').classList.add('d-none')">Dismiss</button>
</div>
</div>
<div class="col-sm-6">
<div class="d-flex align-items-center gap-1 mb-1">
<label asp-for="PaymentAccountId" class="form-label fw-medium mb-0">Paid From <span class="text-danger">*</span></label>
<a tabindex="0" class="help-icon" role="button"
data-bs-toggle="popover" data-bs-placement="right" data-bs-trigger="focus"
data-bs-title="Paid From"
data-bs-content="The bank or cash account the money came out of — e.g. Business Checking, Petty Cash, Company Credit Card. This account is credited when the expense is saved. Used for bank reconciliation.">
<i class="bi bi-question-circle"></i>
</a>
</div>
<select asp-for="PaymentAccountId" asp-items="ViewBag.PaymentAccounts" class="form-select">
<option value="">— Select Account —</option>
</select>
<span asp-validation-for="PaymentAccountId" class="text-danger small"></span>
</div>
<div class="col-sm-6">
<label asp-for="PaymentMethod" class="form-label fw-medium">Payment Method <span class="text-danger">*</span></label>
<select asp-for="PaymentMethod" asp-items="ViewBag.PaymentMethods" class="form-select"></select>
</div>
<div class="col-sm-6">
<label asp-for="VendorId" class="form-label fw-medium">Vendor <span class="text-muted small">(optional)</span></label>
<select asp-for="VendorId" asp-items="ViewBag.Vendors" class="form-select"
data-quick-add-url="/Vendors/Create" data-quick-add-title="Add New Vendor">
<option value="">— None —</option>
<option value="__new__">+ Add New Vendor…</option>
</select>
</div>
<div class="col-sm-6">
<div class="d-flex align-items-center gap-1 mb-1">
<label asp-for="JobId" class="form-label fw-medium mb-0">Job <span class="text-muted small">(optional)</span></label>
<a tabindex="0" class="help-icon" role="button"
data-bs-toggle="popover" data-bs-placement="right" data-bs-trigger="focus"
data-bs-title="Linked Job"
data-bs-content="Attach this expense to a specific job to track its true cost. Job-linked expenses roll up in job profitability reports, helping you see whether a job was profitable after all direct costs.">
<i class="bi bi-question-circle"></i>
</a>
</div>
<select asp-for="JobId" asp-items="ViewBag.Jobs" class="form-select">
<option value="">— None —</option>
</select>
</div>
<div class="col-12">
<label asp-for="Memo" class="form-label fw-medium">Memo</label>
<textarea asp-for="Memo" class="form-control" rows="2" placeholder="What was this for?"></textarea>
</div>
<div class="col-12">
<div class="d-flex align-items-center gap-1 mb-1">
<label for="receiptFile" class="form-label fw-medium mb-0">Receipt <span class="text-muted small">(optional)</span></label>
<a tabindex="0" class="help-icon" role="button"
data-bs-toggle="popover" data-bs-placement="right" data-bs-trigger="focus"
data-bs-title="Receipt"
data-bs-content="Attach a photo or PDF of the receipt for audit purposes and expense reimbursement. Supports JPG, PNG, and PDF up to 10 MB. The image is stored securely and viewable from the expense detail page.">
<i class="bi bi-question-circle"></i>
</a>
</div>
<input type="file" name="receiptFile" id="receiptFile" class="form-control"
accept=".jpg,.jpeg,.png,.gif,.webp,.pdf" />
<div class="form-text">Image or PDF, up to 10 MB.</div>
<div id="receiptPreview" class="mt-2 d-none">
<img id="previewImg" src="" alt="Receipt preview" class="img-thumbnail" style="max-height:200px;" />
</div>
</div>
</div>
<div class="d-flex gap-2 mt-4">
<button type="submit" class="btn btn-primary">
<i class="bi bi-check-lg me-1"></i>Save Expense
</button>
<a asp-action="Index" class="btn btn-outline-secondary">Cancel</a>
</div>
</form>
</div>
</div>
</div>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<script>
document.getElementById('receiptFile').addEventListener('change', function () {
const file = this.files[0];
const preview = document.getElementById('receiptPreview');
const img = document.getElementById('previewImg');
if (file && file.type.startsWith('image/')) {
img.src = URL.createObjectURL(file);
preview.classList.remove('d-none');
} else {
preview.classList.add('d-none');
}
});
// ── AI Suggest Account ────────────────────────────────────────────────
let _expAiSuggestedAccountId = null;
document.getElementById('expAiSuggestBtn').addEventListener('click', async function () {
const vendorSel = document.getElementById('VendorId');
const vendorText = vendorSel ? (vendorSel.options[vendorSel.selectedIndex]?.text ?? '') : '';
const memoEl = document.querySelector('[name="Memo"]');
const description = memoEl ? memoEl.value : '';
const amountEl = document.querySelector('[name="Amount"]');
const amount = amountEl ? parseFloat(amountEl.value) || 0 : 0;
const btn = this;
btn.disabled = true;
btn.innerHTML = '<span class="spinner-border spinner-border-sm me-1"></span>Thinking...';
try {
const resp = await fetch('/Expenses/SuggestAccount', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ vendorName: vendorText, description, amount, availableAccounts: [] })
});
const data = await resp.json();
if (data.success && data.suggestedAccountId) {
_expAiSuggestedAccountId = data.suggestedAccountId;
document.getElementById('expAiSuggestionText').textContent =
'\u2728 ' + (data.suggestedAccountName || 'Suggested') + (data.reasoning ? ' \u2014 ' + data.reasoning : '');
document.getElementById('expAiSuggestionBadge').classList.remove('d-none');
} else {
alert(data.errorMessage || 'Could not suggest an account.');
}
} catch (e) {
alert('Error contacting AI service.');
} finally {
btn.disabled = false;
btn.innerHTML = '<i class="bi bi-stars me-1"></i>AI Suggest';
}
});
document.getElementById('expAiSuggestionUseBtn').addEventListener('click', function () {
if (!_expAiSuggestedAccountId) return;
const sel = document.getElementById('expenseAccountSelect');
if (sel) sel.value = String(_expAiSuggestedAccountId);
document.getElementById('expAiSuggestionBadge').classList.add('d-none');
});
</script>
}