Przeglądaj źródła

Add VAT number to customer table

Alan Lam 3 lat temu
rodzic
commit
1936944898

+ 1 - 2
controllers/customer_form.php

@@ -48,6 +48,7 @@ if($submit) {
 		$customer->phone = $request->string("phone");
 		$customer->fax = $request->string("fax");
 		$customer->email = $request->email("email");
+		$customer->vat_number = $request->string("vat_number");
 
 		$address->address_1 = $request->string("address_1");
 		$address->address_2 = $request->string("address_2");
@@ -73,8 +74,6 @@ if($submit) {
 	catch(RuntimeException $e) {
 		Session::addAlert("danger", $e->getMessage());
 	}
-
-
 }
 
 View::include("header");

+ 3 - 0
controllers/document.php

@@ -169,12 +169,14 @@ $controller = new class($document_type, $document_number) {
 		$document->location_id = $location->id ?? null;
 
 		if($location) {
+			$customer = $location->getCustomer();
 			$address = $location->getAddress();
 			$lines = array_merge([$location->name], $address->getLines());
 			$address_string = implode("\n", $lines);
 
 			$document->billing_address = $address_string;
 			$document->delivery_address = $address_string;
+			$document->vat_number = $customer->vat_number;
 		}
 
 		$document->type = $type;
@@ -354,6 +356,7 @@ $controller = new class($document_type, $document_number) {
 		$document->delivery_company = $source_document->delivery_company;
 		$document->tracking_number = $source_document->tracking_number;
 		$document->notes = $source_document->notes;
+		$document->vat_number = $source_document->vat_number;
 		$document->contact_name = $source_document->contact_name;
 		$document->contact_phone = $source_document->contact_phone;
 		$document->contact_email = $source_document->contact_email;

+ 2 - 0
controllers/sale.php

@@ -256,6 +256,7 @@ $controller = new class($number) {
 	public function createSaleOrderFromItems(): void {
 		$sale = $this->requireSale();
 		$location = $sale->getLocation();
+		$customer = $location->getCustomer();
 		$address = $location->getAddress();
 
 		$item_ids = $this->request->int("sale_item_ids");
@@ -281,6 +282,7 @@ $controller = new class($number) {
 		$document->delivery_address = $address_string;
 		$document->number = Document::getNextNumber(DocumentTypes::SALE_ORDER);
 		$document->date = date("Y-m-d");
+		$document->vat_number = $customer->vat_number;
 		$document->contact_name = $location->contact_name;
 		$document->contact_phone = $location->contact_phone;
 		$document->contact_email = $location->contact_email;

+ 12 - 0
db/migrations/20221224150722_add_vat_number_field_to_customer_table.php

@@ -0,0 +1,12 @@
+<?php
+declare(strict_types=1);
+
+use Phinx\Migration\AbstractMigration;
+
+final class AddVatNumberFieldToCustomerTable extends AbstractMigration {
+	public function change(): void {
+		$this->table("customer")
+			->addColumn("vat_number", "string", ["limit" => 32, "null" => true, "after" => "email"])
+			->update();
+	}
+}

+ 8 - 4
engine/Customer.php

@@ -2,6 +2,9 @@
 
 namespace App;
 
+use App\Traits\DateTimeTrait;
+use App\Traits\SoftDeleteTrait;
+
 /**
  * Class Customer
  * @property int $id
@@ -10,16 +13,17 @@ namespace App;
  * @property string $phone
  * @property string $fax
  * @property string $email
- * @property string $dts_created
- * @property string $dts_updated
- * @property string $dts_deleted
+ * @property string $vat_number
  */
 
 class Customer extends Model {
 
 	protected static $table = "customer";
 	protected static $idField = "id";
-	protected static $fillableFields = ["address_id", "name", "phone", "fax", "email", "dts_created", "dts_updated", "dts_deleted"];
+	protected static $fillableFields = ["address_id", "name", "phone", "fax", "email", "vat_number", "dts_created", "dts_updated", "dts_deleted"];
+
+	use DateTimeTrait;
+	use SoftDeleteTrait;
 
 	// Static methods
 

+ 15 - 7
views/entity_form.php

@@ -12,6 +12,7 @@ $core = Core::getInstance();
 $user = $core->getUser();
 
 $is_company = $model instanceof Company;
+$is_customer = $model instanceof Customer;
 $is_location = $model instanceof Location;
 
 ?>
@@ -76,26 +77,33 @@ $is_location = $model instanceof Location;
 				<input class="form-control" type="email" id="email" name="email" placeholder="<?=htmlspecialchars(__("Type email"))?>" value="<?=htmlspecialchars($model->email)?>" />
 			</div>
 
-			<?php
-			if($is_company) {
-				?>
-				<div class="row">
+
+			<div class="row">
+				<?php
+				if($is_company) {
+					?>
 					<div class="col-6">
 						<div class="mb-3">
 							<label class="form-label" for="company-number"><?=htmlspecialchars(__("Company Number"))?></label>
 							<input class="form-control" type="text" id="company-number" name="company_number" placeholder="<?=htmlspecialchars(__("Type company number"))?>" value="<?=htmlspecialchars($model->company_number)?>" />
 						</div>
 					</div>
+					<?php
+				}
+				if($is_company || $is_customer) {
+					?>
 					<div class="col-6">
 						<div class="mb-3">
 							<label class="form-label" for="vat-number"><?=htmlspecialchars(__("VAT Number"))?></label>
 							<input class="form-control" type="tel" id="vat-number" name="vat_number" placeholder="<?=htmlspecialchars(__("Type VAT number"))?>" value="<?=htmlspecialchars($model->vat_number)?>" />
 						</div>
 					</div>
-				</div>
-				<?php
-			}
+					<?php
+				}
+				?>
+			</div>
 
+			<?php
 			if($is_location) {
 				?>
 				<h4><?=htmlspecialchars(__("Contact Person"))?></h4>