12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263 |
- <?php
- namespace app\Admin\controller;
- use app\BaseController;
- use think\facade\Db;
- use think\App;
- class Report extends BaseController
- {
- /**确认单明细
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function downreportQRD()
- {
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and ordertime >='{$start}'";
- }
- if($end!=""){
- $where.=" and ordertime <='{$end}'";
- }
- $sql = "SELECT
- a.productNo 'QRD-CP确认单产品编号',
- a.companyName '`KH.2客户名称',
- a.supperinfo '公司名称',
- a.suppitem 'PT.1平台类型',
- a.khzzxz 'PT.2平台编码',
- a.poNo 'PT.4PO编号',
- a.qrdNo 'QRD.4确认单编号',
- a.qrd_type 'QRD.确认单类型',
- a.ordertime 'QRD.确认单下单时间',
- a.sale_name 'QRD.业务员',
- a.product_name 'QRD.产品名称',
- a.product_code 'QRD.产品编号',
- a.cat_f 'QRD.一级分类',
- a.cat_t 'QRD.二级分类',
- a.cat_d 'QRD.三级分类',
- a.fund_code 'QRD.财务核算码',
- a.unit 'QRD.单位',
- a.tax 'QRD.税率',
- a.diff_weight 'QRD.重量工差',
- a.diff_price 'QRD.金额工差',
- a.paytime 'QRD.承诺回款时间',
- a.sale_price 'QRD.销售单价',
- a.order_num 'QRD.下单数量',
- a.sale_total 'QRD.销售总额',
- a.income 'QRD.不含税收入',
- a.zxcode 'QRD.咨询单号',
- a.zxtype 'QRD.咨询单类型',
- a.qrd_delivery 'qrd发货方式',
- a.qrd_stock 'qrd.是否库存产品',
- a.cgdNo 'CGD采购单单号',
- a.cgdtime 'CGD采购单下单日期',
- a.cgdtype 'CGD采购单类型',
- a.cgd_saler 'CGD采购单业务员',
- a.suplier_name 'CGD供货商名称',
- a.paking 'CGD出库包装库存',
- a.cgd_tax 'CGD采购单税点',
- a.pakage_fee 'CGD包装费',
- a.cert_fee 'CGD证书费',
- a.mark_fee 'CGD加标费',
- a.open_fee 'CGD开模费',
- a.cost_fee 'CGD成本工艺费',
- a.naked_fee 'CGD裸价',
- a.delivery_fee 'CGD物流费',
- a.cgd_price 'CGD采购单单价',
- a.cgd_num 'CGD采购单数量',
- a.cgd_total 'CGD采购单金额',
- a.cgd_cost 'CGD采购单成本',
- ROUND( b.Number1618249146997, 2 ) 'QRD已回款',
- ROUND( b.number1618249149738+b.paying_fee, 2 ) 'QRD未回款',
- IF
- ( ak.rela_form = 2 || ak.rela_form = 3, ak.addtime, '' ) 'QRD本次回款时间',
- IF
- ( ak.rela_form = 2 || ak.rela_form = 3, ak.cancel_total, '' ) 'QRD本次回款金额',
- ROUND( b.Number1618249202608, 2 ) 'QRD已开票',
- ROUND( b.Number1618249205231+b.inving_fee, 2 ) 'QRD未开票',
- IF
- ( ak.rela_form = 1, ak.addtime, '' ) 'QRD本次开票时间',
- IF
- ( ak.rela_form = 1, ak.cancel_total, '' ) 'QRD本次开票金额',
- ROUND( c.Number1618330470625, 2 ) 'CGD已付款',
- ROUND( c.Number1618330472961, 2 ) 'CGD未付款',
- pc.total_fee 'CGD.本次付款金额',
- ps.paytime 'CGD.本次付款时间',
- ROUND( c.Number1618330541286, 2 ) 'CGD已回票',
- ROUND( c.Number1618330543270, 2 ) 'CGD未回票',
- ps.inv_fee 'CGD.本次回票金额',
- ps.invtime 'CGD.本次回票时间',
- a.delivery_status 'QRD.发货状态',
- ( SELECT sum( send ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'CGD总发货数量',
- f.send 'CGD本次发货',
- f.fhNo 'CGD发货单号',
- f.addtime 'CGD本次发货时间'
- FROM
- source_all a
- LEFT JOIN cfp_qrd_info b ON a.productNo = b.sequenceNo
- LEFT JOIN cfp_cgd_info c ON a.cgdNo = c.ShortText1618315935182
- LEFT JOIN fh_source f ON a.cgdNo = f.cgdNo
- LEFT JOIN
- cfp_order_info AS oi ON ( oi.goodNo = b.sequenceNo AND oi.STATUS = 1 )
- LEFT JOIN cfp_order_pool AS po ON (oi.orderNo = po.orderNo
- AND po.is_del = 0 ) LEFT JOIN (
- SELECT
- `k`.`id` AS `aid`,
- `k`.`assocNo` AS `assocNo`,
- `k`.`companyNo` AS `companyNo`,
- `k`.`type` AS `type`,
- `k`.`rela_form` AS `rela_form`,
- `k`.`codeNo` AS `codeNo`,
- `k`.`total_fee` AS `total_fee`,
- `k`.`balance` AS `balance`,
- `k`.`cancel_total` AS `cancel_total`,
- `k`.`is_del` AS `is_del`,
- `k`.`status` AS `status`,
- `k`.`exam_remark` AS `exam_remark`,
- `k`.`addtime` AS `addtime`,
- `t`.`viceNo` AS `viceNo`,
- `t`.`vice_fee` AS `vice_fee`,
- `t`.`cancel_fee` AS `cancel_fee`,
- `t`.`id` AS `id`,
- `k`.`source` AS `source`,
- `t`.`vice_total` AS `vice_total`,
- `k`.`apply_name` AS `apply_name`,
- `k`.`apply_id` AS `apply_id`,
- `t`.`status` AS `bstatus`
- FROM
- (
- `cfp_assoc_key` `k`
- JOIN `cfp_assoc_rela` `t` ON ((
- `k`.`assocNo` = `t`.`assocNo`
- )))
- ) AS ak ON (
- ( ak.codeNo = oi.orderNo OR ak.viceNo = oi.orderNo )
- AND ( rela_form IN ( 1, 2, 3 ) AND ak.STATUS = 3 AND ak.is_del = 0 )
- ) left join cfp_pay_info as pc on (pc.sequenceNo = c.sequenceNo and pc.`status`=1)
- LEFT JOIN cfp_pay_stages as ps on (ps.payNo= pc.payNo and ps.is_del =0)
- left JOIN cfp_pay as p on (p.payNo=pc.payNo and (p.`status`=2 or p.status=1))
-
- WHERE
- a.productNo <> '' {$where} order by ordertime";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."确认单明细", $header, $list);
- }
- /**
- * 采购单明细
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function downreportCGD()
- {
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and cgdtime >='{$start}'";
- }
- if($end!=""){
- $where.=" and cgdtime <='{$end}'";
- }
- $sql = "SELECT
- b.ShortText1618315935182 AS 'CGD.2采购单号',
- b.ShortText1618270466672 AS 'CGD.14公司主体',
- b.Date1618315953443 AS 'CGD.3采购单下单日期',
- b.ShortText1618270412964 AS 'CGD.1采购单类型',
- b.StaffSelector1620899427104 AS 'CGD.采购员',
- b.ShortText1620399144946 AS 'CGD.45供应商名称',
- b.ShortText1619625566608 AS 'CGD.出库包装库存',
- b.ShortText1617865688485 AS 'CGD.40税点',
- ROUND( b.Number1617865810822, 2 ) AS 'CGD.包装费',
- ROUND( b.Number1617865813284, 2 ) AS 'CGD.证书费',
- ROUND( b.Number1617865807879, 2 ) AS 'CGD.加标费',
- ROUND( b.Number1617865816181, 2 ) AS 'CGD.开模费',
- ROUND( b.number1618240204358, 2 ) AS 'CGD.成本工艺费',
- ROUND( b.Number1617865804813, 2 ) AS 'CGD.成本裸价',
- ROUND( b.number1618240287778, 2 ) AS 'CGD.物流费',
- ROUND( b.Number1619632830397, 2 ) AS 'CGD.工差',
- ROUND( b.Number1619632826654, 2 ) AS 'CGD.采购工差金额',
- ROUND( b.Number1617865818517, 2 ) AS 'CGD.采购单价',
- CAST( b.Number1618240600907 AS SIGNED ) AS 'CGD.采购数量',
- ROUND( b.Number1618240685904, 2 ) AS 'CGD.采购金额',
- ROUND( 0, 2 ) AS 'CGD.不含税采购成本-这个怎么计算',
- b.ShortText1618859161646 AS 'BK.10备库单号',
- b.Date1618859180209 AS 'BK.11备库下单日期',
- b.StaffSelector1618885082387 AS 'BK.15业务员',
- b.ShortText1618900704399 AS 'BK.13备库仓库',
- b.ShortText1617861966146 AS 'CGD.CP.26产品名称',
- b.ShortText1617861001482 AS 'CGD.CP.27产品编号',
- b.ShortText1617865626160 AS 'CGD.CP.28一级分类',
- a.cgd_cat_s 'CGD.二级分类',
- a.cgd_cat_t 'CGD.三级分类',
- a.financial 'CGD.财务核算码',
- b.ShortText1617865685744 AS 'CGD.CP.25单位',
- b.ShortText1618240134229 AS 'CGD.CP.36贵金属种类',
- ROUND( b.Number1618240458074, 2 ) AS 'CGD.CP.38实时金价',
- ROUND( b.Number1618240480148, 2 ) AS 'CGD.CP.37商品重量(g)',
- a.is_stock `CGD.是否库存`,
- b.ShortText1618465932373 `CGD.物流方式`,
- (
- ROUND( ifnull( b.Number1618330470625, 0 ), 2 )+ (
- SELECT
- ifnull( round(sum( pc.wait_fee ),2), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS '已付款',
- (
- ROUND( ifnull( b.Number1618330472961, 0 ), 2 )- (
- SELECT
- ifnull( round(sum( pc.wait_fee ),2), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS '未付款',
- (
- ROUND( ifnull( b.Number1618330541286, 0 ), 2 )+ (
- SELECT
- ifnull( round(sum( pc.winv_fee),2), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=7
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS '已回票',
- (
- ROUND( ifnull( b.Number1618330543270, 0 ), 2 )-(
- SELECT
- ifnull( round(sum( pc.winv_fee),2), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=7
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.invtime DESC
- )
- ) AS '待回票',
- a.cgd_delivery_status 'CGD.发货状态',
- pk.total_fee '本次付款金额',
- pk.ainv_fee '本次回票金额',
- if(pk.pay_status=4,'已付','待付') '本次付款状态',
- if(pk.status=7,'已回','待回') '本次回票状态',
- pk.paytime '本次付款时间',
- pk.invtime '本次回票时间',
- ( SELECT sum( send ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'CGD.总发货数量',
- f.send 'CGD.本次发货',
- f.fhNo 'CGD.发货单号',
- f.addtime 'CGD.本次发货时间'
- FROM
- source_all AS a
- LEFT JOIN cfp_cgd_info AS b ON a.cgdNo = b.ShortText1618315935182
- LEFT JOIN fh_source f ON a.cgdNo = f.cgdNo
- LEFT JOIN
- (select pc.total_fee,pc.ainv_fee,pc.sequenceNo,ps.pay_status,ps.status,ps.inv_fee,ps.paytime,ps.invtime from cfp_pay_info AS pc
- inner JOIN cfp_pay_stages AS ps ON (ps.payNo = pc.payNo
- AND ps.is_del = 0 and (ps.pay_status=4 or ps.pay_status=7))
- inner JOIN cfp_pay AS p ON p.payNo = pc.payNo
- AND (p.`status` = 2 or p.`status` = 1) where pc.STATUS = 1) as pk on pk.sequenceNo =a.cgdjlNo
- WHERE
- a.cgdNo <> '' {$where} order by cgdtime";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."采购单明细", $header, $list);
- }
- public function downreportQRDTZ(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and ordertime >='{$start}'";
- }
- if($end!=""){
- $where.=" and ordertime <='{$end}'";
- }
- $sql="SELECT
- '已完成' AS 'QRD.单据状态',
- DATE_FORMAT(b.Date1617081795606, '%Y年') AS '年',
- DATE_FORMAT(b.Date1617081795606, '%m月') AS '月',
- DATE_FORMAT(b.Date1617081795606, '%d日') AS '日',
- CONCAT(
- '第',
- WEEK(
- DATE_ADD(
- b.Date1617081795606,
- INTERVAL 6 DAY
- ),
- 2
- ),
- '周'
- ) AS '周',
- b.ShortText1618447165317 AS '公司名称',
- b.ShortText1619523892833 AS 'KH.2客户名称',
- b.ShortText1619542951283 AS 'KH.3客户编码',
- b.ShortText1619413394855 AS 'KH.4客户属性',
- b.ShortText1619413401534 AS 'KH.6分公司',
- b.ShortText1619413388848 AS 'KH.5大区',
- b.ShortText1619543001392 AS 'KH.7中支',
- b.ShortText1619523693355 AS 'KH.8县支',
- b.ShortText1619523689586 AS 'PT.1平台类型',
- b.ShortText1617366186330 AS 'PT.2平台编码',
- b.ShortText1617023369580 AS 'PT.3业管系统咨询单号',
- b.text1617365646297 AS 'PT.4PO编号',
- b.ShortText1617650701648 AS 'QRD.4确认单编号',
- b.ShortText1617650669915 AS 'QRD.3确认单类型',
- b.Date1617081795606 AS 'QRD.5确认单下单时间',
- DATE_FORMAT(b.Date1617081795606, '%Y-%m-%d') AS 'TZ.2.8确认单下单日期2',
- b.StaffSelector1618445844046 As 'QRD.1业务人员',
- `b`.`sequenceNo` AS `QRD-CP确认单产品编号`,
- `b`.`ShortText1617365292699` AS `CP.1产品名称`,
- `b`.`text1617499162303` AS `CP.2产品编码`,
- `b`.`ShortText1617499192065` AS `CP.3.0一级分类`,
- `source_all`.`cat_t` AS `CP.C二级分类`,
- `source_all`.`cat_d` AS `CP.C三级分类`,
- `source_all`.`fund_code` AS `CP.28财务核算码`,
- `b`.`text1617365597522` AS `CP.7单位`,
- `b`.`ShortText1617367958909` AS `CP.8税点`,
- `b`.`ShortText1619146965777` AS `QRD.6确认单唯一识别码`,
- round( `b`.`Number1619403905454`, 2 ) AS `CP.26工差重量`,
- round( `b`.`Number1619403908740`, 2 ) AS `CP.27工差金额`,
- `b`.`Date1619542686640` AS `QRD.7承诺回款日期`,
- round( `b`.`Number1618248810624`, 2 ) AS `CP.19销售单价`,
- cast( `b`.`Number1617365688048` AS signed ) AS `CP.20下单数量`,
- round( `b`.`Number1618248813613`, 2 ) AS `CP.21销售总额`,
- ROUND(
- b.Number1618248813613 - IF(
- LENGTH(b.ShortText1617367958909) > 1,
- b.Number1618248813613 * (
- CAST(
- LEFT(
- b.ShortText1617367958909,
- LENGTH(b.ShortText1617367958909) - 1
- ) AS DECIMAL
- ) / 100
- ),
- 0
- ),
- 2
- ) AS 'CP.NEW不含税收入-查看一下这个计算的是否正确',
- '-' AS 'CP.NEW毛利润-不知道怎么计算',
- b.ShortText1617111725596 AS 'ZXD.2咨询单编号',
- b.Date1619626098213 AS 'ZXD.4咨询日期',
- b.ShortText1617670912205 AS 'ZXD.3咨询类型',
- '已完成' AS 'CGD.单据状态',
- c.ShortText1618315935182 AS 'CGD.2采购单号',
- c.Date1618315953443 AS 'CGD.3采购单下单日期',
- c.ShortText1618270412964 AS 'CGD.1采购单类型',
- c.StaffSelector1620899427104 AS 'CGD.采购员',
- c.ShortText1620399144946 AS 'CGD.45供应商名称',
- c.ShortText1617861287265 AS 'CGD.44供应商编号',
- c.ShortText1619625566608 AS 'CGD.出库包装库存',
- c.ShortText1617865688485 AS 'CGD.40税点',
- ROUND(c.Number1617865810822, 2) AS 'CGD.包装费',
- ROUND(c.Number1617865813284, 2) AS 'CGD.证书费',
- ROUND(c.Number1617865807879, 2) AS 'CGD.加标费',
- ROUND(c.Number1617865816181, 2) AS 'CGD.开模费',
- ROUND(c.number1618240204358, 2) AS 'CGD.成本工艺费',
- ROUND(c.Number1617865804813, 2) AS 'CGD.成本裸价',
- ROUND(c.number1618240287778, 2) AS 'CGD.物流费',
- ROUND(c.Number1619632830397, 2) AS 'CGD.工差',
- ROUND(c.Number1619632826654, 2) AS 'CGD.采购工差金额',
- ROUND(c.Number1617865818517, 2) AS 'CGD.采购单价',
- CAST(c.Number1618240600907 AS SIGNED) AS 'CGD.采购数量',
- ROUND(c.Number1618240685904, 2) AS 'CGD.采购金额',
- ROUND(0, 2) AS 'CGD.不含税采购成本-这个怎么计算',
- (
- ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS 'CGD.FK.总-已付款金额',
-
- (
- ROUND( ifnull( c.Number1618330472961, 0 ), 2 )- (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS 'CGD.FK.总-未付款金额',
-
- CASE
- WHEN (
- ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) =0 THEN
- '未付款'
- WHEN (
- ROUND( ifnull( c.Number1618330472961, 0 ), 2 )- (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) =0 THEN
- '全部付款'
- ELSE '部分付款'
- END AS 'CGD.FK.总-付款情况',
-
- (
- ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS 'CGD.FK.MX.总-已付款金额',
- (
- SELECT
- paytime
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.paytime DESC
- LIMIT 1
- ) AS 'CGD.FK.MX.总-最近一次付款时间',
- (
- ROUND( ifnull( c.Number1618330541286, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS 'CGD.HP.总-已回票金额',
- (
- ROUND( ifnull( c.Number1618330543270, 0 ), 2 )-(
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.invtime DESC
- )
- ) AS 'CGD.HP.总-未回票金额',
- CASE
- WHEN (
- ROUND( ifnull( c.Number1618330541286, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- )=0 THEN
- '未回票'
- WHEN (
- ROUND( ifnull( c.Number1618330543270, 0 ), 2 )-(
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.invtime DESC
- )
- ) =0 THEN
- '全部回票'
- ELSE '部分回票'
- END 'CGD.HP.总-回票情况',
- (
- ROUND( ifnull( c.Number1618330543270, 0 ), 2 )-(
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.invtime DESC
- )
- ) AS 'CGD.HP.MX.总-已回票金额',
- (
- SELECT
- invtime
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
-
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.invtime DESC
- LIMIT 1
- ) AS 'CGD.HP.MX.总-最近一次回票时间',
- c.ShortText1620753234895 AS 'CGD.回票方式',
- c.ShortText1620753237335 AS 'CGD.结算方式',
- c.ShortText1617866144054 AS 'CGD.42库房性质',
- c.ShortText1618465932373 AS 'CGD.62发货方式',
- source_all.delivery_num AS 'QRD-CP.FH.总-已发货',
- source_all.delivery_wnum AS 'QRD-CP.FH.总-未发货',
- source_all.delivery_status AS 'QRD-CP.FH.总-发货状态',
- source_all.delivery_send AS 'CGD.FH.总-已发货',
- source_all.delivery_wsend AS 'CGD.FH.总-未发货',
- source_all.cgd_delivery_status AS 'CGD.FH.总-发货状态',
- (SELECT
- SUM(
- send
- )
- FROM
- `fh_source` e_
- WHERE e_.cgdNo = source_all.cgdNo) AS 'CGD.FH.MX.总-已发货',
- (SELECT
- MAX(e_.addtime)
- FROM
- `fh_source` e_
- WHERE e_.cgdNo = source_all.cgdNo) AS 'CGD.FH.MX.总-最近一次发货时间',
- ROUND(b.Number1618249202608, 2) AS 'QRD-CP.KP.总-已开票金额',
- ROUND(b.Number1618249205231+b.inving_fee, 2) AS 'QRD-CP.KP.总-未开票金额',
- if(b.ShortText1618559274859=3,'已开','未开') AS 'QRD-CP.KP.总-开票状态',
- ROUND(
- (SELECT
- sum(oi.ainv_fee)
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_key AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
- LEFT JOIN cfp_assoc_rela AS al ON ( ak.assocNo =al.assocNo AND al.`status` = 1 )
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0
- and oi.goodNo =b.sequenceNo),
- 2
- ) AS 'QRD-CP.KP.MX.总-已开票金额',
- (SELECT
- GROUP_CONCAT(
- al.viceNo
- )
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_key AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
- LEFT JOIN cfp_assoc_rela AS al ON ( ak.assocNo =al.assocNo AND al.`status` = 1 )
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0
- and oi.goodNo =b.sequenceNo) AS 'QRD-CP.KP.MX.总-发票号',
- (SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_key AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0
- and oi.goodNo =b.sequenceNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1) AS 'QRD-CP.KP.MX.最新开票时间',
- ROUND(b.Number1618249146997, 2) AS 'QRD-CP.HK.总-已回款金额',
- ROUND(b.number1618249149738+b.paying_fee, 2) AS 'QRD-CP.HK.总-未回款金额',
- if(b.ShortText1618559043560=3,'已回','未回') AS 'QRD-CP.HK.总-回款状态',
- (SELECT
- sum(oi.afund_fee)
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_key AS ak ON ( ak.codeNo = oi.orderNo AND (rela_form = 2 or rela_form = 3))
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0
- and oi.goodNo =b.sequenceNo
- ORDER BY
- ak.addtime) as 'QRD-CP.HK.MX.总-已回款金额',
- (SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_key AS ak ON ( ak.codeNo = oi.orderNo AND (rela_form = 2 or rela_form = 3))
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0
- and oi.goodNo =b.sequenceNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1) as 'QRD-CP.HK.MX.最新回款时间'
- FROM
- source_all left JOIN cfp_qrd_info b on
- source_all.productNo = b.sequenceNo
- LEFT JOIN cfp_cgd_info c on source_all.cgdNo = c.ShortText1618315935182
- where source_all.productNo<>'' {$where} order by ordertime";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."确认单台账", $header, $list);
- }
- public function downreportCGDTZ(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and cgdtime >='{$start}'";
- }
- if($end!=""){
- $where.=" and cgdtime <='{$end}'";
- }
- $sql="SELECT
- b.ShortText1618315935182 AS 'CGD.2采购单号',
- b.ShortText1618270466672 AS 'CGD.14公司主体',
- b.Date1618315953443 AS 'CGD.3采购单下单日期',
- b.ShortText1618270412964 AS 'CGD.1采购单类型',
- b.StaffSelector1620899427104 AS 'CGD.采购员',
- b.ShortText1620399144946 AS 'CGD.45供应商名称',
- b.ShortText1617861287265 AS 'CGD.44供应商编号',
- b.ShortText1619625566608 AS 'CGD.出库包装库存',
- b.ShortText1617865688485 AS 'CGD.40税点',
- ROUND( b.Number1617865810822, 2 ) AS 'CGD.包装费',
- ROUND( b.Number1617865813284, 2 ) AS 'CGD.证书费',
- ROUND( b.Number1617865807879, 2 ) AS 'CGD.加标费',
- ROUND( b.Number1617865816181, 2 ) AS 'CGD.开模费',
- ROUND( b.number1618240204358, 2 ) AS 'CGD.成本工艺费',
- ROUND( b.Number1617865804813, 2 ) AS 'CGD.成本裸价',
- ROUND( b.number1618240287778, 2 ) AS 'CGD.物流费',
- ROUND( b.Number1619632830397, 2 ) AS 'CGD.工差',
- ROUND( b.Number1619632826654, 2 ) AS 'CGD.采购工差金额',
- ROUND( b.Number1617865818517, 2 ) AS 'CGD.采购单价',
- CAST( b.Number1618240600907 AS SIGNED ) AS 'CGD.采购数量',
- ROUND( b.Number1618240685904, 2 ) AS 'CGD.采购金额',
- ROUND( 0, 2 ) AS 'CGD.不含税采购成本-这个怎么计算',
- b.ShortText1617866362204 AS 'QRD-CP.4确认单类型',
- b.ShortText1617866360004 AS 'QRD-CP.5确认单编号',
- b.Date1618324547052 AS 'QRD-CP.6确认单下单日期',
- b.ShortText1618239976714 AS 'QRD.ZX.7咨询单编号',
- b.ShortText1617866364821 AS 'QRD.ZX.8咨询单类型',
- b.Date1619624209148 AS 'QRD.ZX.9咨询单下单时间',
- b.ShortText1618859161646 AS 'BK.10备库单号',
- b.Date1618859180209 AS 'BK.11备库下单日期',
- b.StaffSelector1618885082387 AS 'BK.15业务员',
- b.ShortText1618900704399 AS 'BK.13备库仓库',
- b.ShortText1617861966146 AS 'CGD.CP.26产品名称',
- b.ShortText1617861001482 AS 'CGD.CP.27产品编号',
- b.ShortText1617865626160 AS 'CGD.CP.28一级分类',
- a.cgd_cat_s AS 'CGD.CP.C二级分类',
- a.cgd_cat_t AS 'CGD.CP.C三级分类',
- a.financial AS 'CGD.CP.C财务核算编码',
- b.ShortText1617865685744 AS 'CGD.CP.25单位',
- b.ShortText1618240134229 AS 'CGD.CP.36贵金属种类',
- ROUND( b.Number1618240458074, 2 ) AS 'CGD.CP.38实时金价',
- ROUND( b.Number1618240480148, 2 ) AS 'CGD.CP.37商品重量(g)',
- (
- ROUND( ifnull( b.Number1618330470625, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS 'CGD.FK.总-已付款金额',
- (
- ROUND( ifnull( b.Number1618330472961, 0 ), 2 )-(
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS 'CGD.FK.总-未付款金额',
- CASE
-
- WHEN (
- ROUND( ifnull( b.Number1618330470625, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) = 0 THEN
- '未付款'
- WHEN (
- ROUND( ifnull( b.Number1618330472961, 0 ), 2 )- (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) = 0 THEN
- '全部付款' ELSE '部分付款'
- END AS 'CGD.FK.总-付款情况',
- (
- round( ifnull( b.Number1618330470625, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = b.sequenceNo
- )
- ) AS 'CGD.FK.MX.总-已付款金额',
- (
- SELECT
- paytime
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- LIMIT 1
- ) AS 'CGD.HP.MX.总最近一次付款时间',
- ROUND(
- ROUND( ifnull( b.Number1618330541286, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = b.sequenceNo
- ),
- 2
- ) AS 'CGD.HP.总-已回票金额',
- ROUND(
- ifnull( b.Number1618330543270, 0 )-(
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = b.sequenceNo
- ),
- 2
- ) AS 'CGD.HP.总-未回票金额',
- CASE
-
- WHEN (
- ROUND( ifnull( b.Number1618330541286, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- )= 0 THEN
- '未回票'
- WHEN (
- ROUND( ifnull( b.Number1618330543270, 0 ), 2 )-(
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.invtime DESC
- LIMIT 1
- )
- ) = 0 THEN
- '全部回票' ELSE '部分回票'
- END AS 'CGD.HP.总-回票情况',
- ROUND(
- ROUND( ifnull( b.Number1618330541286, 0 ), 2 )+ ifnull((
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = b.sequenceNo
- ),
- 0
- ),
- 2
- ) AS 'CGD.HP.MX.总-已回票金额',
- (
- SELECT
- ps.invtime
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.invtime DESC
- LIMIT 1
- ) AS 'CGD.HP.MX.总最近一次回票时间',
- CAST( a.delivery_send AS SIGNED ) AS 'CGD.FH.总-已发货',
- CAST( a.delivery_wsend AS SIGNED ) AS 'CGD.FH.总-未发货',
- a.cgd_delivery_status AS 'CGD.FH.总-发货状态',
- ( SELECT sum( send ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'CGD.FH.MX.总-已发货',
- ( SELECT max( addtime ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'CGD.FH.MX.总-最近一次发货时间'
- FROM
- source_all a
- LEFT JOIN cfp_cgd_info b ON a.cgdNo = b.ShortText1618315935182
- WHERE
- a.cgdNo <> '' {$where} order by cgdtime";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."采购单台账", $header, $list);
- }
- /**退货台账、明细一样的
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function downreportTHTZ(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and t.createtime >='{$start}'";
- }
- if($end!=""){
- $where.=" and t.createtime <='{$end}'";
- }
- $sql="select
- t.thNo `退货单号`,
- case t.th_status
- WHEN 1 THEN '已完成'
- WHEN 2 THEN '进行中'
- WHEN 3 THEN '已取消'
- else '' end AS `流程进度`,
- t.createtime `退货发起日期`,
- t.th_company '公司名称',
- t.th_user '退货人',
- t.th_num '25退货数量',
- t.th_qrd_fee '26退货销售货款',
- t.th_cgd_fee '42退货采购货款',
- IF
- (( t.`is_th` = '1' ), '是', '否' ) '50供应商是否可以退货',
- t.th_remark '27退货备注',
- '' as '52退货备注',
- t.th_post_company '退货物流信息-53物流公司',
- t.th_post_code '退货物流信息-54物流单编号',
- `t`.`th_post_fee` AS `退货物流信息-55物流费用`,
- `t`.`th_receiver` AS `退货物流信息-56收货人`,
- `t`.`th_phone` AS `退货物流信息-57收货人电话`,
- '' AS `退货物流信息-58收货人电话2`,
- `t`.`th_addr` AS `退货物流信息-59收货人地址`,
- companyName AS `KH.2客户名称`,
- companyNo AS `KH.3客户编码`,
- khzzxz AS `KH.4客户属性`,
- khcomp AS `KH.6分公司`,
- '' AS `KH.5大区`,
- middle_branch AS `KH.7中支`,
- area_branch AS `KH.8县支`,
- suppitem AS `PT.1平台类型`,
- itemcode AS `PT.2平台编码`,
- workNo AS `PT.3业管系统咨询单号`,
- poNo AS `PT.4PO编号`,
- source_all.qrdNo AS `QRD.4确认单编号`,
- qrd_type AS `QRD.3确认单类型`,
- ordertime AS `QRD.5确认单下单时间`,
- date_format( ordertime, '%Y-%m-%d' ) AS `TZ.2.8确认单下单日期2`,
- sale_name AS `QRD.1业务人员`,
- productNo AS `QRD-CP确认单产品编号`,
- product_name AS `CP.1产品名称`,
- product_code AS `CP.2产品编码`,
- cat_f AS `CP.3.0一级分类`,
- cat_t AS `CP.C二级分类`,
- cat_d AS `CP.C三级分类`,
- fund_code AS `CP.28财务核算码`,
- unit AS `CP.7单位`,
- tax AS `CP.8税点`,
- qrdkey AS `QRD.6确认单唯一识别码`,
- round( diff_weight, 2 ) AS `CP.26工差重量`,
- round( diff_price, 2 ) AS `CP.27工差金额`,
- paytime AS `QRD.7承诺回款日期`,
- round( sale_price, 2 ) AS `CP.19销售单价`,
- cast( order_num AS signed ) AS `CP.20下单数量`,
- round( sale_total, 2 ) AS `CP.21销售总额`,
- income as `CP.NEW不含税收入-查看一下这个计算的是否正确`,
- '-' AS `CP.NEW毛利润-不知道怎么计算`,
- zxcode AS `ZXD.2咨询单编号`,
-
- zxfktime AS `ZXD.4咨询日期`,
- zxtype AS `ZXD.3咨询类型`,
- cgdNo AS `CGD.2采购单号`,
- cgdtime AS `CGD.3采购单下单日期`,
- cgdtype AS `CGD.1采购单类型`,
- cgd_saler AS `CGD.采购员`,
- supplier AS `CGD.45供应商名称`,
- suppierNo AS `CGD.44供应商编号`,
- paking AS `CGD.出库包装库存`,
- cgd_tax AS `CGD.40税点`,
- round( pakage_fee, 2 ) AS `CGD.包装费`,
- round( cert_fee, 2 ) AS `CGD.证书费`,
- round( mark_fee, 2 ) AS `CGD.加标费`,
- round(open_fee, 2 ) AS `CGD.开模费`,
- round( cost_fee, 2 ) AS `CGD.成本工艺费`,
- round( naked_fee, 2 ) AS `CGD.成本裸价`,
- round( delivery_fee, 2 ) AS `CGD.物流费`,
- round( cgd_diff_weight, 2 ) AS `CGD.工差`,
- round( diff_fee, 2 ) AS `CGD.采购工差金额`,
- round(cgd_price, 2 ) AS `CGD.采购单价`,
- cast( cgd_num AS signed ) AS `CGD.采购数量`,
- round(cgd_total, 2 ) AS `CGD.采购金额`,
- round( 0, 2 ) AS `CGD.不含税采购成本-这个怎么计算`,
-
-
- (ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
- SELECT
- ifnull( round(sum( pc.wait_fee ),2), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )) AS `CGD.FK.总-已付款金额`,
-
-
- (ROUND( ifnull( c.Number1618330472961, 0 ), 2 )- (
- SELECT
- ifnull( round(sum( pc.wait_fee ),2), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- ) ) AS `CGD.FK.总-未付款金额`,
- CASE
-
- WHEN (
- ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) = 0 THEN
- '未付款'
- WHEN (
- ROUND( ifnull( c.Number1618330472961, 0 ), 2 )- (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.pay_status = 4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) = 0 THEN
- '全部付款' ELSE '部分付款'
- END AS 'CGD.FK.总-付款情况',
- (ROUND( ifnull( c.Number1618330541286, 0 ), 2 )+
- (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = b.sequenceNo
- GROUP BY
- pc.sequenceNo
- )
- ) AS 'CGD.HP.总-已回票金额',
- ROUND(
- ifnull( c.Number1618330543270, 0 ) -(
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = b.sequenceNo
- GROUP BY
- pc.sequenceNo
- ),
- 2
- ) AS 'CGD.HP.总-未回票金额',
- CASE
-
- WHEN (
- ROUND( ifnull( c.Number1618330541286, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- )= 0 THEN
- '未回票'
- WHEN (
- ROUND( ifnull( c.Number1618330543270, 0 ), 2 )-(
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND ( p.`status` = 2 OR p.STATUS = 1 )
- AND ps.STATUS = 7
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.invtime DESC limit 1
- )
- ) = 0 THEN
- '全部回票' ELSE '部分回票'
- END AS 'CGD.HP.总-回票情况',
- '' AS `CGD.HP.MX.总-已回票金额`,
-
- return_ticket AS `CGD.回票方式`,
- return_trade AS `CGD.结算方式`,
- c.ShortText1617866144054 AS `CGD.42库房性质`,
- `c`.`ShortText1618465932373` AS `CGD.62发货方式`,
- cast( `b`.`Number1618249015661` AS signed ) AS `QRD-CP.FH.总-已发货`,
- cast( `b`.`Number1618249019294` AS signed ) AS `QRD-CP.FH.总-未发货`,
- `b`.`ShortText1618559007040` AS `QRD-CP.FH.总-发货状态`,
- cast( `c`.`Number1618316157066` AS signed ) AS `CGD.FH.总-已发货`,
- cast( `c`.`Number1618316171848` AS signed ) AS `CGD.FH.总-未发货`,
- if(`c`.`ShortText1618859321070`=1,'未发',if(`c`.`ShortText1618859321070`=3,'已发','部分')) AS `CGD.FH.总-发货状态`,
- (
- SELECT sum( send ) FROM fh_source WHERE source_all.cgdNo = fh_source.cgdNo ) AS `CGD.FH.MX.总-已发货`,
- round( `b`.`Number1618249202608`, 2 ) AS `QRD-CP.KP.总-已开票金额`,
- round( `b`.`Number1618249205231`+b.inving_fee, 2 ) AS `QRD-CP.KP.总-未开票金额`,
- if(`b`.`ShortText1618559274859`=1,'未开',if(`b`.`ShortText1618559274859`=3,'已开','部分')) AS `QRD-CP.KP.总-开票状态`,
- '' AS `QRD-CP.KP.MX.总-已开票金额`,
- round( `b`.`Number1618249146997`, 2 ) AS `QRD-CP.HK.总-已回款金额`,
- round( `b`.`number1618249149738`+b.paying_fee, 2 ) AS `QRD-CP.HK.总-未回款金额`,
- if(`b`.`ShortText1618559043560`=1,'未回',if(`b`.`ShortText1618559043560`=3,'已回','部分')) AS `QRD-CP.HK.总-回款状态`,
- '' AS `QRD-CP.HK.MX.总-已回款金额`
- from cfp_th_source as t left join
- source_all on ((source_all.productNo=t.th_qrdcpNo and t.th_qrdcpNo<>'') or (t.th_cgdNo=source_all.cgdNo and t.th_cgdNo<>'')) left JOIN cfp_qrd_info b on
- t.th_qrdcpNo = b.sequenceNo
- LEFT JOIN cfp_cgd_info c on t.th_cgdNo = c.ShortText1618315935182
- where t.th_status<>3 {$where} order by t.createtime";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."退货台账", $header, $list);
- }
- /**
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function downreportCW(){
- $post = request()->post();
- $condition="";
- $qrd_start = isset($post['qrd_start']) && $post['qrd_start'] != "" ? $post['qrd_start'] :"" ;
- if($qrd_start!=""){
- $condition .=" and ordertime>='". $qrd_start." 00:00:00'";
- }
- $qrd_end = isset($post['qrd_end']) && $post['qrd_end'] != "" ? $post['qrd_end'] :"" ;
- if($qrd_end!=""){
- $condition .=" and ordertime <='". $qrd_end." 23:59:59'";
- }
- $hk_start = isset($post['hk_start']) && $post['hk_start'] != "" ? $post['hk_start'] :"" ;
- $hk_end = isset($post['hk_end']) && $post['hk_end'] != "" ? $post['hk_end'] :"" ;
- if($hk_start!=""){
- $condition .=" and addtime >='". $hk_start." 00:00:00'";
- }
- if($hk_end!=""){
- $condition .=" and addtime <='". $hk_end." 23:59:59'";
- }
- if($qrd_start==""&&$hk_start==""){
- $condition .=" and ordertime>='". date("Y-m-d")." 00:00:00'";
- }
- $sql="SELECT
- supperinfo '公司名称',
- sale_name '销售人员',
- depart '部门',
- qrd_type '订单类型',
- qrdNo '确认单编号',
- cgdNo '采购单单号' ,
- khzzxz '客户属性',
- khcomp '客户分公司',
- companyName '客户名称',
- product_name '产品名称',
- cat_f '一级分类',
- sale_price '销售单价',
- order_num '下单数量',
- sale_total '销售总额',
- ordertime '确认单下单时间',
- addtime '回款日期',
- fund_fee '回款金额',
- pay_day '账期'
- FROM
- cfp_cw_report
- WHERE
- 1=1
- {$condition} order by ordertime";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave("财务台账", $header, $list);
- }
- public function downreportCWTZ(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and ordertime >='{$start}'";
- }
- if($end!=""){
- $where.=" and ordertime <='{$end}'";
- }
- $sql="SELECT
- DATE_FORMAT( ordertime, '%Y' ) '年',
- DATE_FORMAT( ordertime, '%m' ) '月',
- DATE_FORMAT( ordertime, '%d' ) '日',
- productNo 'QRD确认单产品编号',
- supperinfo 'QRD公司名称',
- companyName 'QRD客户名称',
- suppitem 'QRD平台',
- khzzxz 'QRD客户属性',
- khcomp 'QRD客户分公司',
- poNo 'PT.4PO编号',
- zxtype 'QRD线上线下',
- source_all.qrdNo 'QRD.4确认单编号',
- qrd_type 'QRD.确认单类型',
- ordertime 'QRD.确认单下单时间',
- sale_name 'QRD.业务员',
- product_name 'QRD.产品名称',
- cat_f 'QRD.一级分类',
- tax 'QRD.税率',
- sale_price 'QRD.销售单价',
- order_num 'QRD.下单数量',
- sale_total 'QRD.销售总额',
- source_all.cgdNo 'CGD采购单单号',
- ROUND( b.Number1618249146997, 2 ) 'QRD已回款',
- ROUND( b.number1618249149738, 2 ) 'QRD未回款',
- ROUND( b.paying_fee, 2 ) 'QRD回款进行中',
- ROUND( b.Number1618249202608, 2 ) 'QRD已开票',
- ROUND( b.Number1618249205231, 2 ) 'QRD未开票',
- ROUND( b.inving_fee, 2 ) 'QRD开票进行中',
- CASE
- b.ShortText1618559043560
- WHEN 1 THEN
- '未回款'
- WHEN 2 THEN
- '部分回款'
- WHEN 3 THEN
- '全部回款' ELSE ''
- END 'QRD.回款状态',
- CASE
- b.ShortText1618559274859
- WHEN 1 THEN
- '未开票'
- WHEN 2 THEN
- '部分开票'
- WHEN 3 THEN
- '全部开票' ELSE ''
- END 'QRD.开票状态',
- (
- SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1
- ) AS 'QRD.最近开票时间',
- (
- SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_list AS ak ON (
- ak.codeNo = oi.orderNo
- AND ( rela_form = 2 OR rela_form = 3 ))
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1
- ) AS 'QRD.最近回款时间',
- if(ISNULL( (
- SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_list AS ak ON (
- ak.codeNo = oi.orderNo
- AND ( rela_form = 2 OR rela_form = 3 ))
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1
- ) ),ceil(DATEDIFF(NOW(),ordertime)),ceil(DATEDIFF((
- SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_list AS ak ON (
- ak.codeNo = oi.orderNo
- AND ( rela_form = 2 OR rela_form = 3 ))
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1
- ),ordertime))) as '账期',
- if(ISNULL( (
- SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_list AS ak ON (
- ak.codeNo = oi.orderNo
- AND ( rela_form = 2 OR rela_form = 3 ))
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1
- ) ),if(ceil(DATEDIFF(NOW(),ordertime)/30)>6,'是','否'),if(ceil(DATEDIFF((
- SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_list AS ak ON (
- ak.codeNo = oi.orderNo
- AND ( rela_form = 2 OR rela_form = 3 ))
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1
- ),ordertime)/30)>6,'是','否')) as '账期是否超期',
- IF
- ( DATEDIFF( NOW(), ordertime )> 60, '是', '否' ) AS '下单是否超期',
- IF
- (
- ISNULL((
- SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1
- )
- ),
- if(DATEDIFF((
- SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1
- ),
- ordertime
- )>15,'是','否'),
- if(DATEDIFF( NOW(), ordertime )>15,'是','否')) AS '开票是否超期',
- delivery_status 'QRD.发货状态',
- ( SELECT sum( send ) FROM fh_source WHERE source_all.qrdNo = fh_source.qrdNo ) AS 'qrd.总发货数量',
- ( SELECT max( addtime ) FROM fh_source WHERE source_all.qrdNo = fh_source.qrdNo ) AS 'qrd.最近一次发货时间'
- FROM
- source_all
- LEFT JOIN cfp_qrd_info b ON source_all.productNo = b.sequenceNo
- LEFT JOIN cfp_cgd_info c ON source_all.cgdNo = c.ShortText1618315935182
- WHERE
- source_all.productNo <> '' {$where}
- ORDER BY
- ordertime DESC ";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."应收台账", $header, $list);
- }
- /**
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function downQRD(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and ordertime >='{$start}'";
- }
- if($end!=""){
- $where.=" and ordertime <='{$end}'";
- }
- $sql = "SELECT
- DATE_FORMAT(ordertime,'%Y') '年',
- DATE_FORMAT(ordertime,'%m') '月',
- DATE_FORMAT(ordertime,'%d') '日',
- a.supperinfo 'QRD公司名称',
- a.zxtype 'QRD.咨询单类型',
- a.qrdNo 'QRD.4确认单编号',
- a.sale_name 'QRD.业务员',
- a.suppitem 'QRD平台',
- a.khzzxz 'QRD客户属性',
- a.khcomp 'QRD客户分公司',
- a.product_code 'QRD.产品编号',
- a.cat_f 'QRD.一级分类',
- a.fund_code 'QRD.财务核算码',
- a.product_name 'QRD.产品名称',
- a.unit 'QRD.单位',
- a.sale_price 'QRD.销售单价',
- a.order_num 'QRD.下单数量',
- a.sale_total 'QRD.销售总额',
- ROUND( b.Number1618249202608, 2 ) 'QRD已开票',
- ROUND( b.Number1618249205231+b.inving_fee, 2 ) 'QRD未开票',
- IF
- ( ak.rela_form = 1, ak.addtime, '' ) 'QRD本次开票时间',
- IF
- ( ak.rela_form = 1, ak.cancel_total, '' ) 'QRD本次开票金额',
- if(b.ShortText1618559274859=1,'未开票',if(b.ShortText1618559274859=3,'已开票','部分开票')) 'QRD开票完成状态',
- a.cgdNo 'CGD采购单单号',
- pl.invNo '确认单发票申请编号',
- (select ci.company_name from cfp_company_info ci where ci.companyNo=pl.inv_out) '发票开具全称',
- li.inv_number '发票号码'
- FROM
- source_all a
- LEFT JOIN cfp_qrd_info b ON a.productNo = b.sequenceNo
- LEFT JOIN cfp_cgd_info c ON a.cgdNo = c.ShortText1618315935182
- LEFT JOIN fh_source f ON a.cgdNo = f.cgdNo
- LEFT JOIN
- cfp_order_info AS oi ON ( oi.goodNo = b.sequenceNo AND oi.STATUS = 1 )
- LEFT JOIN cfp_order_pool AS po ON (oi.orderNo = po.orderNo
- AND po.is_del = 0 ) LEFT JOIN (
- SELECT
- `k`.`id` AS `aid`,
- `k`.`assocNo` AS `assocNo`,
- `k`.`companyNo` AS `companyNo`,
- `k`.`type` AS `type`,
- `k`.`rela_form` AS `rela_form`,
- `k`.`codeNo` AS `codeNo`,
- `k`.`total_fee` AS `total_fee`,
- `k`.`balance` AS `balance`,
- `k`.`cancel_total` AS `cancel_total`,
- `k`.`is_del` AS `is_del`,
- `k`.`status` AS `status`,
- `k`.`exam_remark` AS `exam_remark`,
- `k`.`addtime` AS `addtime`,
- `t`.`viceNo` AS `viceNo`,
- `t`.`vice_fee` AS `vice_fee`,
- `t`.`cancel_fee` AS `cancel_fee`,
- `t`.`id` AS `id`,
- `k`.`source` AS `source`,
- `t`.`vice_total` AS `vice_total`,
- `k`.`apply_name` AS `apply_name`,
- `k`.`apply_id` AS `apply_id`,
- `t`.`status` AS `bstatus`
- FROM
- (
- `cfp_assoc_key` `k`
- JOIN `cfp_assoc_rela` `t` ON ((
- `k`.`assocNo` = `t`.`assocNo`
- )))
- ) AS ak ON (
- ( ak.codeNo = oi.orderNo OR ak.viceNo = oi.orderNo )
- AND ( rela_form IN ( 1, 2, 3 ) AND ak.STATUS = 3 AND ak.is_del = 0 )
- ) left join cfp_pay_info as pc on (pc.sequenceNo = c.sequenceNo and pc.`status`=1)
- LEFT JOIN cfp_pay_stages as ps on (ps.payNo= pc.payNo and ps.is_del =0)
- left JOIN cfp_pay as p on (p.payNo=pc.payNo and (p.`status`=2 or p.status=1))
- LEFT JOIN cfp_invoice_pool as pl on (ak.viceNo = pl.invNo and ak.rela_form=1)
- LEFT JOIN cfp_invoice_list as li on (pl.invNo =li.invNo and li.`status`=1 and li.is_del=0)
- WHERE
- a.productNo <> '' {$where} order by ordertime";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."确认单核算", $header, $list);
- }
- public function downCGD()
- {
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and cgdtime >='{$start}'";
- }
- if($end!=""){
- $where.=" and cgdtime <='{$end}'";
- }
- $sql = "SELECT
- a.cgd_saler 'CGD.采购员',
- a.cgdtype 'CGD.采购单类型',
- a.cgdNo 'CGD.采购单单号',
- a.bkNo 'CGD.备库单号',
- ifnull( `a`.`pakage_fee`, 0 ) AS `CGD.包装费`,
- ifnull( `a`.`cert_fee`, 0 ) AS `CGD.证书费`,
- ifnull( `a`.`mark_fee`, 0 ) AS `CGD.加标费`,
- ifnull( `a`.`open_fee`, 0 ) AS `CGD.开模费`,
- ifnull( `a`.`cost_fee`, 0 ) AS `CGD.成本工艺费`,
- ifnull( `a`.`naked_fee`, '' ) AS `CGD.成本裸价`,
- ifnull( `a`.`delivery_fee`, 0 ) AS `CGD.物流费`,
- ifnull( `a`.`cgd_price`, '' ) AS `CGD.采购单价`,
- cast( `a`.`cgd_num` AS signed ) AS `CGD.采购数量`,
- `a`.`cgd_total` AS `CGD.采购金额`,
- '' as '毛利率',
- a.is_stock `CGD.是否库存`,
- a.paking 'CGD.出库包装库存',
- a.cgd_tax 'CGD.采购单税率',
- a.supplier 'CGD.供货商',
- a.delivery_type `CGD.物流方式`,
- (
- ROUND( ifnull( b.Number1618330470625, 0 ), 2 )+ (
- SELECT
- ifnull( round(sum( pc.wait_fee ),2), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND p.`status` = 2 and ps.pay_status=4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS '已付款',
- (
- ROUND( ifnull( b.Number1618330472961, 0 ), 2 )- (
- SELECT
- ifnull( round(sum( pc.wait_fee ),2), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND p.`status` = 2 and ps.pay_status=4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS '未付款',
- (
- ROUND( ifnull( b.Number1618330541286, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND p.`status` = 2 and ps.status=7
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS '已回票',
- (
- ROUND( ifnull( b.Number1618330543270, 0 ), 2 )-(
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND p.`status` = 2 and ps.status=7
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.invtime DESC
- )
- ) AS '待回票',
- a.cgd_delivery_status 'CGD.发货状态',
- pc.total_fee '本次付款金额',
- pc.ainv_fee '本次回票金额',
- ps.paytime '本次付款时间',
- ps.invtime '本次回票时间',
- f.send_date '本次发货时间',
- f.send '本次发货数量',
- a.return_ticket '回票方式',
- a.return_trade '结算方式',
- if((
- ROUND( ifnull( b.Number1618330543270, 0 ), 2 )-(
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND p.`status` = 2 and ps.status=7
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.invtime DESC
- )
- )=0,'已回','未回' )AS '回票状态',
- if((
- ROUND( ifnull( b.Number1618330472961, 0 ), 2 )- (
- SELECT
- ifnull( round(sum( pc.wait_fee ),2), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND p.`status` = 2 and ps.status=4
- AND pc.sequenceNo = b.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- )=0,'已付','未付' ) AS '付款状态'
- FROM
- source_all AS a
- LEFT JOIN cfp_cgd_info AS b ON a.cgdNo = b.ShortText1618315935182
- LEFT JOIN fh_source f ON a.cgdNo = f.cgdNo
- LEFT JOIN cfp_pay_info AS pc ON pc.sequenceNo = b.sequenceNo
- AND pc.STATUS = 1
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- AND ps.is_del = 0
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- AND p.`status` = 2
- WHERE
- a.cgdNo <> '' {$where} order by cgdtime";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."采购单核算", $header, $list);
- }
- public function downQRDTZ(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and ordertime >='{$start}'";
- }
- if($end!=""){
- $where.=" and ordertime <='{$end}'";
- }
- $sql="SELECT
- DATE_FORMAT(ordertime,'%Y') '年',
- DATE_FORMAT(ordertime,'%m') '月',
- DATE_FORMAT(ordertime,'%d') '日',
- supperinfo 'QRD公司名称',
- zxcode 'QRD.咨询单号',
- zxtype 'QRD.咨询单类型',
- source_all.qrdNo 'QRD.4确认单编号',
- sale_name 'QRD.业务员',
- suppitem 'QRD平台',
- khzzxz 'QRD客户属性',
- khcomp 'QRD客户分公司',
- product_name 'QRD.产品名称',
- product_code 'QRD.产品编号',
- cat_f 'QRD.一级分类',
- unit 'QRD.单位',
- tax 'QRD.税率',
- sale_price 'QRD.销售单价',
- order_num 'QRD.下单数量',
- sale_total 'QRD.销售总额',
- income 'QRD.不含税收入',
- ROUND(b.Number1618249202608,2) 'QRD已开票',
- ROUND(b.Number1618249205231 ,2) 'QRD未开票',
- b.inving_fee 'QRD开票中',
- source_all.cgdNo 'CGD采购单单号',
- cgdtype 'CGD采购单类型',
- cgd_saler 'CGD采购单业务员',
- suplier_name 'CGD供货商名称',
- cgd_tax 'CGD采购单税点',
- pakage_fee 'CGD包装费',
- cert_fee 'CGD证书费',
- mark_fee 'CGD加标费',
- open_fee 'CGD开模费',
- cost_fee 'CGD成本工艺费',
- naked_fee 'CGD裸价',
- delivery_fee 'CGD物流费',
- cgd_price 'CGD采购单单价',
- cgd_num 'CGD采购单数量',
- cgd_total 'CGD采购单金额',
- (
- ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND p.`status` = 2 and ps.pay_status=4
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS 'CGD已付款',
- (
- ROUND( ifnull( c.Number1618330472961, 0 ), 2 )- (
- SELECT
- ifnull( sum( pc.wait_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND p.`status` = 2 and ps.pay_status=4
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS 'CGD未付款',
- (
- ROUND( ifnull( c.Number1618330541286, 0 ), 2 )+ (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND p.`status` = 2 and ps.status=7
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.paytime DESC
- )
- ) AS 'CGD已回票',
- (
- ROUND( ifnull( c.Number1618330543270, 0 ), 2 )-(
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- cfp_pay_info AS pc
- LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
- LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
- WHERE
- pc.STATUS = 1
- AND ps.is_del = 0
- AND p.`status` = 2 and ps.status=7
- AND pc.sequenceNo = c.sequenceNo
- ORDER BY
- ps.invtime DESC
- )
- ) AS 'CGD待回票',
- ( SELECT source_all.cgd_num-sum( send ) FROM fh_source WHERE source_all.cgdNo = fh_source.cgdNo ) AS 'CGD.未发货数量' ,
- ( SELECT sum( send ) FROM fh_source WHERE source_all.cgdNo = fh_source.cgdNo ) AS 'CGD.总发货数量'
- FROM
- source_all left JOIN cfp_qrd_info b on
- source_all.productNo = b.sequenceNo
- LEFT JOIN cfp_cgd_info c on source_all.cgdNo = c.ShortText1618315935182
- where source_all.productNo<>'' {$where} order by ordertime";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."确认采购单业绩", $header, $list);
- }
- public function downTH(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and t.createtime >='{$start}'";
- }
- if($end!=""){
- $where.=" and t.createtime <='{$end}'";
- }
- $sql = "select
- t.thNo 'TH.退货单号',
- case t.th_status
- WHEN 1 THEN '已完成'
- WHEN 2 THEN '进行中'
- WHEN 3 THEN '已取消'
- else '' end'TH.退货状态',
- t.createtime 'TH.退货时间',
- t.th_company 'TH.公司',
- t.th_user 'TH.退货人',
- t.th_remark 'TH.退货备注',
- suppitem 'QRD平台',
- khzzxz 'QRD客户属性',
- source_all.qrdNo 'QRD.4确认单编号',
- sale_name 'QRD.业务员',
- product_name 'QRD.产品名称',
- product_code 'QRD.产品编号',
- cat_f 'QRD.一级分类',
- financial 'CGD.财务核算码',
- unit 'QRD.单位',
- tax 'QRD.税率',
- sale_price 'QRD.销售单价',
- t.th_num 'TH.退货数量',
- t.th_qrd_fee 'TH.销售货款',
- t.th_cgd_fee 'TH.采购货款',
- income 'QRD.不含税收入',
- zxcode 'QRD.咨询单号',
- zxtype 'QRD.咨询单类型',
- source_all.cgdNo 'CGD采购单单号'
- from cfp_th_source as t left join
- source_all on ((source_all.productNo=t.th_qrdcpNo and t.th_qrdcpNo<>'') or (t.th_cgdNo=source_all.cgdNo and t.th_cgdNo<>'')) left JOIN cfp_qrd_info b on
- t.th_qrdcpNo = b.sequenceNo
- LEFT JOIN cfp_cgd_info c on t.th_cgdNo = c.ShortText1618315935182
- where t.th_status<>3 {$where} order by t.createtime";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."退货单业绩", $header, $list);
- }
- /**
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function QRDPAY(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and a.ordertime >='{$start}'";
- }
- if($end!=""){
- $where.=" and a.ordertime <='{$end}'";
- }
- $sql = "SELECT
- a.qrdNo AS 'QRD.4确认单编号',
- a.productNo AS 'QRD确认单产品编号',
- a.supperinfo AS 'QRD公司名称',
- a.companyName AS 'QRD客户名称',
- a.suppitem AS 'QRD平台',
- a.khzzxz AS 'QRD客户属性',
- a.khcomp AS 'QRD客户分公司',
- a.poNo AS 'PT.4PO编号',
- a.zxtype AS 'QRD线上线下',
- a.sale_name AS 'QRD.业务员',
- a.product_name AS 'QRD.产品名称',
- a.sale_price AS 'QRD.销售单价',
- a.order_num AS 'QRD.下单数量',
- a.sale_total AS '销售总额',
- a.ordertime AS 'QRD.下单时间',
- b.Number1618249146997 '已收款',
- b.paying_fee '结算中',
- (
- a.sale_total - ifnull( b.Number1618249146997, 0 )- ifnull( b.paying_fee, 0 )-(
- SELECT
- ifnull( sum( th_qrd_fee ), 0 )
- FROM
- cfp_th_source
- WHERE
- th_qrdcpNo = a.productNo
- AND th_status = 1
- )) '未收款',
- (
- SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND ak.rela_form = 2 )
- OR ( ak.viceNo = oi.orderNo AND ak.rela_form = 3 )
- WHERE
- po.is_del = 0
- AND ak.rela_form IN ( 2, 3 )
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0
- AND oi.goodNo = a.productNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1
- ) AS '回款日期',
- DATEDIFF(
- ifnull(
- (
- SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND ak.rela_form = 2 )
- OR ( ak.viceNo = oi.orderNo AND ak.rela_form = 3 )
- WHERE
- po.is_del = 0
- AND ak.rela_form IN ( 2, 3 )
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0
- AND oi.goodNo = a.productNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1
- ),
- NOW()),
- a.ordertime
- ) AS '账期',
- a.delivery_status 'QRD.发货状态',
- ( SELECT sum( send ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'qrd.总发货数量',
- ( SELECT max( addtime ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'qrd.最近一次发货时间',
- ( SELECT sum( th_num ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS 'qrd.总退货数量',
- ( SELECT sum( th_qrd_fee ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS '退货金额',
- ( SELECT max( addtime ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS 'qrd.退货时间',
- ( a.sale_total -( SELECT ifnull( sum( th_qrd_fee ), 0 ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) ) AS '减退货付款额',
- IF
- (((
- a.sale_total -(
- SELECT
- ifnull( sum( th_qrd_fee ), 0 )
- FROM
- cfp_th_source
- WHERE
- th_qrdcpNo = a.productNo
- AND th_status = 1
- ))<>(
- ifnull( b.Number1618249146997, 0 )+ ifnull( b.paying_fee, 0 )+ ifnull( b.number1618249149738, 0 ))),
- '否',
- '是'
- ) AS '是否减退货'
- FROM
- `source_all` AS a
- LEFT JOIN `cfp_qrd_info` `b` ON ((
- `a`.`productNo` = `b`.`sequenceNo`
- ))
- WHERE
- a.productNo <> ''
- AND sale_total <> 0
- {$where}
- HAVING
- 减退货付款额 <> 0 order by a.ordertime desc";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."应收账款账龄表", $header, $list);
- }
- /**
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function QRDINV(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and a.ordertime >='{$start}'";
- }
- if($end!=""){
- $where.=" and a.ordertime <='{$end}'";
- }
- $sql = "SELECT
- a.qrdNo as 'QRD.4确认单编号',
- a.productNo as 'QRD确认单产品编号',
- a.supperinfo as 'QRD公司名称',
- a.companyName as 'QRD客户名称',
- a.suppitem as 'QRD平台',
- a.khzzxz as 'QRD客户属性',
- a.khcomp as 'QRD客户分公司',
- a.poNo as 'PT.4PO编号',
- a.zxtype as 'QRD线上线下',
- a.sale_name as 'QRD.业务员',
- a.product_name as 'QRD.产品名称',
- a.sale_price as 'QRD.销售单价',
- a.order_num as 'QRD.下单数量',
- a.sale_total as 'QRD.销售总额',
- a.ordertime as 'QRD.下单时间',
- b.Number1618249202608 '已开票',
- b.inving_fee '开票中',
- (
- a.sale_total - ifnull( b.Number1618249202608, 0 )- ifnull( b.inving_fee, 0 )-(
- SELECT
- ifnull( sum( th_qrd_fee ), 0 )
- FROM
- cfp_th_source
- WHERE
- th_qrdcpNo = a.productNo
- AND th_status = 1
- )) '未开票',
- (
- SELECT
- ak.addtime
- FROM
- cfp_order_info AS oi
- LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
- LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
- WHERE
- po.is_del = 0
- AND oi.STATUS = 1
- AND ak.STATUS = 3
- AND ak.is_del = 0 and oi.goodNo = a.productNo
- ORDER BY
- ak.addtime DESC
- LIMIT 1
- ) AS 'QRD.最近开票时间',
- a.delivery_status 'QRD.发货状态',
- ( SELECT sum( send ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'qrd.总发货数量',
- ( SELECT max( addtime ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'qrd.最近一次发货时间',
- ( SELECT sum( th_num ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS 'qrd.总退货数量',
- ( SELECT sum( th_qrd_fee ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS '退货金额',
- ( SELECT max( addtime ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS 'qrd.退货时间',
- ( a.sale_total -( SELECT ifnull( sum( th_qrd_fee ), 0 ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) ) AS '减退货付款额',
- IF
- (((
- a.sale_total -(
- SELECT
- ifnull( sum( th_qrd_fee ), 0 )
- FROM
- cfp_th_source
- WHERE
- th_qrdcpNo = a.productNo
- AND th_status = 1
- ))<>(
- ifnull( b.Number1618249146997, 0 )+ ifnull( b.paying_fee, 0 )+ ifnull( b.number1618249149738, 0 ))),
- '否',
- '是'
- ) AS '是否减退货'
- FROM
- `source_all` as a
- LEFT JOIN `cfp_qrd_info` `b` ON ((
- `a`.`productNo` = `b`.`sequenceNo`
- ))
- WHERE
- a.productNo <> '' AND sale_total <> 0
- {$where}
- HAVING
- 减退货付款额 <> 0 order by a.ordertime asc";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."应收账款开票汇总表", $header, $list);
- }
- /**
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function jxreport(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and ordertime >='{$start}'";
- }
- if($end!=""){
- $where.=" and ordertime <='{$end}'";
- }
- $sql = "SELECT
- date_format( `source_all`.`ordertime`, '%Y' ) AS `年`,
- date_format( `source_all`.`ordertime`, '%m' ) AS `月`,
- date_format( `source_all`.`ordertime`, '%d' ) AS `日`,
- `source_all`.`suppitem` AS `1.12平台类型`,
- `source_all`.`sale_name` AS `业务人员`,
- `source_all`.`depart` AS `业务部门`,
- `source_all`.`cat_f` AS `3.4产品一级分类`,
- `source_all`.`sale_total` AS `产品货款总额`
- FROM
- `source_all`
- WHERE
- (
- `source_all`.`suppitem` <> '预付卡' and productNo<>'' {$where}) order by ordertime asc";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."确认单绩效报表", $header, $list);
- }
- public function jxthreport(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and a.createtime >='{$start}'";
- }
- if($end!=""){
- $where.=" and a.createtime <='{$end}'";
- }
- $sql = "SELECT
- `a`.`th_user` AS `业务人员`,
- `b`.`suppitem` AS `1.12平台类型`,
- `b`.`depart` AS `业务部门`,
- `b`.`cat_f` AS `3.4产品一级分类`,
- a.th_qrdNo as '确认单编号',
- b.sale_total AS `货款总额`,
- `a`.`th_qrd_fee` AS `退货金额`
- FROM
- (
- `cfp_th_source` `a`
- LEFT JOIN `source_all` `b` ON ((
- `a`.`th_qrdcpNo` = `b`.`productNo`
- )))
- WHERE
- `b`.`suppitem` <> '预付卡' {$where}
- ORDER BY
- `a`.`th_user`";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."退款统计绩效报表", $header, $list);
- }
- /**出入库明细 */
- public function OutInReport(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and a.ordertime >='{$start}'";
- }
- if($end!=""){
- $where.=" and a.ordertime <='{$end}'";
- }
- $sql = "SELECT
- `a`.`supperinfo` AS `公司名称`,
- `a`.`cgdtype` AS `CGD采购单类型`,
- `a`.`qrdNo` AS `QRD.4确认单编号`,
- `a`.`cgdNo` AS `CGD采购单单号`,
- `a`.`financial` AS `QRD.财务核算码`,
- `a`.`product_name` AS `QRD.产品名称`,
- `a`.`order_num` AS `QRD.下单数量`,
- `a`.`qrd_delivery` AS `qrd发货方式`,
- `a`.`qrd_stock` AS `qrd.是否库存产品`,
- `a`.`cgd_tax` AS `CGD采购单税点`,
- `a`.`pakage_fee` AS `CGD包装费`,
- `a`.`cert_fee` AS `CGD证书费`,
- `a`.`mark_fee` AS `CGD加标费`,
- `a`.`open_fee` AS `CGD开模费`,
- `a`.`cost_fee` AS `CGD成本工艺费`,
- `a`.`naked_fee` AS `CGD裸价`,
- `a`.`delivery_fee` AS `CGD物流费`,
- `a`.`cgd_price` AS `CGD采购单单价`,
- `a`.`cgd_total` AS `CGD采购单金额`,
- `c`.`send` AS `CGD本次发货`,
- `c`.`send_date` AS `CGD本次发货时间`,(
- SELECT
- `im`.`buyer_name`
- FROM
- ((((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_invoice_img` `m` ON (((
- `m`.`payid` = `ps`.`id`
- )
- AND ( `m`.`is_del` = 0 ))))
- LEFT JOIN `cfp_invoice_info` `im` ON ((
- `im`.`invid` = `m`.`id`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `m`.`is_del` = 0 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
- LIMIT 1
- ) AS `CGD.HP.MX.回票抬头`
- FROM
- ((
- `source_all` `a`
- LEFT JOIN `cfp_qrd_info` `b` ON ((
- `a`.`productNo` = `b`.`sequenceNo`
- )))
- LEFT JOIN `fh_source` `c` ON ((
- `c`.`cgdNo` = `a`.`cgdNo`
- )))
- WHERE
- ((
- `a`.`productNo` <> ''
- )
- {$where})
- ";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."出入库数据报表", $header, $list);
- }
- /** 收入明细 */
- public function InfoReport(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and a.ordertime >='{$start}'";
- }
- if($end!=""){
- $where.=" and a.ordertime <='{$end}'";
- }
- $sql = "SELECT
- `a`.`qrdNo` AS `QRD.4确认单编号`,
- `a`.`companyName` AS `KH.2.客户名称`,
- `a`.`company` AS `公司名称`,
- `a`.`supplier` AS `供应商名称`,
- `a`.`cgdNo` AS `CGD采购单单号`,
- ifnull( `a`.`financial`, `a`.`fund_code` ) AS `QRD.财务核算码`,
- `a`.`cat_f` AS `QRD.一级分类`,
- `a`.`product_name` AS `QRD.产品名称`,
- `a`.`order_num` AS `QRD.下单数量`,
- `a`.`sale_price` AS `QRD销售单价`,
- `a`.`sale_total` AS `QRD销售总额`,
- `ak`.`viceNo` AS `发票号`,
- IF
- (( `ak`.`status` = 3 ), `oi`.`ainv_fee`, `oi`.`inv_fee` ) AS `本次开票金额`,(
- SELECT
- `l`.`addtime`
- FROM
- `invoice`.`cfp_invoice_list` `l`
- WHERE
- ( `l`.`invNo` = `ak`.`viceNo` )
- LIMIT 1
- ) AS `本次开票时间`,
- `a`.`qrd_delivery` AS `qrd发货方式`,
- `a`.`qrd_stock` AS `qrd.是否库存产品`,
- `a`.`cgd_saler` AS `CGD.采购单业务员`,
- `a`.`pakage_fee` AS `CGD包装费`,
- `a`.`cert_fee` AS `CGD证书费`,
- `a`.`mark_fee` AS `CGD加标费`,
- `a`.`open_fee` AS `CGD开模费`,
- `a`.`cost_fee` AS `CGD成本工艺费`,
- `a`.`naked_fee` AS `CGD裸价`,
- `a`.`delivery_fee` AS `CGD物流费`,
- `a`.`cgd_tax` AS `CGD采购单税点`,
- `a`.`cgd_price` AS `CGD采购单单价`,
- `a`.`cgd_total` AS `CGD采购单金额`,
- `a`.`cgd_tax` AS `CGD采购税点`,(
- SELECT
- `im`.`buyer_name`
- FROM
- ((((
- `invoice`.`cfp_pay_info` `pc`
- LEFT JOIN `invoice`.`cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `invoice`.`cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `invoice`.`cfp_invoice_img` `m` ON (((
- `m`.`payid` = `ps`.`id`
- )
- AND ( `m`.`is_del` = 0 ))))
- LEFT JOIN `invoice`.`cfp_invoice_info` `im` ON ((
- `im`.`invid` = `m`.`id`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `m`.`is_del` = 0 )
- AND ( `pc`.`sequenceNo` = `a`.`cgdjlNo` ))
- LIMIT 1
- ) AS `CGD.HP.MX.回票抬头`,
- IF
- ((
- `p`.`status` = 1
- ),
- '待审核',
- IF
- ((
- `p`.`status` = 2
- ),
- '审核未通过',
- IF
- ((
- `p`.`status` = 3
- ),
- '待开票',
- IF
- ((
- `p`.`status` = 4
- ),
- '待填写物流',
- IF
- (( `p`.`status` = 5 ), '开票完成', '未申请' ))))) AS `开票状态`
- FROM
- (((((
- `invoice`.`source_all` `a`
- LEFT JOIN `invoice`.`cfp_qrd_info` `b` ON ((
- `a`.`productNo` = `b`.`sequenceNo`
- )))
- LEFT JOIN `invoice`.`cfp_order_info` `oi` ON (((
- `oi`.`goodNo` = `b`.`sequenceNo`
- )
- AND ( `oi`.`status` = 1 ))))
- LEFT JOIN `invoice`.`cfp_order_pool` `po` ON (((
- `oi`.`orderNo` = `po`.`orderNo`
- )
- AND ( `po`.`is_del` = 0 ))))
- LEFT JOIN (
- SELECT
- `k`.`id` AS `aid`,
- `k`.`assocNo` AS `assocNo`,
- `k`.`companyNo` AS `companyNo`,
- `k`.`type` AS `type`,
- `k`.`rela_form` AS `rela_form`,
- `k`.`codeNo` AS `codeNo`,
- `k`.`total_fee` AS `total_fee`,
- `k`.`balance` AS `balance`,
- `k`.`cancel_total` AS `cancel_total`,
- `k`.`is_del` AS `is_del`,
- `k`.`status` AS `status`,
- `k`.`exam_remark` AS `exam_remark`,
- `k`.`addtime` AS `addtime`,
- `t`.`viceNo` AS `viceNo`,
- `t`.`vice_fee` AS `vice_fee`,
- `t`.`cancel_fee` AS `cancel_fee`,
- `t`.`id` AS `id`,
- `k`.`source` AS `source`,
- `t`.`vice_total` AS `vice_total`,
- `k`.`apply_name` AS `apply_name`,
- `k`.`apply_id` AS `apply_id`,
- `t`.`status` AS `bstatus`
- FROM
- (
- `invoice`.`cfp_assoc_key` `k`
- JOIN `invoice`.`cfp_assoc_rela` `t` ON ((
- `k`.`assocNo` = `t`.`assocNo`
- )))
- WHERE
- ((
- `k`.`is_del` = 0
- )
- AND ( `t`.`is_del` = 0 )
- AND ( `t`.`status` = 1 )
- AND ( `k`.`rela_form` = 1 ))) `ak` ON ((
- `ak`.`codeNo` = `oi`.`orderNo`
- )))
- LEFT JOIN `invoice`.`cfp_invoice_pool` `p` ON ((
- `ak`.`viceNo` = `p`.`invNo`
- )))
- WHERE
- ((
- `a`.`productNo` <> ''
- )
- AND ((
- `po`.`type` = 1
- )
- OR isnull( `po`.`type` )) )
- {$where}
- ";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."收入明细数据报表", $header, $list);
- }
- /** 回票公明细 */
- public function InvComReport(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and a.cgdtime >='{$start}'";
- }
- if($end!=""){
- $where.=" and a.cgdtime <='{$end}'";
- }
- $sql = "SELECT
- `b`.`ShortText1618270466672` AS `公司名称`,
- `b`.`ShortText1618315935182` AS `采购单编号`,
- round( `b`.`Number1618240685904`, 2 ) AS `货款`,
- `b`.`ShortText1620399144946` AS `供应商名称`,
- `b`.`StaffSelector1620899427104` AS `采购员`,
- `a`.`cgd_delivery_status` AS `发货状态`,
- '' AS `退货状态`,(
- round( ifnull( `b`.`Number1618330470625`, 0 ), 2 ) + (
- SELECT
- ifnull( sum( `pc`.`total_fee` ), 0 )
- FROM
- ((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`pay_status` = 4 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))) AS `已付款金额`,(
- CASE
-
- WHEN ((
- round( ifnull( `b`.`Number1618330541286`, 0 ), 2 ) + (
- SELECT
- ifnull( sum(( `pc`.`winv_fee` + `pc`.`ainv_fee` )), 0 )
- FROM
- ((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))) = 0
- ) THEN
- '未回票'
- WHEN ((
- round( ifnull( `b`.`Number1618330543270`, 0 ), 2 ) - (
- SELECT
- ifnull( sum(( `pc`.`winv_fee` + `pc`.`ainv_fee` )), 0 )
- FROM
- ((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
- LIMIT 1
- )) = 0
- ) THEN
- '全部回票' ELSE '部分回票'
- END
- ) AS `回票状态`,
- round((
- round( ifnull( `b`.`Number1618330541286`, 0 ), 2 ) + (
- SELECT
- ifnull( sum(( `pc`.`winv_fee` + `pc`.`ainv_fee` )), 0 )
- FROM
- ((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))),
- 2
- ) AS `已回票金额`,
- round((
- ifnull( `b`.`Number1618330543270`, 0 ) - (
- SELECT
- ifnull( sum(( `pc`.`winv_fee` + `pc`.`ainv_fee` )), 0 )
- FROM
- ((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))),
- 2
- ) AS `未回票金额`,(
- SELECT
- `im`.`buyer_name`
- FROM
- ((((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_invoice_img` `m` ON (((
- `m`.`payid` = `ps`.`id`
- )
- AND ( `m`.`is_del` = 0 ))))
- LEFT JOIN `cfp_invoice_info` `im` ON ((
- `im`.`invid` = `m`.`id`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `m`.`is_del` = 0 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
- LIMIT 1
- ) AS `回票公司`,
- `b`.`Date1618315953443` AS `下单时间`,
- `b`.`ShortText1617861966146` AS `产品名称`,
- `b`.`ShortText1617865685744` AS `单位`,
- cast( `b`.`Number1618240600907` AS signed ) AS `数量`,
- round( `b`.`Number1618240685904`, 2 ) AS `成本合计`,
- `b`.`ShortText1617865688485` AS `税点`,(
- SELECT
- `ps`.`invtime`
- FROM
- ((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
- ORDER BY
- `ps`.`invtime` DESC
- LIMIT 1
- ) AS `财务审批时间`,
- round( 0, 2 ) AS `CGD.不含税采购成本-这个怎么计算`,
- `a`.`qrdNo` AS `确认单编号`,
- `a`.`financial` AS `财务核算码`,
- `a`.`sale_price` AS `确认单销售单价`
- FROM
- (
- `source_all` `a`
- LEFT JOIN `cfp_cgd_info` `b` ON ((
- `a`.`cgdNo` = `b`.`ShortText1618315935182`
- )))
- WHERE
- ((
- `a`.`cgdNo` <> ''
- )
-
- {$where})
- ";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."回票公司数据报表", $header, $list);
- }
- /** 回票公明细 */
- public function InvReport(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and a.cgdtime >='{$start}'";
- }
- if($end!=""){
- $where.=" and a.cgdtime <='{$end}'";
- }
- $sql = "SELECT
- `b`.`ShortText1618315935182` AS `CGD.2采购单号`,
- `b`.`ShortText1618270466672` AS `CGD.14公司主体`,
- `b`.`Date1618315953443` AS `CGD.3采购单下单日期`,
- `b`.`ShortText1618270412964` AS `CGD.1采购单类型`,
- `b`.`StaffSelector1620899427104` AS `CGD.采购员`,
- `b`.`ShortText1620399144946` AS `CGD.45供应商名称`,
- `b`.`ShortText1617861287265` AS `CGD.44供应商编号`,
- `b`.`ShortText1619625566608` AS `CGD.出库包装库存`,
- `b`.`ShortText1617865688485` AS `CGD.40税点`,
- `a`.`financial` AS `CGD财务核算码`,
- round( `b`.`Number1617865810822`, 2 ) AS `CGD.包装费`,
- round( `b`.`Number1617865813284`, 2 ) AS `CGD.证书费`,
- round( `b`.`Number1617865807879`, 2 ) AS `CGD.加标费`,
- round( `b`.`Number1617865816181`, 2 ) AS `CGD.开模费`,
- round( `b`.`number1618240204358`, 2 ) AS `CGD.成本工艺费`,
- round( `b`.`Number1617865804813`, 2 ) AS `CGD.成本裸价`,
- round( `b`.`number1618240287778`, 2 ) AS `CGD.物流费`,
- round( `b`.`Number1619632830397`, 2 ) AS `CGD.工差`,
- round( `b`.`Number1619632826654`, 2 ) AS `CGD.采购工差金额`,
- round( `b`.`Number1617865818517`, 2 ) AS `CGD.采购单价`,
- cast( `b`.`Number1618240600907` AS signed ) AS `CGD.采购数量`,
- round( `b`.`Number1618240685904`, 2 ) AS `CGD.采购金额`,
- round( 0, 2 ) AS `CGD.不含税采购成本-这个怎么计算`,
- `b`.`ShortText1618859161646` AS `BK.10备库单号`,
- `b`.`Date1618859180209` AS `BK.11备库下单日期`,
- `b`.`StaffSelector1618885082387` AS `BK.15业务员`,
- `b`.`ShortText1618900704399` AS `BK.13备库仓库`,
- `b`.`ShortText1617861966146` AS `CGD.CP.26产品名称`,
- `b`.`ShortText1617861001482` AS `CGD.CP.27产品编号`,
- `b`.`ShortText1617865626160` AS `CGD.CP.28一级分类`,
- `b`.`ShortText1617865685744` AS `CGD.CP.25单位`,
- `b`.`ShortText1618240134229` AS `CGD.CP.36贵金属种类`,
- round((
- round( ifnull( `b`.`Number1618330541286`, 0 ), 2 ) + (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- ((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))),
- 2
- ) AS `CGD.HP.总-已回票金额`,
- round((
- ifnull( `b`.`Number1618330543270`, 0 ) - (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- ((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))),
- 2
- ) AS `CGD.HP.总-未回票金额`,(
- CASE
-
- WHEN ((
- round( ifnull( `b`.`Number1618330541286`, 0 ), 2 ) + (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- ((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))) = 0
- ) THEN
- '未回票'
- WHEN ((
- round( ifnull( `b`.`Number1618330543270`, 0 ), 2 ) - (
- SELECT
- ifnull( sum( pc.winv_fee ), 0 )
- FROM
- ((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
- LIMIT 1
- )) = 0
- ) THEN
- '全部回票' ELSE '部分回票'
- END
- ) AS `CGD.HP.总-回票情况`,(
- SELECT
- `ps`.`invtime`
- FROM
- ((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
- ORDER BY
- `ps`.`invtime` DESC
- LIMIT 1
- ) AS `CGD.HP.MX.总最近一次回票时间`,(
- SELECT
- sum( `pc`.`winv_fee`)
- FROM
- ((((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_invoice_img` `m` ON (((
- `m`.`payid` = `ps`.`id`
- )
- AND ( `m`.`is_del` = 0 ))))
- LEFT JOIN `cfp_invoice_info` `im` ON ((
- `im`.`invid` = `m`.`id`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `m`.`is_del` = 0 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
-
- ) AS `CGD.HP.MX.回票金额`,(
- SELECT
- `im`.`buyer_name`
- FROM
- ((((
- `cfp_pay_info` `pc`
- LEFT JOIN `cfp_pay_stages` `ps` ON ((
- `ps`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_pay` `p` ON ((
- `p`.`payNo` = `pc`.`payNo`
- )))
- LEFT JOIN `cfp_invoice_img` `m` ON (((
- `m`.`payid` = `ps`.`id`
- )
- AND ( `m`.`is_del` = 0 ))))
- LEFT JOIN `cfp_invoice_info` `im` ON ((
- `im`.`invid` = `m`.`id`
- )))
- WHERE
- ((
- `pc`.`status` = 1
- )
- AND ( `ps`.`is_del` = 0 )
- AND ((
- `p`.`status` = 2
- )
- OR ( `p`.`status` = 1 ))
- AND ( `ps`.`status` = 7 )
- AND ( `m`.`is_del` = 0 )
- AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
- LIMIT 1
- ) AS `CGD.HP.MX.回票抬头`
- FROM
- (
- `source_all` `a`
- LEFT JOIN `cfp_cgd_info` `b` ON ((
- `a`.`cgdNo` = `b`.`ShortText1618315935182`
- )))
- WHERE
- ((
- `a`.`cgdNo` <> ''
- )
- {$where})
- ";
- // echo $sql; die();
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."回票数据报表", $header, $list);
- }
- /** 发货报表 */
- public function FhReport(){
- $post = request()->post();
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $where='';
- if($start!=""){
- $where.=" and F.addtime >='{$start}'";
- }
- if($end!=""){
- $where.=" and F.addtime <='{$end}'";
- }
- $sql = "SELECT
- F.fhNo AS '发货单号',
- F.cgdNO AS 'CGD采购单单号',
- F.qrdNo AS '确认单号',
- S.suppitem AS '平台类型',
- S.depart AS '业务部门',
- S.zxtype AS '咨询类型',
- F.addtime AS '发货时间',
- S.cat_f AS '一级品类',
- F.good_name AS '产品名称',
- F.post_company AS '物流公司',
- F.post_code AS '物流单号',
- F.send AS '本次发货数量',
- F.send * S.sale_price AS '本次发货金额',
- F.bala AS '剩余发货数量',
- F.bala * S.sale_price AS '剩余发货金额',
- S.sale_price AS '销售单价',
- S.order_num AS '销售数量',
- S.sale_total AS '销售金额',
- S.zxcode AS '咨询单号',
- S.supplier AS '供应商名称',
- S.cgd_saler AS '采购员'
- FROM fh_source AS F, source_all AS S
- WHERE F.cgdNO = S.cgdNO
- AND S.cgd_saler NOT IN ('张凯旋','骆喜龙')
- {$where}
- ";
- $list = Db::query($sql);
- if(empty($list)){
- $list=[["未找到数据"=>""]];
- }
- $header = array_keys($list[0]);
- array_walk($list, function (&$v) {
- $v = array_values($v);
- });
- excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."发货数据报表", $header, $list);
- }
- }
|