|
|
@@ -65,6 +65,14 @@ $controller = new class($number) {
|
|
|
return $items[0];
|
|
|
}
|
|
|
|
|
|
+ private function requireCompany(?int $company_id): Company {
|
|
|
+ $company = Company::get($company_id);
|
|
|
+ if(!$company) {
|
|
|
+ throw new RuntimeException(__("Company not found."));
|
|
|
+ }
|
|
|
+ return $company;
|
|
|
+ }
|
|
|
+
|
|
|
public function view(): void {
|
|
|
$sale = $this->requireSale();
|
|
|
|
|
|
@@ -89,15 +97,11 @@ $controller = new class($number) {
|
|
|
|
|
|
public function createOrUpdate(): void {
|
|
|
|
|
|
+ $company_id = $this->request->int("company_id");
|
|
|
+ $company = $this->requireCompany($company_id);
|
|
|
+
|
|
|
$sale = $this->getSale();
|
|
|
if(!$sale) {
|
|
|
-
|
|
|
- $company_id = $this->request->int("company_id");
|
|
|
- $company = Company::get($company_id);
|
|
|
- if(!$company) {
|
|
|
- throw new RuntimeException(__("Company not found."));
|
|
|
- }
|
|
|
-
|
|
|
$location_id = $this->request->int("location_id");
|
|
|
$location = Location::get($location_id);
|
|
|
if(!$location) {
|
|
|
@@ -115,6 +119,7 @@ $controller = new class($number) {
|
|
|
$success_message = __("Sale created successfully.");
|
|
|
}
|
|
|
else {
|
|
|
+ $sale->company_id = $company->id;
|
|
|
$sale->status = $this->request->int("status");
|
|
|
$sale->currency = $this->request->string("currency");
|
|
|
$sale->tax_rate = $this->request->decimal("tax_rate", 2);
|