|
@@ -3,7 +3,7 @@
|
|
|
namespace App;
|
|
namespace App;
|
|
|
|
|
|
|
|
use App\Enums\DocumentTypes;
|
|
use App\Enums\DocumentTypes;
|
|
|
-use App\Enums\InvoiceStatuses;
|
|
|
|
|
|
|
+use App\Enums\SaleOrderStatuses;
|
|
|
use App\Enums\SaleStatuses;
|
|
use App\Enums\SaleStatuses;
|
|
|
use RuntimeException;
|
|
use RuntimeException;
|
|
|
|
|
|
|
@@ -253,7 +253,7 @@ $controller = new class($number) {
|
|
|
Http::redirect($sale->getUrl());
|
|
Http::redirect($sale->getUrl());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function createInvoiceFromItems(): void {
|
|
|
|
|
|
|
+ public function createSaleOrderFromItems(): void {
|
|
|
$sale = $this->requireSale();
|
|
$sale = $this->requireSale();
|
|
|
$location = $sale->getLocation();
|
|
$location = $sale->getLocation();
|
|
|
$address = $location->getAddress();
|
|
$address = $location->getAddress();
|
|
@@ -268,40 +268,40 @@ $controller = new class($number) {
|
|
|
$address_string = $location->name . "\n" . $address;
|
|
$address_string = $location->name . "\n" . $address;
|
|
|
|
|
|
|
|
// OK
|
|
// OK
|
|
|
- $invoice = new Document();
|
|
|
|
|
- $invoice->company_id = $sale->company_id;
|
|
|
|
|
- $invoice->user_id = $this->user->id;
|
|
|
|
|
- $invoice->sale_id = $sale->id;
|
|
|
|
|
- $invoice->location_id = $location->id;
|
|
|
|
|
- $invoice->type = DocumentTypes::INVOICE;
|
|
|
|
|
- $invoice->invoice_status = InvoiceStatuses::DRAFT;
|
|
|
|
|
- $invoice->currency = $sale->currency;
|
|
|
|
|
- $invoice->tax_rate = $sale->tax_rate;
|
|
|
|
|
- $invoice->billing_address = $address_string;
|
|
|
|
|
- $invoice->delivery_address = $address_string;
|
|
|
|
|
- $invoice->number = Document::getNextNumber(DocumentTypes::INVOICE);
|
|
|
|
|
- $invoice->date = date("Y-m-d");
|
|
|
|
|
- $invoice->contact_name = $location->contact_name;
|
|
|
|
|
- $invoice->contact_phone = $location->contact_phone;
|
|
|
|
|
- $invoice->contact_email = $location->contact_email;
|
|
|
|
|
- $invoice->dts_created = Database::dts();
|
|
|
|
|
- $invoice->commit();
|
|
|
|
|
|
|
+ $document = new Document();
|
|
|
|
|
+ $document->company_id = $sale->company_id;
|
|
|
|
|
+ $document->user_id = $this->user->id;
|
|
|
|
|
+ $document->sale_id = $sale->id;
|
|
|
|
|
+ $document->location_id = $location->id;
|
|
|
|
|
+ $document->type = DocumentTypes::SALE_ORDER;
|
|
|
|
|
+ $document->invoice_status = SaleOrderStatuses::DRAFT;
|
|
|
|
|
+ $document->currency = $sale->currency;
|
|
|
|
|
+ $document->tax_rate = $sale->tax_rate;
|
|
|
|
|
+ $document->billing_address = $address_string;
|
|
|
|
|
+ $document->delivery_address = $address_string;
|
|
|
|
|
+ $document->number = Document::getNextNumber(DocumentTypes::SALE_ORDER);
|
|
|
|
|
+ $document->date = date("Y-m-d");
|
|
|
|
|
+ $document->contact_name = $location->contact_name;
|
|
|
|
|
+ $document->contact_phone = $location->contact_phone;
|
|
|
|
|
+ $document->contact_email = $location->contact_email;
|
|
|
|
|
+ $document->dts_created = Database::dts();
|
|
|
|
|
+ $document->commit();
|
|
|
|
|
|
|
|
foreach($sale_items as $sale_item) {
|
|
foreach($sale_items as $sale_item) {
|
|
|
$product = $sale_item->getProduct();
|
|
$product = $sale_item->getProduct();
|
|
|
$supplier = $product->getSupplier();
|
|
$supplier = $product->getSupplier();
|
|
|
|
|
|
|
|
- $invoice_item = new DocumentItem();
|
|
|
|
|
- $invoice_item->document_id = $invoice->id;
|
|
|
|
|
- $invoice_item->description = $product->name . " ($supplier->name)";
|
|
|
|
|
- $invoice_item->quantity = $sale_item->quantity;
|
|
|
|
|
- $invoice_item->unit_price = $sale_item->unit_price;
|
|
|
|
|
- $invoice_item->dts_created = Database::dts();
|
|
|
|
|
- $invoice_item->commit();
|
|
|
|
|
|
|
+ $item = new DocumentItem();
|
|
|
|
|
+ $item->document_id = $document->id;
|
|
|
|
|
+ $item->description = $product->name . " ($supplier->name)";
|
|
|
|
|
+ $item->quantity = $sale_item->quantity;
|
|
|
|
|
+ $item->unit_price = $sale_item->unit_price;
|
|
|
|
|
+ $item->dts_created = Database::dts();
|
|
|
|
|
+ $item->commit();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Session::addAlert("success", __("Invoice created successfully."));
|
|
|
|
|
- Http::redirect($sale->getUrl() . "/invoices/" . $invoice->number);
|
|
|
|
|
|
|
+ Session::addAlert("success", __("Sale Order created successfully."));
|
|
|
|
|
+ Http::redirect($sale->getUrl() . "/sale-orders/" . $document->number);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
};
|
|
};
|
|
@@ -330,8 +330,8 @@ switch($action) {
|
|
|
case "items-batch-action":
|
|
case "items-batch-action":
|
|
|
$batch_action = $request->string("batch_action");
|
|
$batch_action = $request->string("batch_action");
|
|
|
switch($batch_action) {
|
|
switch($batch_action) {
|
|
|
- case "create-invoice":
|
|
|
|
|
- $controller->createInvoiceFromItems();
|
|
|
|
|
|
|
+ case "create-sale-order":
|
|
|
|
|
+ $controller->createSaleOrderFromItems();
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case "delete":
|
|
case "delete":
|