PHP实现打印出库单,有没有实现过?

PHP实现打印出库单,有没有实现过?

https://mp.weixin.qq.com/s/X3JldplICRq7KR0HNFcpuw

背景

有时候你在实现一个出库订单之类的功能模块,这里也有可能要你的站点也实现相应的打印出库单预览,今天给大家分享用laravel(TP也行),PHP原生的也行。有需要的可以学习学习

PHP实现打印出库单,有没有实现过?

源码实现,php原生的话,需要include相关的print文件

 

laravel,首先先引入print插件包,我是放在app目录里

PHP实现打印出库单,有没有实现过?

路由文件

Route::any('admin/outWares/{outWares}/printer', ['as'=> 'admin.outWares.printer', 'uses' => 'PrinterController@index']);

控制器文件 PrinterController

public function index($id) { $outWare = $this->outWareRepository->findWithoutFail($id); $since = $outWare->outWareSince; if (empty($outWare)) { Flash::error('OutWare not found'); return redirect(route('admin.outWares.index')); } //处理地址,当为自提时,地址为仓库的地址 if($outWare->mode == 0){ $province_name = count($outWare->regionProvince->where('region_type', 1)) ? current($outWare->regionProvince->where('region_type', 1))[0]->region_name : ''; $city_name = count($outWare->regionCity->where('region_type', 2)) ? current(current($outWare->regionCity->where('region_type', 2)))->region_name : ''; $district_name = count($outWare->regionDistrict->where('region_type', 3)) ? current(current($outWare->regionDistrict->where('region_type', 3)))->region_name : ''; $address = $province_name.$city_name.$district_name.$outWare->address; }else{ $province_name = count($outWare->ware->regionProvince->where('region_type', 1)) ? current($outWare->ware->regionProvince->where('region_type', 1))[0]->region_name : ''; $city_name = count($outWare->ware->regionCity->where('region_type', 2)) ? current(current($outWare->ware->regionCity->where('region_type', 2)))->region_name : ''; $district_name = count($outWare->ware->regionDistrict->where('region_type', 3)) ? current(current($outWare->ware->regionDistrict->where('region_type', 3)))->region_name : ''; $address = isset($outWare->ware) ? $province_name.$city_name.$district_name.$outWare->ware->address : ''; } $consignee = []; if($outWare->mode==0){ $consignee = $outWare->customer_name; $consignee_phone = $outWare->customer_phone; }else{ foreach($since as $so){ $consignee[$so->consignee] = $so->consignee_phone; } list($keys, $values) = array_divide($consignee); if(count($keys) > 0){ $consignee = implode('<br>',$keys); $consignee_phone = implode('<br>',$values); }else{ $consignee = ''; $consignee_phone = ''; } } if($outWare->demand_time == '0000-00-00 00:00:00' || empty($outWare->demand_time)){ $demand_time = ''; }else{ $demand_time = date('Y-m-d',strtotime($outWare->demand_time)); } $out_ware_detail = $this->getWareDetail($outWare->outWareDetail); $data = [ 'out_sn' => $outWare->out_sn, 'ware' => isset($outWare->ware) ? $outWare->ware->name : '', 'company' => isset($outWare->company) ? $outWare->company : '', 'telephone' => isset($outWare->ware) ? $outWare->ware->phone_1 : '', 'consignor' => isset($outWare->ware) ? $outWare->ware->director_1 : '', 'consignee' => $consignee, 'consignee_phone' => $consignee_phone, 'remark' => $outWare->remark, 'demand_time' => $demand_time, 'created_at' => $outWare->created_at->format('Y-m-d') ]; $address = $this->getWareAddress($address); $this->TCPDF($data,$out_ware_detail,$address); }

一些数据的处理,这里只做参考

/** * Function:处理地址样式居中 * User:wucy * @param $address * @return string */ public function getWareAddress($address) { if(strlen($address) < 80){ return <<<Eof <td rowspan="2" colspan="2" style="font-size: 16px;width: 455px;line-height:60px;">{ $address}</td> Eof; }else{ return <<<Eof <td rowspan="2" colspan="2" style="font-size: 16px;width: 455px;">{ $address}</td> Eof; } } /** * Function:获取出库单商品详情 * User:wucy * @param $outWareDetail * @return string */ public function getWareDetail($outWareDetail) { $temp_row_data = []; $collection = collect($outWareDetail); $grouped = $collection->groupBy(function ($item, $key) { return $item['sku_id']; }); $i=1; foreach ($grouped as $key => $item){ $temp_row_data[$key] = [ 'key_num' => $i++, 'goods_name' => isset($item[0]->goodsSku) ? $item[0]->goodsSku->goods->goods_name : '--', 'attr_name' => isset($item[0]->goodsSku) ? $item[0]->goodsSku->value_name : '--', 'goods_unit' => isset($item[0]->goodsSku) ? $item[0]->goodsSku->goods->goods_unit : '--', 'total' => abs($item->sum('goods_number')), 'remark_detail'=>isset($item[0]) ? $item[0]->remark_detail : '--', ]; } //dd($temp_row_data); if ($temp_row_data) { $item = ''; foreach ($temp_row_data as $v) { $item.= $this->getRowsTable($v); } return $item; } } /** * Function: * User:wucy * @param $data * @return string */ public function getRowsTable($data) { if($data){ return <<<Eof <tr> <td style="font-size: 16px;text-align: center;">{ $data['key_num']}</td> <td style="font-size: 16px;">{ $data['goods_name']}</td> <td style="font-size: 16px;text-align: center;">{ $data['attr_name']}</td> <td style="font-size: 16px;text-align: center;">{ $data['goods_unit']}</td> <td style="font-size: 16px;text-align: center;">{ $data['total']}</td> <td></td> <td></td> <td>{ $data['remark_detail']}</td> </tr> Eof; } }

模板文件

/** * Function:TCPDF * User:wucy * @param $data * @param $out_ware_detail */ public function TCPDF($data,$out_ware_detail,$address) { // create new PDF document $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('仓库系统'); $pdf->SetTitle('出库单'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 048', PDF_HEADER_STRING); // set header and footer fonts //$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); //$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //$pdf->SetFont('stsongstdlight','', 14); $pdf->SetFont('droidsansfallback','', 14); // add a page $pdf->AddPage(); $pdf->Write(0, '', '', 0, 'L', true, 0, false, false, 0); $pdf->setCellHeightRatio(1.3); $pdf->SetLineWidth(2); $tbl = <<<EOD <table cellpadding="0" cellspacing="0"> <tr> <th><img src="/adminResource/img/logo_5100.png" width="140" height="40"></th> <th style="font-size: 25px;font-weight: bold">出库单</th> </tr> </table> <table cellpadding="0" cellspacing="0"> <tr> <td style="font-weight: bold">单据日期:{ $data['created_at']}</td> <td colspan="1"></td> <td style="font-weight: bold;text-align: right;width:377px;">出库单号:{ $data['out_sn']}</td> </tr> </table> <table cellpadding="2" cellspacing="0" border="1" summary="出库单"> <tr> <th style="font-size: 18px;width:80px;font-weight: bold;">发货仓</th> <td style="font-size: 16px;width: 100px;">{ $data['ware']}</td> <th style="font-size: 18px;width:120px;font-weight: bold">收货公司</th> <td style="font-size: 16px;width: 150px;">{ $data['company']}</td> <th rowspan="2" style="font-size: 18px;width:130px;font-weight: bold;line-height:60px;">提货/收货地址</th> { $address} </tr> <tr> <th style="font-size: 18px;font-weight: bold">发货人</th> <td style="font-size: 16px;">{ $data['consignor']}</td> <th style="font-size: 18px;font-weight: bold">发货人电话</th> <td style="font-size: 16px;">{ $data['telephone']}</td> </tr> <tr> <th style="font-size: 18px;font-weight: bold">提货人/收货人信息</th> <td colspan="2" style="font-size: 16px;line-height:60px;">{ $data['consignee']}</td> <td style="font-size: 16px;line-height:60px;">{ $data['consignee_phone']}</td> <th style="font-size: 18px;font-weight: bold;line-height:60px;">要求配送时间</th> <td colspan="2" style="font-size: 16px;line-height:60px;">{ $data['demand_time']}</td> </tr> <tr> <th style="font-size: 18px;font-weight: bold">订单备注</th> <td colspan="6" style="font-size: 16px;">{ $data['remark']}</td> </tr> <tr> <th colspan="7" style="font-size: 18px;text-align: center;font-weight: bold">出库明细</th> </tr> <tr> <td style="font-size: 18px;text-align: center;font-weight: bold;width:80px;">编号</td> <td style="font-size: 18px;text-align: center;font-weight: bold;width:275px;">货品名称</td> <td style="font-size: 18px;text-align: center;font-weight: bold;width:60px;">属性</td> <td style="font-size: 18px;text-align: center;font-weight: bold;width:70px;">单位</td> <td style="font-size: 18px;text-align: center;font-weight: bold;width:90px;">出货数量</td> <td style="font-size: 18px;text-align: center;font-weight: bold;width:90px;">实发数量</td> <td style="font-size: 18px;text-align: center;font-weight: bold;width:90px;">实收数量</td> <td style="font-size: 18px;text-align: center;font-weight: bold;width:280px;">备注</td> </tr> { $out_ware_detail} <tr> <th style="font-size: 18px;font-weight: bold">签收人</th> <td colspan="3"></td> <th style="font-size: 18px;font-weight: bold">签收日期</th> <td colspan="3"></td> </tr> <b>请签收人签字后务必将扫描件发至我司联系人邮箱,否则默认实收与实发数量一致</b> </table> EOD; $pdf->writeHTML($tbl, true, false, false, false, ''); // ----------------------------------------------------------------------------- //Close and output PDF document $pdf->Output('出库单_'.date('YmdHis').'.pdf', 'I'); }

全部文件都分享了,因为需求不一样,这里只做参考!

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/112907.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 《JavaScript 模式》读书笔记(8)— DOM和浏览器模式1

    在本书的前面章节中,我们主要集中关注于核心JavaScript(ECMAScript),而并没有太多关注在浏览器中使用JavaScript的模式。本章将探索一些浏览器特定的模式,因为浏览器是使用Jav

  • 爱因斯坦题目谁养鱼_爱因斯坦的问题有哪些

    爱因斯坦题目谁养鱼_爱因斯坦的问题有哪些在一条街上,有5座房子,喷了5种颜色,每个房里住着不同国籍的人,每个人喝不同的饮料,抽不同的香烟,养不同的宠物。请问,谁养鱼?

  • linux重命名文件和文件夹的区别_文件夹如何重命名

    linux重命名文件和文件夹的区别_文件夹如何重命名Linux重命名文件和文件夹1.mvlinux下重命名文件或文件夹的命令mv即可以重命名,又可以移动文件或文件夹。例子:将目录A重命名为BmvAB将/a目录移动到/b下,并重命名为cmv/a/b/c例子:ubuntu@ubuntu:~/Public/a2$tree….

  • extremedb是开源的吗_最简单的数据库开发软件

    extremedb是开源的吗_最简单的数据库开发软件最近我接触了嵌入式数据库eXtremeDB,由于这方面资料很少,网上的参考资料都大同小异,只靠着软件本身提供的参考文档进行开发,所以刚开始开发有些困难。故将基本的用法整理一下。关于eXtremeDB的特性,这里就不阐述了,直接从开发开始。下面以简单的模板为例进行阐述。1.构建.mco文件打开记事本,然后另存为XX.mco后缀文件。.mco文件里面需要定义数据库所需的字段类型,名称等,…

    2022年10月14日
  • redis的问题_redis高级数据类型

    redis的问题_redis高级数据类型备注:针对基本问题做一些基本的总结,不是详细解答!1.Redis在项目中的主要作用是是什么?怎么用的?(应用场景)2.Redis支持的数据类型(必考)3.zset跳表的数据结构(必考)4.Redis的数据过期策略(必考)5.Redis的LRU过期策略的具体实现6.如何解决Redis缓存雪崩,缓存穿透问题7.Redis的持久化机制(必考)8.Redis的管道pipel…

  • VMWARE虚拟机上网三种方法分析

    VMWARE虚拟机上网三种方法分析VMWARE虚拟机不能上网三种方法分析  PostBy:2009-1-2320:43:00 bridged(桥接模式)、NAT(网络地址转换模式)host-only(主机模式)。理论理解:1.bridged(桥接模式)在这处模式下,虚拟机等同于网络内的一台物理主机,可对手动设置IP,子网掩码,DNS,且IP地址要和主机的IP在同一网段内。这样,虚拟机就和主

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号