소스 검색

feat: print pdf purchase master

부모
커밋
680f5b3a28

+ 13
- 6
app/Http/Controllers/PurchaseController.php 파일 보기

@@ -2,18 +2,19 @@
2 2
 
3 3
 namespace App\Http\Controllers;
4 4
 
5
-use App\Http\Requests\Purchase\StorePurchaseRequest;
6
-use App\Http\Requests\Purchase\UpdatePurchaseRequest;
7 5
 use App\Models\Ppn;
6
+use Inertia\Inertia;
8 7
 use App\Models\Product;
9 8
 use App\Models\Purchase;
10
-use App\Models\PurchaseDetail;
11
-use App\Models\StockProduct;
12 9
 use App\Models\Supplier;
10
+use App\Models\StockProduct;
11
+use App\Models\PurchaseDetail;
13 12
 use App\Services\HelperService;
14
-use Illuminate\Database\QueryException;
13
+use Barryvdh\DomPDF\Facade\Pdf;
15 14
 use Illuminate\Support\Facades\DB;
16
-use Inertia\Inertia;
15
+use Illuminate\Database\QueryException;
16
+use App\Http\Requests\Purchase\StorePurchaseRequest;
17
+use App\Http\Requests\Purchase\UpdatePurchaseRequest;
17 18
 
18 19
 class PurchaseController extends Controller
19 20
 {
@@ -319,4 +320,10 @@ class PurchaseController extends Controller
319 320
     {
320 321
         //
321 322
     }
323
+
324
+    public function pdf(Purchase $purchase)
325
+    {
326
+        $pdf = Pdf::loadView("pdf.purchases", compact("purchase"));
327
+        return $pdf->stream();
328
+    }
322 329
 }

+ 12
- 0
resources/js/pages/Purchases/Show.vue 파일 보기

@@ -4,9 +4,11 @@ import { IDRCurrencyFormat } from '@/utils/helpers'
4 4
 import { cartTable } from './config'
5 5
 import Cart from './Components/Cart.vue'
6 6
 import { useCart } from './Composables/useCart'
7
+import AppButtonLink from '@/components/AppButtonLink.vue'
7 8
 import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
8 9
 
