Commit 859be2f3 by hcy001

1

parent 9b0e4a9b
......@@ -114,8 +114,15 @@ class ApiController extends Controller
Export((new InquiryModel())->addInquiry($input));
}
//生成报价/销售 询价单
private function ApiAddInquiryReport($request, $id){
(new InquiryItemsReportModel())->addOffer();
private function ApiAddInquiryReport($input, $id){
$InquiryItemsReportModel = new InquiryItemsReportModel();
$data = $InquiryItemsReportModel->addOffer(1,$input);
if ($data[0] > 0){
Export($data);
}
print_r($data);
$InquiryItemsReportModel->createSalePdf($data[2]["report_sn"]);
}
//删除询价列表
private function ApiDeleteInquiryItems($input, $id){
......
......@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Dompdf\Dompdf;
use Request;
use Barryvdh\DomPDF\PDF;
use Illuminate\Support\Facades\App;
......@@ -21,16 +22,23 @@ class HdController extends Controller
//pdf添加
private function a(){
$dompdf = new \Dompdf\Dompdf();
$options = new \Dompdf\Options();
$options->setIsPhpEnabled(true);
$options->setIsFontSubsettingEnabled(true);//启用字体子集,缩小pdf大小
$dompdf->loadHtml("dgaagagaga");
$dompdf->setPaper('A4', 'portrait');
$dompdf->setOptions($options);
//Init Dompdf object
$dompdf = new Dompdf();
//Generate HTML content
$html = '<h3 style="font-family:simsun;color:blue;">Hello World 你好</h3>';
$dompdf->loadHtml($html);
//Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
//Render the HTML as PDF
$dompdf->render();
$dompdf->save(storage_path('app/public/pdf/date.pdf'));
return $dompdf->stream('44444.pdf');
//Output the generated PDF to Browser
$pdfname = '中文abc';
return $dompdf->stream($pdfname);
}
private function test(){
......
......@@ -17,49 +17,88 @@ class InquiryItemsReportModel extends Model
protected $primaryKey = 'id';
public $timestamps = false;
//生成报价单
public function addOffer(){
/*
* 生成报价单或者销售单插入 report 表
* @param $types 类型: 1 报价单 2 (销售单)生成订单
*/
public function addOffer($types,$input){
$path = 'pdf/销售报价单'.date("Y-m-d").'.pdf';
PDF::loadHTML("<h1>gagagagag</h1>")
->setPaper('a4', 'portrait')
->setWarnings(false)
->save($path);
die();
try{
$con = DB::connection('rfq');
$con->beginTransaction();
$insertArr = []; //批量插入数组
foreach ($input as $k=>$v){
if (strpos($k,'items_') !== false){//实际数量
$inquiry_items_id= str_replace('items_','',$k); //异常明细ID
$abnormal_items_type = $input['abnormal_items_type_'.$itemId]; //处理类型
$report_sn = generateSnWithPreStringShort("R"); //报表单号
$inquiry_id = $input["inquiry_id"];
$currency = $input["currency"]; #币种
foreach ($v as $k1=>$v1){
if (!$v1){
jsonError("实际数量不得为0");
}
$insertArr[]=[
'abnormal_id'=>$abnormalID,
'picking_items_id'=>$picking_items_id,
'abnormal_number' => $k1 > 0 ? 0 : $abnormal_number, //原差异数量
'real_number' => $v1, //实际数量
'abnormal_items_type' => $abnormal_items_type[$k1], //不良品
];
$money = 0; //总计报价
$insertArr = []; //批量插入数组
foreach ($input["items"] as $k=>$inquiry_items_id){
$temp = [
"types"=>$types ,
"report_sn"=>$report_sn ,
"inquiry_id"=>$inquiry_id ,
"inquiry_items_id"=>$inquiry_items_id,
"goods_name"=>@$input["goods_name"][$k] ? $input["goods_name"][$k] : "" ,
"goods_name_pro"=>@$input["goods_name_pro"][$k] ? $input["goods_name_pro"][$k] : "" ,
"brand_id"=>@$input["brand_id"][$k] ? $input["brand_id"][$k] : "" ,
"brand_name"=>@$input["brand_name"][$k] ? $input["brand_name"][$k] : "" ,
"class_id2"=>@$input["class_id2"][$k] ? $input["class_id2"][$k] : "" ,
"class_id2_name"=>@$input["class_id2_name"][$k] ? $input["class_id2_name"][$k] : "" ,
"inquiry_number"=>@$input["inquiry_number"][$k] ? $input["inquiry_number"][$k] : "" ,
"delivery_time"=>@$input["delivery_time"][$k] ? $input["delivery_time"][$k] : "" ,
"batch"=>@$input["batch"][$k] ? $input["batch"][$k] : "" ,
"create_uid"=>$input["user_id"],
"create_name"=>$input["user_name"],
"create_time"=>time() ,
];
if ($currency == 1){
$temp["price_rmb"] =@$input["quote_price"][$k] ? $input["quote_price"][$k] : 0 ;
}else{
$temp["price_origin"] =@$input["quote_price"][$k] ? $input["quote_price"][$k] : 0;
}
}
}
try{
$con = DB::connection('web');
$con->beginTransaction();
array_push($insertArr,$temp);
if ($temp["quote_price"] > 0){
$money = $money + $temp["quote_price_count"];
}
}
print_r($insertArr);
die();
$this->where('abnormal_id', '=', $abnormalID)->delete(); //先批量删除,再插入
$this->insert($insertArr); //批量插入
$con->commit();
jsonSucces('提交审核成功');
return [0,"成功",["report_sn"=>$report_sn]];
}catch (\Exception $e) {
jsonError("提交审核失败,请重试!".$e->getMessage());
return [1001,"提交失败,请重试!".$e->getMessage()];
}
}
//生成报价pdf
public function createSalePdf($report_sn = ""){
if($report_sn == ""){
return [1001,"报表单号不得为空!"];
}
$itemsArr = $this->where("report_sn",$report_sn)->get()->toArray();
$quote_price_count = 0;
foreach ($itemsArr as $k=>&$v){
$v["quote_account"] = $v["price_rmb"] > 0 ? $v["price_rmb"]*$v["inquiry_number"] : $v["price_origin"]*$v["inquiry_number"];
$quote_price_count = $quote_price_count+$v["quote_account"];
}
$html = view('pdf.sale', compact($itemsArr, $quote_price_count))->render();
if (@$_REQUEST["flag"] == 100){
return $html;
}
$path = 'pdf/sale_report_'.time().'.pdf';
PDF::loadHTML($html)
->setPaper('a4', 'landscape') //横列
->setWarnings(false)
->save($path);
Export([0,"成功",$path]);
}
}
\ No newline at end of file
......@@ -37,8 +37,11 @@ return array(
* Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique,
* Times-Roman, Times-Bold, Times-BoldItalic, Times-Italic,
* Symbol, ZapfDingbats.
* \vendor\dompdf\dompdf\lib\fonts
*/
"font_dir" => storage_path('fonts/'), // advised by dompdf (https://github.com/dompdf/dompdf/pull/782)
// "font_dir" => storage_path('fonts/'), // advised by dompdf (https://github.com/dompdf/dompdf/pull/782)
"font_dir" => realpath(base_path())."/vendor/dompdf/dompdf/lib/fonts/",
"font_cache" =>realpath(base_path())."/vendor/dompdf/dompdf/lib/fonts/",
/**
* The location of the DOMPDF font cache directory
......@@ -48,7 +51,7 @@ return array(
*
* Note: This directory must exist and be writable by the webserver process.
*/
"font_cache" => storage_path('fonts/'),
// "font_cache" => storage_path('fonts/'),
/**
* The location of a temporary directory.
......
No preview for this file type
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>ichunt.com--{$data['order_sn']}</title>
<style type="text/css" media="screen">
*{ font-family: "simsun"; font-weight: normal;margin:0px;padding:0px; }
.pdf-box{margin:0 auto;font-size: 14px;color:#333;width:900px;padding:50px;}
.header{ text-align: center;font-size: 28px;color:#000; position: relative;}
.header img{width:120px;position: absolute;left:60px;top:10px;}
.bjdx{background: #ccffff;font-size: 28px;color:#0000DA;text-align: center;}
table{width:100%;border-collapse: collapse;}
table, th, td{border: 1px solid #000;}
table td{padding:10px;}
table td b,.table-tips b,.footer b{font-weight: bold;}
.table-tips{font-weight: bold;padding:20px 0;font-weight: normal;}
.footer{position: relative;}
.footer .pr30{position: relative;left:80px;}
.footer .pr60{position: relative;left:107px;}
.footer img{position: absolute;left: 731px;top: 40px;}
</style>
</head>
<body>
<div class="pdf-box" >
<div class="header" >
<img src="https://static.ichunt.com/dist/res/home/images/new_logo.png" style="float:left;">
<p class="company">
深圳市猎芯科技有限公司<br/>
ICHUNT TECHNOLOGY CO.,LTD
</p>
</div>
<div class="bjdx">报 价 单/ QUOTATION</div>
<div class="table1">
<table>
<tr>
<td colspan="2"></td>
<td colspan="2">Date:2020-7-14</td>
</tr>
<tr>
<td><b>Attn</b>:深圳市度申科技有限公司</td>
<td><b>C.C</b>:李美媛</td>
<td><b>Fax</b>:</td>
<td><b>Tel</b>: 0755-29823982</td>
</tr>
<tr>
<td><b>From</b>:深圳市猎芯科技有限公司</td>
<td><b>C.C</b>:杨娟</td>
<td><b>Fax</b>:18529505446</td>
<td><b>Tel</b>: 0755-23485782-8031</td>
</tr>
</table>
</div>
<div class="table-tips">
很高兴为您提供我们最优惠的价格和货期,请参看如下:<br/>
<b>We are pleased to quote our best price and delivery terms for your requirement as following:</b>
</div>
<div class="table2">
<table>
<tr>
<td>客户型号 Cust PartNo</td>
<td>原厂型号 Mfr PartNo</td>
<td>品牌 Mfr Name</td>
<td>报价(RMB含税)Quoted Price (RMB with 13%VAT,freight fee to factory and import fee )</td>
<td>报价(美金)QuotedPrice In USD</td>
<td>数量 Quantity</td>
<td>金额</td>
<td>货期 Std LeadTime</td>
<td>产品类型 Prod Type</td>
<td>DATE CODE</td>
</tr>
@if(!empty($itemsArr) && is_array($itemsArr))
@foreach($itemsArr as $k=>$v)
<tr>
<td>{{ @$v["goods_name"] }}</td>
<td>{{ @$v["goods_name_pro"] }}</td>
<td>{{ @$v["brand_name"] }}</td>
<td>{{ @$v["price_rmb"] }}</td>
<td>{{ @$v["price_origin"] }}</td>
<td>{{ @$v["inquiry_number"] }}</td>
<td>{{ @$v["quote_account"] }}</td>
<td>{{ @$v["delivery_time"] }}</td>
<td>{{ @$v["class_id2_name"] }}</td>
</tr>
@endforeach
@endif
<tr>
<td></td>
<td></td>
<td colspan="2"></td>
<td></td>
<td></td>
<td><b>TOTAL:</b></td>
<td colspan="2"><b>{{ $quote_price_count }}</b></td>
<td></td>
</tr>
</table>
</div>
<div class="footer" style="padding-top: 20px;">
<img src="./contract.png" width='150' height='150'>
<b style="font-size: 18px;font-weight: bold;color:#000;"> 条款和说明:<br>
Terms and conditions:</b>
<br>1.> <span class="pr30">付款方式:月结30天</span>
<br><span class="pr60">Payment Terms:</span>
<br>2.> <span class="pr30">参考货期仅供参考,需下单后以原厂回复为准。</span>
<br><b class="pr60">Leadtime is for reference only, order actual delivery date is subjected to Supplier’s final confirmation. </b>
<br>3.> <span class="pr30">所有库存均以我司确认为准。</span>
<br><b class="pr60">Available to sell stock is open to all customers based on our confirmation. </b>
<br>4.> <b class="pr30">Subject to ICHUNT TECHNOLOGY' terms </b>
</div>
</div>
</body>
</html>
No preview for this file type
<?php return array (
'sans-serif' => array(
'normal' => $fontDir . '\Helvetica',
'bold' => $fontDir . '\Helvetica-Bold',
'italic' => $fontDir . '\Helvetica-Oblique',
'bold_italic' => $fontDir . '\Helvetica-BoldOblique',
),
'times' => array(
'normal' => $fontDir . '\Times-Roman',
'bold' => $fontDir . '\Times-Bold',
'italic' => $fontDir . '\Times-Italic',
'bold_italic' => $fontDir . '\Times-BoldItalic',
),
'times-roman' => array(
'normal' => $fontDir . '\Times-Roman',
'bold' => $fontDir . '\Times-Bold',
'italic' => $fontDir . '\Times-Italic',
'bold_italic' => $fontDir . '\Times-BoldItalic',
),
'courier' => array(
'normal' => $fontDir . '\Courier',
'bold' => $fontDir . '\Courier-Bold',
'italic' => $fontDir . '\Courier-Oblique',
'bold_italic' => $fontDir . '\Courier-BoldOblique',
),
'helvetica' => array(
'normal' => $fontDir . '\Helvetica',
'bold' => $fontDir . '\Helvetica-Bold',
'italic' => $fontDir . '\Helvetica-Oblique',
'bold_italic' => $fontDir . '\Helvetica-BoldOblique',
),
'zapfdingbats' => array(
'normal' => $fontDir . '\ZapfDingbats',
'bold' => $fontDir . '\ZapfDingbats',
'italic' => $fontDir . '\ZapfDingbats',
'bold_italic' => $fontDir . '\ZapfDingbats',
),
'symbol' => array(
'normal' => $fontDir . '\Symbol',
'bold' => $fontDir . '\Symbol',
'italic' => $fontDir . '\Symbol',
'bold_italic' => $fontDir . '\Symbol',
),
'serif' => array(
'normal' => $fontDir . '\Times-Roman',
'bold' => $fontDir . '\Times-Bold',
'italic' => $fontDir . '\Times-Italic',
'bold_italic' => $fontDir . '\Times-BoldItalic',
),
'monospace' => array(
'normal' => $fontDir . '\Courier',
'bold' => $fontDir . '\Courier-Bold',
'italic' => $fontDir . '\Courier-Oblique',
'bold_italic' => $fontDir . '\Courier-BoldOblique',
),
'fixed' => array(
'normal' => $fontDir . '\Courier',
'bold' => $fontDir . '\Courier-Bold',
'italic' => $fontDir . '\Courier-Oblique',
'bold_italic' => $fontDir . '\Courier-BoldOblique',
),
'dejavu sans' => array(
'bold' => $fontDir . '\DejaVuSans-Bold',
'bold_italic' => $fontDir . '\DejaVuSans-BoldOblique',
'italic' => $fontDir . '\DejaVuSans-Oblique',
'normal' => $fontDir . '\DejaVuSans',
),
'dejavu sans mono' => array(
'bold' => $fontDir . '\DejaVuSansMono-Bold',
'bold_italic' => $fontDir . '\DejaVuSansMono-BoldOblique',
'italic' => $fontDir . '\DejaVuSansMono-Oblique',
'normal' => $fontDir . '\DejaVuSansMono',
),
'dejavu serif' => array(
'bold' => $fontDir . '\DejaVuSerif-Bold',
'bold_italic' => $fontDir . '\DejaVuSerif-BoldItalic',
'italic' => $fontDir . '\DejaVuSerif-Italic',
'normal' => $fontDir . '\DejaVuSerif',
),
'simsun' => array(
'normal' => $fontDir . '/simsun',
'bold' => $fontDir . '/simsun',
'italic' => $fontDir . '/simsun',
'bold_italic' => $fontDir . '/simsun',
),
) ?>
\ No newline at end of file
No preview for this file type
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
<?php
// 1. [Required] Point to the composer or dompdf autoloader
//require_once "vendor/autoload.php";
require_once "../../autoload.php";
// 2. [Optional] Set the path to your font directory
// By default dompdf loads fonts to dompdf/lib/fonts
// If you have modified your font directory set this
// variable appropriately.
//$fontDir = "lib/fonts";
// *** DO NOT MODIFY BELOW THIS POINT ***
use Dompdf\Dompdf;
use Dompdf\CanvasFactory;
use Dompdf\Exception;
use Dompdf\FontMetrics;
use Dompdf\Options;
use FontLib\Font;
/**
* Display command line usage
*/
function usage() {
echo <<<EOD
Usage: {$_SERVER["argv"][0]} font_family [n_file [b_file] [i_file] [bi_file]]
font_family: the name of the font, e.g. Verdana, 'Times New Roman',
monospace, sans-serif. If it equals to "system_fonts",
all the system fonts will be installed.
n_file: the .ttf or .otf file for the normal, non-bold, non-italic
face of the font.
{b|i|bi}_file: the files for each of the respective (bold, italic,
bold-italic) faces.
If the optional b|i|bi files are not specified, load_font.php will search
the directory containing normal font file (n_file) for additional files that
it thinks might be the correct ones (e.g. that end in _Bold or b or B). If
it finds the files they will also be processed. All files will be
automatically copied to the DOMPDF font directory, and afm files will be
generated using php-font-lib (https://github.com/PhenX/php-font-lib).
Examples:
./load_font.php silkscreen /usr/share/fonts/truetype/slkscr.ttf
./load_font.php 'Times New Roman' /mnt/c_drive/WINDOWS/Fonts/times.ttf
EOD;
exit;
}
if ( $_SERVER["argc"] < 3 && @$_SERVER["argv"][1] != "system_fonts" ) {
usage();
}
$dompdf = new Dompdf();
if (isset($fontDir) && realpath($fontDir) !== false) {
$dompdf->getOptions()->set('fontDir', $fontDir);
}
/**
* Installs a new font family
* This function maps a font-family name to a font. It tries to locate the
* bold, italic, and bold italic versions of the font as well. Once the
* files are located, ttf versions of the font are copied to the fonts
* directory. Changes to the font lookup table are saved to the cache.
*
* @param Dompdf $dompdf dompdf main object
* @param string $fontname the font-family name
* @param string $normal the filename of the normal face font subtype
* @param string $bold the filename of the bold face font subtype
* @param string $italic the filename of the italic face font subtype
* @param string $bold_italic the filename of the bold italic face font subtype
*
* @throws Exception
*/
function install_font_family($dompdf, $fontname, $normal, $bold = null, $italic = null, $bold_italic = null) {
$fontMetrics = $dompdf->getFontMetrics();
// Check if the base filename is readable
if ( !is_readable($normal) )
throw new Exception("Unable to read '$normal'.");
$dir = dirname($normal);
$basename = basename($normal);
$last_dot = strrpos($basename, '.');
if ($last_dot !== false) {
$file = substr($basename, 0, $last_dot);
$ext = strtolower(substr($basename, $last_dot));
} else {
$file = $basename;
$ext = '';
}
if ( !in_array($ext, array(".ttf", ".otf")) ) {
throw new Exception("Unable to process fonts of type '$ext'.");
}
// Try $file_Bold.$ext etc.
$path = "$dir/$file";
$patterns = array(
"bold" => array("_Bold", "b", "B", "bd", "BD"),
"italic" => array("_Italic", "i", "I"),
"bold_italic" => array("_Bold_Italic", "bi", "BI", "ib", "IB"),
);
foreach ($patterns as $type => $_patterns) {
if ( !isset($$type) || !is_readable($$type) ) {
foreach($_patterns as $_pattern) {
if ( is_readable("$path$_pattern$ext") ) {
$$type = "$path$_pattern$ext";
break;
}
}
if ( is_null($$type) )
echo ("Unable to find $type face file.\n");
}
}
$fonts = compact("normal", "bold", "italic", "bold_italic");
$entry = array();
// Copy the files to the font directory.
foreach ($fonts as $var => $src) {
if ( is_null($src) ) {
$entry[$var] = $dompdf->getOptions()->get('fontDir') . '/' . mb_substr(basename($normal), 0, -4);
continue;
}
// Verify that the fonts exist and are readable
if ( !is_readable($src) )
throw new Exception("Requested font '$src' is not readable");
$dest = $dompdf->getOptions()->get('fontDir') . '/' . basename($src);
if ( !is_writeable(dirname($dest)) )
throw new Exception("Unable to write to destination '$dest'.");
echo "Copying $src to $dest...\n";
if ( !copy($src, $dest) )
throw new Exception("Unable to copy '$src' to '$dest'");
$entry_name = mb_substr($dest, 0, -4);
echo "Generating Adobe Font Metrics for $entry_name...\n";
$font_obj = Font::load($dest);
$font_obj->saveAdobeFontMetrics("$entry_name.ufm");
$font_obj->close();
$entry[$var] = $entry_name;
}
// Store the fonts in the lookup table
$fontMetrics->setFontFamily($fontname, $entry);
// Save the changes
$fontMetrics->saveFontFamilies();
}
// If installing system fonts (may take a long time)
if ( $_SERVER["argv"][1] === "system_fonts" ) {
$fontMetrics = $dompdf->getFontMetrics();
$files = glob("/usr/share/fonts/truetype/*.ttf") +
glob("/usr/share/fonts/truetype/*/*.ttf") +
glob("/usr/share/fonts/truetype/*/*/*.ttf") +
glob("C:\\Windows\\fonts\\*.ttf") +
glob("C:\\WinNT\\fonts\\*.ttf") +
glob("/mnt/c_drive/WINDOWS/Fonts/");
$fonts = array();
foreach ($files as $file) {
$font = Font::load($file);
$records = $font->getData("name", "records");
$type = $fontMetrics->getType($records[2]);
$fonts[mb_strtolower($records[1])][$type] = $file;
$font->close();
}
foreach ( $fonts as $family => $files ) {
echo " >> Installing '$family'... \n";
if ( !isset($files["normal"]) ) {
echo "No 'normal' style font file\n";
}
else {
install_font_family($dompdf, $family, @$files["normal"], @$files["bold"], @$files["italic"], @$files["bold_italic"]);
echo "Done !\n";
}
echo "\n";
}
}
else {
call_user_func_array("install_font_family", array_merge( array($dompdf), array_slice($_SERVER["argv"], 1) ));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment