feat(patients): service quantity in visit session
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -35,16 +35,20 @@ class SessionService
|
||||
#[ORM\Column(name: 'price_rials', type: 'integer')]
|
||||
private int $priceRials;
|
||||
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private int $quantity = 1;
|
||||
|
||||
#[ORM\Column(name: 'created_at', type: 'integer')]
|
||||
private int $createdAt;
|
||||
|
||||
public function __construct(PatientSession $session, ServiceItem $serviceItem, ?ClinicStaff $staff = null)
|
||||
public function __construct(PatientSession $session, ServiceItem $serviceItem, ?ClinicStaff $staff = null, int $quantity = 1)
|
||||
{
|
||||
$this->uuid = Uuid::v4()->toRfc4122();
|
||||
$this->session = $session;
|
||||
$this->serviceItem = $serviceItem;
|
||||
$this->staff = $staff;
|
||||
$this->priceRials = $serviceItem->getPriceRials();
|
||||
$this->quantity = max(1, $quantity);
|
||||
$this->createdAt = time();
|
||||
}
|
||||
|
||||
@@ -54,6 +58,8 @@ class SessionService
|
||||
public function getServiceItem(): ServiceItem { return $this->serviceItem; }
|
||||
public function getStaff(): ?ClinicStaff { return $this->staff; }
|
||||
public function getPriceRials(): int { return $this->priceRials; }
|
||||
public function getQuantity(): int { return $this->quantity; }
|
||||
public function getLineTotalRials(): int { return $this->priceRials * $this->quantity; }
|
||||
public function getCreatedAt(): int { return $this->createdAt; }
|
||||
|
||||
public function toArray(): array
|
||||
@@ -65,6 +71,8 @@ class SessionService
|
||||
'staff_uuid' => $this->staff?->getUuid(),
|
||||
'staff_name' => $this->staff?->getFullName(),
|
||||
'price_rials' => $this->priceRials,
|
||||
'quantity' => $this->quantity,
|
||||
'line_total_rials' => $this->getLineTotalRials(),
|
||||
'created_at' => $this->createdAt,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -105,12 +105,13 @@ class PatientService
|
||||
$session->setPaymentMethod($data['payment_method'] ?? 'pending');
|
||||
$session->setNotes($data['notes'] ?? null);
|
||||
|
||||
// جمعآوری service items
|
||||
// جمعآوری service items (با احتساب تعداد)
|
||||
$serviceItemsData = [];
|
||||
foreach (($data['services'] ?? []) as $svc) {
|
||||
$item = $this->serviceItemRepo->findByUuid($svc['service_item_uuid'] ?? '');
|
||||
if ($item !== null) {
|
||||
$serviceItemsData[] = ['price_rials' => $item->getPriceRials()];
|
||||
$qty = max(1, (int) ($svc['quantity'] ?? 1));
|
||||
$serviceItemsData[] = ['price_rials' => $item->getPriceRials() * $qty];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +134,8 @@ class PatientService
|
||||
continue;
|
||||
}
|
||||
$staff = !empty($svc['staff_uuid']) ? $this->staffRepo->findByUuid($svc['staff_uuid']) : null;
|
||||
$ss = new SessionService($session, $item, $staff);
|
||||
$qty = max(1, (int) ($svc['quantity'] ?? 1));
|
||||
$ss = new SessionService($session, $item, $staff, $qty);
|
||||
$this->sessionServiceRepo->save($ss);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user