| | |
| | | <mapper namespace="com.ruoyi.sales.mapper.SalesLedgerMapper"> |
| | | |
| | | <select id="selectSequencesByDate" resultType="java.lang.Integer"> |
| | | SELECT CAST(SUBSTR(sales_contract_no,LENGTH(#{datePart})+1 , 3) AS SIGNED) |
| | | SELECT CAST(SUBSTR(sales_contract_no, LENGTH(#{datePart}) + 1, 3) AS SIGNED) |
| | | FROM sales_ledger |
| | | WHERE sales_contract_no LIKE CONCAT('%',#{datePart},'%') |
| | | WHERE sales_contract_no LIKE CONCAT('%', #{datePart}, '%') |
| | | </select> |
| | | <select id="getSalesNo" resultType="com.ruoyi.sales.pojo.SalesLedger"> |
| | | |
| | | |
| | | </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.sales_contract_no, |
| | | T1.customer_contract_no, |
| | | T1.project_name, |
| | | T1.entry_date, |
| | | T1.salesman, |
| | | T1.customer_id, |
| | | T1.customer_name, |
| | | T1.entry_person, |
| | | T1.remarks, |
| | | T1.attachment_materials, |
| | | T1.tenant_id, |
| | | T1.contract_amount, |
| | | T1.execution_date, |
| | | T2.nick_name AS entry_person_name, |
| | | T1.payment_method |
| | | FROM |
| | | sales_ledger T1 |
| | | LEFT JOIN sys_user T2 ON T1.entry_person = T2.user_id |
| | | <where> |
| | | <if test="salesLedgerDto.customerName != null and salesLedgerDto.customerName != '' "> |
| | | T1.customer_name LIKE CONCAT('%',#{salesLedgerDto.customerName},'%') |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="selectSalesLedgerListPage" resultType="com.ruoyi.sales.pojo.SalesLedger"> |
| | | SELECT |
| | | T1.id, |
| | | T1.sales_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.execution_date, |
| | | T2.nick_name AS entry_person_name, |
| | | T1.payment_method, |
| | | t3.shipping_car_number |
| | | DATEDIFF(T1.delivery_date, CURDATE()) AS delivery_days_diff |
| | | FROM |
| | | sales_ledger T1 |
| | | LEFT JOIN sys_user T2 ON T1.entry_person = T2.user_id |
| | | left join shipping_info t3 on T1.id = t3.sales_ledger_id |
| | | <where> |
| | | <if test="salesLedgerDto.customerName != null and salesLedgerDto.customerName != '' "> |
| | | AND T1.customer_name LIKE CONCAT('%',#{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.vo.SalesLedgerVo"> |
| | | SELECT T1.id, |
| | | T1.sales_contract_no, |
| | | T1.customer_contract_no, |
| | | T1.project_name, |
| | | T1.entry_date, |
| | | 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.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, |
| | | 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, |
| | | 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 |
| | | |
| | | <where> |
| | | <if test="salesLedgerDto.customerName != null and salesLedgerDto.customerName != '' "> |
| | | AND T1.customer_name LIKE CONCAT('%',#{salesLedgerDto.customerName},'%') |
| | | </if> |
| | | <if test="salesLedgerDto.customerContractNo != null and salesLedgerDto.customerContractNo !='' "> |
| | | AND T1.customer_contract_no LIKE CONCAT('%',#{salesLedgerDto.customerContractNo},'%') |
| | | AND T1.customer_contract_no LIKE CONCAT('%',#{salesLedgerDto.customerContractNo},'%') |
| | | </if> |
| | | <if test="salesLedgerDto.salesContractNo != null and salesLedgerDto.salesContractNo != '' "> |
| | | AND T1.sales_contract_no LIKE CONCAT('%',#{salesLedgerDto.salesContractNo},'%') |
| | | AND T1.sales_contract_no LIKE CONCAT('%',#{salesLedgerDto.salesContractNo},'%') |
| | | </if> |
| | | <if test="salesLedgerDto.projectName != null and salesLedgerDto.projectName != '' "> |
| | | AND T1.project_name LIKE CONCAT('%',#{salesLedgerDto.projectName},'%') |
| | | </if> |
| | | <if test="salesLedgerDto.entryDateStart != null and salesLedgerDto.entryDateStart != '' "> |
| | | AND T1.entry_date >= DATE_FORMAT(#{salesLedgerDto.entryDateStart},'%Y-%m-%d') |
| | | AND T1.entry_date >= DATE_FORMAT(#{salesLedgerDto.entryDateStart},'%Y-%m-%d') |
| | | </if> |
| | | <if test="salesLedgerDto.entryDateEnd != null and salesLedgerDto.entryDateEnd != '' "> |
| | | AND T1.entry_date <= DATE_FORMAT(#{salesLedgerDto.entryDateEnd},'%Y-%m-%d') |
| | | 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 |
| | | order by T1.entry_date desc |
| | | </select> |
| | | </mapper> |
| | | |
| | | <select id="selectIncomeStats" resultType="com.ruoyi.home.dto.IncomeExpenseAnalysisDto"> |
| | | SELECT DATE_FORMAT(entry_date, #{dateFormat}) as dateStr, IFNULL(SUM(contract_amount), 0) as amount |
| | | FROM sales_ledger |
| | | WHERE entry_date BETWEEN #{startDate} AND #{endDate} |
| | | GROUP BY dateStr |
| | | </select> |
| | | |
| | | <select id="selectCustomerSalesComposition" resultType="com.ruoyi.dto.MapDto"> |
| | | SELECT customer_name as name, CAST(IFNULL(SUM(contract_amount), 0) AS CHAR) as value |
| | | FROM sales_ledger |
| | | GROUP BY customer_name |
| | | </select> |
| | | <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> |
| | | 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> |