123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.yh.saas.plugin.yiliangyiyun.mapper.WarehouseBaseInfoMapper">
- <!-- 质检信息数量包括已删除的 -->
- <select id="getCountByCondition" parameterType="Map" resultType="java.lang.Integer">
- SELECT
- COUNT(q.id)
- FROM quality_inspection_management q
- WHERE
- q.comp_id = #{compId}
- AND q.service_management_type = #{serviceManagementType}
- AND q.warehouse_name = #{warehouseName}
- AND TO_DAYS(q.create_date) = TO_DAYS(NOW())
- </select>
- <!-- 常用仓库数量包括已删除的 -->
- <select id="getWareHouseCountByCondition" parameterType="Map" resultType="java.lang.Integer">
- SELECT
- COUNT(w.id)
- FROM warehouse_base_info w
- WHERE
- w.comp_id = #{compId}
- and w.warehouse_type="1"
- </select>
- <!-- 临时仓库数量包括已删除的 -->
- <select id="getTemWareHouseCountByCondition" parameterType="Map" resultType="java.lang.Integer">
- SELECT
- COUNT(w.id)
- FROM warehouse_base_info w
- WHERE
- w.comp_id = #{compId}
- and w.warehouse_type="2"
- </select>
- <!-- 获得入库导出列表 -->
- <select id="getListByCondition" parameterType="Map"
- resultType="com.yh.saas.plugin.yiliangyiyun.entity.view.ExportVView">
- SELECT
- distinct
- IFNULL(m.buyer,c.comp_name) as compName,
- a.warehouse_name as warehouseName,
- q.bin_number as binNumber,
- a.settlement_date as createDate,
- a.contract_no as contractNo,
- iowt.in_out_task_no as warehousingTaskNo,
- a.payment_no as paymentNo,
- a.customer_name as customerName,
- '收购入库' as inOutType,
- '' as deliveryGrossWeight,
- '' as deliveryTare,
- '' as deliveryVolume,
- '' as sendWarehouse,
- '' as tranPrice,
- a.freight as freight,
- i.supplier as supplier,
- a.goods_name as goodsName,
- case when a.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
- q.grade as grade,
- q.water_content as waterContent,
- q.impurity as impurity,
- q.mildew_grain as mildewGrain,
- q.imperfect_grain as imperfectGrain,
- q.bulk_density as bulkDensity,
- q.jiaorenli as jiaorenli,
- a.car_no as carNo,
- q.box_no as boxNo,
- q.box_no_other as boxNoOther,
- q.title_no as titleNo,
- q.title_no_other as titleNoOther,
- ROUND(case when a.type ='干粮' then q.dry_grain_price*1000 else q.tidal_grain_price*1000 end ,2) as
- netWeightPrice,
- ROUND(a.gross_weight/1000,2) as grossWeight,
- ROUND(a.tare/1000,2) as tare,
- ROUND(a.weight_deduction/1000,2) as buckleWeight,
- ROUND(a.net_weight/1000,5) as netWeight,
- a.unit_deduction as unitDeduction,
- a.unload_deduction as unloadingDeduction,
- a.solid_grain_price as pureWeightPrice,
- case when a.goods_name like '%潮粮%' then a.pure_weight else a.net_weight end as pureWeight,
- a.amount_ing_payable as amountIngPayable,
- a.amount_ed_payable as amountEdPayable,
- i.payee_name as payeeName,
- i.bank_card as cardNo,
- i.bank_deposit as bankDeposit,
- i.bank_deposit_branch as bankDepositBranch
- FROM payment_management a
- left join contract_management_info m on m.comp_id = a.comp_id and m.contract_no = a.contract_no and m.delete_flag = 0
- left join quality_inspection_management q on q.relation_id = a.relation_id and q.comp_id = a.comp_id and q.delete_flag = 0
- left join weighing_management w on w.relation_id = a.relation_id and w.comp_id = a.comp_id and w.delete_flag = 0
- left join common_company c on c.comp_id = a.comp_id and c.delete_flag = 0
- left join identity_authentication_info i on i.customer_name = a.customer_name
- and i.customer_phone = a.customer_phone and i.customer_type_flag = 1 and i.delete_flag = 0 and i.cover = 0
- left join common_company_identity cci on cci.com_id = a.comp_id and cci.delete_flag = 0 and cci.identity_id = i.id
- left join in_out_warehouse_task iowt on iowt.comp_id = a.comp_id and iowt.delete_flag = 0 and iowt.contract_no = a.contract_no
- and iowt.approve_status is null and iowt.in_out_type = '收购入库'
- WHERE a.delete_flag = '0'
- AND a.comp_id = #{compId}
- AND a.management_type = '1'
- AND a.contract_no is not null
- AND q.warehouse_in_out_id is not null
- <if test="warehouseName != null and warehouseName != ''">
- AND a.warehouse_name= #{warehouseName}
- </if>
- <if test="startDate != null">
- AND (DATE_FORMAT(a.settlement_date,"%Y%m%d%H%i%s") >=
- DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
- </if>
- <if test="endDate != null">
- AND (DATE_FORMAT(a.settlement_date,"%Y%m%d%H%i%s") <=
- DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
- </if>
- UNION ALL
- SELECT
- m.buyer as compName,
- s.warehouse_name as warehouseName,
- w.bin_number as binNumber,
- w.update_date as createDate,
- s.contract_no as contractNo,
- iowt.in_out_task_no as warehousingTaskNo,
- '' as paymentNo,
- m.seller as customerName,
- '采购入库' as inOutType,
- '' as deliveryGrossWeight,
- '' as deliveryTare,
- '' as deliveryVolume,
- '' as sendWarehouse,
- '' as tranPrice,
- case when m.deliver_type = '1' then ifNull(r.amount_ed_payable,0) else 0 end as freight,
- '' as supplier,
- w.goods_name as goodsName,
- case when w.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
- w.grade as grade,
- IFNULL(q.water_content,wd.water_content) as waterContent,
- IFNULL(q.impurity,wd.impurity) as impurity,
- IFNULL(q.mildew_grain,wd.mildew_grain) as mildewGrain,
- IFNULL(q.imperfect_grain,wd.imperfect_grain) as imperfectGrain,
- IFNULL(q.bulk_density,wd.bulk_density) as bulkDensity,
- IFNULL(q.jiaorenli,wd.jiaorenli) as jiaorenli,
- s.car_no as carNo,
- w.box_no as boxNo,
- w.box_no_other as boxNoOther,
- w.title_no as titleNo,
- w.title_no_other as titleNoOther,
- s.settlement_price as netWeightPrice,
- ROUND(s.gross_weight,2) as grossWeight,
- ROUND(s.tare,2) as tare,
- s.deduction_weight as buckleWeight,
- s.net_weight as netWeight,
- s.deduction_amount as unitDeduction,
- '' as pureWeightPrice,
- 0 as unloadingDeduction,
- case when w.goods_name like '%潮粮%' then w.pure_weight*1000 else w.net_weight*1000 end as pureWeight,
- s.amount_ing_payable as amountIngPayable,
- s.amount_ed_payable as amountEdPayable,
- i.payee_name as payeeName,
- i.bank_card as cardNo,
- i.bank_deposit as bankDeposit,
- i.bank_deposit_branch as bankDepositBranch
- FROM stock_purchase_receipt_report s
- left join warehouse_in_out_info w on w.id = s.warehouse_record_id and w.delete_flag = 0
- left join in_out_warehouse_task iowt on iowt.in_out_task_no = w.in_out_task_no and iowt.delete_flag = 0
- left join quality_inspection_management q on q.warehouse_in_out_id = w.id and q.delete_flag = 0
- left join warehouse_in_out_detail wd on wd.info_id = w.id
- left join tran_car_info t on t.contract_no = w.contract_no and t.delete_flag = 0 and t.tran_car_no = w.tran_car_no and t.car_no = w.car_no
- left join tran_settlement_report r on r.car_id = t.id and r.delete_flag = 0
- left join common_company c on c.comp_id = s.comp_id and c.delete_flag = 0
- left join contract_management_info m on m.comp_id = s.comp_id and m.contract_no = s.contract_no and m.delete_flag = 0
- left join contract_goods_info g on m.id=g.contract_id and g.delete_flag = 0
- left join customer_info i on ((i.comp_name = m.seller and customer_type='企业客户') or (i.customer_name = m.seller
- and customer_type='个人客户'))
- and i.customer_phone = m.seller_phone and i.delete_flag = 0
- WHERE s.delete_flag = '0'
- AND s.comp_id = #{compId}
- <if test="warehouseName != null and warehouseName != ''">
- AND s.warehouse_name= #{warehouseName}
- </if>
- <if test="startDate != null">
- AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") >=
- DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
- </if>
- <if test="endDate != null">
- AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") <=
- DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
- </if>
- UNION ALL
- SELECT
- c.comp_name as compName,
- w.warehouse_name as warehouseName,
- w.bin_number as binNumber,
- w.update_date as createDate,
- w.contract_no as contractNo,
- iowt.in_out_task_no as warehousingTaskNo,
- '' as paymentNo,
- IFNULL(cmi.seller,'') as customerName,
- '移库入库' as inOutType,
- wi.gross_weight as deliveryGrossWeight,
- wi.tare as deliveryTare,
- t.load_net_weight as deliveryVolume,
- i.send_warehouse as sendWarehouse,
- t.tran_price as tranPrice,
- ROUND(IFNULL(r.amount_ing_payable,IFNULL(t.tran_price,0)*t.load_net_weight),2) as freight,
- '' as supplier,
- w.goods_name as goodsName,
- case when w.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
- w.grade as grade,
- q.water_content as waterContent,
- q.impurity as impurity,
- q.mildew_grain as mildewGrain,
- q.imperfect_grain as imperfectGrain,
- q.bulk_density as bulkDensity,
- q.jiaorenli as jiaorenli,
- w.car_no as carNo,
- w.box_no as boxNo,
- w.box_no_other as boxNoOther,
- w.title_no as titleNo,
- w.title_no_other as titleNoOther,
- w.cost as netWeightPrice,
- ROUND(w.gross_weight,2) as grossWeight,
- ROUND(w.tare,2) as tare,
- w.deduction_weight as buckleWeight,
- w.net_weight as netWeight,
- IFNULL(q.deduction_amount,0) as unitDeduction,
- 0 as unloadingDeduction,
- '' as pureWeightPrice,
- case when w.goods_name like '%潮粮%' then w.pure_weight*1000 else w.net_weight*1000 end as pureWeight,
- -- ROUND(IFNULL(r.amount_ing_payable,(w.cost+IFNULL(t.tran_price,0))*t.load_net_weight),2) as amountIngPayable,
- case when cmi.settlement_weight_method = '1' then
- ROUND((w.cost-IFNULL(q.deduction_amount,0))*t.load_net_weight,2)
- else ROUND((w.cost-IFNULL(q.deduction_amount,0))*w.net_weight,2) end as amountIngPayable,
- 0 as amountEdPayable,
- '' as payeeName,
- '' as cardNo,
- '' as bankDeposit,
- '' as bankDepositBranch
- FROM warehouse_in_out_info w
- left join warehouse_in_out_detail d on w.id=d.info_id and d.delete_flag = 0
- left join quality_inspection_management q on w.id=q.warehouse_in_out_id and q.delete_flag = 0
- left join stock_purchase_receipt_report s on s.warehouse_record_id=w.id and s.delete_flag = 0
- left join warehouse_base_info b on b.id=w.base_id and b.delete_flag = 0
- left join common_company c on c.comp_id = b.comp_id and c.delete_flag = 0
- left join in_out_warehouse_task i on w.contract_no = i.move_task_no and i.delete_flag = 0 and i.in_out_type = '移库出库'
- <if test="warehouseName != null and warehouseName != ''">
- AND i.receive_warehouse = #{warehouseName}
- </if>
- left join tran_car_info t on t.contract_no = w.contract_no and t.delete_flag = 0 and t.tran_car_no = w.tran_car_no and t.car_no = w.car_no
- left join warehouse_in_out_info wi on t.contract_no = wi.contract_no and wi.delete_flag = 0 and t.tran_car_no = wi.tran_car_no and t.car_no = wi.car_no and wi.in_out_flag = 1
- left join tran_settlement_report r on r.car_id = t.id and r.delete_flag = 0
- left join contract_management_info cmi on cmi.contract_no = wi.warehouse_name and cmi.delete_flag = 0
- left join in_out_warehouse_task iowt on iowt.in_out_task_no = w.in_out_task_no and iowt.delete_flag = 0
- WHERE w.delete_flag = '0'
- AND b.comp_id = #{compId}
- and w.in_out_flag = 2
- and w.in_out_type='移库入库'
- and w.status_flag=3
- and s.id is null
- <if test="warehouseName != null and warehouseName != ''">
- AND w.warehouse_name= #{warehouseName}
- </if>
- <if test="startDate != null">
- AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") >=
- DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
- </if>
- <if test="endDate != null">
- AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") <=
- DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
- </if>
- group by w.id
- UNION ALL
- SELECT
- c.comp_name as compName,
- w.warehouse_name as warehouseName,
- w.bin_number as binNumber,
- w.update_date as createDate,
- w.contract_no as contractNo,
- iowt.in_out_task_no as warehousingTaskNo,
- '' as paymentNo,
- '' as customerName,
- '退库' as inOutType,
- '' as deliveryGrossWeight,
- '' as deliveryTare,
- '' as deliveryVolume,
- '' as sendWarehouse,
- 0 as tranPrice,
- 0 as freight,
- '' as supplier,
- w.goods_name as goodsName,
- case when w.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
- w.grade as grade,
- d.water_content as waterContent,
- d.impurity as impurity,
- d.mildew_grain as mildewGrain,
- d.imperfect_grain as imperfectGrain,
- d.bulk_density as bulkDensity,
- d.jiaorenli as jiaorenli,
- w.car_no as carNo,
- w.box_no as boxNo,
- w.box_no_other as boxNoOther,
- w.title_no as titleNo,
- w.title_no_other as titleNoOther,
- w.cost as netWeightPrice,
- ROUND(w.gross_weight,2) as grossWeight,
- ROUND(w.tare,2) as tare,
- w.deduction_weight as buckleWeight,
- w.net_weight as netWeight,
- '' as unitDeduction,
- 0 as unloadingDeduction,
- '' as pureWeightPrice,
- case when w.goods_name like '%潮粮%' then w.pure_weight*1000 else w.net_weight*1000 end as pureWeight,
- 0 as amountIngPayable,
- 0 as amountEdPayable,
- '' as payeeName,
- '' as cardNo,
- '' as bankDeposit,
- '' as bankDepositBranch
- FROM warehouse_in_out_info w
- left join warehouse_in_out_detail d on w.id=d.info_id and d.delete_flag = 0
- left join warehouse_base_info b on b.id=w.base_id and b.delete_flag = 0
- left join common_company c on c.comp_id = b.comp_id and c.delete_flag = 0
- left join in_out_warehouse_task iowt on iowt.in_out_task_no = w.in_out_task_no and iowt.delete_flag = 0
- WHERE w.delete_flag = '0'
- AND b.comp_id = #{compId}
- and w.in_out_flag = 2
- and w.in_out_type='退库'
- and w.status_flag=3
- <if test="warehouseName != null and warehouseName != ''">
- AND w.warehouse_name= #{warehouseName}
- </if>
- <if test="startDate != null">
- AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") >=
- DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
- </if>
- <if test="endDate != null">
- AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") <=
- DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
- </if>
- group by w.id
- </select>
- <!-- 获得出库导出列表 -->
- <select id="getListByConditionOut" parameterType="Map"
- resultType="com.yh.saas.plugin.yiliangyiyun.entity.view.ExportVView">
- SELECT * from (SELECT
- '' as compName,
- w.warehouse_name as warehouseName,
- w.bin_number as binNumber,
- w.update_date as createDate,
- ROUND(sum(sri.avg_cost * sri.proportion * w.net_weight)/w.net_weight,2) as costPrice,
- -- w.warehouse_name as contractNo,
- case when m.contract_type = '1' then m.contract_no else '' end as contractNo,
- IFNULL(m.seller,'') as customerName,
- '' as remark,
- w.in_out_task_no as inOutTaskNo,
- w.goods_name as goodsName,
- case when w.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
- w.grade as grade,
- d.water_content as waterContent,
- d.impurity as impurity,
- d.mildew_grain as mildewGrain,
- d.imperfect_grain as imperfectGrain,
- d.bulk_density as bulkDensity,
- d.jiaorenli as jiaorenli,
- w.car_no as carNo,
- w.box_no as boxNo,
- w.box_no_other as boxNoOther,
- w.title_no as titleNo,
- w.title_no_other as titleNoOther,
- w.wing_number as wingNumber,
- w.ship_number as shipNumber,
- w.ship_name as shipName,
- m.unit_contract_price as unitContractPrice,
- m.weight as weight,
- ROUND(w.gross_weight,2) as grossWeight,
- ROUND(w.tare,2) as tare,
- '' as contractStatus,
- IFNULL(t.unload_net_weight,0) as feedbackWeight,
- w.in_out_date as feedbackDate,
- w.net_weight as settlementWeight,
- 0 as settlementPrice,
- IFNULL(t.tran_price,0) as carFreight,
- '' as trainFreight,
- '' as shipFreight,
- IFNULL(t.tran_price,0) as freight,
- '' as amountIngReceivable,
- '' as amountEdReceivable,
- '' as amountNotReceivable,
- '' as collectionDate,
- '' as money,
- '' as status,
- w.net_weight as netWeight,
- tti.receive_warehouse as receiveWarehouse
- FROM warehouse_in_out_info w
- left join warehouse_in_out_detail d on w.id=d.info_id and d.delete_flag = 0
- left join tran_car_info t on t.contract_no = w.contract_no and t.delete_flag = 0 and t.tran_car_no = w.tran_car_no and t.car_no = w.car_no
- left join tran_task_info tti on tti.id = t.info_id and tti.delete_flag = 0
- left join warehouse_base_info b on b.id=w.base_id and b.delete_flag = 0
- left join contract_management_info m on m.comp_id = b.comp_id and m.contract_no = w.warehouse_name and m.delete_flag = 0
- left join in_out_warehouse_task iowt on iowt.in_out_task_no = w.in_out_task_no and iowt.delete_flag = 0
- left join source_relation_info sri on iowt.id = sri.task_id and sri.delete_flag = 0
- WHERE w.delete_flag = '0'
- AND b.comp_id = #{compId}
- and w.in_out_flag = 1
- and w.in_out_type='移库出库'
- and w.status_flag=3
- <if test="warehouseName != null and warehouseName != ''">
- AND w.warehouse_name= #{warehouseName}
- </if>
- <if test="startDate != null">
- AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") >=
- DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
- </if>
- <if test="endDate != null">
- AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") <=
- DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
- </if>
- GROUP BY w.id
- UNION ALL
- SELECT
- m.seller as compName,
- w.warehouse_name as warehouseName,
- w.bin_number as binNumber,
- s.delivery_date as createDate,ROUND(sum(sri.avg_cost * sri.proportion * w.net_weight)/w.net_weight ,2)as costPrice,
- case when m.contract_type = '1' then m.contract_no else '' end as contractNo,
- m.buyer as customerName,
- wm.customer as remark,
- w.in_out_task_no as inOutTaskNo,
- g.goods_name as goodsName,
- case when g.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
- g.grade as grade,
- g.water_content as waterContent,
- g.impurity as impurity,
- g.mildew_grain as mildewGrain,
- g.imperfect_grain as imperfectGrain,
- g.bulk_density as bulkDensity,
- g.jiaorenli as jiaorenli,
- s.car_no as carNo,
- s.case_no as boxNo,
- s.case_no_other as boxNoOther,
- s.title_no as titleNo,
- s.title_no_other as titleNoOther,
- s.bin_number as wingNumber,
- '' as shipNumber,
- '' as shipName,
- m.unit_contract_price as unitContractPrice,
- m.weight as weight,
- ROUND(s.gross_weight,2) as grossWeight,
- ROUND(s.tare,2) as tare,
- CASE WHEN ( SELECT sum( ssrr.amount_not_receivable ) FROM stock_sale_receipt_report ssrr WHERE ssrr.contract_no
- = s.contract_no ) > 0 THEN
- '未结算' ELSE '已结算' END AS contractStatus,
- s.feedback_weight as feedbackWeight,
- s.feedback_date as feedbackDate,
- s.settlement_weight as settlementWeight,
- s.settlement_price as settlementPrice,
- case when p.tran_type_key = '1' then p.actual_freight else '' end as carFreight,
- case when p.tran_type_key = '2' then p.actual_freight else '' end as trainFreight,
- case when p.tran_type_key = '3' then p.actual_freight else '' end as shipFreight,
- case when m.deliver_type = '1' then IFNULL(r.amount_ed_payable,0) else 0 end as freight,
- s.amount_ing_receivable as amountIngReceivable,
- s.amount_ed_receivable as amountEdReceivable,
- s.amount_not_receivable as amountNotReceivable,
- s.collection_date as collectionDate,
- '' as money,
- s.status as status,
- s.net_weight as netWeight,
- t.receive_warehouse as receiveWarehouse
- FROM stock_sale_receipt_report s
- left join warehouse_in_out_info w on w.id = s.warehouse_record_id and w.delete_flag = 0
- left join weighing_management wm on wm.warehouse_in_out_id = w.id and wm.delete_flag = 0
- left join tran_process_info p on p.id = s.process_id and p.delete_flag = 0
- left join tran_task_info t on t.id = p.info_id and t.delete_flag = 0
- left join tran_car_info i on i.process_id = p.id and i.delete_flag = 0 and i.tran_car_no = s.tran_car_no and i.car_no = s.car_no
- left join tran_settlement_report r on r.car_id = i.id and r.delete_flag = 0
- left join contract_management_info m on m.contract_no = w.contract_no and m.comp_id=s.comp_id and m.delete_flag = 0
- left join contract_goods_info g on m.id = g.contract_id and g.delete_flag = 0
- left join in_out_warehouse_task iowt on iowt.in_out_task_no = w.in_out_task_no and iowt.delete_flag = 0
- left join source_relation_info sri on iowt.id = sri.task_id and sri.delete_flag = 0
- WHERE s.delete_flag = '0'
- AND s.comp_id = #{compId}
- and w.in_out_type='销售出库'
- <if test="warehouseName != null and warehouseName != ''">
- AND s.warehouse_name= #{warehouseName}
- </if>
- <if test="startDate != null">
- AND (DATE_FORMAT(s.delivery_date,"%Y%m%d%H%i%s") >=
- DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
- </if>
- <if test="endDate != null">
- AND (DATE_FORMAT(s.delivery_date,"%Y%m%d%H%i%s") <=
- DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
- </if>
- GROUP BY w.id
- ORDER BY contractNo) tt where tt.warehouseName is not null
- </select>
- <!-- 获得今日储量明细列表 -->
- <select id="getReservesDetailsListByCondition" parameterType="Map"
- resultType="com.yh.saas.plugin.yiliangyiyun.entity.view.WarehouseNumView">
- SELECT
- wpsi.goods_name as goodsName,
- sum( wpsi.`storage` ) as stockNum,
- (
- SELECT
- sum( tci.load_net_weight )
- FROM
- tran_task_info tti
- LEFT JOIN tran_car_info tci ON tci.info_id = tti.id
- AND tci.delete_flag = 0
- AND tci.comp_id = #{compId}
- WHERE
- tti.task_type = '移库'
- AND tti.goods_name = wpsi.goods_name
- AND tti.delete_flag = 0
- AND tci.status_flag = 3
- <if test="compId != null and compId != ''">
- AND tti.comp_id = #{compId}
- </if>
- )as moveNum/* 移库在途数量,已发出未反馈 */,
- (
- SELECT
- SUM(ROUND((cpi.mildew_grain - tt.total)/cmi.unit_contract_price ,3))
- FROM
- (
- SELECT
- cmi.contract_no,
- cgi.goods_name,
- sum( sprr.amount_not_payable ) AS total
- FROM
- contract_management_info cmi
- LEFT JOIN contract_goods_info cgi ON cgi.contract_id = cmi.id
- AND cgi.delete_flag = 0
- LEFT JOIN stock_purchase_receipt_report sprr ON sprr.contract_no = cmi.contract_no
- AND sprr.delete_flag = 0
- WHERE
- cmi.contract_type = 2
- AND cmi.delete_flag = 0
- AND sprr.amount_not_payable IS NOT NULL
- <if test="compId != null and compId != ''">
- AND cmi.comp_id = #{compId}
- </if>
- GROUP BY
- cmi.contract_no,
- cgi.goods_name
- ) tt
- LEFT JOIN contract_management_info cmi ON cmi.contract_no = tt.contract_no
- AND cmi.delete_flag = 0
- LEFT JOIN contract_process_info cpi ON cpi.contract_id = cmi.id
- AND cpi.delete_flag = 0
- WHERE
- tt.goods_name = wpsi.goods_name
- <if test="compId != null and compId != ''">
- AND cmi.comp_id= #{compId}
- </if>
- AND tt.total < cpi.mildew_grain
- ) as purchaseNum/* 采购在途数量,合同已付减应付除以单价得到吨数 */,
- (
- SELECT
- sum( tci.load_net_weight )
- FROM
- tran_task_info tti
- LEFT JOIN tran_car_info tci ON tci.info_id = tti.id
- AND tci.delete_flag = 0
- WHERE
- tti.task_type = '销售出库'
- AND tti.goods_name = wpsi.goods_name
- AND tti.delete_flag = 0
- AND tci.status_flag = 3
- AND tci.comp_id = #{compId}
- AND tti.comp_id = #{compId}
- ) as saleNum
- FROM
- warehouse_base_info wbi
- LEFT JOIN warehouse_position_info wpi ON wpi.base_id = wbi.id and wpi.delete_flag = 0
- LEFT JOIN warehouse_position_storage_info wpsi ON wpsi.position_id = wpi.id and wpsi.delete_flag = 0
- WHERE
- 1 = 1
- <if test="compId != null and compId != ''">
- AND wbi.comp_id= #{compId}
- </if>
- AND wpsi.id IS NOT NULL
- GROUP BY
- wpsi.goods_name
- order by wpsi.goods_name_key
- </select>
- <!-- 获得储量柱形图 -->
- <select id="getReservesWarehouseListByCondition" parameterType="Map"
- resultType="com.yh.saas.plugin.yiliangyiyun.entity.view.WarehouseNumView">
- SELECT
- wpsi.goods_name AS goodsName,
- sum( wpsi.STORAGE ) AS stockNum,
- (
- SELECT
- ROUND( AVG( wo.avg_cost ), 3 )
- FROM
- warehousing_order wo
- WHERE
- wo.warehouse_name = wbi.warehouse_name
- AND wo.delete_flag = 0
- AND wbi.comp_id = wo.comp_id
- and wo.goods_name = wpsi.goods_name
- ) AS cost
- FROM
- warehouse_base_info wbi
- LEFT JOIN warehouse_position_info wpi ON wpi.base_id = wbi.id
- AND wpi.delete_flag = 0
- LEFT JOIN warehouse_position_storage_info wpsi ON wpsi.position_id = wpi.id
- AND wpsi.delete_flag = 0
- WHERE
- wpsi.id IS NOT NULL
- <if test="compId != null and compId != ''">
- AND wbi.comp_id= #{compId}
- </if>
- <if test="warehouseName != null and warehouseName != ''">
- AND wbi.warehouse_name= #{warehouseName}
- </if>
- GROUP BY
- wpsi.goods_name_key
- </select>
- <select id="getAllWarehouseListByCondition" parameterType="Map"
- resultType="com.yh.saas.plugin.yiliangyiyun.entity.view.WarehouseView">
- SELECT
- wbi.warehouse_name as warehouseName,
- wpi.bin_number as binNumber,
- wpi.id as binNumberId,
- wpi.max_storage as capacity,
- (SELECT
- sum(wioi.net_weight)
- FROM
- warehouse_in_out_info wioi
- WHERE
- wioi.in_out_flag = '2'
- AND wioi.delete_flag=0
- AND wioi.status_flag=3
- and wioi.position_id=wpi.id
- and wioi.goods_name=wpsi.goods_name
- )as inNetWeight,/*入库量*/
- (SELECT
- sum(wioi.net_weight)
- FROM
- warehouse_in_out_info wioi
- WHERE
- wioi.in_out_flag = '1'
- AND wioi.delete_flag=0
- AND wioi.status_flag=3
- and wioi.position_id=wpi.id
- and wioi.goods_name=wpsi.goods_name
- )as outNetWeight,/*出库量*/
- wpsi.storage as storage,
- wpsi.goods_name as goodsName
- FROM
- warehouse_base_info wbi
- LEFT JOIN warehouse_position_info wpi ON wpi.base_id = wbi.id
- LEFT JOIN warehouse_position_storage_info wpsi ON wpsi.position_id = wpi.id
- WHERE
- wbi.comp_id= #{compId}
- AND wbi.warehouse_type='1'
- <if test="warehouseName != null and warehouseName != ''">
- AND wbi.warehouse_name= #{warehouseName}
- </if>
- <if test="goodsName != null and goodsName != ''">
- AND wpsi.goods_name= #{goodsName}
- </if>
- GROUP BY
- wpi.id,wpsi.goods_name_key
- order by wbi.common_warehouse_no,wpi.bin_number
- </select>
- <!-- 出入库质检用 -->
- <select id="getTranCarInfo" parameterType="Map"
- resultType="com.yh.saas.plugin.yiliangyiyun.entity.TranCarInfo">
- SELECT
- wbi.id as contractId,
- wpi.*
- FROM
- contract_management_info wbi
- LEFT JOIN tran_car_info wpi ON wpi.contract_no = wbi.contract_no
- WHERE
- wbi.delete_flag ='0'
- AND
- wpi.delete_flag ='0'
- <if test="compId != null and compId != ''">
- AND wbi.comp_id= #{compId}
- </if>
- <if test="contractType != null and contractType != ''">
- AND wbi.contract_type= #{contractType}
- </if>
- <if test="statusFlag != null and statusFlag != ''">
- AND wbi.status_flag= #{statusFlag}
- </if>
- <if test="deliverType != null and deliverType != ''">
- AND wbi.deliver_type= #{deliverType}
- </if>
- <if test="flag != null and flag = '1'">
- <if test="fleetFlag != null and fleetFlag != ''">
- AND wpi.fleet_flag= #{fleetFlag}
- </if>
- <if test="tranType != null and tranType != ''">
- AND wpi.tran_type= #{tranType}
- </if>
- <if test="threeTranType != null and threeTranType != ''">
- AND wpi.three_tran_type= #{threeTranType}
- </if>
- <if test="submit != null and submit != ''">
- AND wpi.submit= #{submit}
- </if>
- </if>
- <if test="flag != null and flag = '2'">
- and(
- <if test="tranType != null and tranType != ''">
- wpi.tran_type= #{tranType}
- </if>
- <if test="threeTranType != null and threeTranType != ''">
- or wpi.three_tran_type= #{threeTranType}
- </if>
- )
- </if>
- ORDER BY
- wbi.update_date;
- </select>
- <!--获得库点利润详情列表总数-->
- <select id="getBaseCountByCondition" parameterType="Map" resultType="java.lang.Integer">
- select
- count(1)
- from(
- SELECT
- COUNT(w.id)
- FROM
- warehouse_base_info w
- LEFT JOIN warehousing_order war ON war.base_id = w.id AND war.in_type = '收购入库'
- AND war.delete_flag = '0'
- WHERE
- w.comp_id = #{compId}
- AND w.warehouse_type = '1'
- <if test="searchKeyWord != null and searchKeyWord != ''">
- AND (lower(w.warehouse_name) like lower(CONCAT('%',#{searchKeyWord},'%')))
- </if>
- GROUP BY
- w.id)t
- </select>
- <!--库点利润详情列表查询-->
- <select id="getBaseListByCondition" parameterType="Map"
- resultType="com.yh.saas.plugin.yiliangyiyun.entity.WarehouseBaseInfo">
- SELECT
- w.id,
- w.comp_id AS compId,
- CASE
- WHEN w.delete_flag = '1' THEN
- CONCAT( w.warehouse_name, '(已删)' ) ELSE w.warehouse_name
- END AS warehouseName,
- sum( war.in_warehouse_weight ) AS acquisitionWeight,
- (SELECT
- sum(ssrr.settlement_weight)*sri.proportion
- FROM
- warehouse_base_info wbi
- LEFT JOIN warehousing_order ward ON ward.base_id = wbi.id
- AND ward.in_type = '收购入库'
- AND ward.delete_flag = '0'
- LEFT JOIN source_relation_info sri ON sri.source_id = ward.id
- AND sri.delete_flag = '0'
- LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
- AND iowt.in_out_flag = 1
- AND iowt.in_out_type_key = 1
- AND iowt.delete_flag = '0'
- LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
- AND wioi1.delete_flag = 0
- AND wioi1.status_flag = 3
- LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.contract_no = iowt.contract_no
- AND ssrr.warehouse_record_id = wioi1.id
- where wbi.id=w.id) as saleWeight,
- (SELECT
- sum(ssrr.amount_ing_receivable)*sri.proportion
- FROM
- warehouse_base_info wbi
- LEFT JOIN warehousing_order ward ON ward.base_id = wbi.id
- AND ward.in_type = '收购入库'
- AND ward.delete_flag = '0'
- LEFT JOIN source_relation_info sri ON sri.source_id = ward.id
- AND sri.delete_flag = '0'
- LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
- AND iowt.in_out_flag = 1
- AND iowt.in_out_type_key = 1
- AND iowt.delete_flag = '0'
- LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
- AND wioi1.delete_flag = 0
- AND wioi1.status_flag = 3
- LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.contract_no = iowt.contract_no
- AND ssrr.warehouse_record_id = wioi1.id
- where wbi.id=w.id) as salesVolume,
- (
- SELECT
- IFNULL( SUM( ei.amount_money ), 0 )
- FROM
- expense_info ei
- WHERE
- ei.warehouse_id = w.id
- AND ei.delete_flag = '0'
- AND ei.expenses_type = '2'
- AND ei.expenses_purpose = '3'
- AND (DATE_FORMAT(ei.create_date,"%Y%m%d") >=
- DATE_FORMAT(#{startDate},"%Y%m%d"))
- AND (DATE_FORMAT(ei.create_date,"%Y%m%d") <=
- DATE_FORMAT(#{endDate},"%Y%m%d"))
- ) AS cost
- FROM
- warehouse_base_info w
- LEFT JOIN warehousing_order war ON war.base_id = w.id AND war.in_type = '收购入库'
- AND war.delete_flag = '0'
- -- LEFT JOIN source_relation_info sri ON sri.source_id = war.id
- -- AND sri.delete_flag = '0'
- -- LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
- -- AND iowt.in_out_flag = 1
- -- AND iowt.in_out_type_key = 1
- -- AND iowt.delete_flag = '0'
- -- LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
- -- AND wioi1.car_no = sri.car_no
- -- AND wioi1.delete_flag = 0
- -- AND wioi1.status_flag = 3
- -- LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.contract_no = iowt.contract_no
- -- AND ssrr.warehouse_record_id = wioi1.id
- -- AND ssrr.delete_flag = 0
- -- LEFT JOIN expense_info ei ON ei.warehouse_id = w.id and ei.delete_flag = '0'
- -- AND ei.expenses_type = '2'
- -- AND ei.expenses_purpose = '3'
- WHERE
- w.comp_id = #{compId}
- AND w.warehouse_type = '1'
- <if test="searchKeyWord != null and searchKeyWord != ''">
- AND (lower(w.warehouse_name) like lower(CONCAT('%',#{searchKeyWord},'%')))
- </if>
- GROUP BY
- w.id
- ORDER BY
- w.delete_flag
- <if test="currentPage != null and currentPage != ''">
- LIMIT ${startRecord}, ${pageSize}
- </if>
- </select>
- <!-- 库点利润图 -->
- <select id="getWarehouseChartByCondition" parameterType="Map"
- resultType="com.yh.saas.plugin.yiliangyiyun.entity.WarehouseBaseInfo">
- SELECT
- pm.goods_name AS goodsName,
- SUM( IFNULL( sri.proportion, 1 ) * IFNULL( ssrr.amount_ing_receivable, 0 )) - sum( pm.amount_ing_payable ) AS profit
- FROM
- payment_management pm
- LEFT JOIN warehouse_base_info wbi ON wbi.warehouse_name = pm.warehouse_name
- AND wbi.comp_id = pm.comp_id
- AND wbi.delete_flag = 0
- LEFT JOIN warehousing_order war ON war.base_id = wbi.id
- AND war.in_type = '收购入库'
- AND war.comp_id = wbi.comp_id
- AND war.delete_flag = '0'
- LEFT JOIN source_relation_info sri ON sri.source_id = war.id
- AND sri.delete_flag = '0'
- LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
- AND iowt.in_out_flag = 1
- AND iowt.in_out_type_key = 1
- AND iowt.delete_flag = '0'
- LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
- AND wioi1.delete_flag = 0
- AND wioi1.status_flag = 3
- and wioi1.in_out_flag = 1
- LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.warehouse_record_id = wioi1.id
- AND ssrr.delete_flag = 0
- WHERE
- pm.delete_flag = 0
- AND wbi.comp_id = #{compId}
- AND (DATE_FORMAT(pm.create_date,"%Y%m%d") >=
- DATE_FORMAT(#{startDate},"%Y%m%d"))
- AND (DATE_FORMAT(pm.create_date,"%Y%m%d") <=
- DATE_FORMAT(#{endDate},"%Y%m%d"))
- GROUP BY
- pm.goods_name;
- </select>
- <!-- 库点利润表 -->
- <select id="getWarehouseFormByCondition" parameterType="Map"
- resultType="com.yh.saas.plugin.yiliangyiyun.entity.WarehouseBaseInfo">
- SELECT
- '收购重量' AS type,
- sum( wioi.net_weight ) AS num
- FROM
- warehouse_in_out_info wioi
- LEFT JOIN warehouse_base_info wbi ON wbi.id = wioi.base_id
- AND wbi.delete_flag = 0
- WHERE
- wioi.in_out_type = '收购入库'
- AND wioi.status_flag = '3'
- AND wbi.comp_id =#{compId}
- AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") >=
- DATE_FORMAT(#{startDate},"%Y%m%d"))
- AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") <=
- DATE_FORMAT(#{endDate},"%Y%m%d"))
- UNION ALL
- SELECT
- '销售重量' AS type,
- sum( ssrr.settlement_weight ) AS num
- FROM
- warehouse_in_out_info wioi
- LEFT JOIN warehouse_base_info wbi ON wbi.id = wioi.base_id
- AND wbi.delete_flag = 0
- LEFT JOIN warehousing_order war ON war.base_id = wbi.id AND war.in_type = '收购入库'
- AND war.comp_id = wbi.comp_id
- AND war.delete_flag = '0'
- LEFT JOIN source_relation_info sri ON sri.source_id = war.id
- AND sri.delete_flag = '0'
- LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
- AND iowt.in_out_flag = 1
- AND iowt.in_out_type_key = 1
- AND iowt.delete_flag = '0'
- LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
- AND wioi1.car_no = sri.car_no
- AND wioi1.delete_flag = 0
- AND wioi1.status_flag = 3
- LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.contract_no = iowt.contract_no
- AND ssrr.warehouse_record_id = wioi1.id
- AND ssrr.delete_flag = 0
- WHERE
- wioi.in_out_type = '收购入库'
- AND wioi.status_flag = '3'
- AND wbi.comp_id= #{compId}
- AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") >=
- DATE_FORMAT(#{startDate},"%Y%m%d"))
- AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") <=
- DATE_FORMAT(#{endDate},"%Y%m%d"))
- UNION ALL
- SELECT
- '支付粮款' AS type,
- sum( ei.amount_money ) AS num
- FROM
- expense_info ei
- WHERE
- ei.delete_flag = '0'
- AND ei.expenses_type = '2'
- AND ei.expenses_purpose = '3'
- AND ei.comp_id= #{compId}
- AND (DATE_FORMAT(ei.create_date,"%Y%m%d") >=
- DATE_FORMAT(#{startDate},"%Y%m%d"))
- AND (DATE_FORMAT(ei.create_date,"%Y%m%d") <=
- DATE_FORMAT(#{endDate},"%Y%m%d"))
- UNION ALL
- SELECT
- '收入粮款' AS type,
- sum( ei.amount_money ) AS num
- FROM
- expense_info ei
- WHERE
- ei.delete_flag = '0'
- AND ei.expenses_type = '1'
- AND ei.expenses_purpose = '3'
- AND ei.comp_id =#{compId}
- AND (DATE_FORMAT(ei.create_date,"%Y%m%d") >=
- DATE_FORMAT(#{startDate},"%Y%m%d"))
- AND (DATE_FORMAT(ei.create_date,"%Y%m%d") <=
- DATE_FORMAT(#{endDate},"%Y%m%d"))
- UNION ALL
- SELECT
- '其他支出' AS type,
- sum( ei.amount_money ) AS num
- FROM
- expense_info ei
- WHERE
- ei.delete_flag = '0'
- AND ei.expenses_type = '2'
- AND ei.expenses_purpose != '3'
- AND ei.comp_id =#{compId}
- AND (DATE_FORMAT(ei.create_date,"%Y%m%d") >=
- DATE_FORMAT(#{startDate},"%Y%m%d"))
- AND (DATE_FORMAT(ei.create_date,"%Y%m%d") <=
- DATE_FORMAT(#{endDate},"%Y%m%d"))
- UNION ALL
- SELECT
- '其他收入' AS type,
- sum( ei.amount_money ) AS num
- FROM
- expense_info ei
- WHERE
- ei.delete_flag = '0'
- AND ei.expenses_type = '1'
- AND ei.expenses_purpose != '3'
- AND ei.comp_id =#{compId}
- AND (DATE_FORMAT(ei.create_date,"%Y%m%d") >=
- DATE_FORMAT(#{startDate},"%Y%m%d"))
- AND (DATE_FORMAT(ei.create_date,"%Y%m%d") <=
- DATE_FORMAT(#{endDate},"%Y%m%d"))
- </select>
- </mapper>
|