BConnect POS - Reference PHP

SaleController extends AbstractController
in package

Central controller for sales and the point of sale (POS).

Brings together three scopes: web sales (cart, creation, detail, export, search, invoice email), invoicing (A4 PDF and ESC/POS thermal receipts), the touch POS interface (endpoints /sale/api/pos/*) and the endpoints consumed by the mobile application. Also handles deferred sales (mark as paid) and cancellation. All operations are scoped to the point of sale of the authenticated user.

Attributes
#[IsGranted]
'IS_AUTHENTICATED_FULLY'
#[Route]
'/sale'

Table of Contents

Methods

__construct()  : mixed
Dependencies are injected directly into each action rather than into the constructor; this one therefore has no service to initialize.
addToCart()  : JsonResponse
API endpoint to add product to cart
cancelSale()  : Response
Cancels a sale (web interface).
clearPOSCart()  : JsonResponse
API endpoint to clear cart
create()  : Response
Method for creating a new sale
datatable()  : JsonResponse
deleteProductToCart()  : RedirectResponse
Method for deleting a product in cart
editSale()  : Response
export()  : Response
exportDownload()  : Response
finalizePOSSale()  : JsonResponse
API endpoint to finalize sale from POS
generateInvoiceBySale()  : Response
Generates a standard PDF invoice for a given sale.
generateReceiptPdfBySale()  : Response
Generates the PDF receipt / invoice (A4 format) of a sale.
generateThermalInvoice()  : Response
Renders the HTML for a thermal printer receipt (80mm width).
generateThermalInvoicePdf()  : Response
Generates a PDF receipt formatted for a thermal printer (80mm width).
getAllProduct()  : JsonResponse
Method for get quantity by product id
getCart()  : JsonResponse
API endpoint to get cart items
getCategoriesForPos()  : JsonResponse
API endpoint to get categories for POS
getProductByBarcode()  : JsonResponse
API endpoint to get product by barcode
getProductsForPos()  : JsonResponse
API endpoint to get products for POS
index()  : Response
Method to displaying a list of sales
markSaleAsPaid()  : Response
Marks a deferred sale as paid (web interface).
pos()  : Response
Renders the modern Point of Sale (POS) interface.
processPOSSale()  : JsonResponse
API endpoint to process POS sale
removeCartItem()  : JsonResponse
API endpoint to remove cart item
retailSale()  : Response
Method to displaying a list of sales
search()  : Response
Method for searching a sale by reference sale
searchProductForPos()  : JsonResponse
API endpoint to get product by barcode for POS
searchSaleByTwoDate()  : RedirectResponse|Response
Method for searching sales by tow date
sendEmailToCustomer()  : Response
Sends an invoice to a customer via email.
showDetailSale()  : Response
Method to display a retail of single sale
updateCartItem()  : JsonResponse
API endpoint to update cart item quantity
updateQuantiyCart()  : Response
Method for updating a quantity product in cart
calculateTotalAmount()  : float
Method for calculate total amount per sale
canUserMarkSaleAsPaid()  : bool
Determines whether the user is allowed to mark the sale as paid.
normalizePaymentMethod()  : string
Normalizes a submitted payment-method label to a canonical value.

Methods

__construct()

Dependencies are injected directly into each action rather than into the constructor; this one therefore has no service to initialize.

public __construct() : mixed

addToCart()

API endpoint to add product to cart

public addToCart(EntityManagerInterface $entityManager, Request $request) : JsonResponse
Parameters
$entityManager : EntityManagerInterface
$request : Request
Attributes
#[Route]
'/api/pos/cart/add'
$name: 'api.pos.cart.add'
$methods: ['POST']
Return values
JsonResponse

cancelSale()

Cancels a sale (web interface).

public cancelSale(Sale $sale, EntityManagerInterface $entityManager, Request $request) : Response

Checks the point-of-sale ownership, then applies the business rules: a sale belonging to an already-validated session or an already-cancelled sale cannot be cancelled. Cancellation triggers, via the subscribers, the readjustment of the fund and the stock.

Parameters
$sale : Sale

Sale to cancel.

$entityManager : EntityManagerInterface

Doctrine entity manager.

$request : Request

HTTP request (used for the referer redirect).

Attributes
#[Route]
'/cancel/{id}'
$name: 'sale.cancel'
Return values
Response

Redirect to the previous page or the sale list.

clearPOSCart()

API endpoint to clear cart

public clearPOSCart(EntityManagerInterface $entityManager) : JsonResponse
Parameters
$entityManager : EntityManagerInterface
Attributes
#[Route]
'/api/pos/cart/clear'
$name: 'api.pos.cart.clear'
$methods: ['DELETE']
Return values
JsonResponse

create()

Method for creating a new sale

public create(Request $request, EntityManagerInterface $entityManager, MailerService $mailer) : Response
Parameters
$request : Request
$entityManager : EntityManagerInterface
$mailer : MailerService
Tags
throws
NonUniqueResultException
TransportExceptionInterface
Attributes
#[Route]
'/cart/add'
$name: 'sale.create'
Return values
Response

datatable()

public datatable(EntityManagerInterface $entityManager, Request $request, DataTableService $dataTableService) : JsonResponse
Parameters
$entityManager : EntityManagerInterface
$request : Request
$dataTableService : DataTableService
Tags
throws
ORMException
NonUniqueResultException
NoResultException
Attributes
#[Route]
'/datatable'
$name: 'sale.datatable'
$methods: ['GET']
Return values
JsonResponse

deleteProductToCart()

Method for deleting a product in cart

public deleteProductToCart(Cart $cart, EntityManagerInterface $entityManager) : RedirectResponse
Parameters
$cart : Cart
$entityManager : EntityManagerInterface
Attributes
#[Route]
'/delete/card/{id}'
$name: 'cart.delete'
Return values
RedirectResponse

editSale()

public editSale(Sale $sale, Request $request, EntityManagerInterface $entityManager, SaleEditService $saleEditService) : Response
Parameters
$sale : Sale
$request : Request
$entityManager : EntityManagerInterface
$saleEditService : SaleEditService
Attributes
#[Route]
'/edit/{id}'
$name: 'sale.edit'
$methods: ['GET', 'POST']
Return values
Response

export()

public export(Request $request) : Response
Parameters
$request : Request
Tags
Route

("/export", name="sale.export", methods={"GET"})

Attributes
#[Route]
'/export'
$name: 'sale.export'
$methods: ['GET']
Return values
Response

exportDownload()

public exportDownload(Request $request, SaleExportService $exportService, PdfService $pdfService) : Response
Parameters
$request : Request
$exportService : SaleExportService
$pdfService : PdfService
Tags
Route

("/export/download", name="sale.export.download", methods={"GET"})

Attributes
#[Route]
'/export/download'
$name: 'sale.export.download'
$methods: ['GET']
Return values
Response

finalizePOSSale()

API endpoint to finalize sale from POS

public finalizePOSSale(EntityManagerInterface $entityManager, Request $request) : JsonResponse
Parameters
$entityManager : EntityManagerInterface
$request : Request
Attributes
#[Route]
'/api/pos/sale/finalize'
$name: 'api.pos.sale.finalize'
$methods: ['POST']
Return values
JsonResponse

generateInvoiceBySale()

Generates a standard PDF invoice for a given sale.

public generateInvoiceBySale(Sale $sale, PdfService $pdfService, ConfigService $configService) : Response

It retrieves sale details, company configuration (including logo), and renders an HTML template before converting it to a PDF file.

Parameters
$sale : Sale

The sale for which to generate the invoice.

$pdfService : PdfService

The service responsible for PDF generation.

$configService : ConfigService

The service to access application configuration.

Tags
throws
Exception

If the logo file does not exist at the specified path.

Attributes
#[Route]
'/invoice/{id}'
$name: 'sale.invoice'
Return values
Response

A response containing the generated PDF file for download.

generateReceiptPdfBySale()

Generates the PDF receipt / invoice (A4 format) of a sale.

public generateReceiptPdfBySale(Sale $sale, PdfService $pdfService, ConfigService $configService) : Response
Parameters
$sale : Sale

Sale to print.

$pdfService : PdfService

PDF generation service.

$configService : ConfigService

Point-of-sale configuration (header, logo, etc.).

Attributes
#[Route]
'/receipt-pdf/{id}'
$name: 'sale.receipt_pdf'
Return values
Response

The PDF document as the response.

generateThermalInvoice()

Renders the HTML for a thermal printer receipt (80mm width).

public generateThermalInvoice(Sale $sale, ConfigService $configService) : Response

This method prepares the data and renders the Twig template for the thermal receipt, but does not generate the final PDF.

Parameters
$sale : Sale

The sale for which to generate the receipt.

$configService : ConfigService

The service to access application configuration.

Tags
throws
Exception

If the logo file does not exist.

Attributes
#[Route]
'/thermal-invoice/{id}'
$name: 'sale.thermal_invoice'
Return values
Response

The rendered HTML view of the thermal receipt.

generateThermalInvoicePdf()

Generates a PDF receipt formatted for a thermal printer (80mm width).

public generateThermalInvoicePdf(Sale $sale, PdfService $pdfService, ConfigService $configService) : Response

It renders the thermal receipt template to HTML and then uses the PDF service to convert it into a downloadable PDF file.

Parameters
$sale : Sale

The sale for which to generate the PDF receipt.

$pdfService : PdfService

The service for PDF generation.

$configService : ConfigService

The service to access application configuration.

Tags
throws
Exception

If the logo file does not exist.

Attributes
#[Route]
'/thermal-invoice-pdf/{id}'
$name: 'sale.thermal_invoice_pdf'
Return values
Response

A response containing the generated PDF file.

getAllProduct()

Method for get quantity by product id

public getAllProduct(Product $product) : JsonResponse
Parameters
$product : Product
Attributes
#[Route]
'/get-product/{id}'
$name: 'product.all'
$methods: 'GET'
Return values
JsonResponse

getCart()

API endpoint to get cart items

public getCart(EntityManagerInterface $entityManager) : JsonResponse
Parameters
$entityManager : EntityManagerInterface
Attributes
#[Route]
'/api/pos/cart'
$name: 'api.pos.cart'
$methods: ['GET']
Return values
JsonResponse

getCategoriesForPos()

API endpoint to get categories for POS

public getCategoriesForPos(EntityManagerInterface $entityManager) : JsonResponse
Parameters
$entityManager : EntityManagerInterface
Attributes
#[Route]
'/api/pos/categories'
$name: 'api.pos.categories'
$methods: ['GET']
Return values
JsonResponse

getProductByBarcode()

API endpoint to get product by barcode

public getProductByBarcode(string $barcode, EntityManagerInterface $entityManager) : JsonResponse
Parameters
$barcode : string
$entityManager : EntityManagerInterface
Attributes
#[Route]
'/api/pos/product/barcode/{barcode}'
$name: 'api.pos.product.barcode'
$methods: ['GET']
Return values
JsonResponse

getProductsForPos()

API endpoint to get products for POS

public getProductsForPos(EntityManagerInterface $entityManager, Request $request) : JsonResponse
Parameters
$entityManager : EntityManagerInterface
$request : Request
Attributes
#[Route]
'/api/pos/products'
$name: 'api.pos.products'
$methods: ['GET']
Return values
JsonResponse

index()

Method to displaying a list of sales

public index(Request $request) : Response
Parameters
$request : Request
Attributes
#[Route]
'/'
$name: 'sale.index'
Return values
Response

markSaleAsPaid()

Marks a deferred sale as paid (web interface).

public markSaleAsPaid(Sale $sale, Request $request, EntityManagerInterface $entityManager) : Response

Checks the point-of-sale ownership, the CSRF token validity and the user's right; rejects a cancelled sale.

Parameters
$sale : Sale

Sale to settle.

$request : Request

POST request carrying the CSRF token.

$entityManager : EntityManagerInterface

Doctrine entity manager.

Attributes
#[Route]
'/mark-paid/{id}'
$name: 'sale.mark_paid'
$methods: ['POST']
Return values
Response

Redirect to the sale detail.

pos()

Renders the modern Point of Sale (POS) interface.

public pos(EntityManagerInterface $entityManager) : Response

This method checks for an active sales session before rendering the POS view. If no session is active, it redirects the user to start one. It also fetches the list of customers for the current point of sale.

Parameters
$entityManager : EntityManagerInterface

The entity manager.

Attributes
#[Route]
'/pos'
$name: 'sale.pos'
Return values
Response

The rendered POS interface or a redirect.

processPOSSale()

API endpoint to process POS sale

public processPOSSale(Request $request, EntityManagerInterface $entityManager) : JsonResponse
Parameters
$request : Request
$entityManager : EntityManagerInterface
Attributes
#[Route]
'/api/pos-sale'
$name: 'sale.api.pos_sale'
$methods: ['POST']
Return values
JsonResponse

removeCartItem()

API endpoint to remove cart item

public removeCartItem(EntityManagerInterface $entityManager, int $id) : JsonResponse
Parameters
$entityManager : EntityManagerInterface
$id : int
Attributes
#[Route]
'/api/pos/cart/remove/{id}'
$name: 'api.pos.cart.remove'
$methods: ['DELETE']
Return values
JsonResponse

retailSale()

Method to displaying a list of sales

public retailSale(SaleRepository $saleRepository) : Response
Parameters
$saleRepository : SaleRepository
Attributes
#[Route]
'/retail/sale'
$name: 'retail.sale'
Return values
Response

Method for searching a sale by reference sale

public search(Request $request, SearchService $searchService) : Response
Parameters
$request : Request
$searchService : SearchService
Attributes
#[Route]
'/search'
$name: 'sale.search'
$methods: 'POST'
Return values
Response

searchProductForPos()

API endpoint to get product by barcode for POS

public searchProductForPos(EntityManagerInterface $entityManager, Request $request) : JsonResponse
Parameters
$entityManager : EntityManagerInterface
$request : Request
Attributes
#[Route]
'/api/pos/product/search'
$name: 'api.pos.product.search'
$methods: ['GET']
Return values
JsonResponse

searchSaleByTwoDate()

Method for searching sales by tow date

public searchSaleByTwoDate(Request $request, SaleRepository $repository, EntityManagerInterface $entityManager, PdfService $pdfService) : RedirectResponse|Response
Parameters
$request : Request
$repository : SaleRepository
$entityManager : EntityManagerInterface
$pdfService : PdfService
Attributes
#[Route]
'/search/sale/'
$name: 'sale.search.date'
Return values
RedirectResponse|Response

sendEmailToCustomer()

Sends an invoice to a customer via email.

public sendEmailToCustomer(Sale $sale, EntityManagerInterface $entityManager, Request $request, MailerService $mailer, PdfService $pdfService, ConfigService $configService) : Response

This method creates and handles a form for composing an email. It generates the invoice as a PDF attachment, sends the email to the customer, and notifies internal users about the action. Flash messages are used to provide feedback on the success or failure of the email operations.

Parameters
$sale : Sale

The sale associated with the invoice.

$entityManager : EntityManagerInterface

The entity manager.

$request : Request

The HTTP request.

$mailer : MailerService

The service for sending emails.

$pdfService : PdfService

The service for generating the PDF invoice.

$configService : ConfigService
Attributes
#[Route]
'/send/email/{id}'
$name: 'sale.send.email'
Return values
Response

A redirect to the sales index or the email composition form.

showDetailSale()

Method to display a retail of single sale

public showDetailSale(Sale $sale, SaleEditService $saleEditService) : Response
Parameters
$sale : Sale
$saleEditService : SaleEditService
Attributes
#[Route]
'/detail/{id}'
$name: "sale.detail"
Return values
Response

updateCartItem()

API endpoint to update cart item quantity

public updateCartItem(EntityManagerInterface $entityManager, Request $request, int $id) : JsonResponse
Parameters
$entityManager : EntityManagerInterface
$request : Request
$id : int
Attributes
#[Route]
'/api/pos/cart/update/{id}'
$name: 'api.pos.cart.update'
$methods: ['PUT']
Return values
JsonResponse

updateQuantiyCart()

Method for updating a quantity product in cart

public updateQuantiyCart(Request $request, EntityManagerInterface $entityManager) : Response
Parameters
$request : Request
$entityManager : EntityManagerInterface
Attributes
#[Route]
'/update/quantity/sale'
$name: 'app.update.quantity.sale'
Return values
Response

calculateTotalAmount()

Method for calculate total amount per sale

private calculateTotalAmount(array<string|int, mixed> $carts) : float
Parameters
$carts : array<string|int, mixed>
Return values
float

canUserMarkSaleAsPaid()

Determines whether the user is allowed to mark the sale as paid.

private canUserMarkSaleAsPaid(Sale $sale, User $user) : bool

ADMIN and MANAGER roles always may; a SELLER only for their own sales.

Parameters
$sale : Sale

Sale concerned.

$user : User

Current user.

Return values
bool

True if the action is allowed.

normalizePaymentMethod()

Normalizes a submitted payment-method label to a canonical value.

private normalizePaymentMethod(string $paymentMethod) : string

Handles case, accent and synonym variants (cash, card, mobile money, etc.); an empty value falls back to "Espèces".

Parameters
$paymentMethod : string

Raw payment-method label.

Return values
string

Normalized label.

On this page

Search results