Path : /var/www/html/jewelry-pos/app/Models/ |
B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H |
Current File : /var/www/html/jewelry-pos/app/Models/Sale.php |
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Model; class Sale extends Model { use HasFactory, SoftDeletes; public $fillable = [ 'product_id', 'part_number' , 'name' , 'cost' , 'description' , 'image' , 'weight' , 'product_category_id' , 'user_id' , 'wages' , 'invoice_no' ,'usd_amount','khr_amount','thb_amount','diamond_size', 'qty' , 'sales_price','invoice_no', 'member_id' , 'discount', 'already_buy_back' , 'buy_back_price' , 'buy_back_note' , 'date_buy_back' , 'buy_by_user' , 'original_wages','weight_description','selling_cost','selling_rate','fixed_price' , 'wages_in_weight' , 'original_wages_in_weight' , 'purity_upgrade_to' , 'selling_purity' , 'supplier_rate' , 'old_code' , 'original_invoice', 'purity_level', 'for_sale' ,'note', 'not_use_rate','gain_lose_amount','rate' ]; public function user() { return $this->belongsTo(User::class); } public function product() { return $this->belongsTo(Product::class); } public function productCategory() { return $this->belongsTo(ProductCategory::class); } public function member() { return $this->belongsTo(Member::class); } public function sellProductAttributes(){ return $this->hasMany(SellProductAttribute::class,'sell_id'); } public function cost(){ return $this->cost; // if($this->productCategory->fixed_price==true || $this->fixed_price==true||($this->productCategory->name=='មាសថៃ'||$this->productCategory->name=='Thai Gold'||$this->productCategory->name=='ทองไทย')){ // return $this->cost; // } // return $this->cost + $this->sellProductAttributes()->sum('cost'); } public function productCategoryNameSelling() { $purity = $this->selling_purity * 10; $productMainCategory = $this->productCategory->parent?->name . 'ទឹក ' .$purity; return $productMainCategory; } public function productCategoryNameUpgrade() { $name = ''; $productCategory = ProductCategory::where('purity_level' , $this->purity_upgrade_to)->first(); if($this->purity_upgrade_to){ $name = $productCategory->name; }else{ $name = $this->productCategory->name; } if($this->selling_purity){ $name = $this->productCategory->parent?->name . 'ទឹក ' . $this->selling_purity * 10; } return $name; } public function goldWeight(){ if(isset($this->productCategory->name)) { if ($this->productCategory->purity_level) { return $this->weight*$this->productCategory->purity_level; } return $this->weight; } return 0; } public function wagesInWeight() { if($this->productCategory->fixed_price||$this->fixed_price){ return $this->wages; }else{ if($this->supplier_rate==0){ return $this->wages; } $wages_in_weight = $this->wages / ($this->supplier_rate / 1000); // dd($wages_in_weight , $this->wages , $this->supplier_rate , $this); return $wages_in_weight; } // if($this->productCategory->parent?->name??'' == 'ផ្លាកទីន' || $this->productCategory->parent?->name??'' == 'Platinum' || $this->productCategory->parent?->name??'' == 'แพลตตินัม') { // $wages_in_weight = $this->wages / ($this->supplier_rate / 1000); // return $wages_in_weight; // } } public function originalWagesInWeight() { if ($this->productCategory->fixed_price||$this->fixed_price){ return $this->original_wages; }else{ if($this->supplier_rate==0){ return $this->original_wages; } $wages_in_weight = $this->original_wages / ($this->supplier_rate / 1000); return $wages_in_weight; } // if($this->productCategory->parent?->name??'' == 'ផ្លាកទីន' || $this->productCategory->parent?->name??'' == 'Platinum' || $this->productCategory->parent?->name??'' == 'แพลตตินัม') { // $wages_in_weight = $this->original_wages / ($this->supplier_rate / 1000); // return $wages_in_weight; // } } }