| 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/BuildStockProduct.php |
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class BuildStockProduct extends Model
{
use HasFactory , SoftDeletes;
protected $fillable = [
'product_id','part_number' , 'name' , 'cost' , 'price' , 'description' , 'image' , 'is_active' , 'weight' , 'grn' ,
'user_id' , 'product_category_id' , 'wages' , 'diamond_size' , 'qty', 'for_sale' , 'original_wages','weight_description','supplier_rate','gia_number','supplier_id',
'fixed_price','build_stock_date_id' , 'wages_in_weight' , 'original_wages_in_weight' , 'old_code' , 'original_invoice','purity_upgrade_to','selling_purity','purity_level',
];
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 sales()
{
return $this->hasMany(Sale::class);
}
public function qtyHistory()
{
return $this->hasMany(QtyHistory::class);
}
public function buildStockProductAttributes(){
return $this->hasMany(BuildStockProductAttribute::class);
}
public function supplier(){
return $this->belongsTo(Supplier::class);
}
public function buildStockDate(){
return $this->belongsTo(BuildStockDate::class);
}
public function goldWeight(){
if(isset($this->productCategory->name)) {
if ($this->productCategory->purity_level) {
// dd($this->product-categories->purity_level * $this->weight , $this->weight);
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;
// }
}
public function sellingPrice(){
if(isset($this->productCategory->name)){
if($this->productCategory->fixed_price==true || $this->fixed_price==true){
return $this->price;
}
else{
// if($this->product-categories->parent?->name=='Platinum'|| $this->product-categories->parent?->name=='ផ្លាកទីន'||$this->product-categories->parent?->name=='แพลตตินัม'){
// $price = ($this->goldWeight()*$this->product-categories->price());
// dd($this->goldWeight(), $this->product-categories->price(),$price);
// }else{
$price = ($this->weight*$this->productCategory->sellingPrice());
// }
$productAttributes = $this->buildStockProductAttributes;
foreach($productAttributes as $productAttribute){
$price = $price+ $productAttribute->price;
}
// dd($this->weight , $this->product-categories->sellingPrice());
// dd($price , $this->wages , $productAttributes);
return $price+$this->wages;
}
}
return null;
}
public function sellingCost($weight=null, $price=null){
if(isset($this->productCategory->name)){
if($this->productCategory->fixed_price==true || $this->fixed_price==true||($this->productCategory->name=='មាសថៃ'||$this->productCategory->name=='Thai Gold'||$this->productCategory->name=='ทองไทย')){
if($this->fixed_price){
return $this->cost;
}
return $this->cost;
}
// else if($this->product-categories->name == 'មាស' || $this->product-categories->name == 'Gold' || $this->product-categories->name == 'ทอง'){
// $cost = $this->cost;
// $productAttributes = $this->productAttributes;
// foreach($productAttributes as $productAttribute){
// $cost = $cost+ $productAttribute->cost;
// }
// return $cost;
// }
else{
$cost = ($weight??$this->weight)*$this->productCategory->price($price);
$productAttributes = $this->buildStockProductAttributes;
foreach($productAttributes as $productAttribute){
$cost = $cost+ $productAttribute->cost;
}
// return $cost+$this->original_wages;
return $cost;
}
}
return null;
}
public function cost($weight = null, $date=null){
if($weight!=null){
$this->weight = $weight;
}
if($this->for_sale == 0){
if($this->part_number == ''){
$cost = $this->weight * ($this->productCategory->price(null, null, $date));
return $cost;
}
$cost = $this->weight * ($this->supplier_rate / 1000);
return $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->productAttributes()->sum('cost');
}
}