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

背景

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

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

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

路由文件

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');
}

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

PHP实现打印出库单,有没有实现过?的更多相关文章

  1. SAP打印出库单 新需求

    *&---------------------------------------------------------------------* *& Report  Z_SD_CKD ...

  2. SAP打印出库单需求

    *&---------------------------------------------------------------------* *& Report  Z_SD_CKD ...

  3. SAP 出库单新版

    *&---------------------------------------------------------------------* *& Report  ZSDR045 ...

  4. U811.1接口EAI系列之二--生成销售出库单调用U8的EAI通用处理方法--PowerBuilder语言

    1.销售系统销售出库,更新U811.1材料库存的EAI的XML生成. 2.主要根据U8配置会生成出库单和同时是否更新库存量,还是更新现存量等等. 3.具体参考代码如下: 作者:王春天 2013-11- ...

  5. SD--怎样增强是同一类出库单使用不同号码段

    在现实的业务中,一个公司有多个销售组织,它们使用同一个出库类型,业务往往希望它们创建的出库单的号码採用不同号码范围.但在sap里出库单号码范围是在出库单类型里设置,也就是使用同样的出库单类型,也就使用 ...

  6. 基于VUE实现的h5网页Web出库单入库单打印设计

    经过将近一个月的研发,初步实现了打印单据的自定义设计,样子还有点丑陋,但是功能基本都实现了,实现了以下功能: 1.表头表尾支持动态添加行.添加列.合并单元格(可多行多列合并). 2.表头表尾分别布局, ...

  7. WMS出库单重复

    发货通知单?WMS备货单选项勾选 不自动复制?新增?

  8. ERP出库审核业务(四十四)

    结束表单流程的代码: protected void btnSubmit_Click(object sender, EventArgs e) { if(this.txtreceiveDate.Text! ...

  9. 使用Jasperreporter生成入库出库单打印等报表操作

    项目需要打印报表:就是那种生成入库单,出库单等的操作.使用到的技术:使用iReport Designer5.1.0设计报表,使用struts2+jasperreporter生成最终填充数据的报表 首先 ...

随机推荐

  1. Ubuntu修改mysql编码格式

    今天在Ubuntu系统上部署了第一个net core的web网站,遇到了mysql入库数据乱码的情况.无奈,ubuntu系统不熟悉,mysql命令不熟悉,只得在网上查找各种资料.还是老规矩,主要参考的 ...

  2. Django项目:CRM(客户关系管理系统)--46--38PerfectCRM实现全局账号登录注销01

    python.exe manage.py startapp gbacc #urls.py """PerfectCRM URL Configuration The `url ...

  3. ios h5 出现的问题

    这几天在测试的时候,忽然发现手机ios 页面中的input 样式出现问题,安卓就没事. 实际应该是第一张图,在ios中出现的结果为第二张图    出现这个原因,主要是ios系统自带的设置,解决方法为 ...

  4. 凸优化 & 1概念

    ---恢复内容开始--- 放射集合 系数之和为1 相加仍然能在集合内,就是 纺射集合 子空间加一个常熟 就是纺射集合 , 例题2.1 一类特殊的线性方程组的解可以看作纺射 集合 纺射包 aff C 是 ...

  5. zk运维注意事项

    1 连接数容易占满 2 watches数 (应用上的比较多建议做个自动监控,告警)

  6. 洛谷P4145 上帝造题的七分钟2 / 花神游历各国(重题:洛谷SP2713 GSS4 - Can you answer these queries IV)

    题目背景 XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. 题目描述 "第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟,L说,要能修改,于是便有了对一段 ...

  7. 计蒜客 Prefix Free Code(字典树+树状数组)

    Consider n initial strings of lower case letters, where no initial string is a prefix of any other i ...

  8. POJ4852 Ants

    Ants Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20047   Accepted: 8330 Description ...

  9. PHP相关

    PHP简介 PHP超文本预处理器.是嵌入HTML文件中的服务器端脚本程序.换句话:PHP只能运行在服务器上. 一个HTML文件中,可以包含的代码:HTML代码.CSS代码.JS代码.PHP代码等. P ...

  10. JS更改字体颜色、背景颜色

    CSS 颜色十六进制值  http://www.w3school.com.cn/cssref/css_colorsfull.asp CSS background-color 属性 body { bac ...