/// <summary> /// 获取产品的成本(根据系统设置相关) /// </summary> /// <param name="ipId"></param> /// <param name="user_id"></param> /// <returns></returns> public decimal?GetProCost(long ipId, long user_id) { decimal?thisCost = null; var thisPro = _dal.FindNoDeleteById(ipId); if (thisPro != null) { if (thisPro.unit_cost != null) { thisCost = (decimal)thisPro.unit_cost; } var onHandNum = _dal.GetProOnHand(thisPro.id); if (onHandNum != null && (Convert.ToInt32(onHandNum)) > 0) // 可用数要大于0 { var thisSysSet = new SysSettingBLL().GetSetById(DTO.SysSettingEnum.INVENTORY_ACCOUNTING_METHOD); if (thisSysSet != null) { var iopDal = new ivt_order_product_dal(); if (thisSysSet.setting_value == ((int)INVENTORY_ACCOUNTING_METHOD.AVERAGE_COST).ToString()) { var avgCosr = iopDal.GetAvgByPro(thisPro.id); if (avgCosr != null) { thisCost = (decimal)avgCosr; } } else if (thisSysSet.setting_value == ((int)INVENTORY_ACCOUNTING_METHOD.FIFO).ToString()) { var firCosr = iopDal.GetFirstByPro(thisPro.id); if (firCosr != null) { thisCost = (decimal)firCosr; } } else if (thisSysSet.setting_value == ((int)INVENTORY_ACCOUNTING_METHOD.LIFO).ToString()) { var lasCosr = iopDal.GetLastByPro(thisPro.id); if (lasCosr != null) { thisCost = (decimal)lasCosr; } } } } else { return(thisCost); } } return(thisCost); }
/// <summary> /// 获取采购项对应的库存产品可用数 /// </summary> /// <param name="orderProductId">采购项id</param> /// <returns></returns> public int GetIvtProductAvaCnt(long orderProductId) { var orderPdt = new ivt_order_product_dal().FindById(orderProductId); if (orderPdt == null) { return(0); } string sql = @" SELECT t.*,ifnull( ( SELECT sum(y.quantity) FROM ivt_order x, ivt_order_product y WHERE y.delete_time = 0 AND x.id = y.order_id AND x.status_id IN (2148, 2149) AND y.product_id = t.id AND y.warehouse_id = t.warehouse_id ), 0 ) as on_order, ifnull( ( SELECT ifnull(sum(y.quantity), 0) - ifnull(sum(z.quantity_received), 0) FROM ivt_order x, ivt_order_product y, ivt_receive z WHERE y.delete_time = 0 AND z.delete_time = 0 AND x.status_id IN (2149) AND x.id = y.order_id AND y.id = z.order_product_id AND y.product_id = t.id AND y.warehouse_id = t.warehouse_id ), 0 ) as back_order, ifnull( ( SELECT sum(x.quantity) FROM ivt_reserve x, crm_quote_item y WHERE x.delete_time = 0 AND x.quote_item_id = y.id AND y.object_id = t.id AND x.warehouse_id = w.id ), 0 ) + ifnull( ( SELECT sum(x.quantity) FROM ctt_contract_cost_product x, ctt_contract_cost y WHERE x.delete_time = 0 AND x.status_id = 2157 AND x.contract_cost_id = y.id AND y.product_id = t.id AND x.warehouse_id = w.id ), 0 ) as reserved_picked, ifnull( ( SELECT sum(x.quantity) FROM ctt_contract_cost_product x, ctt_contract_cost y WHERE x.delete_time = 0 AND x.status_id = 2157 AND x.contract_cost_id = y.id AND y.product_id = t.id AND x.warehouse_id = w.id ), 0 ) as picked, p.name as product_name, w.name as location_name from ivt_warehouse_product as t,ivt_product as p,ivt_warehouse as w WHERE t.product_id=" + orderPdt.product_id + " and t.warehouse_id=" + orderPdt.warehouse_id + " and p.id=t.product_id and w.id=t.warehouse_id"; var dto = dal.FindSignleBySql <InventoryItemEditDto>(sql); if (dto == null) { return(0); } if (string.IsNullOrEmpty(dto.reserved_picked)) { return(dto.quantity); } else { return(dto.quantity - int.Parse(dto.reserved_picked)); } }