| | |
| | | |
| | | </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.tonnage, |
| | | 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> |
| | | |
| | |
| | | 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.tonnage, |
| | | T1.approval_status, |
| | | T1.entry_person, |
| | | T1.remarks, |
| | | T1.attachment_materials, |
| | | T1.tenant_id, |
| | | T1.contract_amount, |
| | | T1.net_contract_amount, |
| | | T1.contract_amount AS noInvoiceAmountTotal, |
| | | T1.execution_date, |
| | | T2.nick_name AS entry_person_name, |
| | |
| | | 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 |
| | | <!-- 是否发货改按到货记录算,分两种台账: |
| | | 卖油:该台账 type=1 明细的合同数量总和 <= 已到货数量总和 才算发完; |
| | | 代储:没有 type=1 明细,基准线改为「该台账全部已审批油品出库单的出库量总和」,同样「全部到货」才算发完。 |
| | | 两个分支各自都要求基准线 > 0,否则 0 <= 0 会被判成「已发货」 --> |
| | | LEFT JOIN ( |
| | | SELECT sales_ledger_id, |
| | | SELECT sl.id AS sales_ledger_id, |
| | | CASE |
| | | WHEN SUM(CASE WHEN status != '已发货' THEN 1 ELSE 0 END) = 0 THEN TRUE |
| | | WHEN IFNULL(d.total_qty, 0) > 0 AND IFNULL(d.total_qty, 0) <= IFNULL(a.total_arrival, 0) THEN TRUE |
| | | WHEN IFNULL(d.total_qty, 0) = 0 AND IFNULL(o.total_out, 0) > 0 |
| | | AND IFNULL(o.total_out, 0) <= IFNULL(a.total_arrival, 0) THEN TRUE |
| | | ELSE FALSE |
| | | END AS is_all_shipped |
| | | FROM shipping_info |
| | | FROM sales_ledger sl |
| | | LEFT JOIN ( |
| | | SELECT sales_ledger_id, SUM(quantity) AS total_qty |
| | | FROM sales_ledger_product |
| | | WHERE type = 1 |
| | | GROUP BY sales_ledger_id |
| | | ) d ON d.sales_ledger_id = sl.id |
| | | LEFT JOIN ( |
| | | SELECT sales_ledger_id, SUM(arrival_quantity) AS total_arrival |
| | | FROM sales_ledger_arrival |
| | | GROUP BY sales_ledger_id |
| | | ) a ON a.sales_ledger_id = sl.id |
| | | <!-- 代储没有绑定表,出库单的单值列 sales_ledger_id 即为权威对应关系 --> |
| | | LEFT JOIN ( |
| | | SELECT sor.sales_ledger_id, SUM(sor.stock_out_num) AS total_out |
| | | FROM stock_out_record sor |
| | | WHERE sor.approval_status = 1 |
| | | AND (sor.type IS NULL OR sor.type = '') |
| | | AND sor.sales_ledger_id IS NOT NULL |
| | | GROUP BY sor.sales_ledger_id |
| | | ) o ON o.sales_ledger_id = sl.id |
| | | ) shipping_status_counts ON T1.id = shipping_status_counts.sales_ledger_id |
| | | |
| | | <where> |
| | |
| | | <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 |
| | | </select> |
| | |
| | | FROM sales_ledger |
| | | GROUP BY customer_name |
| | | </select> |
| | | <!-- 已发货的台账:口径与 is_fh 一致,改为「有到货记录的台账」 --> |
| | | <select id="listSalesLedgerAndShipped" resultType="com.ruoyi.sales.dto.SalesLedgerDto"> |
| | | select distinct sl.id as 'disId', sl.* from |
| | | sales_ledger sl |
| | | left join sales_ledger_product slp on sl.id = slp.sales_ledger_id |
| | | left join shipping_info si on slp.id = si.sales_ledger_product_id |
| | | where si.status = '已发货' |
| | | <if test="ew.customerName != null and ew.customerName != '' "> |
| | | and sl.customer_name like concat('%',#{ew.customerName},'%') |
| | | </if> |
| | | inner join sales_ledger_product slp on sl.id = slp.sales_ledger_id |
| | | inner join sales_ledger_arrival sla on sla.sales_ledger_product_id = slp.id |
| | | <where> |
| | | <if test="ew.customerName != null and ew.customerName != '' "> |
| | | sl.customer_name like concat('%',#{ew.customerName},'%') |
| | | </if> |
| | | </where> |
| | | order by sl.execution_date desc |
| | | </select> |
| | | <select id="selectPurchaseReportVoPage" resultType="com.ruoyi.purchase.vo.PurchaseReportVo"> |
| | |
| | | and c.customer_name like concat('%',#{customerName},'%') |
| | | </if> |
| | | </where> |
| | | order by sl.create_time desc |
| | | order by sl.entry_date desc |
| | | </select> |
| | | |
| | | </mapper> |