diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 81a01bcb6..7f42c8a18 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -154,6 +154,12 @@ abstract class DocumentForm extends Component /** @var bool */ public $hideAmount; + + /** @var bool */ + public $isSalePrice; + + /** @var bool */ + public $isPurchasePrice; /** Items Component End */ /** @@ -183,7 +189,8 @@ abstract class DocumentForm extends Component string $textItems = '', string $textQuantity = '', string $textPrice = '', string $textAmount = '', bool $hideItems = false, bool $hideName = false, bool $hideDescription = false, bool $hideQuantity = false, bool $hidePrice = false, bool $hideDiscount = false, bool $hideAmount = false, - bool $hideEditItemColumns = false + bool $hideEditItemColumns = false, + bool $isSalePrice = false, bool $isPurchasePrice = false /** Items Component End */ ) { $this->type = $type; @@ -249,6 +256,8 @@ abstract class DocumentForm extends Component $this->hideAmount = $this->getHideAmount($type, $hideAmount); $this->hideEditItemColumns = $hideEditItemColumns; + $this->isSalePrice = $isSalePrice; + $this->isPurchasePrice = $isPurchasePrice; /** Items Component End */ } diff --git a/app/View/Components/SelectItemButton.php b/app/View/Components/SelectItemButton.php index ca49d377a..9fa8b4e12 100644 --- a/app/View/Components/SelectItemButton.php +++ b/app/View/Components/SelectItemButton.php @@ -21,7 +21,7 @@ class SelectItemButton extends Component * * @return void */ - public function __construct(string $type = 'sale', bool $isSale = true, bool $isPurchase = false) + public function __construct(string $type = 'sale', bool $isSale = false, bool $isPurchase = false) { $this->type = $type; $this->isSale = $isSale; @@ -36,13 +36,10 @@ class SelectItemButton extends Component public function render() { $items = Item::enabled()->orderBy('name')->take(setting('default.select_limit'))->get(); + $price_type= $this->getPriceType($this->type, $this->isSale, $this->isPurchase); foreach ($items as $item) { - $price = $item->sale_price; - - if ($this->type == 'purchase' || $this->isPurchase) { - $price = $item->purchase_price; - } + $price = $item->{$price_type . '_price'}; $item->price = $price; } @@ -51,4 +48,30 @@ class SelectItemButton extends Component return view('components.select-item-button', compact('items', 'price')); } + + protected function getPriceType($type, $is_sale, $is_purchase) + { + if (!empty($is_sale)) { + return 'sale'; + } + + if (!empty($is_sale)) { + return 'purchase'; + } + + switch ($type) { + case 'bill': + case 'expense': + case 'purchase': + $type = 'purchase'; + break; + case 'sale': + case 'income': + case 'invoice': + default: + $type = 'sale'; + } + + return $type; + } } diff --git a/resources/views/components/documents/form/items.blade.php b/resources/views/components/documents/form/items.blade.php index 140a619f8..d98fdd12e 100644 --- a/resources/views/components/documents/form/items.blade.php +++ b/resources/views/components/documents/form/items.blade.php @@ -80,7 +80,11 @@ @stack('add_item_td_start')