9 10
 const props = defineProps({
11
+  id: Number,
10 12
   number: String,
11 13
   ppn: Number,
12 14
   status: String,
@@ -93,6 +95,16 @@ const { cart, totalCartPrice } = useCart(form, props.purchaseDetail)
93 95
           </div>
94 96
         </div>
95 97
       </div>
98
+
99
+      <div class="col-12 md:col-8 flex justify-content-end">
100
+        <AppButtonLink
101
+          label="Cetak"
102
+          icon="pi pi-print"
103
+          target="_blank"
104
+          :inertia-link="false"
105
+          :href="route('purchases.pdf', id)"
106
+        />
107
+      </div>
96 108
     </div>
97 109
   </DashboardLayout>
98 110
 </template>

+ 213
- 0
resources/views/pdf/purchases.blade.php 파일 보기

@@ -0,0 +1,213 @@
1
+<html>
2
+
3
+<head>
4
+    <style>
5
+        * {
6
+            font-family: Verdana, Arial, sans-serif;
7
+        }
8
+
9
+        table {
10
+            font-size: x-small;
11
+            border-collapse: collapse;
12
+            border-spacing: 0;
13
+            width: 100%;
14
+        }
15
+
16
+        tfoot tr td {
17
+            font-weight: bold;
18
+            font-size: x-small;
19
+        }
20
+
21
+        @page {
22
+            margin: 180px 50px;
23
+        }
24
+
25
+        #header {
26
+            position: fixed;
27
+            left: 0px;
28
+            top: -180px;
29
+            right: 0px;
30
+            height: 140px;
31
+            text-align: center;
32
+            padding-top: 20px;
33
+        }
34
+
35
+        #footer {
36
+            position: fixed;
37
+            left: 0px;
38
+            bottom: -180px;
39
+            right: 0px;
40
+            height: 150px;
41
+        }
42
+
43
+        .page:after {
44
+            content: counter(page, numeric);
45
+        }
46
+    </style>
47
+
48
+<body>
49
+    <div id="header">
50
+        <table>
51
+            <tr>
52
+                <td style="width: 65%;">
53
+                    <table>
54
+                        <tr>
55
+                            <td style="vertical-align: super;"><strong>To</strong></td>
56
+                            <td style="vertical-align: super;">:</td>
57
+                            <td style="padding: 0;">
58
+                                <table style="border-spacing: 0;">
59
+                                    <tr>
60
+                                        <td>Cahaya Agung</td>
61
+                                    </tr>
62
+                                    <tr>
63
+                                        <td>Anonym</td>
64
+                                    </tr>
65
+                                </table>
66
+                            </td>
67
+                        </tr>
68
+                        <tr>
69
+                            <td style="vertical-align: super"><strong>NPWP</strong></td>
70
+                            <td style="vertical-align: super">:</td>
71
+                            <td style="padding: 0">
72
+                                <table style="border-spacing: 0">
73
+                                    <tr>
74
+                                        <td>XXXXXXXXXXXXXXX</td>
75
+                                    </tr>
76
+                                </table>
77
+                            </td>
78
+                        </tr>
79
+                    </table>
80
+                </td>
81
+                <td style="width: 35%;">
82
+                    <table>
83
+                        <tr style="text-align: center">
84
+                            <td> <strong style="text-transform: uppercase; font-size: medium">INVOICE</strong></td>
85
+                        </tr>
86
+                        <tr>
87
+                            <td>
88
+                                <table>
89
+                                    <tr>
90
+                                        <td>Nama</td>
91
+                                        <td>:</td>
92
+                                        <td>XXXXXXXXXXXXXXX</td>
93
+                                    </tr>
94
+                                    <tr>
95
+                                        <td>NPWP</td>
96
+                                        <td>:</td>
97
+                                        <td>XXXXXXXXXXXXXXX</td>
98
+                                    </tr>
99
+                                    <tr>
100
+                                        <td>No HP</td>
101
+                                        <td>:</td>
102
+                                        <td>08XXXXXXXXXX</td>
103
+                                    </tr>
104
+                                    <tr>
105
+                                        <td>Email</td>
106
+                                        <td>:</td>
107
+                                        <td>Anonym</td>
108
+                                    </tr>
109
+                                    <tr>
110
+                                        <td>Nomor Penjualan</td>
111
+                                        <td>:</td>
112
+                                        <td>08XXXXXXXXXX</td>
113
+                                    </tr>
114
+                                    <tr>
115
+                                        <td>Tanggal</td>
116
+                                        <td>:</td>
117
+                                        <td>Anonym</td>
118
+                                    </tr>
119
+                                    <tr>
120
+                                        <td>Halaman</td>
121
+                                        <td>:</td>
122
+                                        <td class="page"></td>
123
+                                    </tr>
124
+                                </table>
125
+                            </td>
126
+                        </tr>
127
+                    </table>
128
+                </td>
129
+            </tr>
130
+        </table>
131
+    </div>
132
+
133
+    <div id="footer">
134
+    </div>
135
+
136
+    <div id="content">
137
+        <table>
138
+            <thead style="border-top: 1px solid black; border-bottom: 1px solid black;">
139
+                <tr>
140
+                    <th>No</th>
141
+                    <th>Keterangan</th>
142
+                    <th>QTY</th>
143
+                    <th>Satuan</th>
144
+                    <th>Harga Satuan</th>
145
+                    <th>Jumlah</th>
146
+                </tr>
147
+            </thead>
148
+            <tbody style="text-align: center;">
149
+                @for ($i = 0; $i < 150; $i++)
150
+                    <tr>
151
+                        <th>1</th>
152
+                        <td style="text-align: left;">Playstation IV - Black</td>
153
+                        <td>1</td>
154
+                        <td>pc</td>
155
+                        <td style="text-align: right;">1400.00</td>
156
+                        <td style="text-align: right;">1400.00</td>
157
+                    </tr>
158
+                @endfor
159
+            </tbody>
160
+            <tfoot style="border-top: 1px solid black; border-bottom: 1px solid black; text-align: right;">
161
+                <tr>
162
+                    <td colspan="4"></td>
163
+                    <td>Subtotal Rp</td>
164
+                    <td>1635.00</td>
165
+                </tr>
166
+                <tr>
167
+                    <td colspan="4"></td>
168
+                    <td>PPN 11%</td>
169
+                    <td>1929.3</td>
170
+                </tr>
171
+                <tr>
172
+                    <td colspan="4"></td>
173
+                    <td>Total Rp</td>
174
+                    <td>1929.3</td>
175
+                </tr>
176
+            </tfoot>
177
+        </table>
178
+
179
+        <table>
180
+            <tbody>
181
+                <tr>
182
+                    <td style="width: 40%;"></td>
183
+                    <td style="width: 60%;">
184
+                        <table style="width: 100%; text-align: right;">
185
+                            <thead style="margin-bottom: 20px;">
186
+                                <tr>
187
+                                    <td></td>
188
+                                    <td colspan="1">
189
+                                        <p style="margin-bottom: 75px; margin-top: 70px;">Cahaya Agung</p>
190
+                                    </td>
191
+                                </tr>
192
+                            </thead>
193
+                            <tbody>
194
+                                <tr>
195
+                                    <td>
196
+                                        <span
197
+                                            style="border-top: 1px solid black; width: 150px;display: inline-block; text-align: left;">Diterima</span>
198
+                                    </td>
199
+                                    <td>
200
+                                        <span
201
+                                            style="border-top: 1px solid black; width: 120px;display: inline-block; text-align: center;">Penjual</span>
202
+                                    </td>
203
+                                </tr>
204
+                            </tbody>
205
+                        </table>
206
+                    </td>
207
+                </tr>
208
+            </tbody>
209
+        </table>
210
+    </div>
211
+</body>
212
+
213
+</html>

+ 1
- 1
resources/views/pdf/sales.blade.php 파일 보기

@@ -81,7 +81,7 @@
81 81
                 <td style="width: 35%;">
82 82
                     <table>
83 83
                         <tr style="text-align: center">
84
-                            <td> <strong style="text-transform: uppercase; font-size: medium">Pembeli</strong></td>
84
+                            <td> <strong style="text-transform: uppercase; font-size: medium">INVOICE</strong></td>
85 85
                         </tr>
86 86
                         <tr>
87 87
                             <td>

+ 5
- 1
routes/web.php 파일 보기

@@ -9,7 +9,6 @@ use App\Http\Controllers\SalesController;
9 9
 use App\Http\Controllers\StockProductController;
10 10
 use App\Http\Controllers\SupplierController;
11 11
 use App\Http\Controllers\UserController;
12
-use App\Models\Sale;
13 12
 use Illuminate\Support\Facades\Route;
14 13
 
15 14
 /*
@@ -51,6 +50,11 @@ Route::middleware(["auth", "verified"])->group(function () {
51 50
 
52 51
     Route::resource("/purchases", PurchaseController::class);
53 52
 
53
+    Route::get("/purchases/pdf/{purchase}", [
54
+        PurchaseController::class,
55
+        "pdf",
56
+    ])->name("purchases.pdf");
57
+
54 58
     Route::resource("/sales", SalesController::class);
55 59
 
56 60
     Route::get("/sales/pdf/{sale}", [SalesController::class, "pdf"])->name(