@ -2552,6 +2552,21 @@ namespace DSWeb.Areas.Account.DAL.Chfee_Invoice
return exrate ;
return exrate ;
}
}
public static Decimal GetExrate2 ( string curr , List < DSWeb . MvcShipping . Models . MsChFee . MsFeeCurr > exratelist )
{
decimal exrate = 0 ;
if ( exratelist ! = null )
{
foreach ( var enumValue in exratelist )
{
if ( enumValue . CURR = = curr )
{
exrate = enumValue . DEFRATE ;
}
}
}
return exrate ;
}
public static DBResult DelFeeDo ( List < Chfee_do_detail > boday , string GID )
public static DBResult DelFeeDo ( List < Chfee_do_detail > boday , string GID )
{
{
var result = new DBResult ( ) ;
var result = new DBResult ( ) ;
@ -2661,6 +2676,378 @@ namespace DSWeb.Areas.Account.DAL.Chfee_Invoice
#region 发票申请开票和取消
#region 发票申请开票和取消
public static DBResult AddAppDetail2 ( ChInvoice headData , List < ChInvoiceapplication > bodyList , string invoiceno , string companyid , string GID )
{
var result = new DBResult ( ) ;
decimal amtttl = 0 ;
decimal acctaxrate = 0 ;
var invfeesumlist = new List < InvoiceFeeSum > ( ) ;
var defGOOD = MsCodeGoodInvDAL . GetData ( " ISDEF='1' and (DEFCURR='' or DEFCURR='" + headData . RECVCURR + "') " ) ;
var exratelist = MsChFeeDAL . GetFeeNowInvCurrList ( DateTime . Now . ToString ( "yyyy-MM-dd" ) , companyid ) ;
var invdetailDataList = GetDetailList ( "PID='" + GID + "'" ) ;
var invbodylist = GetBodyList ( "BILLNO='" + headData . BILLNO + "'" ) ;
foreach ( var invbody in invbodylist )
{
var invfeesum = invfeesumlist . Find ( x = > x . CURR = = invbody . ORIGCURRENCY & & x . exchange = = invbody . EXCHANGERATE ) ;
if ( invfeesum = = null )
{
var newinvfeesum = new InvoiceFeeSum ( ) ;
newinvfeesum . CURR = invbody . ORIGCURRENCY ;
newinvfeesum . exchange = invbody . EXCHANGERATE ;
if ( invbody . FEETYPE = = 1 )
newinvfeesum . amount = invbody . ORIGAMOUNT ;
else
newinvfeesum . amount = - invbody . ORIGAMOUNT ;
invfeesumlist . Add ( newinvfeesum ) ;
}
else
{
if ( invbody . FEETYPE = = 1 )
invfeesum . amount = invfeesum . amount + invbody . ORIGAMOUNT ;
else invfeesum . amount = invfeesum . amount - invbody . ORIGAMOUNT ;
}
}
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
var cmdUpdateInv =
db . GetSqlStringCommand (
@ "update ch_fee_invoice set REMARK=REMARK+' '+@REMARK
WHERE BILLNO = @BILLNO ");
//var cmdInsert =
// db.GetSqlStringCommand(
// @"insert ch_fee_do (GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY
// ,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,ISDELETED,CREATETIME
// ,EXCHANGERATE,ORIGCURRENCY,ORIGAMOUNT,INVOICESETTLENO,COMPANYID)
// SELECT NEWID(),@BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY
// ,AMOUNT,DOAMOUNT,FEETYPE,7,BILLSTATUS,ISDELETED,GETDATE(),EXCHANGERATE,ORIGCURRENCY
// ,ORIGAMOUNT,INVOICESETTLENO,COMPANYID from ch_fee_do WHERE BILLNO=@AppBILLNO ");
var cmdInsert =
db . GetSqlStringCommand (
@ "insert into ch_fee_do (GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY
, AMOUNT , DOAMOUNT , FEETYPE , CATEGORY , BILLSTATUS , ISDELETED , CREATETIME
, EXCHANGERATE , ORIGCURRENCY , ORIGAMOUNT , INVOICESETTLENO , COMPANYID )
values ( @GID , @BILLNO , @BSNO , @MBLNO , @HBLNO , @CUSTOMERNAME , @BSTYPE , @FEEID , @FEENAME , @CURRENCY
, @AMOUNT , @DOAMOUNT , @FEETYPE , @CATEGORY , @BILLSTATUS , @ISDELETED , @CREATETIME
, @EXCHANGERATE , @ORIGCURRENCY , @ORIGAMOUNT , @INVOICESETTLENO , @COMPANYID ) ");
var cmdUpdate =
db . GetSqlStringCommand (
@ "declare @FEEID varchar(100)
declare @ORDERINVOICE numeric ( 19 , 4 )
declare CurBill cursor for
select FEEID , ORIGAMOUNT ORDERINVOICE
from ch_fee_do where BILLNO = @AppBILLNO
open CurBill
fetch next from CurBill into @FEEID , @ORDERINVOICE
while @ @Fetch_Status = 0
begin
UPDATE CH_FEE SET INVOICE = ISNULL ( INVOICE , 0 ) + @ORDERINVOICE , ORDERINVSETTLEMENT = ISNULL ( ORDERINVSETTLEMENT , 0 ) + @ORDERINVOICE , INVOICENUM = @INVOICENUM WHERE GID = @FEEID
fetch next from CurBill into @FEEID , @ORDERINVOICE
end ;
close CurBill
dealLocate CurBill
");
var cmdUpdateApp =
db . GetSqlStringCommand (
@"UPDATE ch_fee_invoiceapplication set BILLSTATUS=3,INVBILLNO=@INVBILLNO,INVOICENO=@INVOICENO where BILLNO=@BILLNO" ) ;
var cmdInsertInvDetail =
db . GetSqlStringCommand (
@ "insert into ch_fee_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values ( @GID , @PID , @SerialNo , @GOODSNAME , @SPEC , @UNIT , @PKGS , @TAXPRICE , @PRICE , @AMOUNT , @TAXRATE , @TAX , @Remark , @GOODCODE ) ");
var cmdUpdateInvDetail =
db . GetSqlStringCommand (
@ "update ch_fee_invoicedetail set TAXPRICE=@TAXPRICE
, PRICE = @PRICE , AMOUNT = @AMOUNT , TAX = @TAX where GID = @GID ");
var currency = "" ;
decimal rate = 0 ;
var custrateno = "" ;
var custaddrtel = "" ;
var custbank = "" ;
var INVOICECATEGORY = "" ;
var ACTUALCUSTOMERNAME = "" ;
var INVOICECUSTNAME = "" ;
var REMARK = "" ;
var invdetailid = "" ;
if ( bodyList ! = null )
{
cmdUpdateInv . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateInv , "@BILLNO" , DbType . String , headData . BILLNO ) ;
foreach ( var enumValue in bodyList )
{
// var Addexratelist = MsChFeeDAL.GetFeeNowInvCurrList(Convert.ToDateTime(enumValue.ENTERTIME).ToString("yyyy-MM-dd"));
currency = enumValue . CURRENCY ;
rate = enumValue . RATE ;
custrateno = enumValue . CUSTRATENO ;
custaddrtel = enumValue . CUSTADDRTEL ;
custbank = enumValue . CUSTBANK ;
INVOICECATEGORY = enumValue . INVOICECATEGORY ;
ACTUALCUSTOMERNAME = enumValue . ACTUALCUSTOMERNAME ;
INVOICECUSTNAME = enumValue . INVOICECUSTNAME ;
REMARK = REMARK + ' ' + enumValue . REMARK ;
var feedolist = ChinvoiceapplicationDAL . GetBodyList ( "c.BILLNO='" + enumValue . BILLNO + "'" , db , tran ) ;
if ( feedolist ! = null & & feedolist . Count ! = 0 ) {
foreach ( var feedo in feedolist ) {
cmdInsert . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsert , "@GID" , DbType . String , Guid . NewGuid ( ) . ToString ( ) ) ;
db . AddInParameter ( cmdInsert , "@BILLNO" , DbType . String , headData . BILLNO ) ;
db . AddInParameter ( cmdInsert , "@BSNO" , DbType . String , feedo . BSNO ) ;
db . AddInParameter ( cmdInsert , "@MBLNO" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsert , "@HBLNO" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsert , "@CUSTOMERNAME" , DbType . String , feedo . CUSTOMERNAME ) ;
db . AddInParameter ( cmdInsert , "@BSTYPE" , DbType . Boolean , false ) ;
db . AddInParameter ( cmdInsert , "@FEEID" , DbType . String , feedo . FEEID ) ;
db . AddInParameter ( cmdInsert , "@FEENAME" , DbType . String , feedo . FEENAME ) ;
db . AddInParameter ( cmdInsert , "@CURRENCY" , DbType . String , feedo . CURRENCY ) ;
decimal exchangerate = 0 ;
if ( feedo . CURRENCY = = enumValue . CURRENCY )
{
db . AddInParameter ( cmdInsert , "@AMOUNT" , DbType . Decimal , feedo . AMOUNT ) ;
db . AddInParameter ( cmdInsert , "@DOAMOUNT" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@EXCHANGERATE" , DbType . Decimal , 1 ) ;
exchangerate = 1 ;
}
else
{
var UExrate = GetExrate2 ( feedo . CURRENCY , exratelist ) ;
if ( UExrate ! = feedo . EXCHANGERATE )
{
db . AddInParameter ( cmdInsert , "@AMOUNT" , DbType . Decimal , Math . Round ( feedo . ORIGAMOUNT * UExrate , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdInsert , "@DOAMOUNT" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@EXCHANGERATE" , DbType . Decimal , UExrate ) ;
exchangerate = UExrate ;
}
else {
db . AddInParameter ( cmdInsert , "@AMOUNT" , DbType . Decimal , feedo . AMOUNT ) ;
db . AddInParameter ( cmdInsert , "@DOAMOUNT" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@EXCHANGERATE" , DbType . Decimal , feedo . EXCHANGERATE ) ;
exchangerate = feedo . EXCHANGERATE ;
}
}
db . AddInParameter ( cmdInsert , "@FEETYPE" , DbType . Int16 , feedo . FEETYPE ) ;
db . AddInParameter ( cmdInsert , "@ORIGCURRENCY" , DbType . String , feedo . ORIGCURRENCY ) ;
db . AddInParameter ( cmdInsert , "@ORIGAMOUNT" , DbType . Decimal , feedo . ORIGAMOUNT ) ;
db . AddInParameter ( cmdInsert , "@CATEGORY" , DbType . Int16 , 7 ) ;
db . AddInParameter ( cmdInsert , "@BILLSTATUS" , DbType . Int16 , 1 ) ;
db . AddInParameter ( cmdInsert , "@ISDELETED" , DbType . Boolean , false ) ;
db . AddInParameter ( cmdInsert , "@CREATETIME" , DbType . DateTime , DateTime . Now ) ;
db . AddInParameter ( cmdInsert , "@INVOICESETTLENO" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsert , "@COMPANYID" , DbType . String , companyid ) ;
db . ExecuteNonQuery ( cmdInsert , tran ) ;
var invfeesum = invfeesumlist . Find ( x = > x . CURR = = feedo . ORIGCURRENCY & & x . exchange = = exchangerate ) ;
if ( invfeesum = = null )
{
var newinvfeesum = new InvoiceFeeSum ( ) ;
newinvfeesum . CURR = feedo . ORIGCURRENCY ;
newinvfeesum . exchange = exchangerate ;
if ( feedo . FEETYPE = = 1 )
newinvfeesum . amount = feedo . ORIGAMOUNT ;
else
newinvfeesum . amount = - feedo . ORIGAMOUNT ;
invfeesumlist . Add ( newinvfeesum ) ;
}
else
{
if ( feedo . FEETYPE = = 1 )
invfeesum . amount = invfeesum . amount + feedo . ORIGAMOUNT ;
else invfeesum . amount = invfeesum . amount - feedo . ORIGAMOUNT ;
}
}
}
//cmdInsert.Parameters.Clear();
//db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, billno);
//db.AddInParameter(cmdInsert, "@AppBILLNO", DbType.String, enumValue.BILLNO);
//db.ExecuteNonQuery(cmdInsert, tran);
cmdUpdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate , "@AppBILLNO" , DbType . String , enumValue . BILLNO ) ;
db . AddInParameter ( cmdUpdate , "@INVOICENUM" , DbType . String , invoiceno ) ;
db . ExecuteNonQuery ( cmdUpdate , tran ) ;
//var invdetaillist = GetDetailList("PID='" + enumValue.GID + "'", db, tran);
//if (invdetaillist != null)
//{
// foreach (var enumInvDetail in invdetaillist)
// {
// bool ishave = false;
// if (invdetailDataList != null && bodyList.Count != 1)
// {
// foreach (var invdetailData in invdetailDataList)
// {
// if (invdetailData.GOODSNAME == enumInvDetail.GOODSNAME)
// {
// invdetailData.TAXPRICE = invdetailData.TAXPRICE + enumInvDetail.TAXPRICE;
// invdetailData.PRICE = invdetailData.PRICE + enumInvDetail.PRICE;
// invdetailData.AMOUNT = invdetailData.AMOUNT + enumInvDetail.AMOUNT;
// invdetailData.TAX = invdetailData.TAX + enumInvDetail.TAX;
// ishave = true;
// }
// }
// }
// if (!ishave)
// {
// var invdetailtmp = enumInvDetail;
// invdetailtmp.GID = "*";
// invdetailtmp.PID = GID;
// invdetailDataList.Add(invdetailtmp);
// }
// }
//}
cmdUpdateApp . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateApp , "@INVBILLNO" , DbType . String , headData . BILLNO ) ;
db . AddInParameter ( cmdUpdateApp , "@INVOICENO" , DbType . String , invoiceno ) ;
db . AddInParameter ( cmdUpdateApp , "@BILLNO" , DbType . String , enumValue . BILLNO ) ;
db . ExecuteNonQuery ( cmdUpdateApp , tran ) ;
}
acctaxrate = headData . EXCHANGERATE ;
amtttl = 0 ;
foreach ( var invfeesum in invfeesumlist )
{
amtttl = amtttl + Math . Round ( invfeesum . amount * invfeesum . exchange , 2 , MidpointRounding . AwayFromZero ) ;
}
var dataList = GetDetailList ( " PID='" + GID + "'" ) ;
if ( dataList . Count ! = 0 )
{
var invlist = dataList [ 0 ] ;
cmdUpdateInvDetail . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@GID" , DbType . String , invlist . GID ) ;
var tax = Math . Round ( amtttl / ( 1 + acctaxrate / 100 ) * ( acctaxrate / 100 ) , 2 , MidpointRounding . AwayFromZero ) ;
var amount = amtttl - tax ;
db . AddInParameter ( cmdUpdateInvDetail , "@TAXPRICE" , DbType . Decimal , Math . Round ( amtttl , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@PRICE" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@AMOUNT" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@TAX" , DbType . Decimal , tax ) ;
db . ExecuteNonQuery ( cmdUpdateInvDetail , tran ) ;
}
else
{
cmdInsertInvDetail . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsertInvDetail , "@GID" , DbType . String , Guid . NewGuid ( ) . ToString ( ) ) ;
db . AddInParameter ( cmdInsertInvDetail , "@PID" , DbType . String , GID ) ;
db . AddInParameter ( cmdInsertInvDetail , "@SerialNo" , DbType . Int32 , 1 ) ;
if ( defGOOD . GOODNAME = = "" )
{
db . AddInParameter ( cmdInsertInvDetail , "@GOODSNAME" , DbType . String , "代理运杂费" ) ;
db . AddInParameter ( cmdInsertInvDetail , "@UNIT" , DbType . String , "票" ) ;
}
else
{
db . AddInParameter ( cmdInsertInvDetail , "@GOODSNAME" , DbType . String , defGOOD . GID ) ;
db . AddInParameter ( cmdInsertInvDetail , "@UNIT" , DbType . String , defGOOD . UNIT ) ;
}
db . AddInParameter ( cmdInsertInvDetail , "@SPEC" , DbType . String , defGOOD . SPEC ) ;
db . AddInParameter ( cmdInsertInvDetail , "@PKGS" , DbType . Decimal , 1 ) ;
db . AddInParameter ( cmdInsertInvDetail , "@TAXPRICE" , DbType . Decimal , amtttl ) ;
db . AddInParameter ( cmdInsertInvDetail , "@TAXRATE" , DbType . Decimal , acctaxrate ) ;
if ( acctaxrate = = 0 )
{
db . AddInParameter ( cmdInsertInvDetail , "@PRICE" , DbType . Decimal , amtttl ) ;
db . AddInParameter ( cmdInsertInvDetail , "@AMOUNT" , DbType . Decimal , amtttl ) ;
db . AddInParameter ( cmdInsertInvDetail , "@TAX" , DbType . Decimal , 0 ) ;
}
else
{
var tax = Math . Round ( amtttl / ( 1 + acctaxrate / 100 ) * ( acctaxrate / 100 ) , 2 , MidpointRounding . AwayFromZero ) ;
var amount = amtttl - tax ;
// var amount = Math.Round(amtttl / (1 + acctaxrate / 100),2);
db . AddInParameter ( cmdInsertInvDetail , "@PRICE" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInvDetail , "@AMOUNT" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInvDetail , "@TAX" , DbType . Decimal , tax ) ;
}
db . AddInParameter ( cmdInsertInvDetail , "@Remark" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsertInvDetail , "@GOODCODE" , DbType . String , defGOOD . GOODCODE ) ;
db . ExecuteNonQuery ( cmdInsertInvDetail , tran ) ;
}
db . AddInParameter ( cmdUpdateInv , "@REMARK" , DbType . String , REMARK ) ;
db . ExecuteNonQuery ( cmdUpdateInv , tran ) ;
}
tran . Commit ( ) ;
}
catch ( Exception )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "保存出现错误,请重试或联系系统管理员" ;
return result ;
}
}
result . Success = true ;
result . Message = "保存成功" + result . Message ;
return result ;
}
public static DBResult AddAppDetail ( string billno , List < ChInvoiceapplication > bodyList , string invoiceno , string companyid , string GID )
public static DBResult AddAppDetail ( string billno , List < ChInvoiceapplication > bodyList , string invoiceno , string companyid , string GID )
{
{
var result = new DBResult ( ) ;
var result = new DBResult ( ) ;