diff --git a/app/Export/CSV/ProductSalesExport.php b/app/Export/CSV/ProductSalesExport.php index f47acfa4dcfe..194a3984bbdf 100644 --- a/app/Export/CSV/ProductSalesExport.php +++ b/app/Export/CSV/ProductSalesExport.php @@ -37,6 +37,7 @@ class ProductSalesExport extends BaseExport 'product_key' => 'product_key', 'notes' => 'notes', 'quantity' => 'quantity', + 'currency' => 'currency', 'cost' => 'price', 'price' => 'cost', 'markup' => 'markup', @@ -163,6 +164,7 @@ class ProductSalesExport extends BaseExport private function buildRow($invoice, $invoice_item) :array { $transformed_entity = (array)$invoice_item; + $transformed_entity['price'] = ($invoice_item->product_cost ?? 1 ) * ($invoice->exchange_rate ?? 1) ; $entity = []; @@ -171,6 +173,8 @@ class ProductSalesExport extends BaseExport if (array_key_exists($key, $transformed_entity)) { $entity[$keyval] = $transformed_entity[$key]; + } elseif($key == 'currency') { + $entity['currency'] = $invoice->client->currency()->code; } else { $entity[$keyval] = ''; } @@ -184,9 +188,9 @@ class ProductSalesExport extends BaseExport private function decorateAdvancedFields(Invoice $invoice, $entity) :array { - $product = $this->getProduct($entity['product_key']); - - $entity['cost'] = $product->cost ?? 0; + + //$product = $this->getProduct($entity['product_key']); + // $entity['cost'] = $product->cost ?? 0; /** @var float $unit_cost */ $unit_cost = $entity['cost'] == 0 ? 1 : $entity['cost']; diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 6083c136d9a7..97c0c68d04be 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -71,7 +71,6 @@ class PreviewController extends BaseController $ps = new PdfService($invitation, 'product', [ 'client' => $client ?? false, - // 'vendor' => $vendor ?? false, "{$entity_prop}s" => [$entity_obj], ]); diff --git a/app/Http/Controllers/PreviewPurchaseOrderController.php b/app/Http/Controllers/PreviewPurchaseOrderController.php index e0dbd3343029..c04748adab12 100644 --- a/app/Http/Controllers/PreviewPurchaseOrderController.php +++ b/app/Http/Controllers/PreviewPurchaseOrderController.php @@ -191,7 +191,7 @@ class PreviewPurchaseOrderController extends BaseController $invitation->setRelation($request->entity, $entity_obj); } - + $ps = new PdfService($invitation, 'purchase_order', [ 'client' => $entity_obj->client ?? false, 'vendor' => $vendor ?? false, diff --git a/app/Http/Controllers/RecurringInvoiceController.php b/app/Http/Controllers/RecurringInvoiceController.php index aae571d71dcb..c0412442dc4b 100644 --- a/app/Http/Controllers/RecurringInvoiceController.php +++ b/app/Http/Controllers/RecurringInvoiceController.php @@ -387,7 +387,6 @@ class RecurringInvoiceController extends BaseController $recurring_invoice->service() ->triggeredActions($request) - // ->deletePdf() ->save(); event(new RecurringInvoiceWasUpdated($recurring_invoice, $recurring_invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); diff --git a/app/Http/Requests/Preview/PreviewPurchaseOrderRequest.php b/app/Http/Requests/Preview/PreviewPurchaseOrderRequest.php index 4ec935f7de4e..b553eb87645c 100644 --- a/app/Http/Requests/Preview/PreviewPurchaseOrderRequest.php +++ b/app/Http/Requests/Preview/PreviewPurchaseOrderRequest.php @@ -58,7 +58,11 @@ class PreviewPurchaseOrderRequest extends Request $input['amount'] = 0; $input['balance'] = 0; $input['number'] = isset($input['number']) ? $input['number'] : ctrans('texts.live_preview').' #'.rand(0, 1000); //30-06-2023 - + + if($input['entity_id'] ?? false) { + $input['entity_id'] = $this->decodePrimaryKey($input['entity_id'], true); + } + $this->replace($input); } diff --git a/app/Models/PurchaseOrder.php b/app/Models/PurchaseOrder.php index 45dc8dc68181..4c4804c1f2a8 100644 --- a/app/Models/PurchaseOrder.php +++ b/app/Models/PurchaseOrder.php @@ -117,6 +117,14 @@ class PurchaseOrder extends BaseModel use SoftDeletes; use MakesDates; + protected $hidden = [ + 'id', + 'private_notes', + 'user_id', + 'vendor_id', + 'company_id', + ]; + protected $fillable = [ 'number', 'discount', diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index 44e8c61265cf..af15ce73bd07 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -343,6 +343,21 @@ class RecurringInvoice extends BaseModel } } + public function calculateStatus() + { + + if($this->remaining_cycles == 0) { + return self::STATUS_COMPLETED; + } + elseif ($this->status_id == self::STATUS_ACTIVE && Carbon::parse($this->next_send_date)->isFuture()) { + return self::STATUS_PENDING; + } + else { + return $this->status_id; + } + + } + public function nextSendDate() :?Carbon { if (! $this->next_send_date_client) { diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 22e2d9cd93d3..6ac2775eeeed 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -365,6 +365,7 @@ class BaseRepository $model = $model->calc()->getRecurringInvoice(); + $model->status_id = $model->calculateStatus(); if ($this->new_model) { event('eloquent.created: App\Models\RecurringInvoice', $model); diff --git a/app/Services/Pdf/PdfConfiguration.php b/app/Services/Pdf/PdfConfiguration.php index 4dfd3f88acfc..a28789321409 100644 --- a/app/Services/Pdf/PdfConfiguration.php +++ b/app/Services/Pdf/PdfConfiguration.php @@ -221,7 +221,6 @@ class PdfConfiguration $this->vendor = $this->entity->vendor; $this->vendor_contact = $this->service->invitation->contact; $this->path = $this->vendor->purchase_order_filepath($this->service->invitation); - $this->entity_design_id = 'invoice_design_id'; $this->entity_design_id = 'purchase_order_design_id'; $this->settings = $this->vendor->company->settings; $this->settings_object = $this->vendor; @@ -274,6 +273,7 @@ class PdfConfiguration */ private function setDesign(): self { + $design_id = $this->entity->design_id ?: $this->decodePrimaryKey($this->settings_object->getSetting($this->entity_design_id)); $this->design = Design::withTrashed()->find($design_id) ?? Design::withTrashed()->find(2); diff --git a/resources/views/setup/index.blade.php b/resources/views/setup/index.blade.php index 0f77ee84b1e2..971289d9de69 100644 --- a/resources/views/setup/index.blade.php +++ b/resources/views/setup/index.blade.php @@ -12,7 +12,7 @@
{{ ctrans('texts.if_you_need_help') }} {{ ctrans('texts.support_forum') }}