Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
35.00% |
7 / 20 |
|
87.50% |
7 / 8 |
CRAP | |
0.00% |
0 / 1 |
| PurchaseDetails | |
35.00% |
7 / 20 |
|
87.50% |
7 / 8 |
25.58 | |
0.00% |
0 / 1 |
| purchase | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| product | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| category | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| brand | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| color | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| origin | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| size | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| storePurchaseDetails | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models\admin; |
| 4 | |
| 5 | use App\Models\Brand; |
| 6 | use App\Models\Category; |
| 7 | use App\Models\Color; |
| 8 | use App\Models\Origin; |
| 9 | use App\Models\Size; |
| 10 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 11 | use Illuminate\Database\Eloquent\Model; |
| 12 | |
| 13 | class PurchaseDetails extends Model |
| 14 | { |
| 15 | use HasFactory; |
| 16 | |
| 17 | protected $table = 'purchase_details'; |
| 18 | |
| 19 | protected $fillable = [ |
| 20 | 'purchase_id', |
| 21 | 'product_id', |
| 22 | 'variation_id', |
| 23 | 'inventory_received', |
| 24 | 'qty', |
| 25 | 'category_id', |
| 26 | 'brand_id', |
| 27 | 'color_id', |
| 28 | 'origin_id', |
| 29 | 'size_id', |
| 30 | 'purchase_price', |
| 31 | 'selling_price', |
| 32 | 'total', |
| 33 | ]; |
| 34 | |
| 35 | public function purchase() |
| 36 | { |
| 37 | return $this->belongsTo(Purchase::class); |
| 38 | } |
| 39 | |
| 40 | public function product() |
| 41 | { |
| 42 | return $this->belongsTo(Product::class, 'product_id'); |
| 43 | } |
| 44 | |
| 45 | public function category() |
| 46 | { |
| 47 | return $this->belongsTo(Category::class); |
| 48 | } |
| 49 | |
| 50 | public function brand() |
| 51 | { |
| 52 | return $this->belongsTo(Brand::class); |
| 53 | } |
| 54 | |
| 55 | public function color() |
| 56 | { |
| 57 | return $this->belongsTo(Color::class); |
| 58 | } |
| 59 | |
| 60 | public function origin() |
| 61 | { |
| 62 | return $this->belongsTo(Origin::class); |
| 63 | } |
| 64 | |
| 65 | public function size() |
| 66 | { |
| 67 | return $this->belongsTo(Size::class); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * ########################################### |
| 72 | * # Repository Methods Start # |
| 73 | * ########################################### |
| 74 | * */ |
| 75 | public static function storePurchaseDetails($purchase, $card) |
| 76 | { |
| 77 | return self::query()->create([ |
| 78 | 'purchase_id' => $purchase->id, |
| 79 | 'product_id' => $card->product_id, |
| 80 | 'qty' => $card->qty, |
| 81 | // purchase_cards has no category column and the add-to-cart form |
| 82 | // doesn't ask for one — take it from the product, which always has one. |
| 83 | 'category_id' => $card->product?->category_id, |
| 84 | 'brand_id' => $card->brand_id, |
| 85 | 'color_id' => $card->color_id, |
| 86 | 'size_id' => $card->size_id, |
| 87 | 'origin_id' => $card->origin_id, |
| 88 | 'purchase_price' => $card->purchase_price, |
| 89 | 'selling_price' => $card->selling_price, |
| 90 | 'total' => $card->total, |
| 91 | ]); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * ########################################### |
| 96 | * # Repository Methods END # |
| 97 | * ########################################### |
| 98 | * */ |
| 99 | } |