Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 77
0.00% covered (danger)
0.00%
0 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
SaleCardRepository
0.00% covered (danger)
0.00%
0 / 77
0.00% covered (danger)
0.00%
0 / 9
342
0.00% covered (danger)
0.00%
0 / 1
 PruductQuery
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 brandCheck
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 colorCheck
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 sizeCheck
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 customer_previews_sale_card
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
6
 customer_details
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
42
 load_recent_add_product
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 save_product_saleCard
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 stockCheck
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Repository;
4
5use App\Models\admin\Customer;
6use App\Models\admin\PurchaseDetails;
7use App\Models\admin\Stock;
8use App\Models\SaleCard;
9
10class SaleCardRepository
11{
12    public function PruductQuery($id)
13    {
14        $product = PurchaseDetails::query()->where('product_id', $id)->first();
15        $price = $product->selling_price;
16
17        return $price;
18    }
19
20    public function brandCheck($id)
21    {
22        $product = Stock::query()->where('product_id', $id)->with(['brand'])->get()->unique('brand_id');
23        $html_data = '';
24        foreach ($product->unique('brand_id') as $val) {
25            $html_data .= '<option value="' . $val->brand_id . '">' . $val->brand->name . '</option>';
26        }
27
28        return $html_data;
29    }
30
31    public function colorCheck($id)
32    {
33        $product = Stock::query()->where('product_id', $id)->with(['color'])->get()->unique('color_id');
34        $html_data = '';
35        foreach ($product as $val) {
36            $html_data .= '<option value="' . $val->color_id . '">' . $val->color->name . '</option>';
37        }
38
39        return $html_data;
40    }
41
42    public function sizeCheck($id)
43    {
44        $product = Stock::query()->where('product_id', $id)->with(['size'])->get()->unique('size_id');
45        $html_data = '';
46        foreach ($product as $val) {
47            $html_data .= '<option value="' . $val->size_id . '">' . $val->size->name . '</option>';
48        }
49
50        return $html_data;
51    }
52
53    public function customer_previews_sale_card($customer_id)
54    {
55        $html_data = '';
56        $old_customers = SaleCard::query()->where('customer_id', $customer_id)->with('customer', 'product')->get();
57        foreach ($old_customers as $val) {
58            $html_data .= '<tr>
59                        <td class="productimgname">
60                            <a class="product-img">
61                            </a>
62                            <a href="javascript:void(0);">' . $val->product->name . '</a>
63                        </td>
64                        <td id="qty' . $val->id . '">' . $val->qty . '</td>
65                        <td>' . $val->brand->name . '</td>
66                        <td>' . $val->color->name . '</td>
67                        <td>' . $val->size->name . '</td>
68                        <td><span>' . $val->selling_price . '</span></td>
69                        <td class="text-end">' . $val->total_price . '<span></span></td>
70                        <td>
71                            <button  onclick="editItem(' . $val->id . ')" class="btn btn-outline-info"> <i class="fas fa-edit"></i> </button>
72                            <button href="#" onclick="deleteItem(' . $val->id . ')" class="btn btn-outline-danger"> <i class="fas fa-trash"></i> </button>
73                        </td>
74                    </tr>';
75        }
76
77        return $html_data;
78    }
79
80    public function customer_details($customer_id)
81    {
82        // BUG FIX: this used to return completely unstyled raw <h3>/<span> tags
83        // (no classes at all) — it looked fine the very first time the POS page
84        // loaded with a customer pre-selected (details.blade.php's own markup),
85        // but the moment you actually picked someone from the dropdown, THIS
86        // unstyled HTML replaced it, which is why the customer card looked
87        // "unorganized" only after selecting. Now matches the .pos-customer-card
88        // markup in sales/create.blade.php exactly, so both paths look the same.
89        // Also fixes a real stored-XSS gap: customer name/phone/address were
90        // being concatenated into HTML completely unescaped before.
91        $customer = Customer::query()->where('id', $customer_id)->first();
92        if (! $customer) {
93            return '<div class="pos-customer-empty"><i class="fas fa-user-slash"></i> Customer not found</div>';
94        }
95
96        $initial = strtoupper(substr($customer->name ?: '?', 0, 1));
97
98        $html = '<div class="pos-customer-card">'
99              . '<div class="pos-customer-avatar">' . e($initial) . '</div>'
100              . '<div class="pos-customer-card-body">'
101              . '<div class="pos-cust-name">' . e($customer->name) . '</div>';
102
103        if ($customer->phone) {
104            $html .= '<div class="pos-cust-meta"><i class="fas fa-phone-alt"></i> ' . e($customer->phone) . '</div>';
105        }
106        if ($customer->email) {
107            $html .= '<div class="pos-cust-meta"><i class="fas fa-envelope"></i> ' . e($customer->email) . '</div>';
108        }
109        if ($customer->address) {
110            $html .= '<div class="pos-cust-meta"><i class="fas fa-map-marker-alt"></i> ' . e($customer->address) . '</div>';
111        }
112
113        $html .= '</div></div>';
114
115        return $html;
116    }
117
118    public function load_recent_add_product($recent)
119    {
120        $html_data = '';
121        $html_data = '';
122        $html_data .= '
123                    <tr>
124                        <td class="productimgname">
125                            <a class="product-img">
126                            </a>
127                            <a href="javascript:void(0);">' . $recent->product->name . '</a>
128                        </td>
129                        <td >' . $recent->qty . '</td>
130                        <td>' . $recent->brand->name . '</td>
131                        <td>' . $recent->color->name . '</td>
132                        <td>' . $recent->size->name . '</td>
133                        <td><span>৳ ' . $recent->selling_price . '</span></td>
134                        <td class="text-end">৳ ' . $recent->total_price . '<span></span></td>
135                        <td>
136                            <a class="delete-set"> <i class="fas fa-trash"></i> </a>
137                        </td>
138                    </tr>';
139
140        return $html_data;
141    }
142
143    public function save_product_saleCard($data)
144    {
145        $product = PurchaseDetails::query()->where('product_id', $data['product_id'])->first();
146        $data['total_price'] = $data['qty'] * $product->selling_price;
147        $data_save = SaleCard::query()->create([
148            'customer_id' => $data['customer_id'],
149            'product_id' => $data['product_id'],
150            'brand_id' => $data['brand_id'],
151            'color_id' => $data['color_id'],
152            'size_id' => $data['size_id'],
153            'qty' => $data['qty'],
154            'selling_price' => $product->selling_price,
155            'total_price' => $data['total_price'],
156        ]);
157
158        return $data_save;
159    }
160
161    public function stockCheck($id)
162    {
163        $stock = Stock::query()->where('product_id', $id)->get();
164        $stockCheck = $stock->sum('stock_in') - $stock->sum('stock_out');
165
166        return $stockCheck;
167    }
168}