123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\facade\Db;
- use think\facade\Validate;
- //报表导出相关
- class Export extends Base
- {
- //相关字段的文字转换
- private $qrdType = [1 => '库存品', 2 => '非库存品', 3 => '采购反馈'];
- private $qrdSource = [1 => '直接下单', 2 => '竞价转单', 3 => '项目转单', 4 => '平台导入', 5 => '有赞平台', 6 => '售后补换货',7=>'报备转单',8=>'支付渠道拆单'];
- private $sendType = [1 => '包邮', 2 => '自提'];
- private $pay_status = [1 => '未回', 2 => '部分回款', 3 => '已回'];
- private $inv_status = [1 => '未开', 2 => '部分开票', 3 => '已开'];
- private $cgd_inv_status = [1 => '未回', 2 => '部分回票', 3 => '已回'];
- private $cgd_pay_status = [1 => '未付', 2 => '部分付款', 3 => '已付'];
- private $invoice_pool_status = [1 => '财务审核通过', 2 => '待财务上传发票', 3 => '金税开票中/验票中', 4 => '开票成功', 5 => '开票失败', 6 => '发票退票/废弃', 7 => '取消申请', 8 => '财务驳回', 9 => '验票失败'];
- private $cgdType = [1 => '库存', 2 => '非库存', 3 => '咨询'];
- private $invoice_return_status = [0 => '待财务审核', 1 => '退票中', 2 => '退票成功', 3 => '审核驳回', 4 => '退票失败'];
- private $sendStatus = [1=>'未发货',2=>'部分发货',3=>'全部发货'];
- public function __construct(App $app) {
- parent::__construct($app);
- $action =$this->request->action();
- switch ($action){
- case 'invoicePoolExport':
- $file ='销售发票申请信息导出';
- break;
- case 'invListExport':
- $file ='进项发票等级导出';
- break;
- case 'orderPayExport':
- $file ='资金认领导出';
- break;
- case 'orderlistExport':
- $file = '回款核销明细表';
- break;
- case 'invExport':
- $file='回票明细表';
- break;
- case 'analysisExport':
- $file='经营分析报表';
- break;
- case 'orderInvExport':
- $file='收入成本明细表';
- break;
- case 'standingBookExport':
- $file='应收台账表';
- break;
- case 'payInvoiceExport':
- $file='用友销票表';
- break;
- case 'cgdManage':
- $file='采购单明细表';
- break;
- case 'payExport':
- $file='对账单汇总表';
- break;
- case 'productPerformance':
- $file='产品部门业绩';
- break;
- case 'productTh':
- $file='产品部门退货单数据';
- break;
- case 'performance':
- $file='业绩报表';
- break;
- default:
- $file='暂无数据';
- break;
- }
- $data =$this->$action();
- $header=[];
- foreach ($data as $value){
- $header = array_keys($value);
- break;
- }
- if(empty($header)){
- $header=['导出数据为空'];
- $data=[];
- }
- excelExport($file, $header, $data);
- }
- //销售发票申请信息导出
- public function invoicePoolExport()
- {
- $param = $this->request->only(['start' => '', 'end' => '', 'status' => '', 'inv_type' => '', 'inv_out' => '', 'invNo' => '', 'relaComNo' => '', 'inv_number' => '', 'inv_code' => '', 'inv_company' => '', 'buyer_name' => '', 'apply_id' => '', 'apply_name' => '',], 'post', 'trim');
- $where = [['a.is_del', '=', 0], ['e.status', 'in', [1,2]]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
- if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
- if ($param['inv_type'] != '') $where[] = ['a.inv_type', '=', $param['inv_type']];
- if ($param['inv_out'] != '') $where[] = ['a.inv_out', '=', $param['inv_out']];
- if ($param['invNo'] != '') $where[] = ['a.invNo', 'in', $param['invNo']];
- if ($param['relaComNo'] != '') $where[] = ['a.inv_out', '=', $param['relaComNo']];
- if ($param['inv_number'] != '') $where[] = ['c.inv_number', 'like', '%' . $param['inv_number'] . '%'];
- if ($param['inv_code'] != '') $where[] = ['c.inv_code', 'like', '%' . $param['inv_code'] . '%'];
- if ($param['inv_company'] != '') $where[] = ['a.inv_company', 'like', '%' . $param['inv_company'] . '%'];
- if ($param['buyer_name'] != '') $where[] = ['b.buyer_title', 'like', '%' . $param['buyer_name'] . '%'];
- if ($param['apply_id'] != '') $where[] = ['a.apply_id', '=', $param['apply_id']];
- if ($param['apply_name'] != '') $where[] = ['a.apply_name', 'like', '%' . $param['apply_name'] . '%'];
- $open_type = [1 => '金税开票', 2 => '金税线下', 3 => '纯线下'];//开票方式
- $inv_type = config('invoiceType.invoiceName');//开票种类(发票类型)
- $list = Db::name('invoice_pool')
- ->alias('a')
- ->field('a.inv_out 卖方公司编码,
- a.inv_company 卖方公司名称,
- a.invNo 申请编号,
- f.department 申请部门,
- a.apply_name 申请人,
- b.buyer_title 发票买方公司名称,
- concat(b.buyer_code," ") 发票买方企业纳税识别号,
- b.buyer_addr 发票买方企业地址,
- b.buyer_mobile 发票买方企业联系方式,
- b.buyer_bank 发票买方企业收款银行,
- concat(b.buyer_bankNo," ") 发票买方企业财务账户,
- d.orderCode 公司订单号,
- b.buyer_title 订单企业客户,
- d.goodName 订单商品名,
- concat(g.inv_cat_code," ") 税收分类编码,
- g.inv_cat_name 税收分类名称,
- d.goodName 发票明细商品名称,
- CONCAT(d.catName,"*",d.goodName) 发票货物或应税劳务、服务名称,
- d.unitName 单位,
- d.goodNum 数量,
- round(d.totalTax/d.goodNum,2) 单价,
- d.tax 税率,
- d.totalTax 总价,
- a.inv_type 开票种类,
- a.open_type 开票方式,
- a.exam_remark 申请备注,
- a.remark 发票备注,
- if(f.cxCode="",f.sequenceNo,f.cxCode) 销售主单号,
- f.goodPrice 商品单价')
- ->leftJoin('invoice_pool_info b', 'a.invNo=b.invNo')
- ->leftJoin('invoice_ticket c', 'a.invNo=c.invNo AND c.type=0 AND c.status=1')
- ->leftJoin('invoice_good d', 'd.invNo=a.invNo')
- ->leftJoin('assoc e', 'e.viceCode=d.invNo AND e.orderCode=d.orderCode AND e.is_del=0')
- ->leftJoin('qrd_info f', 'f.sequenceNo=e.orderCode')
- ->leftJoin('good g', 'g.spuCode=d.goodNo')
- ->where($where)
- ->order('a.addtime desc')
- ->cursor();
- foreach ($list as $value){
- $value["开票方式"] = $open_type[$value["开票方式"]] ?? '';
- $value["开票种类"] = $inv_type[$value["开票种类"]] ?? '';
- // $value["付款银行单位账号"] .=' ';
- // $value["认领企业"] =Db::name("customer_info")->where(["companyNo"=>$value["认领企业"]])->value("companyName","");
- yield $value;
- }
- }
- //进项发票等级导出
- public function invListExport()
- {
- $param = $this->request->only(['start' => '', 'end' => '', 'invType' => '', 'company' => '', 'relaComNo' => '', 'supplierNo' => '', 'hpNo' => '', 'payNo' => '', 'invoiceType' => '', 'status' => '', 'invoiceNumber' => '', 'checkApi' => '', 'invoiceCode' => '', 'open_start' => '', 'open_end' => '', 'apply_id' => '', 'apply_name' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0], ['b.is_del', '=', 0]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
- if ($param['invType'] != '') $where[] = ['a.invType', '=', $param['invType']];
- if ($param['company'] != '') $where[] = ['b.companyNo', 'like', '%' . $param['company'] . '%'];
- if ($param['relaComNo'] != '') $where[] = ['b.companyNo|b.supplierNo', 'like', '%' . $param['relaComNo'] . '%'];
- if ($param['supplierNo'] != '') $where[] = ['b.supplierNo', '=', $param['supplierNo']];
- if ($param['hpNo'] != '') $where[] = ['a.hpNo', 'like', '%' . $param['hpNo'] . '%'];
- if ($param['payNo'] != '') $where[] = ['a.payNo', 'like', '%' . $param['payNo'] . '%'];
- if ($param['invoiceType'] != '') $where[] = ['a.invoiceType', '=', $param['invoiceType']];
- if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
- if ($param['invoiceNumber'] != '') $where[] = ['a.invoiceNumber', '=', $param['invoiceNumber']];
- if ($param['checkApi'] != '') $where[] = ['a.checkApi', '=', $param['checkApi']];
- if ($param['invoiceCode'] != '') $where[] = ['a.invoiceCode', '=', $param['invoiceCode']];
- if (($param['open_start'] != '') && ($param['open_end'] != '')) $where[] = ['a.open_time', 'between', [$param['open_start'], $param['open_end']]];
- if ($param['apply_id'] != '') $where[] = ['a.apply_id', '=', $param['apply_id']];
- if ($param['apply_name'] != '') $where[] = ['a.apply_name', 'like', '%' . $param['apply_name'] . '%'];
- $status = [1 => '待系统验证', 2 => '买方公司审核', 3 => '待买方公司认证', 4 => '认证成功', 5 => '验证失败', 6 => '买方审核驳回', 7 => '认证失败', 8 => '回票流程终止', 9 => '验证超次数', 10 => '回票已退'];//认证状态
- $invoiceType = config('invoiceType.invoiceName');//开票种类(发票类型)
- $list = Db::name('pay_invoice')
- ->alias('a')
- ->leftJoin('pay b', 'a.payNo=b.payNo and b.status=2')
- ->leftJoin('invoice_info c', 'c.hpNo=a.hpNo AND c.status=1')
- ->field('"" 序号,
- a.payNo 对账编号,
- a.hpNo 回票申请编号,
- DATE_FORMAT(a.addtime,\'%Y\') 年,
- DATE_FORMAT(a.addtime,\'%m\') 月,
- a.invoiceNumber 发票号,
- c.total 总额,
- c.subtotal_amount 金额,
- c.subtotal_tax 税额,
- a.open_time 开票日期,
- b.supplierName 供应商,
- a.invoiceType 发票类型,
- "" as 业务类型,
- a.status 认证状态,
- a.updatetime 认证时间,
- a.remark 备注')
- ->where($where)
- ->order('a.addtime desc')
- ->cursor();
- $i=1;
- foreach ($list as $item) {
- $item['序号'] = $i;
- $item['业务类型'] = '采购回票';
- $item['认证状态'] = $status[$item['认证状态']]??"";
- $item['发票类型'] = $invoiceType[$item['发票类型']]??"";
- $i++;
- yield $item;
- }
- }
- //资金认领导出
- public function orderPayExport()
- {
- $param = $this->request->only(['start' => '', 'end' => '', 'name' => '', 'bank' => '', 'status' => '', 'tradNo' => '', 'company' => '', 'userd_lower' => '', 'used_upper' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0],['b.is_del', '=', 0],['d.is_del', '=', 0],['d.is_del', '=', 0],["c.type","=",
- 2],["c.status","in",[1,2]]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.trade_time', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
- if ($param['name'] != '') $where[] = ['a.trade_out', 'like', '%' . $param['name'] . '%'];
- if ($param['bank'] != '') $where[] = ['a.trade_bank', 'like', '%' . $param['bank'] . '%'];
- if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
- if ($param['tradNo'] != '') $where[] = ['a.tradNo', 'like', '%' . $param['tradNo'] . '%'];
- if ($param['company'] != '') $where[] = ['a.companyNo', 'like', '%' . $param['company'] . '%'];
- if ($param['userd_lower'] != '') $where[] = ['a.used_fee', '>=', $param['userd_lower']];
- if ($param['used_upper'] != '') $where[] = ['a.used_fee', '<=', $param['used_upper']];
- $status = [1 => '未认领', 2 => '部分认领', 3 => '全部认领'];//状态
- $b_status = [1 => '待审批', 2 => '审批通过', 3 => '审批驳回', 4 => '退款', 5 => '解除认领'];//认领审批状态
- $list = Db::name('trade')
- ->alias('a')
- ->field('a.companyNo 收款方公司编码,
- a.trade_in 收款单位名称,
- a.trade_account 付款银行单位账号,
- a.trade_out 付款银行单位名称,
- a.trade_used 付款备注,
- a.trade_time 交易时间,
- a.tradNo 资金编号,
- a.status 状态,
- a.total_fee 收入金额,
- a.balance 未认领金额,
- b.total_fee 已认领金额,
- b.logNo 资金认领编号,
- b.customerNo 认领企业,
- c.orderCode 订单编号,
- d.cxCode 销售主单号,
- d.poCode 平台编号,
- d.goodName 产品名称,
- d.ownerName 资金创建人,
- c.apply_name 认领创建人,
- b.status 认领审批状态,
- b.remark 驳回原因')
- ->leftJoin('trade_pool b', 'b.tradNo=a.tradNo')
- ->leftJoin('assoc c', 'c.viceCode=b.logNo')
- ->leftJoin('qrd_info d', 'd.sequenceNo=c.orderCode')
- ->where($where)
- ->order('a.trade_time desc')
- ->cursor();
- foreach ($list as $value){
- $value["付款银行单位账号"] .=' ';
- $value["认领企业"] =Db::name("customer_info")->where(["companyNo"=>$value["认领企业"]])->value("companyName","");
- $value['状态'] = $status[$value['状态']] ?? '';
- $value['认领审批状态'] = $b_status[$value['认领审批状态']] ?? '';
- yield $value;
- }
- }
- //回款核销明细表
- public function orderlistExport()
- {
- $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0],['b.status',">=",2],["b.type","=",2]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['b.addtime', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
- if ($param['company'] != '') $where[] = ['a.companyNo', '=', $param['company']];
- $data = Db::name('assoc')
- ->alias('b')
- ->field('DATE_FORMAT(b.addtime,\'%Y\') 年,DATE_FORMAT(b.addtime,\'%m\') 月,DATE_FORMAT(b.addtime,\'%d\') 日,a.companyName 业务公司名称,a.companyNo 业务公司编号,b.viceCode 资金认领编号,c.tradNo 资金编号,c.total_fee 本次核销金额,c.addtime 本次核销时间,c.status 资金认领状态,a.sequenceNo 确认单编号,a.department 业务员部门,a.ownerName 业务员,a.platName 平台类型,a.qrdSource 确认单类型,a.qrdType 商品类型,a.poCode PO编号,a.customerAttr 客户属性,a.branch 分公司,a.customerName 客户名称,a.firstCat 一级分类,a.goodName 产品名称,round(a.tax/100,2) 税点,(a.goodNum-a.thNum) 下单数量,a.goodPrice 销售单价,(a.totalPrice-a.th_fee) 销售总额')
- ->leftJoin('qrd_info a', 'b.orderCode=a.sequenceNo')
- ->leftJoin('trade_pool c', 'c.logNo=b.viceCode')
- ->where($where)
- ->order(['a.id' => 'desc'])
- ->cursor();
- //资金认领状态
- $status = [1 => '待审批', 2 => '审批通过', 3 => '审批驳回', 4 => '已解除认领', 5 => '已取消认领'];
- // $list = [];
- foreach ($data as $value) {
- $value['资金认领状态'] = $status[$value['资金认领状态']] ?? '';
- $value['确认单类型'] = $this->qrdSource[$value['确认单类型']] ?? '';
- $value['商品类型'] = $this->qrdType[$value['商品类型']] ?? '';
- yield $value;
- }
- //
- // if (empty($list)) $list[] = ['导出数据为空' => ''];
- //
- // excelExport('回款核销明细表', array_keys($list[0]), $list);
- }
- //回票明细表
- public function invExport()
- {
- $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0], ['b.is_del', '=', 0], ['c.is_del', '=', 0], ['d.is_del', '=', 0]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.check_time', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
- if ($param['company'] != '') $where[] = ['b.companyNo', '=', $param['company']];
- $data = Db::name('pay_invoice')
- ->alias('a')
- ->field('d.cgdTime 采购单下单日期,
- b.companyName 业务公司名称,
- b.companyNo 业务公司编号,
- a.hpNo 对账回票编号,
- a.payNo 对账单号,
- c.cgdNo 采购单编号,
- a.check_time 本次回票时间,
- a.invoiceNumber 发票号,
- a.inv_amount 本次回票金额,
- d.totalPrice 采购单回票金额,
- "" 不含税采购成本,
- "" 税额,
- d.companyName 公司回票抬头,
- d.goodNo 商品编号,
- d.firstCat 一级分类,
- d.fundCode 核算码,
- d.goodName 商品名称,
- d.goodNum 商品数量,
- d.goodUnit 单位,
- d.cgdSource 采购单类型,
- d.ownerName 采购员,
- d.supplierName 供应商名称,
- d.supplierNo 供应商编号,
- d.goodType 商品类型,
- round(d.tax/100,2) 税率,
- d.packPrice 包装费,
- d.certPrice 证书费,
- d.markPrice 加标费,
- d.openPrice 开模费,
- d.costPrice 成本工艺费,
- d.deliveryPrice 物流费,
- d.barePrice 成本单价,
- d.diff_weight 工差,
- d.diff_fee 工差金额,
- d.goodPrice 单价,
- d.totalPrice 采购总货款,
- d.qrdCode 确认单编号,
- d.bkCode 备库编号,
- d.thNum 退货数量,
- d.th_fee 退货金额,
- a.exam_remark 回票审核备注,
- a.remark 回票申请备注')
- ->leftJoin('pay b', 'a.payNo=b.payNo')
- ->leftJoin('pay_info c', 'c.payNo=a.payNo and c.status=1 and c.is_del=0')
- ->leftJoin('cgd_info d', 'd.sequenceNo=c.cgdNo')
- ->where($where)
- ->order(['a.id' => 'desc'])
- ->cursor();
- //采购单类型
- $cgdSource = [1 => '直接下单', 2 => '咨询', 3 => '项目', 4 => '平台', 5 => '有赞'];
- //商品类型
- $goodType = [1 => '正常商品', 2 => '赠品', 3 => '样品'];
- // $list = [];
- foreach ($data as $value) {
- $value['采购单类型'] = $cgdSource[$value['采购单类型']] ?? '';
- $value['商品类型'] = $goodType[$value['商品类型']] ?? '';
- $value['不含税采购成本'] = round($value['采购总货款']/(1+$value['税率']),2) ;
- $value['税额'] = round($value['不含税采购成本']*$value['税率'],2) ;
- yield $value;
- }
- }
- //经营分析报表
- public function analysisExport()
- {
- $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.createdTime', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
- if ($param['company'] != '') $where[] = ['a.companyNo', '=', $param['company']];
- $data = Db::name('qrd_info')
- ->alias('a')
- ->field('
- DATE_FORMAT(a.createdTime,\'%Y\') 年,
- DATE_FORMAT(a.createdTime,\'%m\') 月,
- DATE_FORMAT(a.createdTime,\'%d\') 日,
- a.companyName 业务公司名称,
- a.companyNo 业务公司编号,
- a.department 销售部门,
- a.ownerName 销售员,
- a.qrdSource 订单来源,
- a.pay_source 支付来源,
- "" 活动类型,
- a.sequenceNo 确认单编号,
- if(a.cxCode="",a.sequenceNo,a.cxCode) 销售订单号,
- b.bkCode 备库单编号,
- b.sequenceNo 采购单单号,
- a.platName 平台类型,
- a.poCode PO编号,
- a.customerAttr 客户属性,
- a.branch 分公司,
- a.customerName 客户名称,
- a.goodNo 商品编码,
- a.firstCat 一级分类,
- a.secCat 二级分类,
- a.thirdCat 三级分类,
- a.goodName 产品名称,
- a.goodUnit 单位,
- a.goodNum 下单数量,
- a.goodPrice 销售单价,
- (a.totalPrice+a.th_fee) 销售总额,
- round(a.tax/100,2) 税点,
- b.ownerName 采购员,
- b.goodPrice 采购裸价,
- b.markPrice 加标费,
- b.packPrice 包装费,
- b.certPrice 证书费,
- b.openPrice 开模费,
- b.costPrice 工艺费,
- b.deliveryPrice 物流费,
- b.goodPrice 采购单价合计,
- (ifnull(b.totalPrice,a.total_origin_price)+ifnull(b.th_fee,0)) 采购总货款,
- (a.totalPrice -ifnull(b.totalPrice,a.total_origin_price)) 毛利润,
- round((a.totalPrice -ifnull(b.totalPrice,a.total_origin_price))/a.totalPrice,2) 毛利率,
- round(b.tax/100,2) 采购税点,
- round(b.totalPrice/(1+ round(b.tax/100,2)),2) 不含税采购成本,
- a.qrdType 库存性质,
- b.supplierName 供应商名称,
- b.sendType 发货方式,
- a.thNum 退货数量,
- a.fundCode 财务核算编码')
- ->leftJoin('cgd_info b', 'b.sequenceNo=a.cgdNo and b.is_del=0')
- ->where($where)
- ->order(['a.id' => 'desc'])
- ->cursor();
- $list = [];
- foreach ($data as $value) {
- $value['订单来源'] = $this->qrdSource[$value['订单来源']] ?? '';
- $value['库存性质'] = $this->qrdType[$value['库存性质']] ?? '';
- $value['发货方式'] = $this->sendType[$value['发货方式']] ?? '';
- $value['毛利润'] = round(bcsub($value['销售总额'], $value['采购总货款'], 3), 2);
- $value['毛利率'] = $value['销售总额'] == 0 ? 0 : round(bcmul(bcsub(1, bcdiv($value['采购总货款'], $value['销售总额'], 5), 5), 100), 2) . '%';
- $value['不含税采购成本'] = round(bcdiv($value['采购总货款'], bcadd(1,$value['采购税点']), 3), 2);
- yield $value;
- }
- }
- //收入成本明细表
- public function orderInvExport()
- {
- $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0], ['d.is_del', '=', 0], ['a.status', '>=', 4]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
- if ($param['company'] != '') $where[] = ['a.inv_out', '=', $param['company']];
- $data = Db::name('invoice_pool')
- ->alias('a')
- ->field('
- a.invNo 发票申请编号,
- m.orderCode 确认单编号,
- if(e.cxCode="",m.orderCode,e.cxCode) 销售主单编号,
- e.qrdSource 销售来源,
- b.seller_title 销售方抬头,
- e.department 业务部门,
- e.ownerName 业务人员,
- m.goodNum 本次开票数量,
- m.totalPrice 本次开票金额,
- e.goodPrice 销售单价,
- c.open_date 本次开票时间,
- c.inv_number 发票号,
- m.tax 开票税点,
- a.status 开票状态,
- e.customerName 客户名称,
- e.fundCode 财务核算码,
- e.firstCat 一级分类,
- e.secCat 二级分类,
- e.thirdCat 三级分类,
- e.goodNo 产品编号,
- e.goodName 产品名称,
- f.sequenceNo 采购单编号,
- f.supplierName 卖出方公司,
- f.sendType 发货方式,
- e.qrdType 商品类型,
- f.ownerName 采购员,
- ifnull(f.goodNum,e.goodNum) 采购下单数量,
- f.barePrice 采购裸价,
- f.markPrice 加标费,
- f.packPrice 包装费,
- f.certPrice 证书费,
- f.openPrice 开模费,
- f.costPrice 工艺费,
- f.deliveryPrice 物流费,
- f.goodPrice 成本合计,
- ifnull(f.totalPrice,e.total_origin_price) 采购货款,
- round(f.tax/100,2) 采购单税点,
- g.returnCode 退票编号,
- if(g.returnCode<>"",a.inv_value,"") 退票金额,
- g.status 退票状态,
- g.return_type 退票方式,
- f.thNum 退货数量,
- f.th_fee 退货金额
- ')
- ->leftJoin('invoice_pool_info b', 'b.invNo=a.invNo')
- ->leftJoin('invoice_ticket c', 'c.invNo=a.invNo and c.type=0 and c.status in (0,1,2,3)')
- ->leftJoin("invoice_good m","m.invNo=a.invNo and m.invtype=0 and m.is_del=0")
- // ->leftJoin('assoc d', 'd.viceCode=a.invNo and d.type=1')
- ->leftJoin('qrd_info e', 'e.sequenceNo=m.orderCode')
- ->leftJoin('cgd_info f', 'f.sequenceNo=e.cgdNo')
- ->leftJoin('invoice_return g', 'g.invNo=a.invNo and g.status=2')
- ->where($where)
- ->order(['a.id' => 'desc'])
- ->cursor();
- $list = [];
- foreach ($data as $value) {
- $value['开票状态'] = $this->invoice_pool_status[$value['开票状态']] ?? '';
- $value['发货方式'] = $this->sendType[$value['发货方式']] ?? '';
- $value['商品类型'] = $this->qrdType[$value['商品类型']] ?? '';
- $value['退票状态'] = $this->invoice_return_status[$value['退票状态']] ?? '';
- $value['销售来源'] = $this->qrdSource[$value['销售来源']] ?? '';
- yield $value;
- }
- }
- //应收台账表
- public function standingBookExport()
- {
- $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.createdTime', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
- if ($param['company'] != '') $where[] = ['a.companyNo', '=', $param['company']];
- $data = Db::name('qrd_info')
- ->alias('a')
- ->field('
- a.createdTime 下单时间,
- a.companyName 业务公司名称,
- a.companyNo 业务公司编号,
- a.sequenceNo 业务订单编号,
- a.cxCode 销售订单主编号,
- a.department 销售部门,
- a.ownerName 销售员,
- a.qrdSource 订单来源,
- a.platName 平台类型,
- a.poCode PO编号,
- a.customerName 客户名称,
- a.customerAttr 客户属性,
- a.branch 客户分公司,
- a.firstCat 一级分类,
- a.goodName 产品名称,
- round(a.tax/100,2) 税点,
- (a.goodNum - a.thNum) 下单数量,
- a.goodPrice 销售单价,
- a.totalPrice 销售总额,
- a.th_fee 退货总额,
- a.pay_status 回款状态,
- a.apay_fee 总已回款,
- a.pay_fee 回款中,
- a.wpay_fee 总未回款,
- a.pay_tag_fee 回款标签金额,
- a.inv_status 开票状态,
- a.ainv_fee 总已开票,
- a.inv_fee 开票中,
- a.winv_fee 总未开票,
- a.inv_tag_fee 开票标签金额,
- a.invtime 最近开票时间,
- "" 业务提票时间,
- a.paytime 最近回款时间,
- 0 账期,
- 0 比率,
- "" 订单是否超期,
- "" 开票是否超期,
- a.sendStatus 发货状态,
- "" 最近一次发货时间
- ')
- ->where($where)
- ->order(['a.id' => 'desc'])
- ->cursor();
- // echo Db::name('qrd_info')->getLastSql();die;
- $time = time();
- foreach ($data as $value) {
- $value['订单来源'] = $this->qrdSource[$value['订单来源']] ?? '';
- $value['回款状态'] = $this->pay_status[$value['回款状态']] ?? '';
- $value['开票状态'] = $this->inv_status[$value['开票状态']] ?? '';
- $value['发货状态'] = $this->sendStatus[$value['发货状态']] ?? '';
- $value['业务提票时间'] =Db::name("assoc")->where(["type"=>1,"status"=>[1,2],"is_del"=>0,'orderCode'=>$value['业务订单编号']])
- ->order("id desc")->value('addtime','');
- //计算账期
- $value['账期'] = round(bcdiv(bcsub($time,strtotime($value['最近回款时间']??$value['下单时间']), 3), 86400, 3),
- 2);
- $value['比率'] = round(bcdiv($value['账期'], 30, 1));
- $value['订单是否超期'] = $value['比率'] > 6 ? '是' : '否';
- $value['开票是否超期'] = round(bcdiv(bcsub($time, strtotime($value['最近开票时间']??$value['下单时间']), 1), 86400, 1)) > 15 ? '是' : '否';
- $value['最近一次发货时间'] = Db::table('fh_source')
- ->where(['qrdNo' => $value['业务订单编号']])
- ->order(['id' => 'desc'])
- ->value('send_date', '');
- yield $value;
- }
- }
- //用友销票表
- public function payInvoiceExport()
- {
- $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0], ['c.is_del', '=', 0], ['d.is_del', '=', 0], ['e.is_del', '=', 0]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
- if ($param['company'] != '') $where[] = ['e.companyNo', '=', $param['company']];
- $data = Db::name('pay_invoice')
- ->alias('a')
- ->field('
- d.companyName 回票业务公司名称,
- a.hpNo 回票编码,
- c.cgdNo 采购单编号,
- d.fundCode 财务核算编码,
- d.goodName 产品名称,
- d.supplierName 供应商名称,
- a.invoiceNumber 发票号,
- b.item_list,
- "" 发票货物或应税劳务、服务名称,
- "" 回票数量,
- "" 本次回票价款,
- "" 本次回票税额,
- "" 回票税率,
- b.total 本次回票总金额,
- a.check_time 本次回票时间
- ')
- ->leftJoin('invoice_info b', 'b.payNo=a.payNo')
- ->leftJoin('pay_info c', 'c.payNo=a.payNo')
- ->leftJoin('cgd_info d', 'd.sequenceNo=c.cgdNo')
- ->leftJoin('pay e', 'e.payNo=a.payNo')
- ->where($where)
- ->order(['a.id' => 'desc'])
- ->cursor();
- $list = [];
- foreach ($data as $value) {
- $item_list = json_decode($value['item_list'], true);
- unset($value['item_list']);
- foreach ($item_list as $item) {
- $list[] = array_merge($value, [
- '发票货物或应税劳务、服务名称' => $item['name'] ?? '',
- '回票数量' => $item['quantity'] ?? '',
- '本次回票价款' => $item['amount'] ?? '',
- '本次回票税额' => $item['tax'] ?? '',
- '回票税率' => $item['tax_rate'] ?? '',
- ]);
- }
- }
- if (empty($list)) $list[] = ['导出数据为空' => ''];
- excelExport('用友销票表', array_keys($list[0]), $list);
- }
- /** 采购单管理数据
- * @throws \PHPExcel_Exception
- * @throws \PHPExcel_Reader_Exception
- * @throws \PHPExcel_Writer_Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function cgdManage()
- {
- $param = $this->request->only(['companyNo' => '', 'start' => '', 'end' => '', "supplierNo" => ''], 'post', 'trim');
- $where = [];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['createdTime', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
- if ($param['companyNo'] != '') $where[] = ['companyNo', '=', $param['companyNo']];
- if ($param['supplierNo'] != '') $where[] = ['supplierNo', '=', $param['supplierNo']];
- $data = Db::name("cgd_info")->where($where)
- ->field("
- sequenceNo '采购单编号',
- companyName '业务企业',
- supplierName '供应商名称',
- ownerName '采购员',
- department '采购部门',
- createdTime '采购时间',
- cgdType '采购单类型',
- if(qrdCode='',bkCode,qrdCode) '确认单编号/备库单编号',
- cxCode '销售单主单号',
- goodNo '商品编号',
- goodName '商品名称',
- firstCat '一级分类',
- secCat '二级分类',
- thirdCat '三级分类',
- fundCode '核算码',
- round(tax/100,2) '税率',
- barePrice '裸价',
- markPrice '加标费',
- certPrice '证书费',
- openPrice '开模费',
- packPrice '包装费',
- costPrice '工艺费',
- deliveryPrice '物流费',
- goodPrice '单价',
- isStock '是否库存',
- diff_fee '工差金额',
- goodNum '商品数量',
- totalPrice '总价',
- sendStatus '发货状态',
- '' as '对账编号',
- '' as '付款状态',
- '' as '回票状态'
- ")->cursor();
- $list = [];
- foreach ($data as $value) {
- $value['采购单类型'] = $this->cgdType[$value['采购单类型']];
- $payinfo = Db::name("pay_info")->alias("a")
- ->leftJoin("pay b", "a.payNo=b.payNo and b.status=2")
- ->where(["a.status" => 1, "a.is_del" => 0,'cgdNo'=>$value['采购单编号']])
- ->field("b.payNo,b.inv_status,b.pay_status")->find();
- $value['对账编号'] = $payinfo['payNo'] ?? "";
- $value['付款状态'] = $this->cgd_pay_status[$payinfo['pay_status'] ?? "1"];
- $value['回票状态'] = $this->cgd_inv_status[$payinfo['inv_status'] ?? "1"];
- $value['是否库存'] = $value['是否库存']==1?'是':'否';
- $value['发货状态'] = $this->sendStatus[$value['发货状态']];
- yield $value;
- }
- // if (empty($list)) $list[] = ['导出数据为空' => ''];
- //
- // excelExport('采购单明细表', array_keys($list[0]), $list);
- }
- /**
- * 对账单汇总表
- */
- public function payExport()
- {
- $param = $this->request->only(['companyNo' => '', 'start' => '', 'end' => '', "supplierNo" => ''], 'post', 'trim');
- $where = [["is_del", "=", 0], ["status", "=", 2]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['addtime', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
- if ($param['companyNo'] != '') $where[] = ['companyNo', '=', $param['companyNo']];
- if ($param['supplierNo'] != '') $where[] = ['supplierNo', '=', $param['supplierNo']];
- $data = Db::name("pay")->where($where)
- ->field("
- companyName '业务公司',
- apply_name '申请人',
- addtime '申请时间',
- supplierName '供应商名称',
- '' as '付款时间',
- payNo '对账编号',
- total_fee '对账总额',
- apay_fee '已付款',
- pay_fee '付款中',
- wpay_fee '未付款',
- pay_status '付款状态',
- pay_tag_fee '付款加签金额',
- pay_tag as '付款加签时间',
- '' as '付款标签名称',
- ainv_fee '已回票',
- inv_fee '回票中',
- winv_fee '未回票',
- inv_status '回票状态',
- inv_tag_fee '回票加签金额',
- inv_tag as '回票加签时间',
- '' as '回票标签名称',
- remark '备注'
- ")->cursor();
- foreach ($data as $value) {
- $tag = Db::name("tag_log")->alias("a")->leftJoin("order_tag b", "a.tag_id=b.id")->where(["a.code" =>
- $value['对账编号'], "a.status" => 1])->column("a.addtime,b.tag_name", "b.type");
- $value['付款加签时间'] = $tag[1]['addtime'] ?? "";
- $value['回票加签时间'] = $tag[2]['addtime'] ?? "";
- $value['回票标签名称'] = $tag[2]['tag_name'] ?? "";
- $value['付款标签名称'] = $tag[1]['tag_name']?? "";
- $value['付款状态'] = $this->pay_status[$value['付款状态']];
- $value['回票状态'] = $this->inv_status[$value['回票状态']];
- $value['付款时间'] = Db::name("pay_payment")->where(['payNo'=>$value['对账编号'],"is_del"=>0])->order("id desc")
- ->value('return_time','');
- yield $value;
- }
- // if (empty($list)) $list[] = ['导出数据为空' => ''];
- //
- // excelExport('订单对账汇总表', array_keys($list[0]), $list);
- }
- //产品部门销售业绩
- public function productPerformance(){
- $param = $this->request->only([ 'start' => '', 'end' => ''], 'post', 'trim');
- $valid =Validate::rule([
- "start|起始时间"=>"require|date",
- "end|结束时间"=>"require|date|gt:start",
- ]);
- if($valid->check($param)==false) return error_show(1005,$valid->getError());
- $Db= Db::connect("mysql_wsm");
- $list =$Db->name("sale")->field("orderCode 销售单号,apply_name 业务人员,apply_id 业务部门,cat_id 分类,total_price 产品货款总额,addtime 日期")
- ->where(["is_del"=>0,"status"=>[0,1,2]])
- ->whereBetween("addtime",[date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
- strtotime($param['end']))])
- ->cursor();
- foreach ($list as $value){
- $value['业务部门'] = $Db->name("depart_user")->alias("a")->leftjoin("company_item b","a.itemid=b.id")
- ->where(["a.is_del"=>0,"a.status"=>1,"a.uid"=>$value['业务部门']])->value("b.name",'');
- $value['分类'] = $Db->name("cat")->where(["id"=>$value['分类']])->value("search","");
- yield $value;
- }
- }
- //产品部门销售业绩
- public function productTh(){
- $param = $this->request->only([ 'start' => '', 'end' => ''], 'post', 'trim');
- $valid =Validate::rule([
- "start|起始时间"=>"require|date",
- "end|结束时间"=>"require|date|gt:start",
- ]);
- if($valid->check($param)==false) return error_show(1005,$valid->getError());
- $Db= Db::connect("mysql_wsm");
- $list =$Db->name("th_data")->alias("a")
- ->leftjoin("sale b","a.orderCode=b.orderCode")
- ->field("a.thCode 退货单号,a.orderCode 销售单号,b.apply_name 业务人员,b.apply_id 业务部门,a.cat_id 分类,b.total_price 产品货款总额,a.th_fee 退货金额,a.addtime 日期")
- ->where(["a.is_del"=>0])
- ->whereBetween("a.addtime",[date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
- strtotime($param['end']))])
- ->cursor();
- foreach ($list as $value){
- $value['业务部门'] = $Db->name("depart_user")->alias("a")->leftjoin("company_item b","a.itemid=b.id")
- ->where(["a.is_del"=>0,"a.status"=>1,"a.uid"=>$value['业务部门']])->value("b.name",'');
- $value['分类'] = $Db->name("cat")->where(["id"=>$value['分类']])->value("search","");
- yield $value;
- }
- }
- //客服项目部数据业绩下载
- public function performance(){
- $param = $this->request->only(["start"=>"","end"=>""],"post","trim");
- $valid =Validate::rule([
- "start|起始时间"=>"require|date",
- "end|结束时间"=>"require|date|gt:start",
- ]);
- if($valid->check($param)==false) return error_show(1005,$valid->getError());
- $list =Db::name("trade_pool")->alias("a")
- ->leftJoin("assoc b","a.logNo = b.viceCode and b.is_del=0 and b.status=2 and b.type=2")
- ->leftJoin("qrd_info c","b.orderCode=c.sequenceNo and c.is_del=0")
- ->where(["a.status"=>2,"a.is_del"=>0])
- ->whereBetween("a.addtime",[date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
- strtotime($param['end']))])
- ->field("
- a.logNo 回款单号,
- c.ownerName 销售人员,
- c.department 部门,
- c.qrdType 订单类型,
- if(c.cxCode='',c.sequenceNo,c.cxCode) 确认单编号,
- c.cgdNo 采购单号,
- c.customerAttr 客户属性,
- c.branch 客户分公司,
- c.customerName 客户名称,
- c.goodName 产品名称,
- c.firstCat 一级分类,
- c.goodPrice 销售单价,
- c.goodNum-c.thNum 下单数量,
- c.totalPrice 销售总额,
- c.createdTime 确认单下单时间,
- a.addtime 回款日期,
- a.total_fee 回款金额,
- ( timestampdiff( DAY, a.addtime, now())) 账期")
- ->order("a.addtime desc")
- ->cursor();
- foreach ($list as $value){
- yield $value;
- }
- }
- }
|