Skip to content

Commit

Permalink
#59124
Browse files Browse the repository at this point in the history
1.新增開立線上折讓範例
2.修正資料驗證過程中發生型別轉換失敗
  • Loading branch information
adelachang0418 committed Nov 11, 2019
1 parent e98ae73 commit 2b43977
Show file tree
Hide file tree
Showing 172 changed files with 803 additions and 63 deletions.
20 changes: 20 additions & 0 deletions ECPay.Einvoice.Integration/Attributes/NeedReplaceAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ecpay.EInvoice.Integration.Attributes
{

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
internal class NeedReplaceAttribute: Attribute
{
/// <summary>
/// 表示需要Replace動作。
/// </summary>
public NeedReplaceAttribute()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel.DataAnnotations;
using Ecpay.EInvoice.Integration.Enumeration;
using System.Text.RegularExpressions;
using Ecpay.EInvoice.Integration.Models;

namespace Ecpay.EInvoice.Integration.Attributes
{
Expand All @@ -19,23 +20,30 @@ public RequiredByTaxTypeAttribute() : base() { }

public override bool IsValid(object value)
{
PropertyDescriptorCollection pdcProperties = null;
PropertyDescriptorCollection pdcTaxType = null;
PropertyDescriptorCollection pdcItems = null;

object[] oValues = (object[])value;

object oPropertyName = oValues[0]; // 屬性的名稱。
object oPropertyValue = oValues[1]; // 屬性的值。
var oSourceComponent = (Ecpay.EInvoice.Integration.Models.InvoiceCreate)oValues[2]; // 該屬性所屬物件。
object oSourceComponent = oValues[2]; // 該屬性所屬物件。

//特殊驗證:當稅別為零稅率時(ZeroTaxRate),通關方式只能為非經海關出口或經海關出口。
// 當稅別為非零稅率時,通關方式為無。
if (oPropertyName.Equals("ClearanceMark"))
{
var oTaxType = oSourceComponent.TaxType;
var sItemTaxType = oSourceComponent.ItemTaxType;
object oTaxType = null;
ItemCollection oItems = null;

pdcTaxType = TypeDescriptor.GetProperties(oSourceComponent);
pdcItems = TypeDescriptor.GetProperties(oSourceComponent);

oTaxType = pdcTaxType.Find("TaxType", true).GetValue(oSourceComponent);
oItems = (ItemCollection)pdcTaxType.Find("Items", true).GetValue(oSourceComponent);

//#55880 修改為和API同樣判斷邏輯
if (oTaxType.Equals(TaxTypeEnum.ZeroTaxRate) || Regex.IsMatch(sItemTaxType, "[2]{1}"))
if (oTaxType.Equals(TaxTypeEnum.ZeroTaxRate) || oItems.Exists(i=> Regex.IsMatch(i.ItemTaxType??"", "[2]{1}")))
{
if (!(oPropertyValue.Equals(CustomsClearanceMarkEnum.No) || oPropertyValue.Equals(CustomsClearanceMarkEnum.Yes)))
{
Expand Down
11 changes: 2 additions & 9 deletions ECPay.Einvoice.Integration/Ecpay.Einvoice.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@
<Compile Include="Models\AllowanceReturn.cs" />
<Compile Include="Models\InvoiceLoveCode.cs" />
<Compile Include="Models\MobileBarcode.cs" />
<Compile Include="Resource\ApiUrl.Beta.Resource.Designer.cs">
<DependentUpon>ApiUrl.Beta.Resource.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Models\AllowanceByCollegiate.cs" />
<Compile Include="Models\AllowanceByCollegiateReturn.cs" />
<Compile Include="Service\ApiUrlModel.cs" />
<Compile Include="Interface\Iinvoice.cs" />
<Compile Include="Models\InvoiceCreateReturn.cs" />
Expand Down Expand Up @@ -150,10 +147,6 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ApiUrl.Dev.Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resource\ApiUrl.Beta.Resource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ApiUrl.Beta.Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum AllowanceNotifyEnum
/// <summary>
/// 皆不通知
/// </summary>
[Text("E")]
[Text("N")]
None
}
}
7 changes: 1 addition & 6 deletions ECPay.Einvoice.Integration/Enumeration/EnvironmentEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ public enum EnvironmentEnum
/// <summary>
/// 正式環境
/// </summary>
Prod,

/// <summary>
/// 正式環境
/// </summary>
Beta
Prod
}
}
5 changes: 4 additions & 1 deletion ECPay.Einvoice.Integration/Enumeration/InvoiceMethodEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ public enum InvoiceMethodEnum
[Description("觸發延遲開立發票")]
InvoiceTrigger,

[Description("折讓發票")]
[Description("折讓發票(紙本)")]
Allowance,

[Description("折讓發票(線上)")]
AllowanceByCollegiate,

[Description("折讓發票作廢")]
AllowanceInvalid,

Expand Down
12 changes: 6 additions & 6 deletions ECPay.Einvoice.Integration/Enumeration/TheWordTypeEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public enum TheWordTypeEnum : int
/// 一般稅額
/// </summary>
[Text("07")]
Normal = 7,
Normal = 7

/// <summary>
/// 特種稅額
/// </summary>
[Text("08")]
Special = 8
///// <summary>
///// 特種稅額
///// </summary>
//[Text("08")]
//Special = 8
}
}
26 changes: 13 additions & 13 deletions ECPay.Einvoice.Integration/Models/Allowance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ InvoiceMethodEnum Iinvoice.invM
/// 廠商編號(必填)
/// </summary>
[Required(ErrorMessage = "{0} is required.")]
[StringLength(10, ErrorMessage = "{0} max langth as {1}.")]
[StringLength(10, ErrorMessage = "{0} max length is {1}.")]
public string MerchantID { get { return _MerchantID; } set { _MerchantID = value; } }

/// <summary>
Expand All @@ -62,19 +62,19 @@ InvoiceMethodEnum Iinvoice.invM
/// ->若為皆不通知時,則VAL = 'None'
/// ‧如無填寫或空值 ->預設值為Email(電子郵件)
/// </summary>
[Required(ErrorMessage = "{0} is required.")]
[Required(ErrorMessage = "{0} is required.")]
[NonProcessValue]
public AllowanceNotifyEnum allowanceNotify { set { _AllowanceNotify = value; } get { return _AllowanceNotify; } }

[Required(ErrorMessage = "{0} is required.")]
[Required(ErrorMessage = "{0} is required.")]
internal string AllowanceNotify { get { return _AllowanceNotify.ToText(); } }

/// <summary>
/// 客戶名稱(選填) ‧若客戶名稱有值時,則 ->僅能為中英數字格式
/// ->預設最大長度為30碼
/// </summary>
[StringLength(30, ErrorMessage = "{0} max length as {1}.")]
[RegularExpression(@"^[0-9a-zA-Z\u0391-\uFFE5]+$", ErrorMessage = "{0} is incorrect format.")]
[StringLength(30, ErrorMessage = "{0} max length is {1}.")]
[RegularExpression(@"^[0-9a-zA-Z\u0391-\uFFE5]+$", ErrorMessage = "The format of {0} is incorrect.")]
[NeedEncode]
public string CustomerName { get { return _CustomerName; } set { _CustomerName = value; } }

Expand All @@ -84,27 +84,27 @@ InvoiceMethodEnum Iinvoice.invM
/// ‧補充說明(下述情況通知手機號碼不可為空值) ->通知電子信箱為空值
/// ->通知類別為-簡訊
/// </summary>
[RegularExpression(@"^[0-9]+$", ErrorMessage = "{0} is incorrect format.")]
[StringLength(20, ErrorMessage = "{0} max length as {1}.")]
[RequiredByAllowanceNotify(ErrorMessage = "Phone number and e-mail in which a required,or select a incorrect notify type.")]
[RegularExpression(@"^[0-9]+$", ErrorMessage = "The format of {0} is incorrect.")]
[StringLength(20, ErrorMessage = "{0} max length is {1}.")]
[RequiredByAllowanceNotify(ErrorMessage = "NotifyPhone is required in case of AllowanceNotify is A or S.")]
public string NotifyPhone { get { return _NotifyPhone; } set { _NotifyPhone = value; } }

/// <summary>
/// 客戶電子信箱(選填) ‧若客戶電子信箱有值時,則 ->格式僅能為Email的標準格式
/// ‧補充說明(下述情況通知電子信箱不可為空值) ->通知手機號碼為空值
/// ->通知類別為-電子郵件
/// </summary>
[StringLength(80, ErrorMessage = "{0} max length as {1}.")]
[RegularExpression(@"^[^\s]+@[^\s]+\.[^\s]+$", ErrorMessage = "{0} is incorrect format.")]
[RequiredByAllowanceNotify(ErrorMessage = "Phone number and e-mail in which a required,or select a incorrect notify type.")]
/// </summary>
[StringLength(80, ErrorMessage = "{0} max length is {1}.")]
[RegularExpression(@"^[^\s]+@[^\s]+\.[^\s]+$", ErrorMessage = "The format of {0} is incorrect.")]
[RequiredByAllowanceNotify(ErrorMessage = "NotifyMail is required in case of AllowanceNotify is A or E.")]
[NeedEncode]
public string NotifyMail { get { return _NotifyMail; } set { _NotifyMail = value; } }

/// <summary>
/// 折讓單總金額(必填) ‧含稅總金額
/// </summary>
[Required(ErrorMessage = "{0} is required.")]
[RegularExpression("^[0-9]+$", ErrorMessage = "{0} is incorrect format.")]
[RegularExpression("^[0-9]+$", ErrorMessage = "The format of {0} is incorrect.")]
public string AllowanceAmount { get { return _AllowanceAmount; } set { _AllowanceAmount = value; } }

/// <summary>
Expand Down
169 changes: 169 additions & 0 deletions ECPay.Einvoice.Integration/Models/AllowanceByCollegiate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
using System;
using System.ComponentModel.DataAnnotations;
using Ecpay.EInvoice.Integration.Attributes;
using Ecpay.EInvoice.Integration.Enumeration;
using Ecpay.EInvoice.Integration.Interface;
using Ecpay.EInvoice.Integration.Service;

namespace Ecpay.EInvoice.Integration.Models
{
/// <summary>
/// 開立折讓
/// </summary>
public class AllowanceByCollegiate : Iinvoice
{
private int _TimeStamp = Convert.ToInt32((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000);
private string _MerchantID = string.Empty;
private string _InvoiceNo = string.Empty;
private AllowanceNotifyEnum _AllowanceNotify = AllowanceNotifyEnum.Email;
private string _CustomerName = string.Empty;
private string _NotifyMail = string.Empty;
private string _NotifyPhone = string.Empty;
private string _AllowanceAmount = string.Empty;
private ItemCollection _Items;
private string _ReturnURL = string.Empty;

public AllowanceByCollegiate()
{
this.Items = new ItemCollection();
}

/// <summary>
/// 發票類別(自動產生)
/// </summary>
[NonProcessValueAttribute]
InvoiceMethodEnum Iinvoice.invM
{
get { return InvoiceMethodEnum.AllowanceByCollegiate; }
}

/// <summary>
/// 廠商編號(必填)
/// </summary>
[Required(ErrorMessage = "{0} is required.")]
[StringLength(10, ErrorMessage = "{0} max length is {1}.")]
public string MerchantID { get { return _MerchantID; } set { _MerchantID = value; } }

/// <summary>
/// 廠商驗證時間(自動產生)
/// </summary>
internal int TimeStamp { get { return _TimeStamp; } private set { _TimeStamp = value; } }

/// <summary>
/// 發票號碼(必填) ‧預設長度固定10碼
/// </summary>
[Required(ErrorMessage = "{0} is required.")]
[RegularExpression(@"^[A-Z]{2}[0-9]{8}$", ErrorMessage = "{0} is incorrect format.")]
public string InvoiceNo { get { return _InvoiceNo; } set { _InvoiceNo = value; } }

/// <summary>
/// 通知類別(必填) ‧固定給定下述預設值
/// ->若為電子郵件時,則VAL = 'Email'
/// ->若為皆通知時,則VAL = 'All'
/// ->若為皆不通知時,則VAL = 'None'
/// ‧如無填寫或空值 ->預設值為Email(電子郵件)
/// </summary>
[Required(ErrorMessage = "{0} is required.")]
[NonProcessValue]
public AllowanceNotifyEnum allowanceNotify { set { _AllowanceNotify = value; } get { return _AllowanceNotify; } }

[Required(ErrorMessage = "{0} is required.")]
internal string AllowanceNotify { get { return _AllowanceNotify.ToText(); } }

/// <summary>
/// 客戶名稱(選填) ‧若客戶名稱有值時,則 ->僅能為中英數字格式
/// ->預設最大長度為30碼
/// </summary>
[StringLength(30, ErrorMessage = "{0} max length is {1}.")]
[RegularExpression(@"^[0-9a-zA-Z\u0391-\uFFE5]+$", ErrorMessage = "The format of {0} is incorrect.")]
[NeedEncode]
public string CustomerName { get { return _CustomerName; } set { _CustomerName = value; } }

/// <summary>
/// 客戶手機號碼(選填) ‧若客戶手機號碼有值時,則 ->預設格式為數字組成
/// ->預設最小長度為1碼,最大長度為20碼
/// ‧補充說明(下述情況通知手機號碼不可為空值) ->通知電子信箱為空值
/// ->通知類別為-簡訊
/// </summary>
[RegularExpression(@"^[0-9]+$", ErrorMessage = "The format of {0} is incorrect.")]
[StringLength(20, ErrorMessage = "{0} max length is {1}.")]
[RequiredByAllowanceNotify(ErrorMessage = "NotifyPhone is required in case of AllowanceNotify is A or S.")]
public string NotifyPhone { get { return _NotifyPhone; } set { _NotifyPhone = value; } }

/// <summary>
/// 客戶電子信箱(選填) ‧若客戶電子信箱有值時,則 ->格式僅能為Email的標準格式
/// ‧補充說明(下述情況通知電子信箱不可為空值) ->通知手機號碼為空值
/// ->通知類別為-電子郵件
/// </summary>
[Required(ErrorMessage = "{0} is required.")]
[StringLength(80, ErrorMessage = "{0} max length is {1}.")]
[RegularExpression(@"^[^\s]+@[^\s]+\.[^\s]+$", ErrorMessage = "The format of {0} is incorrect.")]
[NeedEncode]
public string NotifyMail { get { return _NotifyMail; } set { _NotifyMail = value; } }

/// <summary>
/// 折讓單總金額(必填) ‧含稅總金額
/// </summary>
[Required(ErrorMessage = "{0} is required.")]
[RegularExpression("^[0-9]+$", ErrorMessage = "The format of {0} is incorrect.")]
public string AllowanceAmount { get { return _AllowanceAmount; } set { _AllowanceAmount = value; } }

/// <summary>
/// 商品名稱(自動產生) ‧預設格式如下 名稱1 | 名稱2 | 名稱3 | … | 名稱n
/// ‧若含二筆或以上的商品名稱時,則以「|」符號區隔
/// </summary>
[NeedEncode]
internal string ItemName { get { return _Items.ItemName; } }

/// <summary>
/// 商品數量(自動產生) ‧預設格式如下 數量1 | 數量2 | 數量3 | … | 數量n
/// ‧若含二筆或以上的商品數量時,則以「|」符號區隔
/// </summary>
internal string ItemCount { get { return _Items.ItemCount; } }

/// <summary>
/// 商品單位(自動產生) ‧預設格式如下 單位1 | 單位2 | 單位3 | … | 單位n
/// ‧若含二筆或以上的商品單位時,則以「|」符號區隔
/// ‧預設最大長度為6碼
/// </summary>
[NeedEncode]
internal string ItemWord { get { return _Items.ItemWord; } }

/// <summary>
/// 商品價格(自動產生) ‧預設格式如下 價格1 | 價格2 | 價格3 | … | 價格n
/// ‧若含二筆或以上的商品價格時,則以「|」符號區隔
/// ‧含稅單價金額
/// </summary>
internal string ItemPrice { get { return _Items.ItemPrice; } }

/// <summary>
/// 商品課稅別(自動產生) ‧預設格式如下 課稅類別1 |課稅類別2 |課稅類別3 | … |課稅類別n
/// ‧若含二筆或以上的商品課稅別時,則以「|」符號區隔
/// ‧課稅類別需混合應稅與免稅,TaxType = 9時
/// ‧商品課稅別固定給定下述預設值 ->若為應稅時,則VAL = '1' ->若為免稅時,則VAL = '3'
/// ‧需含二筆或以上的商品課稅別,且至少需有一筆商品課稅別為應稅及至少需有一筆商品課稅別為免稅
/// </summary>
internal string ItemTaxType { get { return _Items.ItemTaxType; } }

/// <summary>
/// 商品合計(自動產生) ‧預設格式如下 合計1 | 合計2 | 合計3 | … | 合計n
/// ‧若含二筆或以上的商品合計時,則以「|」符號區隔
/// ‧含稅小計金額
/// </summary>
internal string ItemAmount { get { return _Items.ItemAmount; } }

/// <summary>
/// 商品資訊的集合類別(必填)
/// </summary>
public ItemCollection Items { get { return _Items; } set { _Items = value; } }

/// <summary>
/// 消費者同意後回傳網址(選填) ‧預設最大長度為200碼
/// 當消費者點選同意後,綠界會將成功的結果參數以幕後(Server POST)回傳到該網址。
/// 注意事項:
/// 請在收到 Server 端折讓成功結果通知後,請正確回應 1|OK 給綠界。
/// </summary>
[StringLength(200, ErrorMessage = "{0} max length is {1}.")]
public string ReturnURL { get { return _ReturnURL; } set { _ReturnURL = value; } }
}
}
Loading

0 comments on commit 2b43977

Please sign in to comment.