using System ;
using System.Linq ;
using System.Web.Mvc ;
using DSWeb.Areas.Import.DAL.ImportSales ;
using DSWeb.Areas.Import.DAL.ImportTrade ;
using DSWeb.Areas.Import.Models.ImportTrade ;
using DSWeb.MvcShipping.Helper ;
using DSWeb.MvcShipping.Comm.Cookie ;
using DSWeb.Areas.CommMng.DAL ;
using System.Collections.Generic ;
using HcUtility.Comm ;
using HcUtility.Core ;
using DSWeb.EntityDA ;
using DSWeb.Areas.Account.Models.Chfee_Exrate ;
using DSWeb.TruckMng.Helper.Repository ;
using DSWeb.Areas.CommMng.Models ;
using DSWeb.Areas.Import.DAL.Comm ;
using DSWeb.Areas.Import.Models.Comm ;
using DSWeb.Areas.Account.DAL.Chfee_Settlement ;
using DSWeb.MvcShipping.Models.WMS ;
using DSWeb.MvcShipping.DAL.WMS ;
using DSWeb.MvcShipping.Controllers ;
using System.Data ;
using DSWeb.MvcShipping.Models.MsChFee ;
using DSWeb.SoftMng.Filter ;
namespace DSWeb.Areas.Import.Controllers
{
[JsonRequestBehavior]
public class ImportDeliveryController : Controller
{
/ /
// GET:
public ActionResult Index ( )
{
return View ( ) ;
}
/ /
// GET: /
public ActionResult Edit ( )
{
return View ( ) ;
}
/ /
// GET:
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetDataList ( int start , int limit , string sort , string condition )
{
var dataList = ImportSalesDAL . GetDeliveryList ( condition , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) , sort ) ;
var list = dataList . Skip ( start ) . Take ( limit ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = list . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetData ( string handle , string condition )
{
Deliverymb head = null ;
if ( handle = = "edit" )
{
var list = ImportSalesDAL . GetDeliveryList ( condition , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
if ( list . Count > 0 )
head = list [ 0 ] ;
}
if ( head = = null )
{
head = new Deliverymb ( ) ;
}
if ( handle = = "add" )
{
head . OP = Convert . ToString ( Session [ "USERID" ] ) ;
//head.OPRef = Convert.ToString(Session["SHOWNAME"]);
//head.BSSTATUS = "1";
//head.FEESTATUS = "1";
//head.CURRENCY = "RMB";
//head.AMOUNT = "0";
//head.EXCHANGERATE = "1";
//head. = "1";
}
var json = JsonConvert . Serialize (
new { Success = true , Message = "查询成功" , data = head } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult Save ( string opstatus , string data , string DeliveryDetailList , string chfeebody , string chfeedelbody )
{
var headData = JsonConvert . Deserialize < Deliverymb > ( data ) ;
var DeliveryDetailData = JsonConvert . Deserialize < List < DeliveryDetailmb > > ( DeliveryDetailList ) ;
var DeliveryDetailDELData = JsonConvert . Deserialize < List < DeliveryDetailmb > > ( "" ) ;
if ( opstatus = = "add" )
{
headData . GID = Guid . NewGuid ( ) . ToString ( ) ;
headData . DELIVERYNO = PubSysDAL . GetBillNo ( "0208" ) ;
//headData.DELIVERYNO =
headData . CORPID = Convert . ToString ( Session [ "COMPANYID" ] ) ;
headData . OP = Convert . ToString ( Session [ "SHOWNAME" ] ) ;
headData . DELIVERYDATE = DateTime . Now . ToString ( ) ;
headData . DbOperationType = DbOperationType . DbotIns ;
headData . ModelUIStatus = "I" ;
}
else if ( opstatus = = "edit" )
{
headData . DbOperationType = DbOperationType . DbotUpd ;
headData . ModelUIStatus = "E" ;
}
else
{
headData . DbOperationType = DbOperationType . DbotDel ;
}
var DELIVERYNO = headData . DELIVERYNO ;
//if (headData.INVDATE == "") headData.INVDATE = null;
var modb = new ModelObjectRepository ( ) ;
DBResult result = modb . Save ( headData
, ModelObjectConvert < DeliveryDetailmb > . ToModelObjectList ( DeliveryDetailData )
, ModelObjectConvert < DeliveryDetailmb > . ToModelObjectList ( DeliveryDetailDELData )
) ;
var jsonRespose = new JsonResponse
{
Success = result . Success ,
Message = result . Message ,
Data = ImportSalesDAL . GetDeliveryData ( " DELIVERYNO='" + DELIVERYNO + "'" , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) )
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetCargoList ( int start , int limit , string sort , string condition )
{
var dataList = ImportSalesDAL . GetCargoList ( condition , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) , sort ) ;
var list = dataList . Skip ( start ) . Take ( limit ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = list . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult AddDetail ( string DELIVERYNO , string DetailList )
{
var _count = 0 ;
var corpcode = CookieConfig . GetCookie_OrgCode ( Request ) ;
var userid = CookieConfig . GetCookie_UserId ( Request ) ;
_count = ImportSalesDAL . AddDeliveryDetail ( DELIVERYNO , DetailList , corpcode , userid ) ;
var _success = false ;
var CUSTOMERNAME = "" ;
if ( _count > 0 ) {
_success = true ;
}
var json = JsonConvert . Serialize ( new { Success = _success , Message = "查询成功" , totalCount = _count } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetDetailList ( int start , int limit , string sort , string condition )
{
var dataList = ImportSalesDAL . GetDeliveryDetailList ( condition , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) , sort ) ;
var list = dataList . Skip ( start ) . Take ( limit ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = list . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult Delete ( string data )
{
var head = JsonConvert . Deserialize < Deliverymb > ( data ) ;
var modb = new ModelObjectDB ( ) ;
//20170122 首先检测是否有已核销的费用,如有则不能删除出库记录
DBResult result = modb . Delete ( head ) ;
ContentResult _r = DeleteDetail ( head . DELIVERYNO , "" ) ;
if ( result . Success ) {
//20151230 删除时已经经过了费用检测,出库结算单下无费用
var _count = ImportSalesDAL . DelSettlement ( head . DELIVERYNO ) ;
var _r2 = DeleteOUTByBSNO ( head . DELIVERYNO ) ;
}
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
//wms/DeleteOUTByBSNO/.
public ContentResult DeleteOUTByBSNO ( string BSNO )
{
var dataList = WMSDAL . GetWMSOUTList ( " BSNO='" + BSNO + "'" , "" ) ;
var _r = new ContentResult ( ) ;
foreach ( var head in dataList )
{
if ( head . ISCHANGE = = "True" )
{
var HZWMSLockCount = WMSDAL . GetHZWMSLockCount ( head . INGIDNEW ) ;
if ( HZWMSLockCount > 0 )
{
//返回错误
var jsonRespose_0 = new JsonResponse { Success = false , Message = "下属的货转入库已经入账,不能修改" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose_0 ) } ;
}
else
{
WMSDAL . DelHZWMS ( head . INGIDNEW ) ;
}
}
//首先记录 WMS_out_detail的 INBSNO, 即WMS的GID, 将保存前的 剩余件数和剩余量储存
var WMSGIDList = "" ;
var WODList_0 = WMSDAL . GetWMSOUTDetailList_0 ( " OUTBSNO='" + head . BSNO + "'" , "" ) ;
foreach ( var _WO in WODList_0 )
{
if ( WMSGIDList = = "" )
WMSGIDList = "'" + _WO . INBSNO + "'" ;
else WMSGIDList = WMSGIDList + ",'" + _WO . INBSNO + "'" ;
}
var WMSList = new List < WMSmb > ( ) ;
WMSList = WMSDAL . GetDataList ( " ASSOCIATEDNO ='" + head . ASSOCIATEDNO + "'" , "" ) ;
foreach ( var _WMS in WMSList )
{
var GOODSSTOCK = Convert . ToDecimal ( _WMS . GOODSSTOCK ) ;
var GOODSPACKSTOCK = Convert . ToDecimal ( _WMS . GOODSPACKSTOCK ) ;
foreach ( var _WO in WODList_0 )
{
if ( _WO . INBSNO = = _WMS . GID ) //将现有数字全部加回剩余量
{
GOODSSTOCK + = Convert . ToDecimal ( _WO . GOODSPFSL ) ;
GOODSPACKSTOCK + = Convert . ToDecimal ( _WO . GOODSPACKPFSL ) ;
}
}
_WMS . GOODSSTOCK = GOODSSTOCK . ToString ( ) ;
_WMS . GOODSPACKSTOCK = GOODSPACKSTOCK . ToString ( ) ;
}
var modb3 = new ModelObjectRepository ( ) ;
DBResult result3 = modb3 . Save (
ModelObjectConvert < WMSmb > . ToModelObjectList ( WMSList )
) ;
var modb = new ModelObjectDB ( ) ;
DBResult result = modb . Delete ( head , Session [ "USERID" ] . ToString ( ) , true ) ;
var _count = WMSDAL . DeleteOut ( head . BSNO ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
_r = new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
return _r ;
}
public ContentResult DeleteDetail ( string DELIVERYNO , string GIDList )
{
var _count = 0 ;
var corpcode = CookieConfig . GetCookie_OrgCode ( Request ) ;
var userid = CookieConfig . GetCookie_UserId ( Request ) ;
_count = ImportSalesDAL . DeleteDeliveryDetail ( DELIVERYNO , GIDList ) ;
var _success = false ;
if ( _count > 0 )
{
_success = true ;
}
var json = JsonConvert . Serialize ( new { Success = _success , Message = "查询成功" , totalCount = _count } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult GetFeeList ( string DELIVERYNO , string sort )
{
var corpid = Convert . ToString ( Session [ "COMPANYID" ] ) ;
var USERID = Convert . ToString ( Session [ "USERID" ] ) ;
var DEPTGID = Convert . ToString ( Session [ "DEPTGID" ] ) ;
//var OPERATERANGE="";
var VISIBLERANGE = "" ;
var modName = "modImport_Fee" ;
var evList = BasicDataRefDAL . GetAR ( modName , USERID ) ;
AuthorityRangemb head = null ;
if ( evList . Count > 0 )
head = evList [ 0 ] ;
if ( head = = null )
{
head = new AuthorityRangemb ( ) ;
//OPERATERANGE = "3";
VISIBLERANGE = "3" ;
}
else
{
//OPERATERANGE = head.OPERATERANGE;
VISIBLERANGE = head . VISIBLERANGE ;
}
var condition = " isnull(DELIVERYNO,'')<>'' and DELIVERYNO in(select gid from import_deliveryDetail where DELIVERYNO='" + DELIVERYNO + "')" ;
/ *
if ( VISIBLERANGE = = "1" )
{
condition = condition + " and SALER in(select userid from user_company where companyid='" + corpid + "')" ;
}
if ( VISIBLERANGE = = "2" )
{
condition = condition + " and SALER in(select userid from user_baseinfo where companyname=(select name from company where gid='" + corpid + "') " ;
condition = condition + " and deptname=(select deptname from sys_dept where gid='" + DEPTGID + "')) " ;
}
if ( VISIBLERANGE = = "3" )
{
condition = condition + " and SALER ='" + USERID + "'" ;
} * /
var dataList = ImportSalesDAL . GetFeeList ( condition , sort ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
//首先是提交状态
public ContentResult LockDelivery ( string DELIVERYNO )
{ //锁定出库单
var _count = 0 ;
var corpcode = CookieConfig . GetCookie_OrgCode ( Request ) ;
var corpid = Convert . ToString ( Session [ "COMPANYID" ] ) ;
var userid = Convert . ToString ( Session [ "USERID" ] ) ;
var _r = DelFee_ImportDelivery ( DELIVERYNO ) ;
_count = ImportSalesDAL . LockDelivery ( DELIVERYNO ) ;
_r = MakeFee_ImportDelivery ( DELIVERYNO ) ;
var _success = false ;
if ( _count > 0 )
{
_success = true ;
}
/ *
var _r = SaveWMSOUT_OWN ( "add" , WMS_OUT , WMS_OUT_Detail ) ;
//此方法内已包含应收费用生成
if ( result . Success )
{
//调用LockOut
var WMSC = new WMSController ( ) ;
var _k = WMSC . LockWMS ( GID , USERID , "0" ) ;
} * /
//构建WMS_OUT和WMS_OUT_Detail对象, 作为参数调用SaveWMSOUT_OWN进行保存
////////var _r2 = SetWMSOUT(DELIVERYNO,DateTime.Now.ToString());
//最后设置所有该出库单关联的费用的 BSNO, SALESNO和DELIVERYNO
//令其与出库单/销售单/采购合同正确关联
var json = JsonConvert . Serialize ( new { Success = _success , Message = "设置成功" , totalCount = _count } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult UnLockDelivery ( string DELIVERYNO )
{
var _count = 0 ;
var corpcode = CookieConfig . GetCookie_OrgCode ( Request ) ;
var userid = CookieConfig . GetCookie_UserId ( Request ) ;
//首先判断是否存在已核销的费用,如果有的话不允许撤回
var SettledFeeList = new List < DSWeb . Areas . Import . Models . Comm . MsChFee > ( ) ;
SettledFeeList = MsChFeeDAL . GetDataList ( " DELIVERYNO='" + DELIVERYNO + "' and feestatus in(8,9) " , userid ) ;
if ( SettledFeeList . Count > 0 )
{
var json = JsonConvert . Serialize ( new { Success = false , Message = "该出库单包含已结算的费用,不能撤回" , totalCount = _count } ) ;
return new ContentResult ( ) { Content = json } ;
}
else
{
_count = ImportSalesDAL . UnLockDelivery ( DELIVERYNO ) ;
var _r = DelFee_ImportDelivery ( DELIVERYNO ) ;
var _success = false ;
if ( _count > 0 )
{
_success = true ;
}
//var _count2 = ImportSalesDAL.DelSettlement(DELIVERYNO);
//var _count3 = ImportSalesDAL.FeeUnSettlement(DELIVERYNO);
var json = JsonConvert . Serialize ( new { Success = _success , Message = "设置成功" , totalCount = _count } ) ;
return new ContentResult ( ) { Content = json } ;
}
}
//财务审核后成为锁定状态
public ContentResult LockDelivery_2 ( string DELIVERYNO )
{ //锁定出库单
var _count = 0 ;
var _count2 = 0 ;
var corpcode = CookieConfig . GetCookie_OrgCode ( Request ) ;
var corpid = Convert . ToString ( Session [ "COMPANYID" ] ) ;
var userid = Convert . ToString ( Session [ "USERID" ] ) ;
_count = ImportSalesDAL . LockDelivery_2 ( DELIVERYNO ) ;
_count2 = ImportSalesDAL . LockSaleStatus ( DELIVERYNO ) ;
var _success = false ;
if ( _count > 0 )
{
_success = true ;
}
/ *
var _r = SaveWMSOUT_OWN ( "add" , WMS_OUT , WMS_OUT_Detail ) ;
//此方法内已包含应收费用生成
if ( result . Success )
{
//调用LockOut
var WMSC = new WMSController ( ) ;
var _k = WMSC . LockWMS ( GID , USERID , "0" ) ;
} * /
//构建WMS_OUT和WMS_OUT_Detail对象, 作为参数调用SaveWMSOUT_OWN进行保存
////////var _r2 = SetWMSOUT(DELIVERYNO,DateTime.Now.ToString());
//最后设置所有该出库单关联的费用的 BSNO, SALESNO和DELIVERYNO
//令其与出库单/销售单/采购合同正确关联
var json = JsonConvert . Serialize ( new { Success = _success , Message = "设置成功" , totalCount = _count } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult UnLockDelivery_2 ( string DELIVERYNO )
{
var _count = 0 ;
var corpcode = CookieConfig . GetCookie_OrgCode ( Request ) ;
var userid = CookieConfig . GetCookie_UserId ( Request ) ;
_count = ImportSalesDAL . UnLockDelivery_2 ( DELIVERYNO ) ;
var _success = false ;
if ( _count > 0 )
{
_success = true ;
}
//var _count2 = ImportSalesDAL.DelSettlement(DELIVERYNO);
//var _count3 = ImportSalesDAL.FeeUnSettlement(DELIVERYNO);
var json = JsonConvert . Serialize ( new { Success = _success , Message = "设置成功" , totalCount = _count } ) ;
return new ContentResult ( ) { Content = json } ;
}
private ContentResult MakeFee_ImportDelivery ( string DELIVERYNO )
{
var condition = " D.DELIVERYNO='" + DELIVERYNO + "'" ;
var deliverydetail = ImportSalesDAL . GetDeliveryDetailList ( condition , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) , "" ) ;
var headdata = ImportSalesDAL . GetDeliveryData ( "DELIVERYNO='" + DELIVERYNO + "'" ) ;
var saledate = ImportSalesDAL . GetData ( " s.salesno in(select salesno from Import_Saledetail where gid in( select SALEDETAIL_GID from Import_DeliveryDetail where DELIVERYNO='" + DELIVERYNO + "' ))" ) ;
var chfeelist = new List < MsChFeeImportWMS > ( ) ;
var chfeedellist = new List < MsChFeeImportWMS > ( ) ;
WMSOUTmb WMSOUT = null ;
var WMSlist = WMSDAL . GetWMSOUTList ( " BSNO='" + DELIVERYNO + "' " , "" ) ;
if ( WMSlist . Count > 0 ) {
WMSOUT = WMSlist [ 0 ] ;
}
var BSNO = "" ;
var WmsOutBsNo = WMSOUT . GID ;
foreach ( var _dd in deliverydetail )
{
var _fee = new MsChFeeImportWMS ( ) ;
var salesdetaillist = ImportSalesDAL . GetDetailList ( " s.GID='" + _dd . SALEDETAIL_GID + "'" ) ;
var salesdetail = salesdetaillist [ 0 ] ;
BSNO = salesdetail . BSNO ;
_fee . GId = System . Guid . NewGuid ( ) . ToString ( ) ;
_fee . BsNo = "" ;
_fee . FeeName = "尾款" ;
_fee . FeeType = 1 ;
_fee . FeeStatus = 0 ;
_fee . CustomerName = saledate . CUSTOMERNAME ;
_fee . UnitPrice = Convert . ToDecimal ( salesdetail . PRICERMB ) ;
_fee . TaxUnitPrice = Convert . ToDecimal ( salesdetail . PRICERMB ) ;
_fee . Quantity = Convert . ToDecimal ( _dd . WEIGHT ) ;
_fee . Amount = _fee . UnitPrice * _fee . Quantity ;
_fee . NoTaxAmount = _fee . Amount ;
_fee . Currency = "RMB" ;
_fee . ExChangerate = 1 ;
if ( salesdetail . CURRENCY ! = "RMB" )
{
_fee . Remark = salesdetail . CURRENCY + " 汇率" + salesdetail . EXCHANGERATE ;
}
_fee . EnteroPerator = Session [ "USERID" ] . ToString ( ) ;
_fee . EnterDate = System . DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
_fee . DebitNo = "" ;
_fee . IsDebit = "0" ;
_fee . IsOpen = "0" ;
_fee . IsAdvancedpay = "0" ;
_fee . IsInvoice = "0" ;
_fee . FeeFrt = "PP" ;
_fee . IsCrmOrderFee = "0" ;
_fee . AuditStatus = 0 ;
_fee . SALESNO = salesdetail . SALESNO ;
_fee . DELIVERYNO = _dd . GID ;
_fee . WmsOutBsNo = WmsOutBsNo ;
chfeelist . Add ( _fee ) ;
}
var modb = new ModelObjectRepository ( ) ;
var _r = modb . SaveComm ( "BsNo" , BSNO ,
ModelObjectConvert < MsChFeeImportWMS > . ToModelObjectList ( chfeelist ) ,
ModelObjectConvert < MsChFeeImportWMS > . ToModelObjectList ( chfeedellist )
) ;
var jsonRespose = new JsonResponse
{
Success = _r . Success ,
Message = _r . Message ,
Data = null
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
private ContentResult DelFee_ImportDelivery ( string DELIVERYNO )
{
var _count = WMSDAL . DelFee_ImportDelivery ( DELIVERYNO ) ;
var modb = new ModelObjectRepository ( ) ;
var _r = new DBResult ( ) ;
if ( _count > 0 )
{
_r . Success = true ;
}
var jsonRespose = new JsonResponse
{
Success = _r . Success ,
Message = _r . Message ,
Data = null
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult SetSettlement ( string DELIVERYNO ) {
var corpid = Convert . ToString ( Session [ "COMPANYID" ] ) ;
var userid = Convert . ToString ( Session [ "USERID" ] ) ;
//首先删除相关结算
var _count2 = ImportSalesDAL . DelSettlement ( DELIVERYNO ) ;
//此时在前台调用处已同过js中的MakeFees方法生成费用
//此处要做的是
//1 通过DELIVERYNO查询出所有费用,
var condition = " isnull(DELIVERYNO,'')<>'' and DELIVERYNO='" + DELIVERYNO + "'" ;
var FeeList = ImportSalesDAL . GetFeeList ( condition , "" ) ;
//2 建立一个Ch_fee_do的对象List, 依照费用信息编写和插入ch_fee_do信息
var ChFeeDoList = new List < DSWeb . Areas . Import . Models . ImportTrade . MsChFeeDo > ( ) ;
var ChFeeDoDEL = new List < DSWeb . Areas . Import . Models . ImportTrade . MsChFeeDo > ( ) ;
decimal AMOUNT = 0 ;
var CUSTOMERNAME = "" ;
foreach ( var Fee in FeeList )
{
var _do = new DSWeb . Areas . Import . Models . ImportTrade . MsChFeeDo ( ) ;
_do . GID = Guid . NewGuid ( ) . ToString ( ) ;
_do . BILLNO = "" ; //DELIVERYNO;
_do . BSNO = Fee . BsNo ;
_do . CUSTOMERNAME = Fee . CustomerName ;
_do . BSTYPE = "0" ;
_do . FEEID = Fee . GId ;
_do . FEENAME = Fee . FeeName ;
_do . CURRENCY = Fee . Currency ;
_do . AMOUNT = Fee . Amount . ToString ( ) ;
_do . DOAMOUNT = Fee . Amount . ToString ( ) ;
_do . FEETYPE = Fee . FeeType . ToString ( ) ;
_do . CATEGORY = "2" ;
_do . BILLSTATUS = "2" ;
_do . CREATETIME = DateTime . Now . ToString ( ) ;
_do . EXCHANGERATE = Fee . ExChangerate . ToString ( ) ;
_do . ORIGAMOUNT = Fee . Amount . ToString ( ) ;
_do . COMPANYID = corpid ;
CUSTOMERNAME = Fee . CustomerName ;
ChFeeDoList . Add ( _do ) ;
AMOUNT = AMOUNT + Fee . Amount ;
}
// 并计算总金额
condition = " SETTLEBILLNO='" + DELIVERYNO + "' " ;
decimal SettlementAmount = 0 ;
//2 建立一个Ch_fee_do的对象List, 依照费用信息编写和插入ch_fee_do信息
var _APD = ChsettlementDAL . GetAPBodyList ( condition ) ;
foreach ( var apd in _APD )
{
SettlementAmount = SettlementAmount + decimal . Parse ( apd . DOAMOUNT ) ;
}
if ( AMOUNT ! = SettlementAmount ) {
var json2 = JsonConvert . Serialize ( new { Success = false , Message = "核销的费用金额和预收取用的金额不一致" } ) ;
return new ContentResult ( ) { Content = json2 } ;
}
//3 建立一个Ch_fee_settlement对象, 插入数据
var _S = new DSWeb . Areas . Import . Models . ImportTrade . MsChFeeSettlement ( ) ;
_S . GID = Guid . NewGuid ( ) . ToString ( ) ;
_S . BILLNO = DELIVERYNO ;
_S . BILLDATE = DateTime . Now . ToString ( ) ;
_S . SETTLEMODE = "2" ;
_S . CUSTOMERNAME = CUSTOMERNAME ;
_S . SETTLETYPE = "4" ;
_S . AMOUNTRMB = "0" ;
_S . ACCOUNTRMB = "" ;
_S . RATE = "1" ;
_S . AMOUNTUSD = "0" ;
_S . ACCOUNTUSD = "" ;
_S . BILLTYPE = "1" ;
_S . SETTLEUSER = userid ;
_S . SETTLETIME = "" ;
_S . ISEXPORT = "0" ;
_S . BILLSTATUS = "2" ;
_S . COMPANYID = corpid ;
_S . ACCOUNTS_CURRENCY = "0" ;
_S . ACCOUNTS_RATE = "1" ;
_S . ACCOUNTS_MONEY = AMOUNT . ToString ( ) ;
_S . PREPAY_CURRENCY = "0" ;
_S . PREPAY_RATE = "1" ;
_S . PREPAY_MONEY = "0" ;
_S . AHSR_CURRENCY = "0" ;
_S . AHSR_RATE = "1" ;
_S . AHSR_MONEY = "0" ;
_S . FINANCIAL_CURRENCY = "0" ;
_S . FINANCIAL_RATE = "1" ;
_S . FINANCIAL_MONEY = "0" ;
_S . ADVANCE_CURRENCY = "0" ;
_S . ADVANCE_RATE = "1" ;
_S . ADVANCE_MONEY = SettlementAmount . ToString ( ) ;
_S . CURR = "RMB" ;
//4 将Ch_fee_settlement作为主, Ch_fee_doList作为从进行保存
_S . DbOperationType = DbOperationType . DbotIns ;
_S . ModelUIStatus = "I" ;
var modb = new ModelObjectRepository ( ) ;
DBResult result = modb . Save ( _S ,
ModelObjectConvert < DSWeb . Areas . Import . Models . ImportTrade . MsChFeeDo > . ToModelObjectList ( ChFeeDoList ) ,
ModelObjectConvert < DSWeb . Areas . Import . Models . ImportTrade . MsChFeeDo > . ToModelObjectList ( ChFeeDoDEL )
) ;
if ( result . Success ) {
var _count3 = ImportSalesDAL . FeeSettlement ( DELIVERYNO ) ;
}
var json = JsonConvert . Serialize ( new { Success = result . Success , Message = "设置完成" } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult SetWMSOUT ( string DELIVERYNO , string DODATE )
{
//MAKEWMSOUT
//此处生成出库记录
//根据DELIVERYNO获得其明细列表
var DList = ImportSalesDAL . GetDeliveryDetailList ( " D.DELIVERYNO='" + DELIVERYNO + "' " ) ;
var _DE = ImportSalesDAL . GetDeliveryData ( " DELIVERYNO='" + DELIVERYNO + "' " ) ;
//遍历DList, 通过其CARGO_GID来:
//使用主表的列表查询方法,得到该商品所属的采购业务信息
foreach ( var DeliveryDetail in DList )
{
var CargoInfo = ImportTradeDAL . GetData_ALL ( " c.gid = (select cargo_GID from Import_Saledetail where gid='" + DeliveryDetail . SALEDETAIL_GID + "') " , CookieConfig . GetCookie_UserCode ( Request ) , CookieConfig . GetCookie_UserName ( Request ) , CookieConfig . GetCookie_CompanyId ( Request ) ) ;
var WMS = WMSDAL . GetDataList ( " CARGO_GID=(select cargo_GID from Import_Saledetail where gid='" + DeliveryDetail . SALEDETAIL_GID + "') " , "" ) ;
if ( WMS . Count = = 0 ) {
return new ContentResult ( ) { Content = "还未锁定货物生成库存" } ;
}
//WMS_OUT: associatedno来自业务BSNO, bsno根据规则生成, GID自动生成, 数量件数等于出库明细
var WMS_OUT = new WMSOUTmb ( ) ;
WMS_OUT . GID = "WmsOut" + Guid . NewGuid ( ) . ToString ( ) ;
WMS_OUT . ASSOCIATEDNO = CargoInfo . Contacter ;
//var WMSC = new WMSController();
WMS_OUT . BSNO = getCodeRule ( "出库单号" , "BSNO" , "WMS_OUT" , DODATE ) ; //调用编码规则
WMS_OUT . CUSTOMERNAME = _DE . CUSTOMERNAME ;
WMS_OUT . DODATE = DODATE ;
WMS_OUT . STORAGENAME = WMS [ 0 ] . STORAGENAME ;
WMS_OUT . GOODSNAME = CargoInfo . name ;
WMS_OUT . GOODSMODEL = CargoInfo . FactoryNo ;
WMS_OUT . GOODSPFSL = DeliveryDetail . WEIGHT ;
WMS_OUT . GOODSPACKPFSL = DeliveryDetail . BOXCOUNT ;
WMS_OUT . GOODSOUTFEE = "0" ;
WMS_OUT . GOODSOUTFEEAP = "0" ;
WMS_OUT . ARFEE = "0" ;
WMS_OUT . APFEE = "0" ;
WMS_OUT . TRUCKNO = _DE . TRUCKNO ;
WMS_OUT . CREATEUSER = Convert . ToString ( Session [ "USERID" ] ) ;
WMS_OUT . CREATETIME = DateTime . Now . ToString ( ) ;
WMS_OUT . DbOperationType = DbOperationType . DbotIns ;
WMS_OUT . ModelUIStatus = "I" ;
var modb = new ModelObjectRepository ( ) ;
DBResult result = modb . Save ( WMS_OUT
) ;
}
return new ContentResult ( ) { Content = "" } ;
}
public ContentResult SaveFee ( string SALESNO , string chfeebody , string chfeedelbody )
{
var chfeeBodyList = JsonConvert . Deserialize < List < MsChFee_Sales > > ( chfeebody ) ;
var chfeeDelBodyList = JsonConvert . Deserialize < List < MsChFee_Sales > > ( chfeedelbody ) ;
var modb = new ModelObjectRepository ( ) ;
DBResult result = modb . SaveComm ( "BsNo" , SALESNO ,
ModelObjectConvert < MsChFee_Sales > . ToModelObjectList ( chfeeBodyList ) ,
ModelObjectConvert < MsChFee_Sales > . ToModelObjectList ( chfeeDelBodyList )
) ;
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result . Success ,
Message = result . Message ,
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
# region
/ *
public ContentResult SetSettlement ( int newStatus , string DELIVERYNO )
{
var chfeeList = JsonConvert . Deserialize < List < Baoxiaomb > > ( chfeelist ) ;
var USERID = Convert . ToString ( CookieConfig . GetCookie_UserId ( Request ) ) ;
//var DEPTGID = Convert.ToString(Session["DEPTGID"]);
DBResult result = ImportSalesDAL . SetSettlement ( newStatus , DELIVERYNO ) ;
var json = JsonConvert . Serialize ( result ) ;
return new ContentResult ( ) { Content = json } ;
} * /
# endregion
#region 参照部分
# endregion
public String getCodeRule ( string strRULENAME , string strfield , string tablename , string DODATE )
{
//调用编码规则
string strRULEYEAR = "" ;
string strRULECONTENT = "" ;
string strCODENAME = "" ;
string strDEPTNO = "" ;
string strRULENOLENGTH = "" ;
int iRULENOLENGTH = 0 ;
int inum = 0 ;
string strCONTENT = "" ;
string USERID = Session [ "USERID" ] . ToString ( ) ;
T_ALL_DA T_ALL_DA = new T_ALL_DA ( ) ;
DataSet ds = T_ALL_DA . GetAllSQL ( "select * from code_rule where RULENAME='" + strRULENAME . Trim ( ) + "' and RULETYPE=3" ) ;
if ( ds ! = null )
{
if ( ds . Tables [ 0 ] . Rows . Count > 0 )
{
if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "ISSTARTUSING" ] . ToString ( ) . Trim ( ) . Equals ( "True" ) )
{
//getCodeRuleEnabled(strRULENAME, strfield);
/ /
if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULEDATE" ] . ToString ( ) . Trim ( ) . Equals ( "业务日期" ) )
{
if ( DODATE = = "" )
{
return "" ;
}
DateTime dETD = System . Convert . ToDateTime ( DODATE ) ;
if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "ISCLEAREDINEARLY" ] . ToString ( ) . Trim ( ) . Equals ( "True" ) )
{
if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULEYEAR" ] . ToString ( ) . Trim ( ) = = "4" )
{
strRULEYEAR = dETD . ToString ( "yyyy" ) + dETD . ToString ( "MM" ) ;
}
else if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULEYEAR" ] . ToString ( ) . Trim ( ) = = "2" )
{
strRULEYEAR = dETD . ToString ( "yy" ) + dETD . ToString ( "MM" ) ;
}
}
else
{
if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULEYEAR" ] . ToString ( ) . Trim ( ) = = "4" )
{
strRULEYEAR = dETD . ToString ( "yyyy" ) ;
}
else if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULEYEAR" ] . ToString ( ) . Trim ( ) = = "2" )
{
strRULEYEAR = dETD . ToString ( "yy" ) ;
}
}
}
else if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULEDATE" ] . ToString ( ) . Trim ( ) . Equals ( "自然月份" ) )
{
DateTime fwqdate = System . Convert . ToDateTime ( T_ALL_DA . GetStrSQL ( "fwqdate" , "select fwqdate=getdate()" ) ) ;
if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "ISCLEAREDINEARLY" ] . ToString ( ) . Trim ( ) . Equals ( "True" ) )
{
if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULEYEAR" ] . ToString ( ) . Trim ( ) = = "4" )
{
strRULEYEAR = fwqdate . ToString ( "yyyy" ) + fwqdate . ToString ( "MM" ) ;
}
else if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULEYEAR" ] . ToString ( ) . Trim ( ) = = "2" )
{
strRULEYEAR = fwqdate . ToString ( "yy" ) + fwqdate . ToString ( "MM" ) ;
}
}
else
{
if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULEYEAR" ] . ToString ( ) . Trim ( ) = = "4" )
{
strRULEYEAR = fwqdate . ToString ( "yyyy" ) ;
}
else if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULEYEAR" ] . ToString ( ) . Trim ( ) = = "2" )
{
strRULEYEAR = fwqdate . ToString ( "yy" ) ;
}
}
}
/ /
if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "ISCOMPANY" ] . ToString ( ) . Trim ( ) . Equals ( "True" ) )
{
strCODENAME = T_ALL_DA . GetStrSQL ( "CODENAME" , "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + USERID + "')" ) ;
}
if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "ISDEPT" ] . ToString ( ) . Trim ( ) . Equals ( "True" ) )
{
strDEPTNO = T_ALL_DA . GetStrSQL ( "DEPTNO" , "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + Convert . ToString ( Session [ "USERID" ] ) + "')" ) ;
}
strRULECONTENT = ds . Tables [ 0 ] . Rows [ 0 ] [ "RULECONTENT" ] . ToString ( ) . Trim ( ) ;
strRULECONTENT = strRULECONTENT . Replace ( "《COMPANY》" , strCODENAME ) ;
strRULECONTENT = strRULECONTENT . Replace ( "《DEPT》" , strDEPTNO ) ;
/ /
if ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULENOLENGTH" ] . ToString ( ) . Trim ( ) = = "" )
{
iRULENOLENGTH = 0 ;
}
else
{
iRULENOLENGTH = int . Parse ( ds . Tables [ 0 ] . Rows [ 0 ] [ "RULENOLENGTH" ] . ToString ( ) . Trim ( ) ) ;
}
strCONTENT = strRULECONTENT + strRULEYEAR ;
//获取分公司的票号头字符
string tempBANKSHEAD = T_ALL_DA . GetStrSQL ( "BANKSHEAD" , "SELECT TOP 1 BANKSHEAD FROM company WHERE codename='" + Session [ "COMPANYID" ] . ToString ( ) + "'" ) ;
strCONTENT = tempBANKSHEAD + strCONTENT ;
/ /
strRULENOLENGTH = T_ALL_DA . GetStrSQL ( strfield , "select top 1 " + strfield + " from [" + tablename + "] where " + strfield + " like '" + strCONTENT . Trim ( ) + "%' and ISDELETE=0 order by " + strfield + " DESC" ) ;
if ( strRULENOLENGTH = = "" )
{
strRULENOLENGTH = "1" ;
}
else
{
strRULENOLENGTH = strRULENOLENGTH . Replace ( strCONTENT . Trim ( ) , "" ) ;
inum = int . Parse ( strRULENOLENGTH . Trim ( ) ) ;
inum = inum + 1 ;
strRULENOLENGTH = inum . ToString ( ) ;
}
int j = iRULENOLENGTH - strRULENOLENGTH . Length ;
for ( int i = 1 ; i < = j ; i + + )
{
strRULENOLENGTH = "0" + strRULENOLENGTH ;
}
/ /
strCONTENT = strCONTENT + strRULENOLENGTH ;
return strCONTENT ;
}
}
}
return "" ;
}
}
}