|
@@ -106,17 +106,26 @@ $controller = new class($document_type, $document_number) {
|
|
|
if($document->isInvoice() || $document->isDeliveryNote()) {
|
|
if($document->isInvoice() || $document->isDeliveryNote()) {
|
|
|
/** @var Sale $sale */
|
|
/** @var Sale $sale */
|
|
|
$sale = $document->getSale();
|
|
$sale = $document->getSale();
|
|
|
- $core->addBreadcrumb("/sales", __("Sales"));
|
|
|
|
|
- $core->addBreadcrumb($sale->getUrl(), __("Sale %d", $sale->getNumber()));
|
|
|
|
|
-
|
|
|
|
|
- if($document->isInvoice()) {
|
|
|
|
|
- $core->addBreadcrumb($document->getUrl(), __("Invoice %d", $document->number));
|
|
|
|
|
|
|
+ if($sale) {
|
|
|
|
|
+ $core->addBreadcrumb("/sales", __("Sales"));
|
|
|
|
|
+ $core->addBreadcrumb($sale->getUrl(), __("Sale %d", $sale->getNumber()));
|
|
|
}
|
|
}
|
|
|
- if($document->isDeliveryNote()) {
|
|
|
|
|
- $core->addBreadcrumb($document->getUrl(), __("Delivery Note %d", $document->number));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if($document->isPartOfAru()) {
|
|
|
|
|
+ /** @var Document $aru */
|
|
|
|
|
+ $aru = $document->getRelatedDocument();
|
|
|
|
|
+ $core->addBreadcrumb("/arus", __("ARUs"));
|
|
|
|
|
+ $core->addBreadcrumb($aru->getUrl(), $aru->getTitle());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ else if($document->isGoodsIn()) {
|
|
|
|
|
+ $core->addBreadcrumb("/goods-in", __("Goods-In"));
|
|
|
|
|
+ }
|
|
|
|
|
+ else if($document->isAru()) {
|
|
|
|
|
+ $core->addBreadcrumb("/arus", __("ARUs"));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ $core->addBreadcrumb($document->getUrl(), $document->getTitle());
|
|
|
|
|
|
|
|
$core->addScript("/js/document-item-modal.js");
|
|
$core->addScript("/js/document-item-modal.js");
|
|
|
$core->addScript("/js/document-page.js");
|
|
$core->addScript("/js/document-page.js");
|
|
@@ -136,16 +145,16 @@ $controller = new class($document_type, $document_number) {
|
|
|
$supplier_id = $this->request->int("supplier_id");
|
|
$supplier_id = $this->request->int("supplier_id");
|
|
|
$supplier = $supplier_id ? $this->requireSupplier($supplier_id) : null;
|
|
$supplier = $supplier_id ? $this->requireSupplier($supplier_id) : null;
|
|
|
|
|
|
|
|
-// $company_id = $this->request->int("company_id");
|
|
|
|
|
-// $company = $company_id ? $this->requireCompany($company_id) : null;
|
|
|
|
|
|
|
+ $company_id = $this->request->int("company_id");
|
|
|
|
|
+ $company = $company_id ? $this->requireCompany($company_id) : null;
|
|
|
|
|
|
|
|
$location_id = $this->request->int("location_id");
|
|
$location_id = $this->request->int("location_id");
|
|
|
$location = $location_id ? $this->requireLocation($location_id) : null;
|
|
$location = $location_id ? $this->requireLocation($location_id) : null;
|
|
|
|
|
|
|
|
$document = new Document();
|
|
$document = new Document();
|
|
|
|
|
+ $document->company_id = $company->id ?? null;
|
|
|
$document->user_id = $this->user->id;
|
|
$document->user_id = $this->user->id;
|
|
|
$document->supplier_id = $supplier->id ?? null;
|
|
$document->supplier_id = $supplier->id ?? null;
|
|
|
-// $document->company_id = $company->id ?? null;
|
|
|
|
|
$document->location_id = $location->id ?? null;
|
|
$document->location_id = $location->id ?? null;
|
|
|
$document->type = $type;
|
|
$document->type = $type;
|
|
|
$document->number = Document::getNextNumber($type);
|
|
$document->number = Document::getNextNumber($type);
|
|
@@ -161,6 +170,29 @@ $controller = new class($document_type, $document_number) {
|
|
|
|
|
|
|
|
$document->commit();
|
|
$document->commit();
|
|
|
|
|
|
|
|
|
|
+ $item_description = $this->request->string("item_description");
|
|
|
|
|
+ $item_serial_number = $this->request->string("item_serial_number");
|
|
|
|
|
+
|
|
|
|
|
+ if($item_description) {
|
|
|
|
|
+ $item = new DocumentItem();
|
|
|
|
|
+ $item->document_id = $document->id;
|
|
|
|
|
+ $item->description = $item_description;
|
|
|
|
|
+ $item->serial_number = $item_serial_number;
|
|
|
|
|
+ $item->quantity = 1;
|
|
|
|
|
+ $item->unit_price = "0.00";
|
|
|
|
|
+ $item->dts_created = Database::dts();
|
|
|
|
|
+ $item->commit();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($document->hasCosts() && $location) {
|
|
|
|
|
+ $address = $location->getAddress();
|
|
|
|
|
+ $document->currency = "GBP";
|
|
|
|
|
+ $document->tax_rate = "20.00";
|
|
|
|
|
+ $document->billing_address = (string) $address;
|
|
|
|
|
+ $document->delivery_address = (string) $address;
|
|
|
|
|
+ $document->commit();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
JSON::success([
|
|
JSON::success([
|
|
|
"url" => $document->getUrl()
|
|
"url" => $document->getUrl()
|
|
|
]);
|
|
]);
|
|
@@ -252,44 +284,47 @@ $controller = new class($document_type, $document_number) {
|
|
|
Http::redirect($document->getUrl());
|
|
Http::redirect($document->getUrl());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function createDeliveryNote(): void {
|
|
|
|
|
|
|
+ public function createDocumentWithItems(int $document_type): void {
|
|
|
$document_item_ids = $this->request->int("document_item_ids");
|
|
$document_item_ids = $this->request->int("document_item_ids");
|
|
|
if(!$document_item_ids || !is_array($document_item_ids)) {
|
|
if(!$document_item_ids || !is_array($document_item_ids)) {
|
|
|
throw new RuntimeException(__("No items selected."));
|
|
throw new RuntimeException(__("No items selected."));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $invoice = $this->requireDocument();
|
|
|
|
|
|
|
+ $source_document = $this->requireDocument();
|
|
|
|
|
|
|
|
$items = $this->validateItemIds($document_item_ids);
|
|
$items = $this->validateItemIds($document_item_ids);
|
|
|
|
|
|
|
|
- $delivery_note = new Document();
|
|
|
|
|
- $delivery_note->user_id = $this->user->id;
|
|
|
|
|
- $delivery_note->sale_id = $invoice->sale_id;
|
|
|
|
|
- $delivery_note->location_id = $invoice->location_id;
|
|
|
|
|
- $delivery_note->related_document_id = $invoice->id;
|
|
|
|
|
- $delivery_note->type = DocumentTypes::DELIVERY_NOTE;
|
|
|
|
|
- $delivery_note->billing_address = $invoice->billing_address;
|
|
|
|
|
- $delivery_note->delivery_address = $invoice->delivery_address;
|
|
|
|
|
- $delivery_note->number = Document::getNextNumber(DocumentTypes::DELIVERY_NOTE);
|
|
|
|
|
- $delivery_note->date = date("Y-m-d");
|
|
|
|
|
- $delivery_note->delivery_company = $invoice->delivery_company;
|
|
|
|
|
- $delivery_note->tracking_number = $invoice->tracking_number;
|
|
|
|
|
- $delivery_note->dts_created = Database::dts();
|
|
|
|
|
- $delivery_note->commit();
|
|
|
|
|
|
|
+ $document = new Document();
|
|
|
|
|
+ $document->company_id = $source_document->company_id;
|
|
|
|
|
+ $document->user_id = $this->user->id;
|
|
|
|
|
+ $document->sale_id = $source_document->sale_id;
|
|
|
|
|
+ $document->location_id = $source_document->location_id;
|
|
|
|
|
+ $document->related_document_id = $source_document->id;
|
|
|
|
|
+ $document->type = $document_type;
|
|
|
|
|
+ $document->currency = $source_document->currency;
|
|
|
|
|
+ $document->tax_rate = $source_document->tax_rate;
|
|
|
|
|
+ $document->billing_address = $source_document->billing_address;
|
|
|
|
|
+ $document->delivery_address = $source_document->delivery_address;
|
|
|
|
|
+ $document->number = Document::getNextNumber($document_type);
|
|
|
|
|
+ $document->date = date("Y-m-d");
|
|
|
|
|
+ $document->delivery_company = $source_document->delivery_company;
|
|
|
|
|
+ $document->tracking_number = $source_document->tracking_number;
|
|
|
|
|
+ $document->dts_created = Database::dts();
|
|
|
|
|
+ $document->commit();
|
|
|
|
|
|
|
|
foreach($items as $item) {
|
|
foreach($items as $item) {
|
|
|
- $delivery_note_item = new DocumentItem();
|
|
|
|
|
- $delivery_note_item->document_id = $delivery_note->id;
|
|
|
|
|
- $delivery_note_item->description = $item->description;
|
|
|
|
|
- $delivery_note_item->serial_number = $item->serial_number;
|
|
|
|
|
- $delivery_note_item->quantity = $item->quantity;
|
|
|
|
|
- $delivery_note_item->unit_price = $item->unit_price;
|
|
|
|
|
- $delivery_note_item->dts_created = Database::dts();
|
|
|
|
|
- $delivery_note_item->commit();
|
|
|
|
|
|
|
+ $document_item = new DocumentItem();
|
|
|
|
|
+ $document_item->document_id = $document->id;
|
|
|
|
|
+ $document_item->description = $item->description;
|
|
|
|
|
+ $document_item->serial_number = $item->serial_number;
|
|
|
|
|
+ $document_item->quantity = $item->quantity;
|
|
|
|
|
+ $document_item->unit_price = $item->unit_price;
|
|
|
|
|
+ $document_item->dts_created = Database::dts();
|
|
|
|
|
+ $document_item->commit();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Session::addAlert("success", __("Delivery note created successfully."));
|
|
|
|
|
- Http::redirect($delivery_note->getUrl());
|
|
|
|
|
|
|
+ Session::addAlert("success", __("%s created successfully.", $document->getDisplayType()));
|
|
|
|
|
+ Http::redirect($document->getUrl());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -357,6 +392,7 @@ $controller = new class($document_type, $document_number) {
|
|
|
switch($action) {
|
|
switch($action) {
|
|
|
case "create":
|
|
case "create":
|
|
|
$controller->create();
|
|
$controller->create();
|
|
|
|
|
+ break;
|
|
|
|
|
|
|
|
case "submit":
|
|
case "submit":
|
|
|
$controller->update();
|
|
$controller->update();
|
|
@@ -379,8 +415,12 @@ switch($action) {
|
|
|
$controller->deleteItems();
|
|
$controller->deleteItems();
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
|
|
+ case "create-invoice":
|
|
|
|
|
+ $controller->createDocumentWithItems(DocumentTypes::INVOICE);
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
case "create-delivery-note":
|
|
case "create-delivery-note":
|
|
|
- $controller->createDeliveryNote();
|
|
|
|
|
|
|
+ $controller->createDocumentWithItems(DocumentTypes::DELIVERY_NOTE);
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
default:
|