| | |
| | | |
| | | </select> |
| | | |
| | | <!-- 代储金额:该客户全部「类型=代储」台账合同金额合计。跨客户汇总,加 /*data_scope*/ 跳过数据权限, |
| | | 否则非管理员看到的是被 dept_id 过滤过的部分金额,会把「已超信托基金」误判成未超 --> |
| | | <select id="selectDepositAmountByCustomerIds" resultType="com.ruoyi.sales.dto.CustomerDepositAmountDto"> |
| | | select /*data_scope*/ customer_id as customerId, |
| | | IFNULL(sum(contract_amount), 0) as depositTotalAmount |
| | | from sales_ledger |
| | | where ledger_type = '代储' |
| | | <if test="customerIds != null and customerIds.size() > 0"> |
| | | and customer_id in |
| | | <foreach collection="customerIds" item="cid" open="(" separator="," close=")"> |
| | | #{cid} |
| | | </foreach> |
| | | </if> |
| | | group by customer_id |
| | | </select> |
| | | |
| | | <select id="selectSalesLedgerList" resultType="com.ruoyi.sales.pojo.SalesLedger"> |
| | | SELECT |
| | | T1.id, |
| | |
| | | T1.salesman, |
| | | T1.customer_id, |
| | | T1.customer_name, |
| | | T1.ledger_type, |
| | | T1.oil_depot_id, |
| | | T1.oil_depot_name, |
| | | T1.tank_id, |
| | | T1.tank_no, |
| | | T1.approval_status, |
| | | T1.entry_person, |
| | | T1.remarks, |
| | | T1.attachment_materials, |
| | |
| | | <if test="salesLedgerDto.customerName != null and salesLedgerDto.customerName != '' "> |
| | | T1.customer_name LIKE CONCAT('%',#{salesLedgerDto.customerName},'%') |
| | | </if> |
| | | <if test="salesLedgerDto.ledgerType != null and salesLedgerDto.ledgerType != '' "> |
| | | AND T1.ledger_type = #{salesLedgerDto.ledgerType} |
| | | </if> |
| | | <if test="salesLedgerDto.approvalStatus != null and salesLedgerDto.approvalStatus != '' "> |
| | | AND T1.approval_status = #{salesLedgerDto.approvalStatus} |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="selectSalesLedgerListPage" resultType="com.ruoyi.sales.pojo.SalesLedger"> |
| | | <select id="selectSalesLedgerListPage" resultType="com.ruoyi.sales.vo.SalesLedgerVo"> |
| | | SELECT T1.id, |
| | | T1.sales_contract_no, |
| | | T1.customer_contract_no, |
| | |
| | | T1.salesman, |
| | | T1.customer_id, |
| | | T1.customer_name, |
| | | T1.ledger_type, |
| | | T1.oil_depot_id, |
| | | T1.oil_depot_name, |
| | | T1.tank_id, |
| | | T1.tank_no, |
| | | T1.approval_status, |
| | | T1.entry_person, |
| | | T1.remarks, |
| | | T1.attachment_materials, |
| | | T1.tenant_id, |
| | | T1.contract_amount, |
| | | T1.contract_amount as noInvoiceAmountTotal, |
| | | T1.net_contract_amount, |
| | | T1.contract_amount AS noInvoiceAmountTotal, |
| | | T1.execution_date, |
| | | T2.nick_name AS entry_person_name, |
| | | T1.payment_method, |
| | | T1.delivery_date, |
| | | DATEDIFF(T1.delivery_date, CURDATE()) AS delivery_days_diff, |
| | | CASE |
| | | WHEN shipping_status_counts.total_count = 0 THEN false |
| | | WHEN shipping_status_counts.unshipped_count = 0 THEN true |
| | | ELSE false |
| | | END AS is_fh, |
| | | CASE |
| | | WHEN EXISTS ( |
| | | SELECT 1 |
| | | FROM product_order po2 |
| | | INNER JOIN product_work_order wo2 ON wo2.product_order_id = po2.id |
| | | INNER JOIN production_product_main pm2 ON pm2.work_order_id = wo2.id |
| | | WHERE po2.sales_ledger_id = T1.id |
| | | LIMIT 1 |
| | | ) THEN true |
| | | ELSE false |
| | | END AS has_production_record |
| | | IFNULL(shipping_status_counts.is_all_shipped, FALSE) AS is_fh |
| | | FROM sales_ledger T1 |
| | | LEFT JOIN sys_user T2 ON T1.entry_person = T2.user_id |
| | | LEFT JOIN ( |
| | | SELECT sales_ledger_id, |
| | | COUNT(*) as total_count, |
| | | SUM(CASE WHEN status != '已发货' THEN 1 ELSE 0 END) as unshipped_count |
| | | CASE |
| | | WHEN SUM(CASE WHEN status != '已发货' THEN 1 ELSE 0 END) = 0 THEN TRUE |
| | | ELSE FALSE |
| | | END AS is_all_shipped |
| | | FROM shipping_info |
| | | GROUP BY sales_ledger_id |
| | | ) shipping_status_counts ON T1.id = shipping_status_counts.sales_ledger_id |
| | |
| | | </if> |
| | | <if test="salesLedgerDto.entryDateEnd != null and salesLedgerDto.entryDateEnd != '' "> |
| | | AND T1.entry_date <= DATE_FORMAT(#{salesLedgerDto.entryDateEnd},'%Y-%m-%d') |
| | | </if> |
| | | <if test="salesLedgerDto.ledgerType != null and salesLedgerDto.ledgerType != '' "> |
| | | AND T1.ledger_type = #{salesLedgerDto.ledgerType} |
| | | </if> |
| | | <if test="salesLedgerDto.approvalStatus != null and salesLedgerDto.approvalStatus != '' "> |
| | | AND T1.approval_status = #{salesLedgerDto.approvalStatus} |
| | | </if> |
| | | </where> |
| | | order by T1.entry_date desc |
| | |
| | | </if> |
| | | order by sl.execution_date desc |
| | | </select> |
| | | <select id="selectPurchaseReportVoPage" resultType="com.ruoyi.purchase.vo.PurchaseReportVo"> |
| | | select sl.sales_contract_no customerContractNo, |
| | | c.customer_name, |
| | | sl.project_name, |
| | | sl.contract_amount contractAmount, |
| | | pl.contract_amount purchaseAmount, |
| | | sl.contract_amount-pl.contract_amount balance, |
| | | (sl.contract_amount-pl.contract_amount)/sl.contract_amount balanceRatio |
| | | from sales_ledger sl |
| | | left join purchase_ledger pl on sl.id = pl.sales_ledger_id |
| | | left join customer c on sl.customer_id = c.id |
| | | <where> |
| | | <if test="customerName != null and customerName != '' "> |
| | | and c.customer_name like concat('%',#{customerName},'%') |
| | | </if> |
| | | </where> |
| | | order by sl.entry_date desc |
| | | </select> |
| | | |
| | | </mapper> |
| | | </mapper> |