@@ -152,16 +152,14 @@ class Invoice
152152 *
153153 * @throws \Illuminate\Contracts\Container\BindingResolutionException
154154 */
155- public function __construct ($ name = 'Invoice ' )
155+ public function __construct ($ name = '' )
156156 {
157157 // Invoice
158- $ this ->name = $ name ;
158+ $ this ->name = $ name ?: __ ( ' invoices::invoice.invoice ' ) ;
159159 $ this ->seller = app ()->make (config ('invoices.seller.class ' ));
160160 $ this ->items = Collection::make ([]);
161161 $ this ->template = 'default ' ;
162162
163- $ this ->status = config ('invoices.status ' );
164-
165163 // Date
166164 $ this ->date = Carbon::now ();
167165 $ this ->date_format = config ('invoices.date.format ' );
@@ -197,7 +195,7 @@ public function __construct($name = 'Invoice')
197195 *
198196 * @return Invoice
199197 */
200- public static function make ($ name = 'Invoice ' )
198+ public static function make ($ name = '' )
201199 {
202200 return new static ($ name );
203201 }
@@ -249,20 +247,31 @@ public function addItems($items)
249247 */
250248 public function render ()
251249 {
252- if (!$ this ->pdf ) {
253- $ this ->beforeRender ();
250+ if ($ this ->pdf ) {
251+ return $ this ;
252+ }
254253
255- $ template = sprintf ('invoices::templates.%s ' , $ this ->template );
256- $ view = View::make ($ template , ['invoice ' => $ this ]);
257- $ html = mb_convert_encoding ($ view , 'HTML-ENTITIES ' , 'UTF-8 ' );
254+ $ this ->beforeRender ();
258255
259- $ this ->pdf = PDF ::setOptions (['enable_php ' => true ])->loadHtml ($ html );
260- $ this ->output = $ this ->pdf ->output ();
261- }
256+ $ template = sprintf ('invoices::templates.%s ' , $ this ->template );
257+ $ view = View::make ($ template , ['invoice ' => $ this ]);
258+ $ html = mb_convert_encoding ($ view , 'HTML-ENTITIES ' , 'UTF-8 ' );
259+
260+ $ this ->pdf = PDF ::setOptions (['enable_php ' => true ])->loadHtml ($ html );
261+ $ this ->output = $ this ->pdf ->output ();
262262
263263 return $ this ;
264264 }
265265
266+ public function toHtml ()
267+ {
268+ $ this ->beforeRender ();
269+
270+ $ template = sprintf ('invoices::templates.%s ' , $ this ->template );
271+
272+ return View::make ($ template , ['invoice ' => $ this ]);
273+ }
274+
266275 /**
267276 * @throws Exception
268277 *
0 commit comments