Forráskód Böngészése

Allow editing of company for sales and documents

Alan Lam 3 éve
szülő
commit
ac9099d96d
4 módosított fájl, 40 hozzáadás és 17 törlés
  1. 4 0
      controllers/document.php
  2. 12 7
      controllers/sale.php
  3. 11 7
      views/document.php
  4. 13 3
      views/sale.php

+ 4 - 0
controllers/document.php

@@ -227,6 +227,10 @@ $controller = new class($document_type, $document_number) {
 	public function update(): void {
 		$document = $this->requireDocument();
 
+		$company_id = $this->request->int("company_id");
+		$company = $this->requireCompany($company_id);
+		$document->company_id = $company->id;
+
 		if($document->isInvoice()) {
 			$document->invoice_status = $this->request->int("invoice_status");
 			$document->terms = $this->request->string("terms");

+ 12 - 7
controllers/sale.php

@@ -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);

+ 11 - 7
views/document.php

@@ -246,6 +246,17 @@ $related_document = $document->getRelatedDocument();
 					</label>
 					<input type="text" class="form-control" name="contact_email" id="contact-email" placeholder="<?=htmlspecialchars(__("Type contact email address"))?>" value="<?=htmlspecialchars($document->contact_email)?>" />
 				</div>
+				<div class="mb-3">
+					<label class="form-label" for="company-id">
+						<?=htmlspecialchars(__("Company"))?>
+					</label>
+					<select class="form-control" name="company_id" id="company-id" required>
+						<option value=""><?=htmlspecialchars(__("Select Company"))?></option>
+						<?php
+						HtmlHelper::renderOptions(Company::getOptions(), $document->company_id);
+						?>
+					</select>
+				</div>
 
 				<dl>
 					<?php
@@ -266,13 +277,6 @@ $related_document = $document->getRelatedDocument();
 							<?php
 						}
 					}
-
-					if($company) {
-						?>
-						<dt><?=htmlspecialchars(__("Company"))?></dt>
-						<dd><?=htmlspecialchars($company->name)?></dd>
-						<?php
-					}
 					?>
 
 					<dt><?=htmlspecialchars(__("Created By"))?></dt>

+ 13 - 3
views/sale.php

@@ -57,10 +57,20 @@ $user = $core->getUser();
 			<div class="col-xl-6">
 
 				<h4><?=htmlspecialchars(__("Additional Details"))?></h4>
-				<dl>
-					<dt><?=htmlspecialchars(__("Company"))?></dt>
-					<dd><?=htmlspecialchars($sale->getCompany()->name)?></dd>
 
+				<div class="mb-3">
+					<label class="form-label" for="company-id">
+						<?=htmlspecialchars(__("Company"))?>
+					</label>
+					<select class="form-control" name="company_id" id="company-id" required>
+						<option value=""><?=htmlspecialchars(__("Select Company"))?></option>
+						<?php
+						HtmlHelper::renderOptions(Company::getOptions(), $sale->company_id);
+						?>
+					</select>
+				</div>
+
+				<dl>
 					<dt><?=htmlspecialchars(__("Location"))?></dt>
 					<dd><?=htmlspecialchars($sale->getLocation()->getDisplayName())?></dd>