Path : /var/www/html/jewelry-pos/app/Console/Commands/ |
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/Console/Commands/BuildStock.php |
<?php namespace App\Console\Commands; use App\Models\BuildStockDate; use App\Models\BuildStockProduct; use App\Models\BuildStockProductAttribute; use App\Models\Product; use App\Models\ProductCategory; use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Support\Facades\Auth; class BuildStock extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'build:stock {id}'; /** * The console command description. * * @var string */ protected $description = 'This Commands will run Build Ending Stock From Products'; /** * Execute the console command. */ public function handle() { $id = $this->argument('id'); $buildStock = BuildStockDate::create([ 'user_id' => Auth::user()->id, 'build_date' => Carbon::now()->toDateTimeString(), ]); if($id){ $category = ProductCategory::findOrFail($id); $products = Product::where('qty' , '>' , 0)->whereIn('product_category_id' , $category->IdvsAllSubCategories())->get(); } else{ $category_ids = ProductCategory::where('is_active', true)->pluck('id'); $products = Product::where('qty' , '>' , 0)->whereIn('product_category_id' , $category_ids)->get(); } foreach ($products as $product){ // $product['created_at'] = Carbon::now()->toDateTimeString(); $buildStockProduct = BuildStockProduct::create([ 'product_id' => $product->id, 'part_number'=> $product->part_number , 'name' => $product->name, 'cost' => $product->cost, 'price' => $product->price, 'description' => $product->description, 'image' => $product->image, 'is_active' => $product->is_active, 'weight' => $product->weight??0, 'grn'=> $product->grn , 'user_id'=> $product->user_id , 'product_category_id'=> $product->product_category_id , 'wages'=> $product->selling_wagesInWeight(), 'wages_in_weight'=> $product->wages_in_weight , 'original_wages_in_weight'=> $product->original_wages_in_weight , 'diamond_size'=> $product->diamond_size , 'qty'=> $product->qty, 'for_sale'=> $product->for_sale , 'original_wages'=> $product->cost_wagesInWeight(), 'weight_description'=> $product->weight_description, 'supplier_id' => $product->supplier_id, 'supplier_rate' => $product->supplier_rate, 'gia_number' => $product->gia_number, 'fixed_price' => $product->fixed_price??false, 'build_stock_date_id'=>$buildStock->id, 'created_at'=>$buildStock->created_at, 'purity_level' => $product->purity_level??0, 'purity_upgrade_to' => $product->purity_upgrade_to??0, 'selling_purity' => $product->selling_purity??0, 'old_code' => $product->old_code??0, 'original_invoice' => $product->original_invoice, ]); foreach($product->productAttributes as $productAttribute){ BuildStockProductAttribute::create([ 'name' =>$productAttribute->name, 'cost' =>$productAttribute->cost, 'price'=>$productAttribute->price , 'qty'=>$productAttribute->qty, 'build_stock_product_id'=>$buildStockProduct->id, ]); } } } }