4.7 KiB
4.7 KiB
task, cycles, context, private, started, finished
| task | cycles | context | private | started | finished |
|---|---|---|---|---|---|
| Add print button for POS scan code and sales statistics (sold today + sold to date) on BuyViewProductMarket page | 5 | true | false | 2026-05-16T19:01:29Z | 2026-05-16T19:02:00Z |
files
resources/js/Pages/BuyViewProductMarket.vue[lines 159-167] — existing POS QR section; add print button + statistics displayapp/Http/Controllers/Market/ProductController.php[lines 223-360] —viewProductDetailsstatic method; addsold_todayandstore_sold_todayto$dataarray
steps
- In
ProductController.php, adduse App\Models\Market\ProductTransaction;to the import block (after line 14) if not already present. - In
ProductController.phpinsideviewProductDetails, after line 290 ($storeProductSold = $storeProduct->pivot->sold;), add:$storeSoldToday = ProductTransaction::where('product_id', $product->id) ->where('store_id', $targetStore->id) ->whereDate('created_at', today()) ->sum('quantity'); - After the
if ($targetStore)block (before line 312$data = [), add a global sold_today query:$soldToday = ProductTransaction::where('product_id', $product->id) ->whereDate('created_at', today()) ->sum('quantity'); - In
$dataarray (lines 312-338), add after'sold' => $product->sold,:'sold_today' => (int) $soldToday, 'store_sold_today' => isset($storeSoldToday) ? (int) $storeSoldToday : null, - In
BuyViewProductMarket.vue, add aprintPosCode()function in<script setup>that opens a new window rendering the QR image + product name + barcode value formatted for printing, then callswindow.print()and closes. - In
BuyViewProductMarket.vue, replace the existingpos-qr-sectionblock (lines 160-167) with an enhanced version that:- Keeps the existing QR image
- Adds a "Print" button (
fas fa-print) below the QR image (visible to['ult','superoperator','operator']roles OR always — per user preference; default: always visible) - Adds a stats row below showing:
Sold Today: XandTotal Sold: Yusingproduct.sold_today,product.store_sold,product.sold,product.store_sold_today— prefer store-specific values whenproduct.is_from_storeis true
- Use theme variables (
var(--bg-card),var(--text-primary)) for the new stats section; no hardcodedbg-white/text-dark.
context
Backend — ProductController.php
viewProductDetailsstatic method at line 223; receives$target(hashkey) and optional$withStoresflag$targetStoreis set only when a store hash was in request ($req->input('data.store_hash'))- Pivot
soldalready extracted:$storeProductSold = $storeProduct->pivot->sold;(line 290) - Returned in
$data:'store_sold' => $storeProductSold(line 326),'sold' => $product->sold(line 327) ProductTransactionmodel: tableprd_trx, fieldsproduct_id,store_id,quantity(int),created_at; model atapp/Models/Market/ProductTransaction.php- Response format:
ResponseHelper::returnSuccessResponse($data, $data['hashkey'])→{ success: true, data: {...} }
Frontend — BuyViewProductMarket.vue
productis a computed ref fromproductStore.currentProduct(line 26)- Existing QR section (line 160-167):
v-if="product.pos_qrcode", shows QR viahttps://api.qrserver.com/v1/create-qr-code/?size=150x150&data=... pos_qrcodevalue ismd5(product_hashkey + store_hashkey)for store products, orbarcodeorhashkeyfor standalone productsrolefromuseAuth()— values:'ult','superoperator','operator','customer', etc.- Print function pattern — open new window with minimal HTML:
const printPosCode = () => { const w = window.open('', '_blank', 'width=400,height=500'); w.document.write(`<html><body style="text-align:center;font-family:sans-serif"> <h3>${product.value.name}</h3> <img src="https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(product.value.pos_qrcode)}" /> <p style="font-size:12px">${product.value.pos_qrcode}</p> <script>window.onload=()=>{window.print();window.close();}<\/script> </body></html>`); w.document.close(); }; - Stats display: show
store_sold_today ?? sold_todayfor "Today" andstore_sold ?? soldfor "Total" whenis_from_storeis true; otherwise use global values
notes
- dictionary: ai-docs/dictionary.md
- linters: eslint, tsc
- constraints: Use canonical table name
prd_trxin any raw SQL (not needed here — using Eloquent). Nobg-white/text-darkhardcoded. No new routes needed — extends existing/View/Product/Details/dataresponse. Definition-of-done checklist: no new page/route, so only theming + audit-field rules apply.