You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

343 lines
15 KiB

using CK.SCP.Models;
using CK.SCP.Models.ExchangeCenterTables;
using CK.SCP.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity.Migrations;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CK.SCP.Controller
{
public class UN_EC_CONTROLLER_INVOICE
{
public static void Get_TED_INVOICE_MSTR_List(TED_INVOICE_MSTR p_entity, Action<ResultObject<IQueryable<TED_INVOICE_MSTR>>> p_action)
{
ResultObject<IQueryable<TED_INVOICE_MSTR>> _ret = new ResultObject<IQueryable<TED_INVOICE_MSTR>>();
try
{
using (var db = EntitiesFactory.CreateExchangeCenterInstance())
{
IQueryable<TED_INVOICE_MSTR> q = db.TED_INVOICE_MSTR;
if (!string.IsNullOrEmpty(p_entity.Status))
{
q = q.Where(p => p.Status.Contains(p_entity.Status));
}
if (p_entity.Invoice_ID != 0)
{
q = q.Where(p => p.Invoice_ID == p_entity.Invoice_ID);
}
if (!string.IsNullOrEmpty(p_entity.InvoiceReference))
{
q = q.Where(p => p.InvoiceReference.Contains(p_entity.InvoiceReference));
}
if (!string.IsNullOrEmpty(p_entity.PurchaseOrder))
{
q = q.Where(p => p.PurchaseOrder.Contains(p_entity.PurchaseOrder));
}
if (!string.IsNullOrEmpty(p_entity.ReceiveNbr))
{
q = q.Where(p => p.ReceiveNbr.Contains(p_entity.ReceiveNbr));
}
if (p_entity.CreateInvoice != false)
{
q = q.Where(p => p.CreateInvoice == p_entity.CreateInvoice);
}
if (!string.IsNullOrEmpty(p_entity.Supplier))
{
q = q.Where(p => p.Supplier.Contains(p_entity.Supplier));
}
if (!string.IsNullOrEmpty(p_entity.SupplierName))
{
q = q.Where(p => p.SupplierName.Contains(p_entity.SupplierName));
}
if (!string.IsNullOrEmpty(p_entity.AddressStreet1))
{
q = q.Where(p => p.AddressStreet1.Contains(p_entity.AddressStreet1));
}
if (!string.IsNullOrEmpty(p_entity.AddressStreet2))
{
q = q.Where(p => p.AddressStreet2.Contains(p_entity.AddressStreet2));
}
if (!string.IsNullOrEmpty(p_entity.AddressStreet3))
{
q = q.Where(p => p.AddressStreet3.Contains(p_entity.AddressStreet3));
}
if (!string.IsNullOrEmpty(p_entity.City))
{
q = q.Where(p => p.City.Contains(p_entity.City));
}
if (!string.IsNullOrEmpty(p_entity.StateCode))
{
q = q.Where(p => p.StateCode.Contains(p_entity.StateCode));
}
if (!string.IsNullOrEmpty(p_entity.ZIP))
{
q = q.Where(p => p.ZIP.Contains(p_entity.ZIP));
}
if (!string.IsNullOrEmpty(p_entity.Format))
{
q = q.Where(p => p.Format.Contains(p_entity.Format));
}
if (!string.IsNullOrEmpty(p_entity.Country))
{
q = q.Where(p => p.Country.Contains(p_entity.Country));
}
if (!string.IsNullOrEmpty(p_entity.County))
{
q = q.Where(p => p.County.Contains(p_entity.County));
}
if (!string.IsNullOrEmpty(p_entity.Currency))
{
q = q.Where(p => p.Currency.Contains(p_entity.Currency));
}
if (!string.IsNullOrEmpty(p_entity.OwnBank))
{
q = q.Where(p => p.OwnBank.Contains(p_entity.OwnBank));
}
if (!string.IsNullOrEmpty(p_entity.PaymentCondCode))
{
q = q.Where(p => p.PaymentCondCode.Contains(p_entity.PaymentCondCode));
}
if (!string.IsNullOrEmpty(p_entity.InvoiceControlGLCode))
{
q = q.Where(p => p.InvoiceControlGLCode.Contains(p_entity.InvoiceControlGLCode));
}
if (!string.IsNullOrEmpty(p_entity.InvoiceCostCentreCode))
{
q = q.Where(p => p.InvoiceCostCentreCode.Contains(p_entity.InvoiceCostCentreCode));
}
if (!string.IsNullOrEmpty(p_entity.InvoiceDiscountGLCode))
{
q = q.Where(p => p.InvoiceDiscountGLCode.Contains(p_entity.InvoiceDiscountGLCode));
}
if (!string.IsNullOrEmpty(p_entity.InvoiceDiscountCostCentre))
{
q = q.Where(p => p.InvoiceDiscountCostCentre.Contains(p_entity.InvoiceDiscountCostCentre));
}
if (!string.IsNullOrEmpty(p_entity.CompanyCode))
{
q = q.Where(p => p.CompanyCode.Contains(p_entity.CompanyCode));
}
if (!string.IsNullOrEmpty(p_entity.InvoiceRemark))
{
q = q.Where(p => p.InvoiceRemark.Contains(p_entity.InvoiceRemark));
}
if (!string.IsNullOrEmpty(p_entity.InvoiceBankNbr))
{
q = q.Where(p => p.InvoiceBankNbr.Contains(p_entity.InvoiceBankNbr));
}
if (!string.IsNullOrEmpty(p_entity.InvoiceCheckForm))
{
q = q.Where(p => p.InvoiceCheckForm.Contains(p_entity.InvoiceCheckForm));
}
if (p_entity.InvoiceIsHoldAmount != false)
{
q = q.Where(p => p.InvoiceIsHoldAmount == p_entity.InvoiceIsHoldAmount);
}
if (p_entity.InvoiceHoldAmountTC != 0)
{
q = q.Where(p => p.InvoiceHoldAmountTC == p_entity.InvoiceHoldAmountTC);
}
if (p_entity.InvoiceIsStatusFinal != false)
{
q = q.Where(p => p.InvoiceIsStatusFinal == p_entity.InvoiceIsStatusFinal);
}
if (!string.IsNullOrEmpty(p_entity.InvoiceDivisionCode))
{
q = q.Where(p => p.InvoiceDivisionCode.Contains(p_entity.InvoiceDivisionCode));
}
if (!string.IsNullOrEmpty(p_entity.InvoiceDiscountDivision))
{
q = q.Where(p => p.InvoiceDiscountDivision.Contains(p_entity.InvoiceDiscountDivision));
}
if (!string.IsNullOrEmpty(p_entity.Rowid))
{
q = q.Where(p => p.Rowid.Contains(p_entity.Rowid));
}
if (!string.IsNullOrEmpty(p_entity.ParentRowid))
{
q = q.Where(p => p.ParentRowid.Contains(p_entity.ParentRowid));
}
if (p_entity.InvoicePostingYear != 0)
{
q = q.Where(p => p.InvoicePostingYear == p_entity.InvoicePostingYear);
}
if (!string.IsNullOrEmpty(p_entity.JournalCode))
{
q = q.Where(p => p.JournalCode.Contains(p_entity.JournalCode));
}
if (p_entity.InvoiceVoucher != 0)
{
q = q.Where(p => p.InvoiceVoucher == p_entity.InvoiceVoucher);
}
if (p_entity.APMatchingIsStatusFinal != false)
{
q = q.Where(p => p.APMatchingIsStatusFinal == p_entity.APMatchingIsStatusFinal);
}
if (p_entity.InvoiceRegistrationNbr != 0)
{
q = q.Where(p => p.InvoiceRegistrationNbr == p_entity.InvoiceRegistrationNbr);
}
if (!string.IsNullOrEmpty(p_entity.InvoiceTSMNumber))
{
q = q.Where(p => p.InvoiceTSMNumber.Contains(p_entity.InvoiceTSMNumber));
}
if (p_entity.CreateWithAmountIsTax != false)
{
q = q.Where(p => p.CreateWithAmountIsTax == p_entity.CreateWithAmountIsTax);
}
if (p_entity.InvoiceAmountTC != 0)
{
q = q.Where(p => p.InvoiceAmountTC == p_entity.InvoiceAmountTC);
}
if (p_entity.InvoiceIsTaxable != false)
{
q = q.Where(p => p.InvoiceIsTaxable == p_entity.InvoiceIsTaxable);
}
if (p_entity.UID != 0)
{
q = q.Where(p => p.UID == p_entity.UID);
}
if (!string.IsNullOrEmpty(p_entity.CreateUser))
{
q = q.Where(p => p.CreateUser.Contains(p_entity.CreateUser));
}
if (!string.IsNullOrEmpty(p_entity.Remark))
{
q = q.Where(p => p.Remark.Contains(p_entity.Remark));
}
if (!string.IsNullOrEmpty(p_entity.CommandType))
{
q = q.Where(p => p.CommandType.Contains(p_entity.CommandType));
}
if (!string.IsNullOrEmpty(p_entity.Domain))
{
q = q.Where(p => p.Domain.Contains(p_entity.Domain));
}
if (!string.IsNullOrEmpty(p_entity.Site))
{
q = q.Where(p => p.Site.Contains(p_entity.Site));
}
if (!string.IsNullOrEmpty(p_entity.CInvoiceReference))
{
q = q.Where(p => p.CInvoiceReference.Contains(p_entity.CInvoiceReference));
}
if (!string.IsNullOrEmpty(p_entity.CInvoiceDescription))
{
q = q.Where(p => p.CInvoiceDescription.Contains(p_entity.CInvoiceDescription));
}
if (!string.IsNullOrEmpty(p_entity.CInvoiceType))
{
q = q.Where(p => p.CInvoiceType.Contains(p_entity.CInvoiceType));
}
if (!string.IsNullOrEmpty(p_entity.CInvoiceCostCenterCode))
{
q = q.Where(p => p.CInvoiceCostCenterCode.Contains(p_entity.CInvoiceCostCenterCode));
}
if (!string.IsNullOrEmpty(p_entity.CInvoiceDivisionCode))
{
q = q.Where(p => p.CInvoiceDivisionCode.Contains(p_entity.CInvoiceDivisionCode));
}
_ret.Result = q;
_ret.State = ReturnStatus.Succeed;
p_action(_ret);
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TED_INVOICE_MSTR), "Get_TED_INVOICE_MSTR_List", e.Message);
throw e;
}
}
public static DataTable Get_TED_INVOICE_MSTR_List( string p_tableName, string p_TaskID)
{
DataTable dt = new DataTable(); ;
var dbSetting = GlobalConfig.ExchangeCenterDB;
try
{
var strConn = EntitiesFactory.GetEfConnectionString(dbSetting);
SqlConnection conn = new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = strConn;
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
string _sql = string.Format("select * from {0} where TaskID='{1}'", p_tableName, p_TaskID);
cmd.CommandText = _sql;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(dt);
}
catch (SqlException ex)
{
throw new Exception($"系统无法连接到数据库:{dbSetting},请检查配置的服务器,数据库,用户名和密码等信息是否正确。{Environment.NewLine}{ex}");
}
return dt;
}
public static ResultObject<bool> Save_TED_INVOICE_DET(int p_listUid, Decimal MatchQuantity, Decimal MatchPrice)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (var db = EntitiesFactory.CreateExchangeCenterInstance())
{
var _lst = db.TED_INVOICE_DET.Where(p => p.UID == p_listUid).ToList();
foreach (var itm in _lst)
{
itm.MatchPrice = MatchPrice;
itm.MatchQuantity = MatchQuantity;
db.TED_INVOICE_DET.AddOrUpdate(itm);
}
if (db.SaveChanges() != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TED_INVOICE_MSTR), "Save_TED_INVOICE_MSTR", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
}
}