Report.php 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263
  1. <?php
  2. namespace app\Admin\controller;
  3. use app\BaseController;
  4. use think\facade\Db;
  5. use think\App;
  6. class Report extends BaseController
  7. {
  8. /**确认单明细
  9. * @throws \think\db\exception\BindParamException
  10. * @throws \think\exception\PDOException
  11. */
  12. public function downreportQRD()
  13. {
  14. $post = request()->post();
  15. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  16. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  17. $where='';
  18. if($start!=""){
  19. $where.=" and ordertime >='{$start}'";
  20. }
  21. if($end!=""){
  22. $where.=" and ordertime <='{$end}'";
  23. }
  24. $sql = "SELECT
  25. a.productNo 'QRD-CP确认单产品编号',
  26. a.companyName '`KH.2客户名称',
  27. a.supperinfo '公司名称',
  28. a.suppitem 'PT.1平台类型',
  29. a.khzzxz 'PT.2平台编码',
  30. a.poNo 'PT.4PO编号',
  31. a.qrdNo 'QRD.4确认单编号',
  32. a.qrd_type 'QRD.确认单类型',
  33. a.ordertime 'QRD.确认单下单时间',
  34. a.sale_name 'QRD.业务员',
  35. a.product_name 'QRD.产品名称',
  36. a.product_code 'QRD.产品编号',
  37. a.cat_f 'QRD.一级分类',
  38. a.cat_t 'QRD.二级分类',
  39. a.cat_d 'QRD.三级分类',
  40. a.fund_code 'QRD.财务核算码',
  41. a.unit 'QRD.单位',
  42. a.tax 'QRD.税率',
  43. a.diff_weight 'QRD.重量工差',
  44. a.diff_price 'QRD.金额工差',
  45. a.paytime 'QRD.承诺回款时间',
  46. a.sale_price 'QRD.销售单价',
  47. a.order_num 'QRD.下单数量',
  48. a.sale_total 'QRD.销售总额',
  49. a.income 'QRD.不含税收入',
  50. a.zxcode 'QRD.咨询单号',
  51. a.zxtype 'QRD.咨询单类型',
  52. a.qrd_delivery 'qrd发货方式',
  53. a.qrd_stock 'qrd.是否库存产品',
  54. a.cgdNo 'CGD采购单单号',
  55. a.cgdtime 'CGD采购单下单日期',
  56. a.cgdtype 'CGD采购单类型',
  57. a.cgd_saler 'CGD采购单业务员',
  58. a.suplier_name 'CGD供货商名称',
  59. a.paking 'CGD出库包装库存',
  60. a.cgd_tax 'CGD采购单税点',
  61. a.pakage_fee 'CGD包装费',
  62. a.cert_fee 'CGD证书费',
  63. a.mark_fee 'CGD加标费',
  64. a.open_fee 'CGD开模费',
  65. a.cost_fee 'CGD成本工艺费',
  66. a.naked_fee 'CGD裸价',
  67. a.delivery_fee 'CGD物流费',
  68. a.cgd_price 'CGD采购单单价',
  69. a.cgd_num 'CGD采购单数量',
  70. a.cgd_total 'CGD采购单金额',
  71. a.cgd_cost 'CGD采购单成本',
  72. ROUND( b.Number1618249146997, 2 ) 'QRD已回款',
  73. ROUND( b.number1618249149738+b.paying_fee, 2 ) 'QRD未回款',
  74. IF
  75. ( ak.rela_form = 2 || ak.rela_form = 3, ak.addtime, '' ) 'QRD本次回款时间',
  76. IF
  77. ( ak.rela_form = 2 || ak.rela_form = 3, ak.cancel_total, '' ) 'QRD本次回款金额',
  78. ROUND( b.Number1618249202608, 2 ) 'QRD已开票',
  79. ROUND( b.Number1618249205231+b.inving_fee, 2 ) 'QRD未开票',
  80. IF
  81. ( ak.rela_form = 1, ak.addtime, '' ) 'QRD本次开票时间',
  82. IF
  83. ( ak.rela_form = 1, ak.cancel_total, '' ) 'QRD本次开票金额',
  84. ROUND( c.Number1618330470625, 2 ) 'CGD已付款',
  85. ROUND( c.Number1618330472961, 2 ) 'CGD未付款',
  86. pc.total_fee 'CGD.本次付款金额',
  87. ps.paytime 'CGD.本次付款时间',
  88. ROUND( c.Number1618330541286, 2 ) 'CGD已回票',
  89. ROUND( c.Number1618330543270, 2 ) 'CGD未回票',
  90. ps.inv_fee 'CGD.本次回票金额',
  91. ps.invtime 'CGD.本次回票时间',
  92. a.delivery_status 'QRD.发货状态',
  93. ( SELECT sum( send ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'CGD总发货数量',
  94. f.send 'CGD本次发货',
  95. f.fhNo 'CGD发货单号',
  96. f.addtime 'CGD本次发货时间'
  97. FROM
  98. source_all a
  99. LEFT JOIN cfp_qrd_info b ON a.productNo = b.sequenceNo
  100. LEFT JOIN cfp_cgd_info c ON a.cgdNo = c.ShortText1618315935182
  101. LEFT JOIN fh_source f ON a.cgdNo = f.cgdNo
  102. LEFT JOIN
  103. cfp_order_info AS oi ON ( oi.goodNo = b.sequenceNo AND oi.STATUS = 1 )
  104. LEFT JOIN cfp_order_pool AS po ON (oi.orderNo = po.orderNo
  105. AND po.is_del = 0 ) LEFT JOIN (
  106. SELECT
  107. `k`.`id` AS `aid`,
  108. `k`.`assocNo` AS `assocNo`,
  109. `k`.`companyNo` AS `companyNo`,
  110. `k`.`type` AS `type`,
  111. `k`.`rela_form` AS `rela_form`,
  112. `k`.`codeNo` AS `codeNo`,
  113. `k`.`total_fee` AS `total_fee`,
  114. `k`.`balance` AS `balance`,
  115. `k`.`cancel_total` AS `cancel_total`,
  116. `k`.`is_del` AS `is_del`,
  117. `k`.`status` AS `status`,
  118. `k`.`exam_remark` AS `exam_remark`,
  119. `k`.`addtime` AS `addtime`,
  120. `t`.`viceNo` AS `viceNo`,
  121. `t`.`vice_fee` AS `vice_fee`,
  122. `t`.`cancel_fee` AS `cancel_fee`,
  123. `t`.`id` AS `id`,
  124. `k`.`source` AS `source`,
  125. `t`.`vice_total` AS `vice_total`,
  126. `k`.`apply_name` AS `apply_name`,
  127. `k`.`apply_id` AS `apply_id`,
  128. `t`.`status` AS `bstatus`
  129. FROM
  130. (
  131. `cfp_assoc_key` `k`
  132. JOIN `cfp_assoc_rela` `t` ON ((
  133. `k`.`assocNo` = `t`.`assocNo`
  134. )))
  135. ) AS ak ON (
  136. ( ak.codeNo = oi.orderNo OR ak.viceNo = oi.orderNo )
  137. AND ( rela_form IN ( 1, 2, 3 ) AND ak.STATUS = 3 AND ak.is_del = 0 )
  138. ) left join cfp_pay_info as pc on (pc.sequenceNo = c.sequenceNo and pc.`status`=1)
  139. LEFT JOIN cfp_pay_stages as ps on (ps.payNo= pc.payNo and ps.is_del =0)
  140. left JOIN cfp_pay as p on (p.payNo=pc.payNo and (p.`status`=2 or p.status=1))
  141. WHERE
  142. a.productNo <> '' {$where} order by ordertime";
  143. $list = Db::query($sql);
  144. if(empty($list)){
  145. $list=[["未找到数据"=>""]];
  146. }
  147. $header = array_keys($list[0]);
  148. array_walk($list, function (&$v) {
  149. $v = array_values($v);
  150. });
  151. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."确认单明细", $header, $list);
  152. }
  153. /**
  154. * 采购单明细
  155. * @throws \think\db\exception\BindParamException
  156. * @throws \think\exception\PDOException
  157. */
  158. public function downreportCGD()
  159. {
  160. $post = request()->post();
  161. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  162. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  163. $where='';
  164. if($start!=""){
  165. $where.=" and cgdtime >='{$start}'";
  166. }
  167. if($end!=""){
  168. $where.=" and cgdtime <='{$end}'";
  169. }
  170. $sql = "SELECT
  171. b.ShortText1618315935182 AS 'CGD.2采购单号',
  172. b.ShortText1618270466672 AS 'CGD.14公司主体',
  173. b.Date1618315953443 AS 'CGD.3采购单下单日期',
  174. b.ShortText1618270412964 AS 'CGD.1采购单类型',
  175. b.StaffSelector1620899427104 AS 'CGD.采购员',
  176. b.ShortText1620399144946 AS 'CGD.45供应商名称',
  177. b.ShortText1619625566608 AS 'CGD.出库包装库存',
  178. b.ShortText1617865688485 AS 'CGD.40税点',
  179. ROUND( b.Number1617865810822, 2 ) AS 'CGD.包装费',
  180. ROUND( b.Number1617865813284, 2 ) AS 'CGD.证书费',
  181. ROUND( b.Number1617865807879, 2 ) AS 'CGD.加标费',
  182. ROUND( b.Number1617865816181, 2 ) AS 'CGD.开模费',
  183. ROUND( b.number1618240204358, 2 ) AS 'CGD.成本工艺费',
  184. ROUND( b.Number1617865804813, 2 ) AS 'CGD.成本裸价',
  185. ROUND( b.number1618240287778, 2 ) AS 'CGD.物流费',
  186. ROUND( b.Number1619632830397, 2 ) AS 'CGD.工差',
  187. ROUND( b.Number1619632826654, 2 ) AS 'CGD.采购工差金额',
  188. ROUND( b.Number1617865818517, 2 ) AS 'CGD.采购单价',
  189. CAST( b.Number1618240600907 AS SIGNED ) AS 'CGD.采购数量',
  190. ROUND( b.Number1618240685904, 2 ) AS 'CGD.采购金额',
  191. ROUND( 0, 2 ) AS 'CGD.不含税采购成本-这个怎么计算',
  192. b.ShortText1618859161646 AS 'BK.10备库单号',
  193. b.Date1618859180209 AS 'BK.11备库下单日期',
  194. b.StaffSelector1618885082387 AS 'BK.15业务员',
  195. b.ShortText1618900704399 AS 'BK.13备库仓库',
  196. b.ShortText1617861966146 AS 'CGD.CP.26产品名称',
  197. b.ShortText1617861001482 AS 'CGD.CP.27产品编号',
  198. b.ShortText1617865626160 AS 'CGD.CP.28一级分类',
  199. a.cgd_cat_s 'CGD.二级分类',
  200. a.cgd_cat_t 'CGD.三级分类',
  201. a.financial 'CGD.财务核算码',
  202. b.ShortText1617865685744 AS 'CGD.CP.25单位',
  203. b.ShortText1618240134229 AS 'CGD.CP.36贵金属种类',
  204. ROUND( b.Number1618240458074, 2 ) AS 'CGD.CP.38实时金价',
  205. ROUND( b.Number1618240480148, 2 ) AS 'CGD.CP.37商品重量(g)',
  206. a.is_stock `CGD.是否库存`,
  207. b.ShortText1618465932373 `CGD.物流方式`,
  208. (
  209. ROUND( ifnull( b.Number1618330470625, 0 ), 2 )+ (
  210. SELECT
  211. ifnull( round(sum( pc.wait_fee ),2), 0 )
  212. FROM
  213. cfp_pay_info AS pc
  214. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  215. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  216. WHERE
  217. pc.STATUS = 1
  218. AND ps.is_del = 0
  219. AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=4
  220. AND pc.sequenceNo = b.sequenceNo
  221. ORDER BY
  222. ps.paytime DESC
  223. )
  224. ) AS '已付款',
  225. (
  226. ROUND( ifnull( b.Number1618330472961, 0 ), 2 )- (
  227. SELECT
  228. ifnull( round(sum( pc.wait_fee ),2), 0 )
  229. FROM
  230. cfp_pay_info AS pc
  231. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  232. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  233. WHERE
  234. pc.STATUS = 1
  235. AND ps.is_del = 0
  236. AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=4
  237. AND pc.sequenceNo = b.sequenceNo
  238. ORDER BY
  239. ps.paytime DESC
  240. )
  241. ) AS '未付款',
  242. (
  243. ROUND( ifnull( b.Number1618330541286, 0 ), 2 )+ (
  244. SELECT
  245. ifnull( round(sum( pc.winv_fee),2), 0 )
  246. FROM
  247. cfp_pay_info AS pc
  248. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  249. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  250. WHERE
  251. pc.STATUS = 1
  252. AND ps.is_del = 0
  253. AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=7
  254. AND pc.sequenceNo = b.sequenceNo
  255. ORDER BY
  256. ps.paytime DESC
  257. )
  258. ) AS '已回票',
  259. (
  260. ROUND( ifnull( b.Number1618330543270, 0 ), 2 )-(
  261. SELECT
  262. ifnull( round(sum( pc.winv_fee),2), 0 )
  263. FROM
  264. cfp_pay_info AS pc
  265. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  266. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  267. WHERE
  268. pc.STATUS = 1
  269. AND ps.is_del = 0
  270. AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=7
  271. AND pc.sequenceNo = b.sequenceNo
  272. ORDER BY
  273. ps.invtime DESC
  274. )
  275. ) AS '待回票',
  276. a.cgd_delivery_status 'CGD.发货状态',
  277. pk.total_fee '本次付款金额',
  278. pk.ainv_fee '本次回票金额',
  279. if(pk.pay_status=4,'已付','待付') '本次付款状态',
  280. if(pk.status=7,'已回','待回') '本次回票状态',
  281. pk.paytime '本次付款时间',
  282. pk.invtime '本次回票时间',
  283. ( SELECT sum( send ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'CGD.总发货数量',
  284. f.send 'CGD.本次发货',
  285. f.fhNo 'CGD.发货单号',
  286. f.addtime 'CGD.本次发货时间'
  287. FROM
  288. source_all AS a
  289. LEFT JOIN cfp_cgd_info AS b ON a.cgdNo = b.ShortText1618315935182
  290. LEFT JOIN fh_source f ON a.cgdNo = f.cgdNo
  291. LEFT JOIN
  292. (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
  293. inner JOIN cfp_pay_stages AS ps ON (ps.payNo = pc.payNo
  294. AND ps.is_del = 0 and (ps.pay_status=4 or ps.pay_status=7))
  295. inner JOIN cfp_pay AS p ON p.payNo = pc.payNo
  296. AND (p.`status` = 2 or p.`status` = 1) where pc.STATUS = 1) as pk on pk.sequenceNo =a.cgdjlNo
  297. WHERE
  298. a.cgdNo <> '' {$where} order by cgdtime";
  299. $list = Db::query($sql);
  300. if(empty($list)){
  301. $list=[["未找到数据"=>""]];
  302. }
  303. $header = array_keys($list[0]);
  304. array_walk($list, function (&$v) {
  305. $v = array_values($v);
  306. });
  307. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."采购单明细", $header, $list);
  308. }
  309. public function downreportQRDTZ(){
  310. $post = request()->post();
  311. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  312. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  313. $where='';
  314. if($start!=""){
  315. $where.=" and ordertime >='{$start}'";
  316. }
  317. if($end!=""){
  318. $where.=" and ordertime <='{$end}'";
  319. }
  320. $sql="SELECT
  321. '已完成' AS 'QRD.单据状态',
  322. DATE_FORMAT(b.Date1617081795606, '%Y年') AS '年',
  323. DATE_FORMAT(b.Date1617081795606, '%m月') AS '月',
  324. DATE_FORMAT(b.Date1617081795606, '%d日') AS '日',
  325. CONCAT(
  326. '第',
  327. WEEK(
  328. DATE_ADD(
  329. b.Date1617081795606,
  330. INTERVAL 6 DAY
  331. ),
  332. 2
  333. ),
  334. '周'
  335. ) AS '周',
  336. b.ShortText1618447165317 AS '公司名称',
  337. b.ShortText1619523892833 AS 'KH.2客户名称',
  338. b.ShortText1619542951283 AS 'KH.3客户编码',
  339. b.ShortText1619413394855 AS 'KH.4客户属性',
  340. b.ShortText1619413401534 AS 'KH.6分公司',
  341. b.ShortText1619413388848 AS 'KH.5大区',
  342. b.ShortText1619543001392 AS 'KH.7中支',
  343. b.ShortText1619523693355 AS 'KH.8县支',
  344. b.ShortText1619523689586 AS 'PT.1平台类型',
  345. b.ShortText1617366186330 AS 'PT.2平台编码',
  346. b.ShortText1617023369580 AS 'PT.3业管系统咨询单号',
  347. b.text1617365646297 AS 'PT.4PO编号',
  348. b.ShortText1617650701648 AS 'QRD.4确认单编号',
  349. b.ShortText1617650669915 AS 'QRD.3确认单类型',
  350. b.Date1617081795606 AS 'QRD.5确认单下单时间',
  351. DATE_FORMAT(b.Date1617081795606, '%Y-%m-%d') AS 'TZ.2.8确认单下单日期2',
  352. b.StaffSelector1618445844046 As 'QRD.1业务人员',
  353. `b`.`sequenceNo` AS `QRD-CP确认单产品编号`,
  354. `b`.`ShortText1617365292699` AS `CP.1产品名称`,
  355. `b`.`text1617499162303` AS `CP.2产品编码`,
  356. `b`.`ShortText1617499192065` AS `CP.3.0一级分类`,
  357. `source_all`.`cat_t` AS `CP.C二级分类`,
  358. `source_all`.`cat_d` AS `CP.C三级分类`,
  359. `source_all`.`fund_code` AS `CP.28财务核算码`,
  360. `b`.`text1617365597522` AS `CP.7单位`,
  361. `b`.`ShortText1617367958909` AS `CP.8税点`,
  362. `b`.`ShortText1619146965777` AS `QRD.6确认单唯一识别码`,
  363. round( `b`.`Number1619403905454`, 2 ) AS `CP.26工差重量`,
  364. round( `b`.`Number1619403908740`, 2 ) AS `CP.27工差金额`,
  365. `b`.`Date1619542686640` AS `QRD.7承诺回款日期`,
  366. round( `b`.`Number1618248810624`, 2 ) AS `CP.19销售单价`,
  367. cast( `b`.`Number1617365688048` AS signed ) AS `CP.20下单数量`,
  368. round( `b`.`Number1618248813613`, 2 ) AS `CP.21销售总额`,
  369. ROUND(
  370. b.Number1618248813613 - IF(
  371. LENGTH(b.ShortText1617367958909) > 1,
  372. b.Number1618248813613 * (
  373. CAST(
  374. LEFT(
  375. b.ShortText1617367958909,
  376. LENGTH(b.ShortText1617367958909) - 1
  377. ) AS DECIMAL
  378. ) / 100
  379. ),
  380. 0
  381. ),
  382. 2
  383. ) AS 'CP.NEW不含税收入-查看一下这个计算的是否正确',
  384. '-' AS 'CP.NEW毛利润-不知道怎么计算',
  385. b.ShortText1617111725596 AS 'ZXD.2咨询单编号',
  386. b.Date1619626098213 AS 'ZXD.4咨询日期',
  387. b.ShortText1617670912205 AS 'ZXD.3咨询类型',
  388. '已完成' AS 'CGD.单据状态',
  389. c.ShortText1618315935182 AS 'CGD.2采购单号',
  390. c.Date1618315953443 AS 'CGD.3采购单下单日期',
  391. c.ShortText1618270412964 AS 'CGD.1采购单类型',
  392. c.StaffSelector1620899427104 AS 'CGD.采购员',
  393. c.ShortText1620399144946 AS 'CGD.45供应商名称',
  394. c.ShortText1617861287265 AS 'CGD.44供应商编号',
  395. c.ShortText1619625566608 AS 'CGD.出库包装库存',
  396. c.ShortText1617865688485 AS 'CGD.40税点',
  397. ROUND(c.Number1617865810822, 2) AS 'CGD.包装费',
  398. ROUND(c.Number1617865813284, 2) AS 'CGD.证书费',
  399. ROUND(c.Number1617865807879, 2) AS 'CGD.加标费',
  400. ROUND(c.Number1617865816181, 2) AS 'CGD.开模费',
  401. ROUND(c.number1618240204358, 2) AS 'CGD.成本工艺费',
  402. ROUND(c.Number1617865804813, 2) AS 'CGD.成本裸价',
  403. ROUND(c.number1618240287778, 2) AS 'CGD.物流费',
  404. ROUND(c.Number1619632830397, 2) AS 'CGD.工差',
  405. ROUND(c.Number1619632826654, 2) AS 'CGD.采购工差金额',
  406. ROUND(c.Number1617865818517, 2) AS 'CGD.采购单价',
  407. CAST(c.Number1618240600907 AS SIGNED) AS 'CGD.采购数量',
  408. ROUND(c.Number1618240685904, 2) AS 'CGD.采购金额',
  409. ROUND(0, 2) AS 'CGD.不含税采购成本-这个怎么计算',
  410. (
  411. ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
  412. SELECT
  413. ifnull( sum( pc.wait_fee ), 0 )
  414. FROM
  415. cfp_pay_info AS pc
  416. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  417. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  418. WHERE
  419. pc.STATUS = 1
  420. AND ps.is_del = 0
  421. AND ( p.`status` = 2 OR p.STATUS = 1 )
  422. AND ps.pay_status = 4
  423. AND pc.sequenceNo = c.sequenceNo
  424. ORDER BY
  425. ps.paytime DESC
  426. )
  427. ) AS 'CGD.FK.总-已付款金额',
  428. (
  429. ROUND( ifnull( c.Number1618330472961, 0 ), 2 )- (
  430. SELECT
  431. ifnull( sum( pc.wait_fee ), 0 )
  432. FROM
  433. cfp_pay_info AS pc
  434. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  435. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  436. WHERE
  437. pc.STATUS = 1
  438. AND ps.is_del = 0
  439. AND ( p.`status` = 2 OR p.STATUS = 1 )
  440. AND ps.pay_status = 4
  441. AND pc.sequenceNo = c.sequenceNo
  442. ORDER BY
  443. ps.paytime DESC
  444. )
  445. ) AS 'CGD.FK.总-未付款金额',
  446. CASE
  447. WHEN (
  448. ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
  449. SELECT
  450. ifnull( sum( pc.wait_fee ), 0 )
  451. FROM
  452. cfp_pay_info AS pc
  453. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  454. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  455. WHERE
  456. pc.STATUS = 1
  457. AND ps.is_del = 0
  458. AND ( p.`status` = 2 OR p.STATUS = 1 )
  459. AND ps.pay_status = 4
  460. AND pc.sequenceNo = c.sequenceNo
  461. ORDER BY
  462. ps.paytime DESC
  463. )
  464. ) =0 THEN
  465. '未付款'
  466. WHEN (
  467. ROUND( ifnull( c.Number1618330472961, 0 ), 2 )- (
  468. SELECT
  469. ifnull( sum( pc.wait_fee ), 0 )
  470. FROM
  471. cfp_pay_info AS pc
  472. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  473. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  474. WHERE
  475. pc.STATUS = 1
  476. AND ps.is_del = 0
  477. AND ( p.`status` = 2 OR p.STATUS = 1 )
  478. AND ps.pay_status = 4
  479. AND pc.sequenceNo = c.sequenceNo
  480. ORDER BY
  481. ps.paytime DESC
  482. )
  483. ) =0 THEN
  484. '全部付款'
  485. ELSE '部分付款'
  486. END AS 'CGD.FK.总-付款情况',
  487. (
  488. ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
  489. SELECT
  490. ifnull( sum( pc.wait_fee ), 0 )
  491. FROM
  492. cfp_pay_info AS pc
  493. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  494. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  495. WHERE
  496. pc.STATUS = 1
  497. AND ps.is_del = 0
  498. AND ( p.`status` = 2 OR p.STATUS = 1 )
  499. AND ps.pay_status = 4
  500. AND pc.sequenceNo = c.sequenceNo
  501. ORDER BY
  502. ps.paytime DESC
  503. )
  504. ) AS 'CGD.FK.MX.总-已付款金额',
  505. (
  506. SELECT
  507. paytime
  508. FROM
  509. cfp_pay_info AS pc
  510. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  511. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  512. WHERE
  513. pc.STATUS = 1
  514. AND ps.is_del = 0
  515. AND ( p.`status` = 2 OR p.STATUS = 1 )
  516. AND ps.pay_status = 4
  517. AND pc.sequenceNo = c.sequenceNo
  518. ORDER BY
  519. ps.paytime DESC
  520. LIMIT 1
  521. ) AS 'CGD.FK.MX.总-最近一次付款时间',
  522. (
  523. ROUND( ifnull( c.Number1618330541286, 0 ), 2 )+ (
  524. SELECT
  525. ifnull( sum( pc.winv_fee ), 0 )
  526. FROM
  527. cfp_pay_info AS pc
  528. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  529. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  530. WHERE
  531. pc.STATUS = 1
  532. AND ps.is_del = 0
  533. AND ( p.`status` = 2 OR p.STATUS = 1 )
  534. AND ps.STATUS = 7
  535. AND pc.sequenceNo = c.sequenceNo
  536. ORDER BY
  537. ps.paytime DESC
  538. )
  539. ) AS 'CGD.HP.总-已回票金额',
  540. (
  541. ROUND( ifnull( c.Number1618330543270, 0 ), 2 )-(
  542. SELECT
  543. ifnull( sum( pc.winv_fee ), 0 )
  544. FROM
  545. cfp_pay_info AS pc
  546. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  547. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  548. WHERE
  549. pc.STATUS = 1
  550. AND ps.is_del = 0
  551. AND ( p.`status` = 2 OR p.STATUS = 1 )
  552. AND ps.STATUS = 7
  553. AND pc.sequenceNo = c.sequenceNo
  554. ORDER BY
  555. ps.invtime DESC
  556. )
  557. ) AS 'CGD.HP.总-未回票金额',
  558. CASE
  559. WHEN (
  560. ROUND( ifnull( c.Number1618330541286, 0 ), 2 )+ (
  561. SELECT
  562. ifnull( sum( pc.winv_fee ), 0 )
  563. FROM
  564. cfp_pay_info AS pc
  565. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  566. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  567. WHERE
  568. pc.STATUS = 1
  569. AND ps.is_del = 0
  570. AND ( p.`status` = 2 OR p.STATUS = 1 )
  571. AND ps.STATUS = 7
  572. AND pc.sequenceNo = c.sequenceNo
  573. ORDER BY
  574. ps.paytime DESC
  575. )
  576. )=0 THEN
  577. '未回票'
  578. WHEN (
  579. ROUND( ifnull( c.Number1618330543270, 0 ), 2 )-(
  580. SELECT
  581. ifnull( sum( pc.winv_fee ), 0 )
  582. FROM
  583. cfp_pay_info AS pc
  584. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  585. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  586. WHERE
  587. pc.STATUS = 1
  588. AND ps.is_del = 0
  589. AND ( p.`status` = 2 OR p.STATUS = 1 )
  590. AND ps.STATUS = 7
  591. AND pc.sequenceNo = c.sequenceNo
  592. ORDER BY
  593. ps.invtime DESC
  594. )
  595. ) =0 THEN
  596. '全部回票'
  597. ELSE '部分回票'
  598. END 'CGD.HP.总-回票情况',
  599. (
  600. ROUND( ifnull( c.Number1618330543270, 0 ), 2 )-(
  601. SELECT
  602. ifnull( sum( pc.winv_fee ), 0 )
  603. FROM
  604. cfp_pay_info AS pc
  605. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  606. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  607. WHERE
  608. pc.STATUS = 1
  609. AND ps.is_del = 0
  610. AND ( p.`status` = 2 OR p.STATUS = 1 )
  611. AND ps.STATUS = 7
  612. AND pc.sequenceNo = c.sequenceNo
  613. ORDER BY
  614. ps.invtime DESC
  615. )
  616. ) AS 'CGD.HP.MX.总-已回票金额',
  617. (
  618. SELECT
  619. invtime
  620. FROM
  621. cfp_pay_info AS pc
  622. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  623. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  624. WHERE
  625. pc.STATUS = 1
  626. AND ps.is_del = 0
  627. AND ( p.`status` = 2 OR p.STATUS = 1 )
  628. AND ps.STATUS = 7
  629. AND pc.sequenceNo = c.sequenceNo
  630. ORDER BY
  631. ps.invtime DESC
  632. LIMIT 1
  633. ) AS 'CGD.HP.MX.总-最近一次回票时间',
  634. c.ShortText1620753234895 AS 'CGD.回票方式',
  635. c.ShortText1620753237335 AS 'CGD.结算方式',
  636. c.ShortText1617866144054 AS 'CGD.42库房性质',
  637. c.ShortText1618465932373 AS 'CGD.62发货方式',
  638. source_all.delivery_num AS 'QRD-CP.FH.总-已发货',
  639. source_all.delivery_wnum AS 'QRD-CP.FH.总-未发货',
  640. source_all.delivery_status AS 'QRD-CP.FH.总-发货状态',
  641. source_all.delivery_send AS 'CGD.FH.总-已发货',
  642. source_all.delivery_wsend AS 'CGD.FH.总-未发货',
  643. source_all.cgd_delivery_status AS 'CGD.FH.总-发货状态',
  644. (SELECT
  645. SUM(
  646. send
  647. )
  648. FROM
  649. `fh_source` e_
  650. WHERE e_.cgdNo = source_all.cgdNo) AS 'CGD.FH.MX.总-已发货',
  651. (SELECT
  652. MAX(e_.addtime)
  653. FROM
  654. `fh_source` e_
  655. WHERE e_.cgdNo = source_all.cgdNo) AS 'CGD.FH.MX.总-最近一次发货时间',
  656. ROUND(b.Number1618249202608, 2) AS 'QRD-CP.KP.总-已开票金额',
  657. ROUND(b.Number1618249205231+b.inving_fee, 2) AS 'QRD-CP.KP.总-未开票金额',
  658. if(b.ShortText1618559274859=3,'已开','未开') AS 'QRD-CP.KP.总-开票状态',
  659. ROUND(
  660. (SELECT
  661. sum(oi.ainv_fee)
  662. FROM
  663. cfp_order_info AS oi
  664. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  665. LEFT JOIN cfp_assoc_key AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
  666. LEFT JOIN cfp_assoc_rela AS al ON ( ak.assocNo =al.assocNo AND al.`status` = 1 )
  667. WHERE
  668. po.is_del = 0
  669. AND oi.STATUS = 1
  670. AND ak.STATUS = 3
  671. AND ak.is_del = 0
  672. and oi.goodNo =b.sequenceNo),
  673. 2
  674. ) AS 'QRD-CP.KP.MX.总-已开票金额',
  675. (SELECT
  676. GROUP_CONCAT(
  677. al.viceNo
  678. )
  679. FROM
  680. cfp_order_info AS oi
  681. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  682. LEFT JOIN cfp_assoc_key AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
  683. LEFT JOIN cfp_assoc_rela AS al ON ( ak.assocNo =al.assocNo AND al.`status` = 1 )
  684. WHERE
  685. po.is_del = 0
  686. AND oi.STATUS = 1
  687. AND ak.STATUS = 3
  688. AND ak.is_del = 0
  689. and oi.goodNo =b.sequenceNo) AS 'QRD-CP.KP.MX.总-发票号',
  690. (SELECT
  691. ak.addtime
  692. FROM
  693. cfp_order_info AS oi
  694. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  695. LEFT JOIN cfp_assoc_key AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
  696. WHERE
  697. po.is_del = 0
  698. AND oi.STATUS = 1
  699. AND ak.STATUS = 3
  700. AND ak.is_del = 0
  701. and oi.goodNo =b.sequenceNo
  702. ORDER BY
  703. ak.addtime DESC
  704. LIMIT 1) AS 'QRD-CP.KP.MX.最新开票时间',
  705. ROUND(b.Number1618249146997, 2) AS 'QRD-CP.HK.总-已回款金额',
  706. ROUND(b.number1618249149738+b.paying_fee, 2) AS 'QRD-CP.HK.总-未回款金额',
  707. if(b.ShortText1618559043560=3,'已回','未回') AS 'QRD-CP.HK.总-回款状态',
  708. (SELECT
  709. sum(oi.afund_fee)
  710. FROM
  711. cfp_order_info AS oi
  712. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  713. LEFT JOIN cfp_assoc_key AS ak ON ( ak.codeNo = oi.orderNo AND (rela_form = 2 or rela_form = 3))
  714. WHERE
  715. po.is_del = 0
  716. AND oi.STATUS = 1
  717. AND ak.STATUS = 3
  718. AND ak.is_del = 0
  719. and oi.goodNo =b.sequenceNo
  720. ORDER BY
  721. ak.addtime) as 'QRD-CP.HK.MX.总-已回款金额',
  722. (SELECT
  723. ak.addtime
  724. FROM
  725. cfp_order_info AS oi
  726. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  727. LEFT JOIN cfp_assoc_key AS ak ON ( ak.codeNo = oi.orderNo AND (rela_form = 2 or rela_form = 3))
  728. WHERE
  729. po.is_del = 0
  730. AND oi.STATUS = 1
  731. AND ak.STATUS = 3
  732. AND ak.is_del = 0
  733. and oi.goodNo =b.sequenceNo
  734. ORDER BY
  735. ak.addtime DESC
  736. LIMIT 1) as 'QRD-CP.HK.MX.最新回款时间'
  737. FROM
  738. source_all left JOIN cfp_qrd_info b on
  739. source_all.productNo = b.sequenceNo
  740. LEFT JOIN cfp_cgd_info c on source_all.cgdNo = c.ShortText1618315935182
  741. where source_all.productNo<>'' {$where} order by ordertime";
  742. $list = Db::query($sql);
  743. if(empty($list)){
  744. $list=[["未找到数据"=>""]];
  745. }
  746. $header = array_keys($list[0]);
  747. array_walk($list, function (&$v) {
  748. $v = array_values($v);
  749. });
  750. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."确认单台账", $header, $list);
  751. }
  752. public function downreportCGDTZ(){
  753. $post = request()->post();
  754. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  755. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  756. $where='';
  757. if($start!=""){
  758. $where.=" and cgdtime >='{$start}'";
  759. }
  760. if($end!=""){
  761. $where.=" and cgdtime <='{$end}'";
  762. }
  763. $sql="SELECT
  764. b.ShortText1618315935182 AS 'CGD.2采购单号',
  765. b.ShortText1618270466672 AS 'CGD.14公司主体',
  766. b.Date1618315953443 AS 'CGD.3采购单下单日期',
  767. b.ShortText1618270412964 AS 'CGD.1采购单类型',
  768. b.StaffSelector1620899427104 AS 'CGD.采购员',
  769. b.ShortText1620399144946 AS 'CGD.45供应商名称',
  770. b.ShortText1617861287265 AS 'CGD.44供应商编号',
  771. b.ShortText1619625566608 AS 'CGD.出库包装库存',
  772. b.ShortText1617865688485 AS 'CGD.40税点',
  773. ROUND( b.Number1617865810822, 2 ) AS 'CGD.包装费',
  774. ROUND( b.Number1617865813284, 2 ) AS 'CGD.证书费',
  775. ROUND( b.Number1617865807879, 2 ) AS 'CGD.加标费',
  776. ROUND( b.Number1617865816181, 2 ) AS 'CGD.开模费',
  777. ROUND( b.number1618240204358, 2 ) AS 'CGD.成本工艺费',
  778. ROUND( b.Number1617865804813, 2 ) AS 'CGD.成本裸价',
  779. ROUND( b.number1618240287778, 2 ) AS 'CGD.物流费',
  780. ROUND( b.Number1619632830397, 2 ) AS 'CGD.工差',
  781. ROUND( b.Number1619632826654, 2 ) AS 'CGD.采购工差金额',
  782. ROUND( b.Number1617865818517, 2 ) AS 'CGD.采购单价',
  783. CAST( b.Number1618240600907 AS SIGNED ) AS 'CGD.采购数量',
  784. ROUND( b.Number1618240685904, 2 ) AS 'CGD.采购金额',
  785. ROUND( 0, 2 ) AS 'CGD.不含税采购成本-这个怎么计算',
  786. b.ShortText1617866362204 AS 'QRD-CP.4确认单类型',
  787. b.ShortText1617866360004 AS 'QRD-CP.5确认单编号',
  788. b.Date1618324547052 AS 'QRD-CP.6确认单下单日期',
  789. b.ShortText1618239976714 AS 'QRD.ZX.7咨询单编号',
  790. b.ShortText1617866364821 AS 'QRD.ZX.8咨询单类型',
  791. b.Date1619624209148 AS 'QRD.ZX.9咨询单下单时间',
  792. b.ShortText1618859161646 AS 'BK.10备库单号',
  793. b.Date1618859180209 AS 'BK.11备库下单日期',
  794. b.StaffSelector1618885082387 AS 'BK.15业务员',
  795. b.ShortText1618900704399 AS 'BK.13备库仓库',
  796. b.ShortText1617861966146 AS 'CGD.CP.26产品名称',
  797. b.ShortText1617861001482 AS 'CGD.CP.27产品编号',
  798. b.ShortText1617865626160 AS 'CGD.CP.28一级分类',
  799. a.cgd_cat_s AS 'CGD.CP.C二级分类',
  800. a.cgd_cat_t AS 'CGD.CP.C三级分类',
  801. a.financial AS 'CGD.CP.C财务核算编码',
  802. b.ShortText1617865685744 AS 'CGD.CP.25单位',
  803. b.ShortText1618240134229 AS 'CGD.CP.36贵金属种类',
  804. ROUND( b.Number1618240458074, 2 ) AS 'CGD.CP.38实时金价',
  805. ROUND( b.Number1618240480148, 2 ) AS 'CGD.CP.37商品重量(g)',
  806. (
  807. ROUND( ifnull( b.Number1618330470625, 0 ), 2 )+ (
  808. SELECT
  809. ifnull( sum( pc.wait_fee ), 0 )
  810. FROM
  811. cfp_pay_info AS pc
  812. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  813. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  814. WHERE
  815. pc.STATUS = 1
  816. AND ps.is_del = 0
  817. AND ( p.`status` = 2 OR p.STATUS = 1 )
  818. AND ps.pay_status = 4
  819. AND pc.sequenceNo = b.sequenceNo
  820. ORDER BY
  821. ps.paytime DESC
  822. )
  823. ) AS 'CGD.FK.总-已付款金额',
  824. (
  825. ROUND( ifnull( b.Number1618330472961, 0 ), 2 )-(
  826. SELECT
  827. ifnull( sum( pc.wait_fee ), 0 )
  828. FROM
  829. cfp_pay_info AS pc
  830. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  831. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  832. WHERE
  833. pc.STATUS = 1
  834. AND ps.is_del = 0
  835. AND ( p.`status` = 2 OR p.STATUS = 1 )
  836. AND ps.pay_status = 4
  837. AND pc.sequenceNo = b.sequenceNo
  838. ORDER BY
  839. ps.paytime DESC
  840. )
  841. ) AS 'CGD.FK.总-未付款金额',
  842. CASE
  843. WHEN (
  844. ROUND( ifnull( b.Number1618330470625, 0 ), 2 )+ (
  845. SELECT
  846. ifnull( sum( pc.wait_fee ), 0 )
  847. FROM
  848. cfp_pay_info AS pc
  849. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  850. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  851. WHERE
  852. pc.STATUS = 1
  853. AND ps.is_del = 0
  854. AND ( p.`status` = 2 OR p.STATUS = 1 )
  855. AND ps.pay_status = 4
  856. AND pc.sequenceNo = b.sequenceNo
  857. ORDER BY
  858. ps.paytime DESC
  859. )
  860. ) = 0 THEN
  861. '未付款'
  862. WHEN (
  863. ROUND( ifnull( b.Number1618330472961, 0 ), 2 )- (
  864. SELECT
  865. ifnull( sum( pc.wait_fee ), 0 )
  866. FROM
  867. cfp_pay_info AS pc
  868. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  869. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  870. WHERE
  871. pc.STATUS = 1
  872. AND ps.is_del = 0
  873. AND ( p.`status` = 2 OR p.STATUS = 1 )
  874. AND ps.pay_status = 4
  875. AND pc.sequenceNo = b.sequenceNo
  876. ORDER BY
  877. ps.paytime DESC
  878. )
  879. ) = 0 THEN
  880. '全部付款' ELSE '部分付款'
  881. END AS 'CGD.FK.总-付款情况',
  882. (
  883. round( ifnull( b.Number1618330470625, 0 ), 2 )+ (
  884. SELECT
  885. ifnull( sum( pc.wait_fee ), 0 )
  886. FROM
  887. cfp_pay_info AS pc
  888. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  889. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  890. WHERE
  891. pc.STATUS = 1
  892. AND ps.is_del = 0
  893. AND ( p.`status` = 2 OR p.STATUS = 1 )
  894. AND ps.pay_status = 4
  895. AND pc.sequenceNo = b.sequenceNo
  896. )
  897. ) AS 'CGD.FK.MX.总-已付款金额',
  898. (
  899. SELECT
  900. paytime
  901. FROM
  902. cfp_pay_info AS pc
  903. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  904. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  905. WHERE
  906. pc.STATUS = 1
  907. AND ps.is_del = 0
  908. AND ( p.`status` = 2 OR p.STATUS = 1 )
  909. AND ps.pay_status = 4
  910. AND pc.sequenceNo = b.sequenceNo
  911. ORDER BY
  912. ps.paytime DESC
  913. LIMIT 1
  914. ) AS 'CGD.HP.MX.总最近一次付款时间',
  915. ROUND(
  916. ROUND( ifnull( b.Number1618330541286, 0 ), 2 )+ (
  917. SELECT
  918. ifnull( sum( pc.winv_fee ), 0 )
  919. FROM
  920. cfp_pay_info AS pc
  921. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  922. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  923. WHERE
  924. pc.STATUS = 1
  925. AND ps.is_del = 0
  926. AND ( p.`status` = 2 OR p.STATUS = 1 )
  927. AND ps.STATUS = 7
  928. AND pc.sequenceNo = b.sequenceNo
  929. ),
  930. 2
  931. ) AS 'CGD.HP.总-已回票金额',
  932. ROUND(
  933. ifnull( b.Number1618330543270, 0 )-(
  934. SELECT
  935. ifnull( sum( pc.winv_fee ), 0 )
  936. FROM
  937. cfp_pay_info AS pc
  938. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  939. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  940. WHERE
  941. pc.STATUS = 1
  942. AND ps.is_del = 0
  943. AND ( p.`status` = 2 OR p.STATUS = 1 )
  944. AND ps.STATUS = 7
  945. AND pc.sequenceNo = b.sequenceNo
  946. ),
  947. 2
  948. ) AS 'CGD.HP.总-未回票金额',
  949. CASE
  950. WHEN (
  951. ROUND( ifnull( b.Number1618330541286, 0 ), 2 )+ (
  952. SELECT
  953. ifnull( sum( pc.winv_fee ), 0 )
  954. FROM
  955. cfp_pay_info AS pc
  956. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  957. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  958. WHERE
  959. pc.STATUS = 1
  960. AND ps.is_del = 0
  961. AND ( p.`status` = 2 OR p.STATUS = 1 )
  962. AND ps.STATUS = 7
  963. AND pc.sequenceNo = b.sequenceNo
  964. ORDER BY
  965. ps.paytime DESC
  966. )
  967. )= 0 THEN
  968. '未回票'
  969. WHEN (
  970. ROUND( ifnull( b.Number1618330543270, 0 ), 2 )-(
  971. SELECT
  972. ifnull( sum( pc.winv_fee ), 0 )
  973. FROM
  974. cfp_pay_info AS pc
  975. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  976. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  977. WHERE
  978. pc.STATUS = 1
  979. AND ps.is_del = 0
  980. AND ( p.`status` = 2 OR p.STATUS = 1 )
  981. AND ps.STATUS = 7
  982. AND pc.sequenceNo = b.sequenceNo
  983. ORDER BY
  984. ps.invtime DESC
  985. LIMIT 1
  986. )
  987. ) = 0 THEN
  988. '全部回票' ELSE '部分回票'
  989. END AS 'CGD.HP.总-回票情况',
  990. ROUND(
  991. ROUND( ifnull( b.Number1618330541286, 0 ), 2 )+ ifnull((
  992. SELECT
  993. ifnull( sum( pc.winv_fee ), 0 )
  994. FROM
  995. cfp_pay_info AS pc
  996. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  997. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  998. WHERE
  999. pc.STATUS = 1
  1000. AND ps.is_del = 0
  1001. AND ( p.`status` = 2 OR p.STATUS = 1 )
  1002. AND ps.STATUS = 7
  1003. AND pc.sequenceNo = b.sequenceNo
  1004. ),
  1005. 0
  1006. ),
  1007. 2
  1008. ) AS 'CGD.HP.MX.总-已回票金额',
  1009. (
  1010. SELECT
  1011. ps.invtime
  1012. FROM
  1013. cfp_pay_info AS pc
  1014. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1015. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1016. WHERE
  1017. pc.STATUS = 1
  1018. AND ps.is_del = 0
  1019. AND ( p.`status` = 2 OR p.STATUS = 1 )
  1020. AND ps.STATUS = 7
  1021. AND pc.sequenceNo = b.sequenceNo
  1022. ORDER BY
  1023. ps.invtime DESC
  1024. LIMIT 1
  1025. ) AS 'CGD.HP.MX.总最近一次回票时间',
  1026. CAST( a.delivery_send AS SIGNED ) AS 'CGD.FH.总-已发货',
  1027. CAST( a.delivery_wsend AS SIGNED ) AS 'CGD.FH.总-未发货',
  1028. a.cgd_delivery_status AS 'CGD.FH.总-发货状态',
  1029. ( SELECT sum( send ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'CGD.FH.MX.总-已发货',
  1030. ( SELECT max( addtime ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'CGD.FH.MX.总-最近一次发货时间'
  1031. FROM
  1032. source_all a
  1033. LEFT JOIN cfp_cgd_info b ON a.cgdNo = b.ShortText1618315935182
  1034. WHERE
  1035. a.cgdNo <> '' {$where} order by cgdtime";
  1036. $list = Db::query($sql);
  1037. if(empty($list)){
  1038. $list=[["未找到数据"=>""]];
  1039. }
  1040. $header = array_keys($list[0]);
  1041. array_walk($list, function (&$v) {
  1042. $v = array_values($v);
  1043. });
  1044. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."采购单台账", $header, $list);
  1045. }
  1046. /**退货台账、明细一样的
  1047. * @throws \think\db\exception\BindParamException
  1048. * @throws \think\exception\PDOException
  1049. */
  1050. public function downreportTHTZ(){
  1051. $post = request()->post();
  1052. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  1053. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  1054. $where='';
  1055. if($start!=""){
  1056. $where.=" and t.createtime >='{$start}'";
  1057. }
  1058. if($end!=""){
  1059. $where.=" and t.createtime <='{$end}'";
  1060. }
  1061. $sql="select
  1062. t.thNo `退货单号`,
  1063. case t.th_status
  1064. WHEN 1 THEN '已完成'
  1065. WHEN 2 THEN '进行中'
  1066. WHEN 3 THEN '已取消'
  1067. else '' end AS `流程进度`,
  1068. t.createtime `退货发起日期`,
  1069. t.th_company '公司名称',
  1070. t.th_user '退货人',
  1071. t.th_num '25退货数量',
  1072. t.th_qrd_fee '26退货销售货款',
  1073. t.th_cgd_fee '42退货采购货款',
  1074. IF
  1075. (( t.`is_th` = '1' ), '是', '否' ) '50供应商是否可以退货',
  1076. t.th_remark '27退货备注',
  1077. '' as '52退货备注',
  1078. t.th_post_company '退货物流信息-53物流公司',
  1079. t.th_post_code '退货物流信息-54物流单编号',
  1080. `t`.`th_post_fee` AS `退货物流信息-55物流费用`,
  1081. `t`.`th_receiver` AS `退货物流信息-56收货人`,
  1082. `t`.`th_phone` AS `退货物流信息-57收货人电话`,
  1083. '' AS `退货物流信息-58收货人电话2`,
  1084. `t`.`th_addr` AS `退货物流信息-59收货人地址`,
  1085. companyName AS `KH.2客户名称`,
  1086. companyNo AS `KH.3客户编码`,
  1087. khzzxz AS `KH.4客户属性`,
  1088. khcomp AS `KH.6分公司`,
  1089. '' AS `KH.5大区`,
  1090. middle_branch AS `KH.7中支`,
  1091. area_branch AS `KH.8县支`,
  1092. suppitem AS `PT.1平台类型`,
  1093. itemcode AS `PT.2平台编码`,
  1094. workNo AS `PT.3业管系统咨询单号`,
  1095. poNo AS `PT.4PO编号`,
  1096. source_all.qrdNo AS `QRD.4确认单编号`,
  1097. qrd_type AS `QRD.3确认单类型`,
  1098. ordertime AS `QRD.5确认单下单时间`,
  1099. date_format( ordertime, '%Y-%m-%d' ) AS `TZ.2.8确认单下单日期2`,
  1100. sale_name AS `QRD.1业务人员`,
  1101. productNo AS `QRD-CP确认单产品编号`,
  1102. product_name AS `CP.1产品名称`,
  1103. product_code AS `CP.2产品编码`,
  1104. cat_f AS `CP.3.0一级分类`,
  1105. cat_t AS `CP.C二级分类`,
  1106. cat_d AS `CP.C三级分类`,
  1107. fund_code AS `CP.28财务核算码`,
  1108. unit AS `CP.7单位`,
  1109. tax AS `CP.8税点`,
  1110. qrdkey AS `QRD.6确认单唯一识别码`,
  1111. round( diff_weight, 2 ) AS `CP.26工差重量`,
  1112. round( diff_price, 2 ) AS `CP.27工差金额`,
  1113. paytime AS `QRD.7承诺回款日期`,
  1114. round( sale_price, 2 ) AS `CP.19销售单价`,
  1115. cast( order_num AS signed ) AS `CP.20下单数量`,
  1116. round( sale_total, 2 ) AS `CP.21销售总额`,
  1117. income as `CP.NEW不含税收入-查看一下这个计算的是否正确`,
  1118. '-' AS `CP.NEW毛利润-不知道怎么计算`,
  1119. zxcode AS `ZXD.2咨询单编号`,
  1120. zxfktime AS `ZXD.4咨询日期`,
  1121. zxtype AS `ZXD.3咨询类型`,
  1122. cgdNo AS `CGD.2采购单号`,
  1123. cgdtime AS `CGD.3采购单下单日期`,
  1124. cgdtype AS `CGD.1采购单类型`,
  1125. cgd_saler AS `CGD.采购员`,
  1126. supplier AS `CGD.45供应商名称`,
  1127. suppierNo AS `CGD.44供应商编号`,
  1128. paking AS `CGD.出库包装库存`,
  1129. cgd_tax AS `CGD.40税点`,
  1130. round( pakage_fee, 2 ) AS `CGD.包装费`,
  1131. round( cert_fee, 2 ) AS `CGD.证书费`,
  1132. round( mark_fee, 2 ) AS `CGD.加标费`,
  1133. round(open_fee, 2 ) AS `CGD.开模费`,
  1134. round( cost_fee, 2 ) AS `CGD.成本工艺费`,
  1135. round( naked_fee, 2 ) AS `CGD.成本裸价`,
  1136. round( delivery_fee, 2 ) AS `CGD.物流费`,
  1137. round( cgd_diff_weight, 2 ) AS `CGD.工差`,
  1138. round( diff_fee, 2 ) AS `CGD.采购工差金额`,
  1139. round(cgd_price, 2 ) AS `CGD.采购单价`,
  1140. cast( cgd_num AS signed ) AS `CGD.采购数量`,
  1141. round(cgd_total, 2 ) AS `CGD.采购金额`,
  1142. round( 0, 2 ) AS `CGD.不含税采购成本-这个怎么计算`,
  1143. (ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
  1144. SELECT
  1145. ifnull( round(sum( pc.wait_fee ),2), 0 )
  1146. FROM
  1147. cfp_pay_info AS pc
  1148. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1149. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1150. WHERE
  1151. pc.STATUS = 1
  1152. AND ps.is_del = 0
  1153. AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=4
  1154. AND pc.sequenceNo = b.sequenceNo
  1155. ORDER BY
  1156. ps.paytime DESC
  1157. )) AS `CGD.FK.总-已付款金额`,
  1158. (ROUND( ifnull( c.Number1618330472961, 0 ), 2 )- (
  1159. SELECT
  1160. ifnull( round(sum( pc.wait_fee ),2), 0 )
  1161. FROM
  1162. cfp_pay_info AS pc
  1163. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1164. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1165. WHERE
  1166. pc.STATUS = 1
  1167. AND ps.is_del = 0
  1168. AND (p.`status` = 2 or p.`status` = 1) and ps.pay_status=4
  1169. AND pc.sequenceNo = b.sequenceNo
  1170. ORDER BY
  1171. ps.paytime DESC
  1172. ) ) AS `CGD.FK.总-未付款金额`,
  1173. CASE
  1174. WHEN (
  1175. ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
  1176. SELECT
  1177. ifnull( sum( pc.wait_fee ), 0 )
  1178. FROM
  1179. cfp_pay_info AS pc
  1180. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1181. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1182. WHERE
  1183. pc.STATUS = 1
  1184. AND ps.is_del = 0
  1185. AND ( p.`status` = 2 OR p.STATUS = 1 )
  1186. AND ps.pay_status = 4
  1187. AND pc.sequenceNo = b.sequenceNo
  1188. ORDER BY
  1189. ps.paytime DESC
  1190. )
  1191. ) = 0 THEN
  1192. '未付款'
  1193. WHEN (
  1194. ROUND( ifnull( c.Number1618330472961, 0 ), 2 )- (
  1195. SELECT
  1196. ifnull( sum( pc.wait_fee ), 0 )
  1197. FROM
  1198. cfp_pay_info AS pc
  1199. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1200. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1201. WHERE
  1202. pc.STATUS = 1
  1203. AND ps.is_del = 0
  1204. AND ( p.`status` = 2 OR p.STATUS = 1 )
  1205. AND ps.pay_status = 4
  1206. AND pc.sequenceNo = b.sequenceNo
  1207. ORDER BY
  1208. ps.paytime DESC
  1209. )
  1210. ) = 0 THEN
  1211. '全部付款' ELSE '部分付款'
  1212. END AS 'CGD.FK.总-付款情况',
  1213. (ROUND( ifnull( c.Number1618330541286, 0 ), 2 )+
  1214. (
  1215. SELECT
  1216. ifnull( sum( pc.winv_fee ), 0 )
  1217. FROM
  1218. cfp_pay_info AS pc
  1219. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1220. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1221. WHERE
  1222. pc.STATUS = 1
  1223. AND ps.is_del = 0
  1224. AND ( p.`status` = 2 OR p.STATUS = 1 )
  1225. AND ps.STATUS = 7
  1226. AND pc.sequenceNo = b.sequenceNo
  1227. GROUP BY
  1228. pc.sequenceNo
  1229. )
  1230. ) AS 'CGD.HP.总-已回票金额',
  1231. ROUND(
  1232. ifnull( c.Number1618330543270, 0 ) -(
  1233. SELECT
  1234. ifnull( sum( pc.winv_fee ), 0 )
  1235. FROM
  1236. cfp_pay_info AS pc
  1237. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1238. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1239. WHERE
  1240. pc.STATUS = 1
  1241. AND ps.is_del = 0
  1242. AND ( p.`status` = 2 OR p.STATUS = 1 )
  1243. AND ps.STATUS = 7
  1244. AND pc.sequenceNo = b.sequenceNo
  1245. GROUP BY
  1246. pc.sequenceNo
  1247. ),
  1248. 2
  1249. ) AS 'CGD.HP.总-未回票金额',
  1250. CASE
  1251. WHEN (
  1252. ROUND( ifnull( c.Number1618330541286, 0 ), 2 )+ (
  1253. SELECT
  1254. ifnull( sum( pc.winv_fee ), 0 )
  1255. FROM
  1256. cfp_pay_info AS pc
  1257. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1258. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1259. WHERE
  1260. pc.STATUS = 1
  1261. AND ps.is_del = 0
  1262. AND ( p.`status` = 2 OR p.STATUS = 1 )
  1263. AND ps.STATUS = 7
  1264. AND pc.sequenceNo = b.sequenceNo
  1265. ORDER BY
  1266. ps.paytime DESC
  1267. )
  1268. )= 0 THEN
  1269. '未回票'
  1270. WHEN (
  1271. ROUND( ifnull( c.Number1618330543270, 0 ), 2 )-(
  1272. SELECT
  1273. ifnull( sum( pc.winv_fee ), 0 )
  1274. FROM
  1275. cfp_pay_info AS pc
  1276. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1277. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1278. WHERE
  1279. pc.STATUS = 1
  1280. AND ps.is_del = 0
  1281. AND ( p.`status` = 2 OR p.STATUS = 1 )
  1282. AND ps.STATUS = 7
  1283. AND pc.sequenceNo = b.sequenceNo
  1284. ORDER BY
  1285. ps.invtime DESC limit 1
  1286. )
  1287. ) = 0 THEN
  1288. '全部回票' ELSE '部分回票'
  1289. END AS 'CGD.HP.总-回票情况',
  1290. '' AS `CGD.HP.MX.总-已回票金额`,
  1291. return_ticket AS `CGD.回票方式`,
  1292. return_trade AS `CGD.结算方式`,
  1293. c.ShortText1617866144054 AS `CGD.42库房性质`,
  1294. `c`.`ShortText1618465932373` AS `CGD.62发货方式`,
  1295. cast( `b`.`Number1618249015661` AS signed ) AS `QRD-CP.FH.总-已发货`,
  1296. cast( `b`.`Number1618249019294` AS signed ) AS `QRD-CP.FH.总-未发货`,
  1297. `b`.`ShortText1618559007040` AS `QRD-CP.FH.总-发货状态`,
  1298. cast( `c`.`Number1618316157066` AS signed ) AS `CGD.FH.总-已发货`,
  1299. cast( `c`.`Number1618316171848` AS signed ) AS `CGD.FH.总-未发货`,
  1300. if(`c`.`ShortText1618859321070`=1,'未发',if(`c`.`ShortText1618859321070`=3,'已发','部分')) AS `CGD.FH.总-发货状态`,
  1301. (
  1302. SELECT sum( send ) FROM fh_source WHERE source_all.cgdNo = fh_source.cgdNo ) AS `CGD.FH.MX.总-已发货`,
  1303. round( `b`.`Number1618249202608`, 2 ) AS `QRD-CP.KP.总-已开票金额`,
  1304. round( `b`.`Number1618249205231`+b.inving_fee, 2 ) AS `QRD-CP.KP.总-未开票金额`,
  1305. if(`b`.`ShortText1618559274859`=1,'未开',if(`b`.`ShortText1618559274859`=3,'已开','部分')) AS `QRD-CP.KP.总-开票状态`,
  1306. '' AS `QRD-CP.KP.MX.总-已开票金额`,
  1307. round( `b`.`Number1618249146997`, 2 ) AS `QRD-CP.HK.总-已回款金额`,
  1308. round( `b`.`number1618249149738`+b.paying_fee, 2 ) AS `QRD-CP.HK.总-未回款金额`,
  1309. if(`b`.`ShortText1618559043560`=1,'未回',if(`b`.`ShortText1618559043560`=3,'已回','部分')) AS `QRD-CP.HK.总-回款状态`,
  1310. '' AS `QRD-CP.HK.MX.总-已回款金额`
  1311. from cfp_th_source as t left join
  1312. 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
  1313. t.th_qrdcpNo = b.sequenceNo
  1314. LEFT JOIN cfp_cgd_info c on t.th_cgdNo = c.ShortText1618315935182
  1315. where t.th_status<>3 {$where} order by t.createtime";
  1316. $list = Db::query($sql);
  1317. if(empty($list)){
  1318. $list=[["未找到数据"=>""]];
  1319. }
  1320. $header = array_keys($list[0]);
  1321. array_walk($list, function (&$v) {
  1322. $v = array_values($v);
  1323. });
  1324. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."退货台账", $header, $list);
  1325. }
  1326. /**
  1327. * @throws \think\db\exception\BindParamException
  1328. * @throws \think\exception\PDOException
  1329. */
  1330. public function downreportCW(){
  1331. $post = request()->post();
  1332. $condition="";
  1333. $qrd_start = isset($post['qrd_start']) && $post['qrd_start'] != "" ? $post['qrd_start'] :"" ;
  1334. if($qrd_start!=""){
  1335. $condition .=" and ordertime>='". $qrd_start." 00:00:00'";
  1336. }
  1337. $qrd_end = isset($post['qrd_end']) && $post['qrd_end'] != "" ? $post['qrd_end'] :"" ;
  1338. if($qrd_end!=""){
  1339. $condition .=" and ordertime <='". $qrd_end." 23:59:59'";
  1340. }
  1341. $hk_start = isset($post['hk_start']) && $post['hk_start'] != "" ? $post['hk_start'] :"" ;
  1342. $hk_end = isset($post['hk_end']) && $post['hk_end'] != "" ? $post['hk_end'] :"" ;
  1343. if($hk_start!=""){
  1344. $condition .=" and addtime >='". $hk_start." 00:00:00'";
  1345. }
  1346. if($hk_end!=""){
  1347. $condition .=" and addtime <='". $hk_end." 23:59:59'";
  1348. }
  1349. if($qrd_start==""&&$hk_start==""){
  1350. $condition .=" and ordertime>='". date("Y-m-d")." 00:00:00'";
  1351. }
  1352. $sql="SELECT
  1353. supperinfo '公司名称',
  1354. sale_name '销售人员',
  1355. depart '部门',
  1356. qrd_type '订单类型',
  1357. qrdNo '确认单编号',
  1358. cgdNo '采购单单号' ,
  1359. khzzxz '客户属性',
  1360. khcomp '客户分公司',
  1361. companyName '客户名称',
  1362. product_name '产品名称',
  1363. cat_f '一级分类',
  1364. sale_price '销售单价',
  1365. order_num '下单数量',
  1366. sale_total '销售总额',
  1367. ordertime '确认单下单时间',
  1368. addtime '回款日期',
  1369. fund_fee '回款金额',
  1370. pay_day '账期'
  1371. FROM
  1372. cfp_cw_report
  1373. WHERE
  1374. 1=1
  1375. {$condition} order by ordertime";
  1376. $list = Db::query($sql);
  1377. if(empty($list)){
  1378. $list=[["未找到数据"=>""]];
  1379. }
  1380. $header = array_keys($list[0]);
  1381. array_walk($list, function (&$v) {
  1382. $v = array_values($v);
  1383. });
  1384. excelSave("财务台账", $header, $list);
  1385. }
  1386. public function downreportCWTZ(){
  1387. $post = request()->post();
  1388. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  1389. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  1390. $where='';
  1391. if($start!=""){
  1392. $where.=" and ordertime >='{$start}'";
  1393. }
  1394. if($end!=""){
  1395. $where.=" and ordertime <='{$end}'";
  1396. }
  1397. $sql="SELECT
  1398. DATE_FORMAT( ordertime, '%Y' ) '年',
  1399. DATE_FORMAT( ordertime, '%m' ) '月',
  1400. DATE_FORMAT( ordertime, '%d' ) '日',
  1401. productNo 'QRD确认单产品编号',
  1402. supperinfo 'QRD公司名称',
  1403. companyName 'QRD客户名称',
  1404. suppitem 'QRD平台',
  1405. khzzxz 'QRD客户属性',
  1406. khcomp 'QRD客户分公司',
  1407. poNo 'PT.4PO编号',
  1408. zxtype 'QRD线上线下',
  1409. source_all.qrdNo 'QRD.4确认单编号',
  1410. qrd_type 'QRD.确认单类型',
  1411. ordertime 'QRD.确认单下单时间',
  1412. sale_name 'QRD.业务员',
  1413. product_name 'QRD.产品名称',
  1414. cat_f 'QRD.一级分类',
  1415. tax 'QRD.税率',
  1416. sale_price 'QRD.销售单价',
  1417. order_num 'QRD.下单数量',
  1418. sale_total 'QRD.销售总额',
  1419. source_all.cgdNo 'CGD采购单单号',
  1420. ROUND( b.Number1618249146997, 2 ) 'QRD已回款',
  1421. ROUND( b.number1618249149738, 2 ) 'QRD未回款',
  1422. ROUND( b.paying_fee, 2 ) 'QRD回款进行中',
  1423. ROUND( b.Number1618249202608, 2 ) 'QRD已开票',
  1424. ROUND( b.Number1618249205231, 2 ) 'QRD未开票',
  1425. ROUND( b.inving_fee, 2 ) 'QRD开票进行中',
  1426. CASE
  1427. b.ShortText1618559043560
  1428. WHEN 1 THEN
  1429. '未回款'
  1430. WHEN 2 THEN
  1431. '部分回款'
  1432. WHEN 3 THEN
  1433. '全部回款' ELSE ''
  1434. END 'QRD.回款状态',
  1435. CASE
  1436. b.ShortText1618559274859
  1437. WHEN 1 THEN
  1438. '未开票'
  1439. WHEN 2 THEN
  1440. '部分开票'
  1441. WHEN 3 THEN
  1442. '全部开票' ELSE ''
  1443. END 'QRD.开票状态',
  1444. (
  1445. SELECT
  1446. ak.addtime
  1447. FROM
  1448. cfp_order_info AS oi
  1449. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  1450. LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
  1451. WHERE
  1452. po.is_del = 0
  1453. AND oi.STATUS = 1
  1454. AND ak.STATUS = 3
  1455. AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
  1456. ORDER BY
  1457. ak.addtime DESC
  1458. LIMIT 1
  1459. ) AS 'QRD.最近开票时间',
  1460. (
  1461. SELECT
  1462. ak.addtime
  1463. FROM
  1464. cfp_order_info AS oi
  1465. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  1466. LEFT JOIN cfp_assoc_list AS ak ON (
  1467. ak.codeNo = oi.orderNo
  1468. AND ( rela_form = 2 OR rela_form = 3 ))
  1469. WHERE
  1470. po.is_del = 0
  1471. AND oi.STATUS = 1
  1472. AND ak.STATUS = 3
  1473. AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
  1474. ORDER BY
  1475. ak.addtime DESC
  1476. LIMIT 1
  1477. ) AS 'QRD.最近回款时间',
  1478. if(ISNULL( (
  1479. SELECT
  1480. ak.addtime
  1481. FROM
  1482. cfp_order_info AS oi
  1483. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  1484. LEFT JOIN cfp_assoc_list AS ak ON (
  1485. ak.codeNo = oi.orderNo
  1486. AND ( rela_form = 2 OR rela_form = 3 ))
  1487. WHERE
  1488. po.is_del = 0
  1489. AND oi.STATUS = 1
  1490. AND ak.STATUS = 3
  1491. AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
  1492. ORDER BY
  1493. ak.addtime DESC
  1494. LIMIT 1
  1495. ) ),ceil(DATEDIFF(NOW(),ordertime)),ceil(DATEDIFF((
  1496. SELECT
  1497. ak.addtime
  1498. FROM
  1499. cfp_order_info AS oi
  1500. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  1501. LEFT JOIN cfp_assoc_list AS ak ON (
  1502. ak.codeNo = oi.orderNo
  1503. AND ( rela_form = 2 OR rela_form = 3 ))
  1504. WHERE
  1505. po.is_del = 0
  1506. AND oi.STATUS = 1
  1507. AND ak.STATUS = 3
  1508. AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
  1509. ORDER BY
  1510. ak.addtime DESC
  1511. LIMIT 1
  1512. ),ordertime))) as '账期',
  1513. if(ISNULL( (
  1514. SELECT
  1515. ak.addtime
  1516. FROM
  1517. cfp_order_info AS oi
  1518. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  1519. LEFT JOIN cfp_assoc_list AS ak ON (
  1520. ak.codeNo = oi.orderNo
  1521. AND ( rela_form = 2 OR rela_form = 3 ))
  1522. WHERE
  1523. po.is_del = 0
  1524. AND oi.STATUS = 1
  1525. AND ak.STATUS = 3
  1526. AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
  1527. ORDER BY
  1528. ak.addtime DESC
  1529. LIMIT 1
  1530. ) ),if(ceil(DATEDIFF(NOW(),ordertime)/30)>6,'是','否'),if(ceil(DATEDIFF((
  1531. SELECT
  1532. ak.addtime
  1533. FROM
  1534. cfp_order_info AS oi
  1535. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  1536. LEFT JOIN cfp_assoc_list AS ak ON (
  1537. ak.codeNo = oi.orderNo
  1538. AND ( rela_form = 2 OR rela_form = 3 ))
  1539. WHERE
  1540. po.is_del = 0
  1541. AND oi.STATUS = 1
  1542. AND ak.STATUS = 3
  1543. AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
  1544. ORDER BY
  1545. ak.addtime DESC
  1546. LIMIT 1
  1547. ),ordertime)/30)>6,'是','否')) as '账期是否超期',
  1548. IF
  1549. ( DATEDIFF( NOW(), ordertime )> 60, '是', '否' ) AS '下单是否超期',
  1550. IF
  1551. (
  1552. ISNULL((
  1553. SELECT
  1554. ak.addtime
  1555. FROM
  1556. cfp_order_info AS oi
  1557. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  1558. LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
  1559. WHERE
  1560. po.is_del = 0
  1561. AND oi.STATUS = 1
  1562. AND ak.STATUS = 3
  1563. AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
  1564. ORDER BY
  1565. ak.addtime DESC
  1566. LIMIT 1
  1567. )
  1568. ),
  1569. if(DATEDIFF((
  1570. SELECT
  1571. ak.addtime
  1572. FROM
  1573. cfp_order_info AS oi
  1574. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  1575. LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
  1576. WHERE
  1577. po.is_del = 0
  1578. AND oi.STATUS = 1
  1579. AND ak.STATUS = 3
  1580. AND ak.is_del = 0 and oi.qrdNo = source_all.qrdNo
  1581. ORDER BY
  1582. ak.addtime DESC
  1583. LIMIT 1
  1584. ),
  1585. ordertime
  1586. )>15,'是','否'),
  1587. if(DATEDIFF( NOW(), ordertime )>15,'是','否')) AS '开票是否超期',
  1588. delivery_status 'QRD.发货状态',
  1589. ( SELECT sum( send ) FROM fh_source WHERE source_all.qrdNo = fh_source.qrdNo ) AS 'qrd.总发货数量',
  1590. ( SELECT max( addtime ) FROM fh_source WHERE source_all.qrdNo = fh_source.qrdNo ) AS 'qrd.最近一次发货时间'
  1591. FROM
  1592. source_all
  1593. LEFT JOIN cfp_qrd_info b ON source_all.productNo = b.sequenceNo
  1594. LEFT JOIN cfp_cgd_info c ON source_all.cgdNo = c.ShortText1618315935182
  1595. WHERE
  1596. source_all.productNo <> '' {$where}
  1597. ORDER BY
  1598. ordertime DESC ";
  1599. $list = Db::query($sql);
  1600. if(empty($list)){
  1601. $list=[["未找到数据"=>""]];
  1602. }
  1603. $header = array_keys($list[0]);
  1604. array_walk($list, function (&$v) {
  1605. $v = array_values($v);
  1606. });
  1607. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."应收台账", $header, $list);
  1608. }
  1609. /**
  1610. * @throws \think\db\exception\BindParamException
  1611. * @throws \think\exception\PDOException
  1612. */
  1613. public function downQRD(){
  1614. $post = request()->post();
  1615. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  1616. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  1617. $where='';
  1618. if($start!=""){
  1619. $where.=" and ordertime >='{$start}'";
  1620. }
  1621. if($end!=""){
  1622. $where.=" and ordertime <='{$end}'";
  1623. }
  1624. $sql = "SELECT
  1625. DATE_FORMAT(ordertime,'%Y') '年',
  1626. DATE_FORMAT(ordertime,'%m') '月',
  1627. DATE_FORMAT(ordertime,'%d') '日',
  1628. a.supperinfo 'QRD公司名称',
  1629. a.zxtype 'QRD.咨询单类型',
  1630. a.qrdNo 'QRD.4确认单编号',
  1631. a.sale_name 'QRD.业务员',
  1632. a.suppitem 'QRD平台',
  1633. a.khzzxz 'QRD客户属性',
  1634. a.khcomp 'QRD客户分公司',
  1635. a.product_code 'QRD.产品编号',
  1636. a.cat_f 'QRD.一级分类',
  1637. a.fund_code 'QRD.财务核算码',
  1638. a.product_name 'QRD.产品名称',
  1639. a.unit 'QRD.单位',
  1640. a.sale_price 'QRD.销售单价',
  1641. a.order_num 'QRD.下单数量',
  1642. a.sale_total 'QRD.销售总额',
  1643. ROUND( b.Number1618249202608, 2 ) 'QRD已开票',
  1644. ROUND( b.Number1618249205231+b.inving_fee, 2 ) 'QRD未开票',
  1645. IF
  1646. ( ak.rela_form = 1, ak.addtime, '' ) 'QRD本次开票时间',
  1647. IF
  1648. ( ak.rela_form = 1, ak.cancel_total, '' ) 'QRD本次开票金额',
  1649. if(b.ShortText1618559274859=1,'未开票',if(b.ShortText1618559274859=3,'已开票','部分开票')) 'QRD开票完成状态',
  1650. a.cgdNo 'CGD采购单单号',
  1651. pl.invNo '确认单发票申请编号',
  1652. (select ci.company_name from cfp_company_info ci where ci.companyNo=pl.inv_out) '发票开具全称',
  1653. li.inv_number '发票号码'
  1654. FROM
  1655. source_all a
  1656. LEFT JOIN cfp_qrd_info b ON a.productNo = b.sequenceNo
  1657. LEFT JOIN cfp_cgd_info c ON a.cgdNo = c.ShortText1618315935182
  1658. LEFT JOIN fh_source f ON a.cgdNo = f.cgdNo
  1659. LEFT JOIN
  1660. cfp_order_info AS oi ON ( oi.goodNo = b.sequenceNo AND oi.STATUS = 1 )
  1661. LEFT JOIN cfp_order_pool AS po ON (oi.orderNo = po.orderNo
  1662. AND po.is_del = 0 ) LEFT JOIN (
  1663. SELECT
  1664. `k`.`id` AS `aid`,
  1665. `k`.`assocNo` AS `assocNo`,
  1666. `k`.`companyNo` AS `companyNo`,
  1667. `k`.`type` AS `type`,
  1668. `k`.`rela_form` AS `rela_form`,
  1669. `k`.`codeNo` AS `codeNo`,
  1670. `k`.`total_fee` AS `total_fee`,
  1671. `k`.`balance` AS `balance`,
  1672. `k`.`cancel_total` AS `cancel_total`,
  1673. `k`.`is_del` AS `is_del`,
  1674. `k`.`status` AS `status`,
  1675. `k`.`exam_remark` AS `exam_remark`,
  1676. `k`.`addtime` AS `addtime`,
  1677. `t`.`viceNo` AS `viceNo`,
  1678. `t`.`vice_fee` AS `vice_fee`,
  1679. `t`.`cancel_fee` AS `cancel_fee`,
  1680. `t`.`id` AS `id`,
  1681. `k`.`source` AS `source`,
  1682. `t`.`vice_total` AS `vice_total`,
  1683. `k`.`apply_name` AS `apply_name`,
  1684. `k`.`apply_id` AS `apply_id`,
  1685. `t`.`status` AS `bstatus`
  1686. FROM
  1687. (
  1688. `cfp_assoc_key` `k`
  1689. JOIN `cfp_assoc_rela` `t` ON ((
  1690. `k`.`assocNo` = `t`.`assocNo`
  1691. )))
  1692. ) AS ak ON (
  1693. ( ak.codeNo = oi.orderNo OR ak.viceNo = oi.orderNo )
  1694. AND ( rela_form IN ( 1, 2, 3 ) AND ak.STATUS = 3 AND ak.is_del = 0 )
  1695. ) left join cfp_pay_info as pc on (pc.sequenceNo = c.sequenceNo and pc.`status`=1)
  1696. LEFT JOIN cfp_pay_stages as ps on (ps.payNo= pc.payNo and ps.is_del =0)
  1697. left JOIN cfp_pay as p on (p.payNo=pc.payNo and (p.`status`=2 or p.status=1))
  1698. LEFT JOIN cfp_invoice_pool as pl on (ak.viceNo = pl.invNo and ak.rela_form=1)
  1699. LEFT JOIN cfp_invoice_list as li on (pl.invNo =li.invNo and li.`status`=1 and li.is_del=0)
  1700. WHERE
  1701. a.productNo <> '' {$where} order by ordertime";
  1702. $list = Db::query($sql);
  1703. if(empty($list)){
  1704. $list=[["未找到数据"=>""]];
  1705. }
  1706. $header = array_keys($list[0]);
  1707. array_walk($list, function (&$v) {
  1708. $v = array_values($v);
  1709. });
  1710. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."确认单核算", $header, $list);
  1711. }
  1712. public function downCGD()
  1713. {
  1714. $post = request()->post();
  1715. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  1716. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  1717. $where='';
  1718. if($start!=""){
  1719. $where.=" and cgdtime >='{$start}'";
  1720. }
  1721. if($end!=""){
  1722. $where.=" and cgdtime <='{$end}'";
  1723. }
  1724. $sql = "SELECT
  1725. a.cgd_saler 'CGD.采购员',
  1726. a.cgdtype 'CGD.采购单类型',
  1727. a.cgdNo 'CGD.采购单单号',
  1728. a.bkNo 'CGD.备库单号',
  1729. ifnull( `a`.`pakage_fee`, 0 ) AS `CGD.包装费`,
  1730. ifnull( `a`.`cert_fee`, 0 ) AS `CGD.证书费`,
  1731. ifnull( `a`.`mark_fee`, 0 ) AS `CGD.加标费`,
  1732. ifnull( `a`.`open_fee`, 0 ) AS `CGD.开模费`,
  1733. ifnull( `a`.`cost_fee`, 0 ) AS `CGD.成本工艺费`,
  1734. ifnull( `a`.`naked_fee`, '' ) AS `CGD.成本裸价`,
  1735. ifnull( `a`.`delivery_fee`, 0 ) AS `CGD.物流费`,
  1736. ifnull( `a`.`cgd_price`, '' ) AS `CGD.采购单价`,
  1737. cast( `a`.`cgd_num` AS signed ) AS `CGD.采购数量`,
  1738. `a`.`cgd_total` AS `CGD.采购金额`,
  1739. '' as '毛利率',
  1740. a.is_stock `CGD.是否库存`,
  1741. a.paking 'CGD.出库包装库存',
  1742. a.cgd_tax 'CGD.采购单税率',
  1743. a.supplier 'CGD.供货商',
  1744. a.delivery_type `CGD.物流方式`,
  1745. (
  1746. ROUND( ifnull( b.Number1618330470625, 0 ), 2 )+ (
  1747. SELECT
  1748. ifnull( round(sum( pc.wait_fee ),2), 0 )
  1749. FROM
  1750. cfp_pay_info AS pc
  1751. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1752. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1753. WHERE
  1754. pc.STATUS = 1
  1755. AND ps.is_del = 0
  1756. AND p.`status` = 2 and ps.pay_status=4
  1757. AND pc.sequenceNo = b.sequenceNo
  1758. ORDER BY
  1759. ps.paytime DESC
  1760. )
  1761. ) AS '已付款',
  1762. (
  1763. ROUND( ifnull( b.Number1618330472961, 0 ), 2 )- (
  1764. SELECT
  1765. ifnull( round(sum( pc.wait_fee ),2), 0 )
  1766. FROM
  1767. cfp_pay_info AS pc
  1768. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1769. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1770. WHERE
  1771. pc.STATUS = 1
  1772. AND ps.is_del = 0
  1773. AND p.`status` = 2 and ps.pay_status=4
  1774. AND pc.sequenceNo = b.sequenceNo
  1775. ORDER BY
  1776. ps.paytime DESC
  1777. )
  1778. ) AS '未付款',
  1779. (
  1780. ROUND( ifnull( b.Number1618330541286, 0 ), 2 )+ (
  1781. SELECT
  1782. ifnull( sum( pc.winv_fee ), 0 )
  1783. FROM
  1784. cfp_pay_info AS pc
  1785. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1786. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1787. WHERE
  1788. pc.STATUS = 1
  1789. AND ps.is_del = 0
  1790. AND p.`status` = 2 and ps.status=7
  1791. AND pc.sequenceNo = b.sequenceNo
  1792. ORDER BY
  1793. ps.paytime DESC
  1794. )
  1795. ) AS '已回票',
  1796. (
  1797. ROUND( ifnull( b.Number1618330543270, 0 ), 2 )-(
  1798. SELECT
  1799. ifnull( sum( pc.winv_fee ), 0 )
  1800. FROM
  1801. cfp_pay_info AS pc
  1802. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1803. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1804. WHERE
  1805. pc.STATUS = 1
  1806. AND ps.is_del = 0
  1807. AND p.`status` = 2 and ps.status=7
  1808. AND pc.sequenceNo = b.sequenceNo
  1809. ORDER BY
  1810. ps.invtime DESC
  1811. )
  1812. ) AS '待回票',
  1813. a.cgd_delivery_status 'CGD.发货状态',
  1814. pc.total_fee '本次付款金额',
  1815. pc.ainv_fee '本次回票金额',
  1816. ps.paytime '本次付款时间',
  1817. ps.invtime '本次回票时间',
  1818. f.send_date '本次发货时间',
  1819. f.send '本次发货数量',
  1820. a.return_ticket '回票方式',
  1821. a.return_trade '结算方式',
  1822. if((
  1823. ROUND( ifnull( b.Number1618330543270, 0 ), 2 )-(
  1824. SELECT
  1825. ifnull( sum( pc.winv_fee ), 0 )
  1826. FROM
  1827. cfp_pay_info AS pc
  1828. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1829. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1830. WHERE
  1831. pc.STATUS = 1
  1832. AND ps.is_del = 0
  1833. AND p.`status` = 2 and ps.status=7
  1834. AND pc.sequenceNo = b.sequenceNo
  1835. ORDER BY
  1836. ps.invtime DESC
  1837. )
  1838. )=0,'已回','未回' )AS '回票状态',
  1839. if((
  1840. ROUND( ifnull( b.Number1618330472961, 0 ), 2 )- (
  1841. SELECT
  1842. ifnull( round(sum( pc.wait_fee ),2), 0 )
  1843. FROM
  1844. cfp_pay_info AS pc
  1845. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1846. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1847. WHERE
  1848. pc.STATUS = 1
  1849. AND ps.is_del = 0
  1850. AND p.`status` = 2 and ps.status=4
  1851. AND pc.sequenceNo = b.sequenceNo
  1852. ORDER BY
  1853. ps.paytime DESC
  1854. )
  1855. )=0,'已付','未付' ) AS '付款状态'
  1856. FROM
  1857. source_all AS a
  1858. LEFT JOIN cfp_cgd_info AS b ON a.cgdNo = b.ShortText1618315935182
  1859. LEFT JOIN fh_source f ON a.cgdNo = f.cgdNo
  1860. LEFT JOIN cfp_pay_info AS pc ON pc.sequenceNo = b.sequenceNo
  1861. AND pc.STATUS = 1
  1862. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1863. AND ps.is_del = 0
  1864. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1865. AND p.`status` = 2
  1866. WHERE
  1867. a.cgdNo <> '' {$where} order by cgdtime";
  1868. $list = Db::query($sql);
  1869. if(empty($list)){
  1870. $list=[["未找到数据"=>""]];
  1871. }
  1872. $header = array_keys($list[0]);
  1873. array_walk($list, function (&$v) {
  1874. $v = array_values($v);
  1875. });
  1876. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."采购单核算", $header, $list);
  1877. }
  1878. public function downQRDTZ(){
  1879. $post = request()->post();
  1880. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  1881. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  1882. $where='';
  1883. if($start!=""){
  1884. $where.=" and ordertime >='{$start}'";
  1885. }
  1886. if($end!=""){
  1887. $where.=" and ordertime <='{$end}'";
  1888. }
  1889. $sql="SELECT
  1890. DATE_FORMAT(ordertime,'%Y') '年',
  1891. DATE_FORMAT(ordertime,'%m') '月',
  1892. DATE_FORMAT(ordertime,'%d') '日',
  1893. supperinfo 'QRD公司名称',
  1894. zxcode 'QRD.咨询单号',
  1895. zxtype 'QRD.咨询单类型',
  1896. source_all.qrdNo 'QRD.4确认单编号',
  1897. sale_name 'QRD.业务员',
  1898. suppitem 'QRD平台',
  1899. khzzxz 'QRD客户属性',
  1900. khcomp 'QRD客户分公司',
  1901. product_name 'QRD.产品名称',
  1902. product_code 'QRD.产品编号',
  1903. cat_f 'QRD.一级分类',
  1904. unit 'QRD.单位',
  1905. tax 'QRD.税率',
  1906. sale_price 'QRD.销售单价',
  1907. order_num 'QRD.下单数量',
  1908. sale_total 'QRD.销售总额',
  1909. income 'QRD.不含税收入',
  1910. ROUND(b.Number1618249202608,2) 'QRD已开票',
  1911. ROUND(b.Number1618249205231 ,2) 'QRD未开票',
  1912. b.inving_fee 'QRD开票中',
  1913. source_all.cgdNo 'CGD采购单单号',
  1914. cgdtype 'CGD采购单类型',
  1915. cgd_saler 'CGD采购单业务员',
  1916. suplier_name 'CGD供货商名称',
  1917. cgd_tax 'CGD采购单税点',
  1918. pakage_fee 'CGD包装费',
  1919. cert_fee 'CGD证书费',
  1920. mark_fee 'CGD加标费',
  1921. open_fee 'CGD开模费',
  1922. cost_fee 'CGD成本工艺费',
  1923. naked_fee 'CGD裸价',
  1924. delivery_fee 'CGD物流费',
  1925. cgd_price 'CGD采购单单价',
  1926. cgd_num 'CGD采购单数量',
  1927. cgd_total 'CGD采购单金额',
  1928. (
  1929. ROUND( ifnull( c.Number1618330470625, 0 ), 2 )+ (
  1930. SELECT
  1931. ifnull( sum( pc.wait_fee ), 0 )
  1932. FROM
  1933. cfp_pay_info AS pc
  1934. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1935. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1936. WHERE
  1937. pc.STATUS = 1
  1938. AND ps.is_del = 0
  1939. AND p.`status` = 2 and ps.pay_status=4
  1940. AND pc.sequenceNo = c.sequenceNo
  1941. ORDER BY
  1942. ps.paytime DESC
  1943. )
  1944. ) AS 'CGD已付款',
  1945. (
  1946. ROUND( ifnull( c.Number1618330472961, 0 ), 2 )- (
  1947. SELECT
  1948. ifnull( sum( pc.wait_fee ), 0 )
  1949. FROM
  1950. cfp_pay_info AS pc
  1951. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1952. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1953. WHERE
  1954. pc.STATUS = 1
  1955. AND ps.is_del = 0
  1956. AND p.`status` = 2 and ps.pay_status=4
  1957. AND pc.sequenceNo = c.sequenceNo
  1958. ORDER BY
  1959. ps.paytime DESC
  1960. )
  1961. ) AS 'CGD未付款',
  1962. (
  1963. ROUND( ifnull( c.Number1618330541286, 0 ), 2 )+ (
  1964. SELECT
  1965. ifnull( sum( pc.winv_fee ), 0 )
  1966. FROM
  1967. cfp_pay_info AS pc
  1968. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1969. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1970. WHERE
  1971. pc.STATUS = 1
  1972. AND ps.is_del = 0
  1973. AND p.`status` = 2 and ps.status=7
  1974. AND pc.sequenceNo = c.sequenceNo
  1975. ORDER BY
  1976. ps.paytime DESC
  1977. )
  1978. ) AS 'CGD已回票',
  1979. (
  1980. ROUND( ifnull( c.Number1618330543270, 0 ), 2 )-(
  1981. SELECT
  1982. ifnull( sum( pc.winv_fee ), 0 )
  1983. FROM
  1984. cfp_pay_info AS pc
  1985. LEFT JOIN cfp_pay_stages AS ps ON ps.payNo = pc.payNo
  1986. LEFT JOIN cfp_pay AS p ON p.payNo = pc.payNo
  1987. WHERE
  1988. pc.STATUS = 1
  1989. AND ps.is_del = 0
  1990. AND p.`status` = 2 and ps.status=7
  1991. AND pc.sequenceNo = c.sequenceNo
  1992. ORDER BY
  1993. ps.invtime DESC
  1994. )
  1995. ) AS 'CGD待回票',
  1996. ( SELECT source_all.cgd_num-sum( send ) FROM fh_source WHERE source_all.cgdNo = fh_source.cgdNo ) AS 'CGD.未发货数量' ,
  1997. ( SELECT sum( send ) FROM fh_source WHERE source_all.cgdNo = fh_source.cgdNo ) AS 'CGD.总发货数量'
  1998. FROM
  1999. source_all left JOIN cfp_qrd_info b on
  2000. source_all.productNo = b.sequenceNo
  2001. LEFT JOIN cfp_cgd_info c on source_all.cgdNo = c.ShortText1618315935182
  2002. where source_all.productNo<>'' {$where} order by ordertime";
  2003. $list = Db::query($sql);
  2004. if(empty($list)){
  2005. $list=[["未找到数据"=>""]];
  2006. }
  2007. $header = array_keys($list[0]);
  2008. array_walk($list, function (&$v) {
  2009. $v = array_values($v);
  2010. });
  2011. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."确认采购单业绩", $header, $list);
  2012. }
  2013. public function downTH(){
  2014. $post = request()->post();
  2015. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  2016. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  2017. $where='';
  2018. if($start!=""){
  2019. $where.=" and t.createtime >='{$start}'";
  2020. }
  2021. if($end!=""){
  2022. $where.=" and t.createtime <='{$end}'";
  2023. }
  2024. $sql = "select
  2025. t.thNo 'TH.退货单号',
  2026. case t.th_status
  2027. WHEN 1 THEN '已完成'
  2028. WHEN 2 THEN '进行中'
  2029. WHEN 3 THEN '已取消'
  2030. else '' end'TH.退货状态',
  2031. t.createtime 'TH.退货时间',
  2032. t.th_company 'TH.公司',
  2033. t.th_user 'TH.退货人',
  2034. t.th_remark 'TH.退货备注',
  2035. suppitem 'QRD平台',
  2036. khzzxz 'QRD客户属性',
  2037. source_all.qrdNo 'QRD.4确认单编号',
  2038. sale_name 'QRD.业务员',
  2039. product_name 'QRD.产品名称',
  2040. product_code 'QRD.产品编号',
  2041. cat_f 'QRD.一级分类',
  2042. financial 'CGD.财务核算码',
  2043. unit 'QRD.单位',
  2044. tax 'QRD.税率',
  2045. sale_price 'QRD.销售单价',
  2046. t.th_num 'TH.退货数量',
  2047. t.th_qrd_fee 'TH.销售货款',
  2048. t.th_cgd_fee 'TH.采购货款',
  2049. income 'QRD.不含税收入',
  2050. zxcode 'QRD.咨询单号',
  2051. zxtype 'QRD.咨询单类型',
  2052. source_all.cgdNo 'CGD采购单单号'
  2053. from cfp_th_source as t left join
  2054. 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
  2055. t.th_qrdcpNo = b.sequenceNo
  2056. LEFT JOIN cfp_cgd_info c on t.th_cgdNo = c.ShortText1618315935182
  2057. where t.th_status<>3 {$where} order by t.createtime";
  2058. $list = Db::query($sql);
  2059. if(empty($list)){
  2060. $list=[["未找到数据"=>""]];
  2061. }
  2062. $header = array_keys($list[0]);
  2063. array_walk($list, function (&$v) {
  2064. $v = array_values($v);
  2065. });
  2066. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."退货单业绩", $header, $list);
  2067. }
  2068. /**
  2069. * @throws \think\db\exception\BindParamException
  2070. * @throws \think\exception\PDOException
  2071. */
  2072. public function QRDPAY(){
  2073. $post = request()->post();
  2074. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  2075. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  2076. $where='';
  2077. if($start!=""){
  2078. $where.=" and a.ordertime >='{$start}'";
  2079. }
  2080. if($end!=""){
  2081. $where.=" and a.ordertime <='{$end}'";
  2082. }
  2083. $sql = "SELECT
  2084. a.qrdNo AS 'QRD.4确认单编号',
  2085. a.productNo AS 'QRD确认单产品编号',
  2086. a.supperinfo AS 'QRD公司名称',
  2087. a.companyName AS 'QRD客户名称',
  2088. a.suppitem AS 'QRD平台',
  2089. a.khzzxz AS 'QRD客户属性',
  2090. a.khcomp AS 'QRD客户分公司',
  2091. a.poNo AS 'PT.4PO编号',
  2092. a.zxtype AS 'QRD线上线下',
  2093. a.sale_name AS 'QRD.业务员',
  2094. a.product_name AS 'QRD.产品名称',
  2095. a.sale_price AS 'QRD.销售单价',
  2096. a.order_num AS 'QRD.下单数量',
  2097. a.sale_total AS '销售总额',
  2098. a.ordertime AS 'QRD.下单时间',
  2099. b.Number1618249146997 '已收款',
  2100. b.paying_fee '结算中',
  2101. (
  2102. a.sale_total - ifnull( b.Number1618249146997, 0 )- ifnull( b.paying_fee, 0 )-(
  2103. SELECT
  2104. ifnull( sum( th_qrd_fee ), 0 )
  2105. FROM
  2106. cfp_th_source
  2107. WHERE
  2108. th_qrdcpNo = a.productNo
  2109. AND th_status = 1
  2110. )) '未收款',
  2111. (
  2112. SELECT
  2113. ak.addtime
  2114. FROM
  2115. cfp_order_info AS oi
  2116. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  2117. LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND ak.rela_form = 2 )
  2118. OR ( ak.viceNo = oi.orderNo AND ak.rela_form = 3 )
  2119. WHERE
  2120. po.is_del = 0
  2121. AND ak.rela_form IN ( 2, 3 )
  2122. AND oi.STATUS = 1
  2123. AND ak.STATUS = 3
  2124. AND ak.is_del = 0
  2125. AND oi.goodNo = a.productNo
  2126. ORDER BY
  2127. ak.addtime DESC
  2128. LIMIT 1
  2129. ) AS '回款日期',
  2130. DATEDIFF(
  2131. ifnull(
  2132. (
  2133. SELECT
  2134. ak.addtime
  2135. FROM
  2136. cfp_order_info AS oi
  2137. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  2138. LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND ak.rela_form = 2 )
  2139. OR ( ak.viceNo = oi.orderNo AND ak.rela_form = 3 )
  2140. WHERE
  2141. po.is_del = 0
  2142. AND ak.rela_form IN ( 2, 3 )
  2143. AND oi.STATUS = 1
  2144. AND ak.STATUS = 3
  2145. AND ak.is_del = 0
  2146. AND oi.goodNo = a.productNo
  2147. ORDER BY
  2148. ak.addtime DESC
  2149. LIMIT 1
  2150. ),
  2151. NOW()),
  2152. a.ordertime
  2153. ) AS '账期',
  2154. a.delivery_status 'QRD.发货状态',
  2155. ( SELECT sum( send ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'qrd.总发货数量',
  2156. ( SELECT max( addtime ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'qrd.最近一次发货时间',
  2157. ( SELECT sum( th_num ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS 'qrd.总退货数量',
  2158. ( SELECT sum( th_qrd_fee ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS '退货金额',
  2159. ( SELECT max( addtime ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS 'qrd.退货时间',
  2160. ( a.sale_total -( SELECT ifnull( sum( th_qrd_fee ), 0 ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) ) AS '减退货付款额',
  2161. IF
  2162. (((
  2163. a.sale_total -(
  2164. SELECT
  2165. ifnull( sum( th_qrd_fee ), 0 )
  2166. FROM
  2167. cfp_th_source
  2168. WHERE
  2169. th_qrdcpNo = a.productNo
  2170. AND th_status = 1
  2171. ))<>(
  2172. ifnull( b.Number1618249146997, 0 )+ ifnull( b.paying_fee, 0 )+ ifnull( b.number1618249149738, 0 ))),
  2173. '否',
  2174. '是'
  2175. ) AS '是否减退货'
  2176. FROM
  2177. `source_all` AS a
  2178. LEFT JOIN `cfp_qrd_info` `b` ON ((
  2179. `a`.`productNo` = `b`.`sequenceNo`
  2180. ))
  2181. WHERE
  2182. a.productNo <> ''
  2183. AND sale_total <> 0
  2184. {$where}
  2185. HAVING
  2186. 减退货付款额 <> 0 order by a.ordertime desc";
  2187. $list = Db::query($sql);
  2188. if(empty($list)){
  2189. $list=[["未找到数据"=>""]];
  2190. }
  2191. $header = array_keys($list[0]);
  2192. array_walk($list, function (&$v) {
  2193. $v = array_values($v);
  2194. });
  2195. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."应收账款账龄表", $header, $list);
  2196. }
  2197. /**
  2198. * @throws \think\db\exception\BindParamException
  2199. * @throws \think\exception\PDOException
  2200. */
  2201. public function QRDINV(){
  2202. $post = request()->post();
  2203. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  2204. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  2205. $where='';
  2206. if($start!=""){
  2207. $where.=" and a.ordertime >='{$start}'";
  2208. }
  2209. if($end!=""){
  2210. $where.=" and a.ordertime <='{$end}'";
  2211. }
  2212. $sql = "SELECT
  2213. a.qrdNo as 'QRD.4确认单编号',
  2214. a.productNo as 'QRD确认单产品编号',
  2215. a.supperinfo as 'QRD公司名称',
  2216. a.companyName as 'QRD客户名称',
  2217. a.suppitem as 'QRD平台',
  2218. a.khzzxz as 'QRD客户属性',
  2219. a.khcomp as 'QRD客户分公司',
  2220. a.poNo as 'PT.4PO编号',
  2221. a.zxtype as 'QRD线上线下',
  2222. a.sale_name as 'QRD.业务员',
  2223. a.product_name as 'QRD.产品名称',
  2224. a.sale_price as 'QRD.销售单价',
  2225. a.order_num as 'QRD.下单数量',
  2226. a.sale_total as 'QRD.销售总额',
  2227. a.ordertime as 'QRD.下单时间',
  2228. b.Number1618249202608 '已开票',
  2229. b.inving_fee '开票中',
  2230. (
  2231. a.sale_total - ifnull( b.Number1618249202608, 0 )- ifnull( b.inving_fee, 0 )-(
  2232. SELECT
  2233. ifnull( sum( th_qrd_fee ), 0 )
  2234. FROM
  2235. cfp_th_source
  2236. WHERE
  2237. th_qrdcpNo = a.productNo
  2238. AND th_status = 1
  2239. )) '未开票',
  2240. (
  2241. SELECT
  2242. ak.addtime
  2243. FROM
  2244. cfp_order_info AS oi
  2245. LEFT JOIN cfp_order_pool AS po ON oi.orderNo = po.orderNo
  2246. LEFT JOIN cfp_assoc_list AS ak ON ( ak.codeNo = oi.orderNo AND rela_form = 1 )
  2247. WHERE
  2248. po.is_del = 0
  2249. AND oi.STATUS = 1
  2250. AND ak.STATUS = 3
  2251. AND ak.is_del = 0 and oi.goodNo = a.productNo
  2252. ORDER BY
  2253. ak.addtime DESC
  2254. LIMIT 1
  2255. ) AS 'QRD.最近开票时间',
  2256. a.delivery_status 'QRD.发货状态',
  2257. ( SELECT sum( send ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'qrd.总发货数量',
  2258. ( SELECT max( addtime ) FROM fh_source WHERE a.cgdNo = fh_source.cgdNo ) AS 'qrd.最近一次发货时间',
  2259. ( SELECT sum( th_num ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS 'qrd.总退货数量',
  2260. ( SELECT sum( th_qrd_fee ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS '退货金额',
  2261. ( SELECT max( addtime ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) AS 'qrd.退货时间',
  2262. ( a.sale_total -( SELECT ifnull( sum( th_qrd_fee ), 0 ) FROM cfp_th_source WHERE th_qrdcpNo = a.productNo AND th_status = 1 ) ) AS '减退货付款额',
  2263. IF
  2264. (((
  2265. a.sale_total -(
  2266. SELECT
  2267. ifnull( sum( th_qrd_fee ), 0 )
  2268. FROM
  2269. cfp_th_source
  2270. WHERE
  2271. th_qrdcpNo = a.productNo
  2272. AND th_status = 1
  2273. ))<>(
  2274. ifnull( b.Number1618249146997, 0 )+ ifnull( b.paying_fee, 0 )+ ifnull( b.number1618249149738, 0 ))),
  2275. '否',
  2276. '是'
  2277. ) AS '是否减退货'
  2278. FROM
  2279. `source_all` as a
  2280. LEFT JOIN `cfp_qrd_info` `b` ON ((
  2281. `a`.`productNo` = `b`.`sequenceNo`
  2282. ))
  2283. WHERE
  2284. a.productNo <> '' AND sale_total <> 0
  2285. {$where}
  2286. HAVING
  2287. 减退货付款额 <> 0 order by a.ordertime asc";
  2288. $list = Db::query($sql);
  2289. if(empty($list)){
  2290. $list=[["未找到数据"=>""]];
  2291. }
  2292. $header = array_keys($list[0]);
  2293. array_walk($list, function (&$v) {
  2294. $v = array_values($v);
  2295. });
  2296. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."应收账款开票汇总表", $header, $list);
  2297. }
  2298. /**
  2299. * @throws \think\db\exception\BindParamException
  2300. * @throws \think\exception\PDOException
  2301. */
  2302. public function jxreport(){
  2303. $post = request()->post();
  2304. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  2305. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  2306. $where='';
  2307. if($start!=""){
  2308. $where.=" and ordertime >='{$start}'";
  2309. }
  2310. if($end!=""){
  2311. $where.=" and ordertime <='{$end}'";
  2312. }
  2313. $sql = "SELECT
  2314. date_format( `source_all`.`ordertime`, '%Y' ) AS `年`,
  2315. date_format( `source_all`.`ordertime`, '%m' ) AS `月`,
  2316. date_format( `source_all`.`ordertime`, '%d' ) AS `日`,
  2317. `source_all`.`suppitem` AS `1.12平台类型`,
  2318. `source_all`.`sale_name` AS `业务人员`,
  2319. `source_all`.`depart` AS `业务部门`,
  2320. `source_all`.`cat_f` AS `3.4产品一级分类`,
  2321. `source_all`.`sale_total` AS `产品货款总额`
  2322. FROM
  2323. `source_all`
  2324. WHERE
  2325. (
  2326. `source_all`.`suppitem` <> '预付卡' and productNo<>'' {$where}) order by ordertime asc";
  2327. $list = Db::query($sql);
  2328. if(empty($list)){
  2329. $list=[["未找到数据"=>""]];
  2330. }
  2331. $header = array_keys($list[0]);
  2332. array_walk($list, function (&$v) {
  2333. $v = array_values($v);
  2334. });
  2335. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."确认单绩效报表", $header, $list);
  2336. }
  2337. public function jxthreport(){
  2338. $post = request()->post();
  2339. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  2340. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  2341. $where='';
  2342. if($start!=""){
  2343. $where.=" and a.createtime >='{$start}'";
  2344. }
  2345. if($end!=""){
  2346. $where.=" and a.createtime <='{$end}'";
  2347. }
  2348. $sql = "SELECT
  2349. `a`.`th_user` AS `业务人员`,
  2350. `b`.`suppitem` AS `1.12平台类型`,
  2351. `b`.`depart` AS `业务部门`,
  2352. `b`.`cat_f` AS `3.4产品一级分类`,
  2353. a.th_qrdNo as '确认单编号',
  2354. b.sale_total AS `货款总额`,
  2355. `a`.`th_qrd_fee` AS `退货金额`
  2356. FROM
  2357. (
  2358. `cfp_th_source` `a`
  2359. LEFT JOIN `source_all` `b` ON ((
  2360. `a`.`th_qrdcpNo` = `b`.`productNo`
  2361. )))
  2362. WHERE
  2363. `b`.`suppitem` <> '预付卡' {$where}
  2364. ORDER BY
  2365. `a`.`th_user`";
  2366. $list = Db::query($sql);
  2367. if(empty($list)){
  2368. $list=[["未找到数据"=>""]];
  2369. }
  2370. $header = array_keys($list[0]);
  2371. array_walk($list, function (&$v) {
  2372. $v = array_values($v);
  2373. });
  2374. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."退款统计绩效报表", $header, $list);
  2375. }
  2376. /**出入库明细 */
  2377. public function OutInReport(){
  2378. $post = request()->post();
  2379. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  2380. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  2381. $where='';
  2382. if($start!=""){
  2383. $where.=" and a.ordertime >='{$start}'";
  2384. }
  2385. if($end!=""){
  2386. $where.=" and a.ordertime <='{$end}'";
  2387. }
  2388. $sql = "SELECT
  2389. `a`.`supperinfo` AS `公司名称`,
  2390. `a`.`cgdtype` AS `CGD采购单类型`,
  2391. `a`.`qrdNo` AS `QRD.4确认单编号`,
  2392. `a`.`cgdNo` AS `CGD采购单单号`,
  2393. `a`.`financial` AS `QRD.财务核算码`,
  2394. `a`.`product_name` AS `QRD.产品名称`,
  2395. `a`.`order_num` AS `QRD.下单数量`,
  2396. `a`.`qrd_delivery` AS `qrd发货方式`,
  2397. `a`.`qrd_stock` AS `qrd.是否库存产品`,
  2398. `a`.`cgd_tax` AS `CGD采购单税点`,
  2399. `a`.`pakage_fee` AS `CGD包装费`,
  2400. `a`.`cert_fee` AS `CGD证书费`,
  2401. `a`.`mark_fee` AS `CGD加标费`,
  2402. `a`.`open_fee` AS `CGD开模费`,
  2403. `a`.`cost_fee` AS `CGD成本工艺费`,
  2404. `a`.`naked_fee` AS `CGD裸价`,
  2405. `a`.`delivery_fee` AS `CGD物流费`,
  2406. `a`.`cgd_price` AS `CGD采购单单价`,
  2407. `a`.`cgd_total` AS `CGD采购单金额`,
  2408. `c`.`send` AS `CGD本次发货`,
  2409. `c`.`send_date` AS `CGD本次发货时间`,(
  2410. SELECT
  2411. `im`.`buyer_name`
  2412. FROM
  2413. ((((
  2414. `cfp_pay_info` `pc`
  2415. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  2416. `ps`.`payNo` = `pc`.`payNo`
  2417. )))
  2418. LEFT JOIN `cfp_pay` `p` ON ((
  2419. `p`.`payNo` = `pc`.`payNo`
  2420. )))
  2421. LEFT JOIN `cfp_invoice_img` `m` ON (((
  2422. `m`.`payid` = `ps`.`id`
  2423. )
  2424. AND ( `m`.`is_del` = 0 ))))
  2425. LEFT JOIN `cfp_invoice_info` `im` ON ((
  2426. `im`.`invid` = `m`.`id`
  2427. )))
  2428. WHERE
  2429. ((
  2430. `pc`.`status` = 1
  2431. )
  2432. AND ( `ps`.`is_del` = 0 )
  2433. AND ((
  2434. `p`.`status` = 2
  2435. )
  2436. OR ( `p`.`status` = 1 ))
  2437. AND ( `ps`.`status` = 7 )
  2438. AND ( `m`.`is_del` = 0 )
  2439. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
  2440. LIMIT 1
  2441. ) AS `CGD.HP.MX.回票抬头`
  2442. FROM
  2443. ((
  2444. `source_all` `a`
  2445. LEFT JOIN `cfp_qrd_info` `b` ON ((
  2446. `a`.`productNo` = `b`.`sequenceNo`
  2447. )))
  2448. LEFT JOIN `fh_source` `c` ON ((
  2449. `c`.`cgdNo` = `a`.`cgdNo`
  2450. )))
  2451. WHERE
  2452. ((
  2453. `a`.`productNo` <> ''
  2454. )
  2455. {$where})
  2456. ";
  2457. $list = Db::query($sql);
  2458. if(empty($list)){
  2459. $list=[["未找到数据"=>""]];
  2460. }
  2461. $header = array_keys($list[0]);
  2462. array_walk($list, function (&$v) {
  2463. $v = array_values($v);
  2464. });
  2465. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."出入库数据报表", $header, $list);
  2466. }
  2467. /** 收入明细 */
  2468. public function InfoReport(){
  2469. $post = request()->post();
  2470. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  2471. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  2472. $where='';
  2473. if($start!=""){
  2474. $where.=" and a.ordertime >='{$start}'";
  2475. }
  2476. if($end!=""){
  2477. $where.=" and a.ordertime <='{$end}'";
  2478. }
  2479. $sql = "SELECT
  2480. `a`.`qrdNo` AS `QRD.4确认单编号`,
  2481. `a`.`companyName` AS `KH.2.客户名称`,
  2482. `a`.`company` AS `公司名称`,
  2483. `a`.`supplier` AS `供应商名称`,
  2484. `a`.`cgdNo` AS `CGD采购单单号`,
  2485. ifnull( `a`.`financial`, `a`.`fund_code` ) AS `QRD.财务核算码`,
  2486. `a`.`cat_f` AS `QRD.一级分类`,
  2487. `a`.`product_name` AS `QRD.产品名称`,
  2488. `a`.`order_num` AS `QRD.下单数量`,
  2489. `a`.`sale_price` AS `QRD销售单价`,
  2490. `a`.`sale_total` AS `QRD销售总额`,
  2491. `ak`.`viceNo` AS `发票号`,
  2492. IF
  2493. (( `ak`.`status` = 3 ), `oi`.`ainv_fee`, `oi`.`inv_fee` ) AS `本次开票金额`,(
  2494. SELECT
  2495. `l`.`addtime`
  2496. FROM
  2497. `invoice`.`cfp_invoice_list` `l`
  2498. WHERE
  2499. ( `l`.`invNo` = `ak`.`viceNo` )
  2500. LIMIT 1
  2501. ) AS `本次开票时间`,
  2502. `a`.`qrd_delivery` AS `qrd发货方式`,
  2503. `a`.`qrd_stock` AS `qrd.是否库存产品`,
  2504. `a`.`cgd_saler` AS `CGD.采购单业务员`,
  2505. `a`.`pakage_fee` AS `CGD包装费`,
  2506. `a`.`cert_fee` AS `CGD证书费`,
  2507. `a`.`mark_fee` AS `CGD加标费`,
  2508. `a`.`open_fee` AS `CGD开模费`,
  2509. `a`.`cost_fee` AS `CGD成本工艺费`,
  2510. `a`.`naked_fee` AS `CGD裸价`,
  2511. `a`.`delivery_fee` AS `CGD物流费`,
  2512. `a`.`cgd_tax` AS `CGD采购单税点`,
  2513. `a`.`cgd_price` AS `CGD采购单单价`,
  2514. `a`.`cgd_total` AS `CGD采购单金额`,
  2515. `a`.`cgd_tax` AS `CGD采购税点`,(
  2516. SELECT
  2517. `im`.`buyer_name`
  2518. FROM
  2519. ((((
  2520. `invoice`.`cfp_pay_info` `pc`
  2521. LEFT JOIN `invoice`.`cfp_pay_stages` `ps` ON ((
  2522. `ps`.`payNo` = `pc`.`payNo`
  2523. )))
  2524. LEFT JOIN `invoice`.`cfp_pay` `p` ON ((
  2525. `p`.`payNo` = `pc`.`payNo`
  2526. )))
  2527. LEFT JOIN `invoice`.`cfp_invoice_img` `m` ON (((
  2528. `m`.`payid` = `ps`.`id`
  2529. )
  2530. AND ( `m`.`is_del` = 0 ))))
  2531. LEFT JOIN `invoice`.`cfp_invoice_info` `im` ON ((
  2532. `im`.`invid` = `m`.`id`
  2533. )))
  2534. WHERE
  2535. ((
  2536. `pc`.`status` = 1
  2537. )
  2538. AND ( `ps`.`is_del` = 0 )
  2539. AND ((
  2540. `p`.`status` = 2
  2541. )
  2542. OR ( `p`.`status` = 1 ))
  2543. AND ( `ps`.`status` = 7 )
  2544. AND ( `m`.`is_del` = 0 )
  2545. AND ( `pc`.`sequenceNo` = `a`.`cgdjlNo` ))
  2546. LIMIT 1
  2547. ) AS `CGD.HP.MX.回票抬头`,
  2548. IF
  2549. ((
  2550. `p`.`status` = 1
  2551. ),
  2552. '待审核',
  2553. IF
  2554. ((
  2555. `p`.`status` = 2
  2556. ),
  2557. '审核未通过',
  2558. IF
  2559. ((
  2560. `p`.`status` = 3
  2561. ),
  2562. '待开票',
  2563. IF
  2564. ((
  2565. `p`.`status` = 4
  2566. ),
  2567. '待填写物流',
  2568. IF
  2569. (( `p`.`status` = 5 ), '开票完成', '未申请' ))))) AS `开票状态`
  2570. FROM
  2571. (((((
  2572. `invoice`.`source_all` `a`
  2573. LEFT JOIN `invoice`.`cfp_qrd_info` `b` ON ((
  2574. `a`.`productNo` = `b`.`sequenceNo`
  2575. )))
  2576. LEFT JOIN `invoice`.`cfp_order_info` `oi` ON (((
  2577. `oi`.`goodNo` = `b`.`sequenceNo`
  2578. )
  2579. AND ( `oi`.`status` = 1 ))))
  2580. LEFT JOIN `invoice`.`cfp_order_pool` `po` ON (((
  2581. `oi`.`orderNo` = `po`.`orderNo`
  2582. )
  2583. AND ( `po`.`is_del` = 0 ))))
  2584. LEFT JOIN (
  2585. SELECT
  2586. `k`.`id` AS `aid`,
  2587. `k`.`assocNo` AS `assocNo`,
  2588. `k`.`companyNo` AS `companyNo`,
  2589. `k`.`type` AS `type`,
  2590. `k`.`rela_form` AS `rela_form`,
  2591. `k`.`codeNo` AS `codeNo`,
  2592. `k`.`total_fee` AS `total_fee`,
  2593. `k`.`balance` AS `balance`,
  2594. `k`.`cancel_total` AS `cancel_total`,
  2595. `k`.`is_del` AS `is_del`,
  2596. `k`.`status` AS `status`,
  2597. `k`.`exam_remark` AS `exam_remark`,
  2598. `k`.`addtime` AS `addtime`,
  2599. `t`.`viceNo` AS `viceNo`,
  2600. `t`.`vice_fee` AS `vice_fee`,
  2601. `t`.`cancel_fee` AS `cancel_fee`,
  2602. `t`.`id` AS `id`,
  2603. `k`.`source` AS `source`,
  2604. `t`.`vice_total` AS `vice_total`,
  2605. `k`.`apply_name` AS `apply_name`,
  2606. `k`.`apply_id` AS `apply_id`,
  2607. `t`.`status` AS `bstatus`
  2608. FROM
  2609. (
  2610. `invoice`.`cfp_assoc_key` `k`
  2611. JOIN `invoice`.`cfp_assoc_rela` `t` ON ((
  2612. `k`.`assocNo` = `t`.`assocNo`
  2613. )))
  2614. WHERE
  2615. ((
  2616. `k`.`is_del` = 0
  2617. )
  2618. AND ( `t`.`is_del` = 0 )
  2619. AND ( `t`.`status` = 1 )
  2620. AND ( `k`.`rela_form` = 1 ))) `ak` ON ((
  2621. `ak`.`codeNo` = `oi`.`orderNo`
  2622. )))
  2623. LEFT JOIN `invoice`.`cfp_invoice_pool` `p` ON ((
  2624. `ak`.`viceNo` = `p`.`invNo`
  2625. )))
  2626. WHERE
  2627. ((
  2628. `a`.`productNo` <> ''
  2629. )
  2630. AND ((
  2631. `po`.`type` = 1
  2632. )
  2633. OR isnull( `po`.`type` )) )
  2634. {$where}
  2635. ";
  2636. $list = Db::query($sql);
  2637. if(empty($list)){
  2638. $list=[["未找到数据"=>""]];
  2639. }
  2640. $header = array_keys($list[0]);
  2641. array_walk($list, function (&$v) {
  2642. $v = array_values($v);
  2643. });
  2644. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."收入明细数据报表", $header, $list);
  2645. }
  2646. /** 回票公明细 */
  2647. public function InvComReport(){
  2648. $post = request()->post();
  2649. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  2650. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  2651. $where='';
  2652. if($start!=""){
  2653. $where.=" and a.cgdtime >='{$start}'";
  2654. }
  2655. if($end!=""){
  2656. $where.=" and a.cgdtime <='{$end}'";
  2657. }
  2658. $sql = "SELECT
  2659. `b`.`ShortText1618270466672` AS `公司名称`,
  2660. `b`.`ShortText1618315935182` AS `采购单编号`,
  2661. round( `b`.`Number1618240685904`, 2 ) AS `货款`,
  2662. `b`.`ShortText1620399144946` AS `供应商名称`,
  2663. `b`.`StaffSelector1620899427104` AS `采购员`,
  2664. `a`.`cgd_delivery_status` AS `发货状态`,
  2665. '' AS `退货状态`,(
  2666. round( ifnull( `b`.`Number1618330470625`, 0 ), 2 ) + (
  2667. SELECT
  2668. ifnull( sum( `pc`.`total_fee` ), 0 )
  2669. FROM
  2670. ((
  2671. `cfp_pay_info` `pc`
  2672. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  2673. `ps`.`payNo` = `pc`.`payNo`
  2674. )))
  2675. LEFT JOIN `cfp_pay` `p` ON ((
  2676. `p`.`payNo` = `pc`.`payNo`
  2677. )))
  2678. WHERE
  2679. ((
  2680. `pc`.`status` = 1
  2681. )
  2682. AND ( `ps`.`is_del` = 0 )
  2683. AND ((
  2684. `p`.`status` = 2
  2685. )
  2686. OR ( `p`.`status` = 1 ))
  2687. AND ( `ps`.`pay_status` = 4 )
  2688. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))) AS `已付款金额`,(
  2689. CASE
  2690. WHEN ((
  2691. round( ifnull( `b`.`Number1618330541286`, 0 ), 2 ) + (
  2692. SELECT
  2693. ifnull( sum(( `pc`.`winv_fee` + `pc`.`ainv_fee` )), 0 )
  2694. FROM
  2695. ((
  2696. `cfp_pay_info` `pc`
  2697. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  2698. `ps`.`payNo` = `pc`.`payNo`
  2699. )))
  2700. LEFT JOIN `cfp_pay` `p` ON ((
  2701. `p`.`payNo` = `pc`.`payNo`
  2702. )))
  2703. WHERE
  2704. ((
  2705. `pc`.`status` = 1
  2706. )
  2707. AND ( `ps`.`is_del` = 0 )
  2708. AND ((
  2709. `p`.`status` = 2
  2710. )
  2711. OR ( `p`.`status` = 1 ))
  2712. AND ( `ps`.`status` = 7 )
  2713. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))) = 0
  2714. ) THEN
  2715. '未回票'
  2716. WHEN ((
  2717. round( ifnull( `b`.`Number1618330543270`, 0 ), 2 ) - (
  2718. SELECT
  2719. ifnull( sum(( `pc`.`winv_fee` + `pc`.`ainv_fee` )), 0 )
  2720. FROM
  2721. ((
  2722. `cfp_pay_info` `pc`
  2723. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  2724. `ps`.`payNo` = `pc`.`payNo`
  2725. )))
  2726. LEFT JOIN `cfp_pay` `p` ON ((
  2727. `p`.`payNo` = `pc`.`payNo`
  2728. )))
  2729. WHERE
  2730. ((
  2731. `pc`.`status` = 1
  2732. )
  2733. AND ( `ps`.`is_del` = 0 )
  2734. AND ((
  2735. `p`.`status` = 2
  2736. )
  2737. OR ( `p`.`status` = 1 ))
  2738. AND ( `ps`.`status` = 7 )
  2739. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
  2740. LIMIT 1
  2741. )) = 0
  2742. ) THEN
  2743. '全部回票' ELSE '部分回票'
  2744. END
  2745. ) AS `回票状态`,
  2746. round((
  2747. round( ifnull( `b`.`Number1618330541286`, 0 ), 2 ) + (
  2748. SELECT
  2749. ifnull( sum(( `pc`.`winv_fee` + `pc`.`ainv_fee` )), 0 )
  2750. FROM
  2751. ((
  2752. `cfp_pay_info` `pc`
  2753. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  2754. `ps`.`payNo` = `pc`.`payNo`
  2755. )))
  2756. LEFT JOIN `cfp_pay` `p` ON ((
  2757. `p`.`payNo` = `pc`.`payNo`
  2758. )))
  2759. WHERE
  2760. ((
  2761. `pc`.`status` = 1
  2762. )
  2763. AND ( `ps`.`is_del` = 0 )
  2764. AND ((
  2765. `p`.`status` = 2
  2766. )
  2767. OR ( `p`.`status` = 1 ))
  2768. AND ( `ps`.`status` = 7 )
  2769. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))),
  2770. 2
  2771. ) AS `已回票金额`,
  2772. round((
  2773. ifnull( `b`.`Number1618330543270`, 0 ) - (
  2774. SELECT
  2775. ifnull( sum(( `pc`.`winv_fee` + `pc`.`ainv_fee` )), 0 )
  2776. FROM
  2777. ((
  2778. `cfp_pay_info` `pc`
  2779. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  2780. `ps`.`payNo` = `pc`.`payNo`
  2781. )))
  2782. LEFT JOIN `cfp_pay` `p` ON ((
  2783. `p`.`payNo` = `pc`.`payNo`
  2784. )))
  2785. WHERE
  2786. ((
  2787. `pc`.`status` = 1
  2788. )
  2789. AND ( `ps`.`is_del` = 0 )
  2790. AND ((
  2791. `p`.`status` = 2
  2792. )
  2793. OR ( `p`.`status` = 1 ))
  2794. AND ( `ps`.`status` = 7 )
  2795. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))),
  2796. 2
  2797. ) AS `未回票金额`,(
  2798. SELECT
  2799. `im`.`buyer_name`
  2800. FROM
  2801. ((((
  2802. `cfp_pay_info` `pc`
  2803. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  2804. `ps`.`payNo` = `pc`.`payNo`
  2805. )))
  2806. LEFT JOIN `cfp_pay` `p` ON ((
  2807. `p`.`payNo` = `pc`.`payNo`
  2808. )))
  2809. LEFT JOIN `cfp_invoice_img` `m` ON (((
  2810. `m`.`payid` = `ps`.`id`
  2811. )
  2812. AND ( `m`.`is_del` = 0 ))))
  2813. LEFT JOIN `cfp_invoice_info` `im` ON ((
  2814. `im`.`invid` = `m`.`id`
  2815. )))
  2816. WHERE
  2817. ((
  2818. `pc`.`status` = 1
  2819. )
  2820. AND ( `ps`.`is_del` = 0 )
  2821. AND ((
  2822. `p`.`status` = 2
  2823. )
  2824. OR ( `p`.`status` = 1 ))
  2825. AND ( `ps`.`status` = 7 )
  2826. AND ( `m`.`is_del` = 0 )
  2827. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
  2828. LIMIT 1
  2829. ) AS `回票公司`,
  2830. `b`.`Date1618315953443` AS `下单时间`,
  2831. `b`.`ShortText1617861966146` AS `产品名称`,
  2832. `b`.`ShortText1617865685744` AS `单位`,
  2833. cast( `b`.`Number1618240600907` AS signed ) AS `数量`,
  2834. round( `b`.`Number1618240685904`, 2 ) AS `成本合计`,
  2835. `b`.`ShortText1617865688485` AS `税点`,(
  2836. SELECT
  2837. `ps`.`invtime`
  2838. FROM
  2839. ((
  2840. `cfp_pay_info` `pc`
  2841. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  2842. `ps`.`payNo` = `pc`.`payNo`
  2843. )))
  2844. LEFT JOIN `cfp_pay` `p` ON ((
  2845. `p`.`payNo` = `pc`.`payNo`
  2846. )))
  2847. WHERE
  2848. ((
  2849. `pc`.`status` = 1
  2850. )
  2851. AND ( `ps`.`is_del` = 0 )
  2852. AND ((
  2853. `p`.`status` = 2
  2854. )
  2855. OR ( `p`.`status` = 1 ))
  2856. AND ( `ps`.`status` = 7 )
  2857. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
  2858. ORDER BY
  2859. `ps`.`invtime` DESC
  2860. LIMIT 1
  2861. ) AS `财务审批时间`,
  2862. round( 0, 2 ) AS `CGD.不含税采购成本-这个怎么计算`,
  2863. `a`.`qrdNo` AS `确认单编号`,
  2864. `a`.`financial` AS `财务核算码`,
  2865. `a`.`sale_price` AS `确认单销售单价`
  2866. FROM
  2867. (
  2868. `source_all` `a`
  2869. LEFT JOIN `cfp_cgd_info` `b` ON ((
  2870. `a`.`cgdNo` = `b`.`ShortText1618315935182`
  2871. )))
  2872. WHERE
  2873. ((
  2874. `a`.`cgdNo` <> ''
  2875. )
  2876. {$where})
  2877. ";
  2878. $list = Db::query($sql);
  2879. if(empty($list)){
  2880. $list=[["未找到数据"=>""]];
  2881. }
  2882. $header = array_keys($list[0]);
  2883. array_walk($list, function (&$v) {
  2884. $v = array_values($v);
  2885. });
  2886. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."回票公司数据报表", $header, $list);
  2887. }
  2888. /** 回票公明细 */
  2889. public function InvReport(){
  2890. $post = request()->post();
  2891. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  2892. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  2893. $where='';
  2894. if($start!=""){
  2895. $where.=" and a.cgdtime >='{$start}'";
  2896. }
  2897. if($end!=""){
  2898. $where.=" and a.cgdtime <='{$end}'";
  2899. }
  2900. $sql = "SELECT
  2901. `b`.`ShortText1618315935182` AS `CGD.2采购单号`,
  2902. `b`.`ShortText1618270466672` AS `CGD.14公司主体`,
  2903. `b`.`Date1618315953443` AS `CGD.3采购单下单日期`,
  2904. `b`.`ShortText1618270412964` AS `CGD.1采购单类型`,
  2905. `b`.`StaffSelector1620899427104` AS `CGD.采购员`,
  2906. `b`.`ShortText1620399144946` AS `CGD.45供应商名称`,
  2907. `b`.`ShortText1617861287265` AS `CGD.44供应商编号`,
  2908. `b`.`ShortText1619625566608` AS `CGD.出库包装库存`,
  2909. `b`.`ShortText1617865688485` AS `CGD.40税点`,
  2910. `a`.`financial` AS `CGD财务核算码`,
  2911. round( `b`.`Number1617865810822`, 2 ) AS `CGD.包装费`,
  2912. round( `b`.`Number1617865813284`, 2 ) AS `CGD.证书费`,
  2913. round( `b`.`Number1617865807879`, 2 ) AS `CGD.加标费`,
  2914. round( `b`.`Number1617865816181`, 2 ) AS `CGD.开模费`,
  2915. round( `b`.`number1618240204358`, 2 ) AS `CGD.成本工艺费`,
  2916. round( `b`.`Number1617865804813`, 2 ) AS `CGD.成本裸价`,
  2917. round( `b`.`number1618240287778`, 2 ) AS `CGD.物流费`,
  2918. round( `b`.`Number1619632830397`, 2 ) AS `CGD.工差`,
  2919. round( `b`.`Number1619632826654`, 2 ) AS `CGD.采购工差金额`,
  2920. round( `b`.`Number1617865818517`, 2 ) AS `CGD.采购单价`,
  2921. cast( `b`.`Number1618240600907` AS signed ) AS `CGD.采购数量`,
  2922. round( `b`.`Number1618240685904`, 2 ) AS `CGD.采购金额`,
  2923. round( 0, 2 ) AS `CGD.不含税采购成本-这个怎么计算`,
  2924. `b`.`ShortText1618859161646` AS `BK.10备库单号`,
  2925. `b`.`Date1618859180209` AS `BK.11备库下单日期`,
  2926. `b`.`StaffSelector1618885082387` AS `BK.15业务员`,
  2927. `b`.`ShortText1618900704399` AS `BK.13备库仓库`,
  2928. `b`.`ShortText1617861966146` AS `CGD.CP.26产品名称`,
  2929. `b`.`ShortText1617861001482` AS `CGD.CP.27产品编号`,
  2930. `b`.`ShortText1617865626160` AS `CGD.CP.28一级分类`,
  2931. `b`.`ShortText1617865685744` AS `CGD.CP.25单位`,
  2932. `b`.`ShortText1618240134229` AS `CGD.CP.36贵金属种类`,
  2933. round((
  2934. round( ifnull( `b`.`Number1618330541286`, 0 ), 2 ) + (
  2935. SELECT
  2936. ifnull( sum( pc.winv_fee ), 0 )
  2937. FROM
  2938. ((
  2939. `cfp_pay_info` `pc`
  2940. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  2941. `ps`.`payNo` = `pc`.`payNo`
  2942. )))
  2943. LEFT JOIN `cfp_pay` `p` ON ((
  2944. `p`.`payNo` = `pc`.`payNo`
  2945. )))
  2946. WHERE
  2947. ((
  2948. `pc`.`status` = 1
  2949. )
  2950. AND ( `ps`.`is_del` = 0 )
  2951. AND ((
  2952. `p`.`status` = 2
  2953. )
  2954. OR ( `p`.`status` = 1 ))
  2955. AND ( `ps`.`status` = 7 )
  2956. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))),
  2957. 2
  2958. ) AS `CGD.HP.总-已回票金额`,
  2959. round((
  2960. ifnull( `b`.`Number1618330543270`, 0 ) - (
  2961. SELECT
  2962. ifnull( sum( pc.winv_fee ), 0 )
  2963. FROM
  2964. ((
  2965. `cfp_pay_info` `pc`
  2966. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  2967. `ps`.`payNo` = `pc`.`payNo`
  2968. )))
  2969. LEFT JOIN `cfp_pay` `p` ON ((
  2970. `p`.`payNo` = `pc`.`payNo`
  2971. )))
  2972. WHERE
  2973. ((
  2974. `pc`.`status` = 1
  2975. )
  2976. AND ( `ps`.`is_del` = 0 )
  2977. AND ((
  2978. `p`.`status` = 2
  2979. )
  2980. OR ( `p`.`status` = 1 ))
  2981. AND ( `ps`.`status` = 7 )
  2982. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))),
  2983. 2
  2984. ) AS `CGD.HP.总-未回票金额`,(
  2985. CASE
  2986. WHEN ((
  2987. round( ifnull( `b`.`Number1618330541286`, 0 ), 2 ) + (
  2988. SELECT
  2989. ifnull( sum( pc.winv_fee ), 0 )
  2990. FROM
  2991. ((
  2992. `cfp_pay_info` `pc`
  2993. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  2994. `ps`.`payNo` = `pc`.`payNo`
  2995. )))
  2996. LEFT JOIN `cfp_pay` `p` ON ((
  2997. `p`.`payNo` = `pc`.`payNo`
  2998. )))
  2999. WHERE
  3000. ((
  3001. `pc`.`status` = 1
  3002. )
  3003. AND ( `ps`.`is_del` = 0 )
  3004. AND ((
  3005. `p`.`status` = 2
  3006. )
  3007. OR ( `p`.`status` = 1 ))
  3008. AND ( `ps`.`status` = 7 )
  3009. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` )))) = 0
  3010. ) THEN
  3011. '未回票'
  3012. WHEN ((
  3013. round( ifnull( `b`.`Number1618330543270`, 0 ), 2 ) - (
  3014. SELECT
  3015. ifnull( sum( pc.winv_fee ), 0 )
  3016. FROM
  3017. ((
  3018. `cfp_pay_info` `pc`
  3019. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  3020. `ps`.`payNo` = `pc`.`payNo`
  3021. )))
  3022. LEFT JOIN `cfp_pay` `p` ON ((
  3023. `p`.`payNo` = `pc`.`payNo`
  3024. )))
  3025. WHERE
  3026. ((
  3027. `pc`.`status` = 1
  3028. )
  3029. AND ( `ps`.`is_del` = 0 )
  3030. AND ((
  3031. `p`.`status` = 2
  3032. )
  3033. OR ( `p`.`status` = 1 ))
  3034. AND ( `ps`.`status` = 7 )
  3035. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
  3036. LIMIT 1
  3037. )) = 0
  3038. ) THEN
  3039. '全部回票' ELSE '部分回票'
  3040. END
  3041. ) AS `CGD.HP.总-回票情况`,(
  3042. SELECT
  3043. `ps`.`invtime`
  3044. FROM
  3045. ((
  3046. `cfp_pay_info` `pc`
  3047. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  3048. `ps`.`payNo` = `pc`.`payNo`
  3049. )))
  3050. LEFT JOIN `cfp_pay` `p` ON ((
  3051. `p`.`payNo` = `pc`.`payNo`
  3052. )))
  3053. WHERE
  3054. ((
  3055. `pc`.`status` = 1
  3056. )
  3057. AND ( `ps`.`is_del` = 0 )
  3058. AND ((
  3059. `p`.`status` = 2
  3060. )
  3061. OR ( `p`.`status` = 1 ))
  3062. AND ( `ps`.`status` = 7 )
  3063. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
  3064. ORDER BY
  3065. `ps`.`invtime` DESC
  3066. LIMIT 1
  3067. ) AS `CGD.HP.MX.总最近一次回票时间`,(
  3068. SELECT
  3069. sum( `pc`.`winv_fee`)
  3070. FROM
  3071. ((((
  3072. `cfp_pay_info` `pc`
  3073. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  3074. `ps`.`payNo` = `pc`.`payNo`
  3075. )))
  3076. LEFT JOIN `cfp_pay` `p` ON ((
  3077. `p`.`payNo` = `pc`.`payNo`
  3078. )))
  3079. LEFT JOIN `cfp_invoice_img` `m` ON (((
  3080. `m`.`payid` = `ps`.`id`
  3081. )
  3082. AND ( `m`.`is_del` = 0 ))))
  3083. LEFT JOIN `cfp_invoice_info` `im` ON ((
  3084. `im`.`invid` = `m`.`id`
  3085. )))
  3086. WHERE
  3087. ((
  3088. `pc`.`status` = 1
  3089. )
  3090. AND ( `ps`.`is_del` = 0 )
  3091. AND ((
  3092. `p`.`status` = 2
  3093. )
  3094. OR ( `p`.`status` = 1 ))
  3095. AND ( `ps`.`status` = 7 )
  3096. AND ( `m`.`is_del` = 0 )
  3097. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
  3098. ) AS `CGD.HP.MX.回票金额`,(
  3099. SELECT
  3100. `im`.`buyer_name`
  3101. FROM
  3102. ((((
  3103. `cfp_pay_info` `pc`
  3104. LEFT JOIN `cfp_pay_stages` `ps` ON ((
  3105. `ps`.`payNo` = `pc`.`payNo`
  3106. )))
  3107. LEFT JOIN `cfp_pay` `p` ON ((
  3108. `p`.`payNo` = `pc`.`payNo`
  3109. )))
  3110. LEFT JOIN `cfp_invoice_img` `m` ON (((
  3111. `m`.`payid` = `ps`.`id`
  3112. )
  3113. AND ( `m`.`is_del` = 0 ))))
  3114. LEFT JOIN `cfp_invoice_info` `im` ON ((
  3115. `im`.`invid` = `m`.`id`
  3116. )))
  3117. WHERE
  3118. ((
  3119. `pc`.`status` = 1
  3120. )
  3121. AND ( `ps`.`is_del` = 0 )
  3122. AND ((
  3123. `p`.`status` = 2
  3124. )
  3125. OR ( `p`.`status` = 1 ))
  3126. AND ( `ps`.`status` = 7 )
  3127. AND ( `m`.`is_del` = 0 )
  3128. AND ( `pc`.`sequenceNo` = `b`.`sequenceNo` ))
  3129. LIMIT 1
  3130. ) AS `CGD.HP.MX.回票抬头`
  3131. FROM
  3132. (
  3133. `source_all` `a`
  3134. LEFT JOIN `cfp_cgd_info` `b` ON ((
  3135. `a`.`cgdNo` = `b`.`ShortText1618315935182`
  3136. )))
  3137. WHERE
  3138. ((
  3139. `a`.`cgdNo` <> ''
  3140. )
  3141. {$where})
  3142. ";
  3143. // echo $sql; die();
  3144. $list = Db::query($sql);
  3145. if(empty($list)){
  3146. $list=[["未找到数据"=>""]];
  3147. }
  3148. $header = array_keys($list[0]);
  3149. array_walk($list, function (&$v) {
  3150. $v = array_values($v);
  3151. });
  3152. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."回票数据报表", $header, $list);
  3153. }
  3154. /** 发货报表 */
  3155. public function FhReport(){
  3156. $post = request()->post();
  3157. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  3158. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  3159. $where='';
  3160. if($start!=""){
  3161. $where.=" and F.addtime >='{$start}'";
  3162. }
  3163. if($end!=""){
  3164. $where.=" and F.addtime <='{$end}'";
  3165. }
  3166. $sql = "SELECT
  3167. F.fhNo AS '发货单号',
  3168. F.cgdNO AS 'CGD采购单单号',
  3169. F.qrdNo AS '确认单号',
  3170. S.suppitem AS '平台类型',
  3171. S.depart AS '业务部门',
  3172. S.zxtype AS '咨询类型',
  3173. F.addtime AS '发货时间',
  3174. S.cat_f AS '一级品类',
  3175. F.good_name AS '产品名称',
  3176. F.post_company AS '物流公司',
  3177. F.post_code AS '物流单号',
  3178. F.send AS '本次发货数量',
  3179. F.send * S.sale_price AS '本次发货金额',
  3180. F.bala AS '剩余发货数量',
  3181. F.bala * S.sale_price AS '剩余发货金额',
  3182. S.sale_price AS '销售单价',
  3183. S.order_num AS '销售数量',
  3184. S.sale_total AS '销售金额',
  3185. S.zxcode AS '咨询单号',
  3186. S.supplier AS '供应商名称',
  3187. S.cgd_saler AS '采购员'
  3188. FROM fh_source AS F, source_all AS S
  3189. WHERE F.cgdNO = S.cgdNO
  3190. AND S.cgd_saler NOT IN ('张凯旋','骆喜龙')
  3191. {$where}
  3192. ";
  3193. $list = Db::query($sql);
  3194. if(empty($list)){
  3195. $list=[["未找到数据"=>""]];
  3196. }
  3197. $header = array_keys($list[0]);
  3198. array_walk($list, function (&$v) {
  3199. $v = array_values($v);
  3200. });
  3201. excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."发货数据报表", $header, $list);
  3202. }
  3203. }