修复仓库订单导出功能
- 移除了 IndexController 中的旧代码,该代码已不再使用 - 优化了 WarehouseOrderController 中的导出逻辑: - 移除了 withTrashed() 方法,避免导出已删除的产品 - 修改了导出表格的列,增加了 'oid' 字段 - 调整了导出文件名的生成逻辑,现在使用仓库名称和日期组合
This commit is contained in:
parent
7d1e1055b8
commit
18fbbdeb36
@ -230,15 +230,15 @@ class WarehouseOrderController extends BaseAdminController
|
|||||||
$total_price=0;
|
$total_price=0;
|
||||||
foreach ($data as $key => &$value) {
|
foreach ($data as $key => &$value) {
|
||||||
if(in_array($order['store_id'],[17,18])){
|
if(in_array($order['store_id'],[17,18])){
|
||||||
$find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->withTrashed()->find();
|
$find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->find();
|
||||||
}else{
|
}else{
|
||||||
$find = StoreProduct::where('id', $value->product_id)->withTrashed()->find();
|
$find = StoreProduct::where('id', $value->product_id)->find();
|
||||||
}
|
}
|
||||||
$value->store_name = $find['store_name'] ?? '';
|
$value->store_name = $find['store_name'] ?? '';
|
||||||
$value->store_info = $find['store_info'] ?? '';
|
$value->store_info = $find['store_info'] ?? '';
|
||||||
if($type==2){
|
if($type==2){
|
||||||
$value->price = $find['purchase'];
|
$value->price = $value['purchase'];
|
||||||
$value->total_price=bcmul($find['purchase'],$value['nums'],2);
|
$value->total_price=bcmul($value['purchase'],$value['nums'],2);
|
||||||
$total_price+=$value->total_price;
|
$total_price+=$value->total_price;
|
||||||
}elseif($type==3){
|
}elseif($type==3){
|
||||||
$value->price = $find['cost'];
|
$value->price = $find['cost'];
|
||||||
@ -284,14 +284,14 @@ class WarehouseOrderController extends BaseAdminController
|
|||||||
{
|
{
|
||||||
$id = $this->request->post('id');
|
$id = $this->request->post('id');
|
||||||
$warehouseOrder = WarehouseOrder::where('id', $id)->field('store_id,delivery_time')->find();
|
$warehouseOrder = WarehouseOrder::where('id', $id)->field('store_id,delivery_time')->find();
|
||||||
$system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('name');
|
$system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('introduction');
|
||||||
$data = WarehouseProduct::where('oid', $id)->where('financial_pm',0)->field('product_id,nums')->select()
|
$data = WarehouseProduct::where('oid', $id)->where('financial_pm',0)->field('oid,product_id,nums')->select()
|
||||||
->each(function ($item) use ($system_store,$warehouseOrder) {
|
->each(function ($item) use ($system_store,$warehouseOrder) {
|
||||||
$item['system_store'] = $system_store;
|
$item['system_store'] = $system_store.' '.$item['oid'];
|
||||||
$find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->find();
|
$find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->find();
|
||||||
$item['store_name'] = $find['store_name'];
|
$item['store_name'] = $find['store_name'];
|
||||||
$unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
|
$unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||||
$item['unit_name'] = $item['nums'].'/'.$unit_name.' '.date('m-d',$warehouseOrder['delivery_time']);
|
$item['unit_name'] = $item['nums'].'/'.$unit_name.' '.date('m-d',$warehouseOrder['delivery_time']);
|
||||||
})
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
$file_path=(new Beforehand())->export($data, $system_store);
|
$file_path=(new Beforehand())->export($data, $system_store);
|
||||||
|
@ -48,41 +48,6 @@ class IndexController extends BaseApiController
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
// 创建一个新的PHPWord文档
|
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
||||||
|
|
||||||
// 添加一个节
|
|
||||||
$section = $phpWord->addSection(array(
|
|
||||||
'pageSizeW' => Converter::cmToTwip(4), // 宽度转换为twips
|
|
||||||
'pageSizeH' => Converter::cmToTwip(2), // 高度转换为twips
|
|
||||||
'marginLeft' => Converter::cmToTwip(0.2),
|
|
||||||
'marginRight' => Converter::cmToTwip(0),
|
|
||||||
'marginTop' => Converter::cmToTwip(0.2),
|
|
||||||
'marginBottom' => Converter::cmToTwip(0),
|
|
||||||
));
|
|
||||||
|
|
||||||
// 在节中添加一些内容
|
|
||||||
// 添加文本
|
|
||||||
$text = '这是一段测试文本,啊实打实的';
|
|
||||||
$text1 = '这是一段测试文本,啊实打实的';
|
|
||||||
$text2 = '这是一段测试文本,啊实打实的';
|
|
||||||
// 检查文本宽度是否超过纸张宽度
|
|
||||||
$fontStyle = ['name' => 'Arial', 'size' => 12, 'bold' => true];
|
|
||||||
|
|
||||||
// 比较文本宽度和纸张宽度
|
|
||||||
$section->addText(mb_substr($text, 0, 8, 'UTF-8'), $fontStyle);
|
|
||||||
$section->addText(mb_substr($text1, 0, 8, 'UTF-8'), $fontStyle);
|
|
||||||
$section->addText(mb_substr($text2, 0, 8, 'UTF-8'), $fontStyle);
|
|
||||||
$section->addText(mb_substr($text, 0, 8, 'UTF-8'), $fontStyle);
|
|
||||||
$section->addText(mb_substr($text1, 0, 8, 'UTF-8'), $fontStyle);
|
|
||||||
$section->addText(mb_substr($text2, 0, 8, 'UTF-8'), $fontStyle);
|
|
||||||
|
|
||||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
|
|
||||||
|
|
||||||
$url = '/export/' . date('Y-m') . '/' . '标签单-' . date('Y-m-d') . '.docx';
|
|
||||||
|
|
||||||
$a = $objWriter->save(public_path() . $url);
|
|
||||||
d($a);
|
|
||||||
return json(1);
|
return json(1);
|
||||||
|
|
||||||
$financeFlow = new StoreFinanceFlow();
|
$financeFlow = new StoreFinanceFlow();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user