Esempio n. 1
0
        public static void Upload(List <TWNGUITrans> tWNGUITrans)
        {
            try
            {
                // Avoid to create empty content file in automation schedule.
                if (tWNGUITrans.Count == 0)
                {
                    return;
                }

                TWNExpOnlineStrGUIInv graph    = CreateInstance <TWNExpOnlineStrGUIInv>();
                TWNExpGUIInv2BankPro  invGraph = CreateInstance <TWNExpGUIInv2BankPro>();

                string lines = "", fileName = "";

                TWNGUIPreferences preferences = PXSelect <TWNGUIPreferences> .Select(graph);

                fileName = preferences.OurTaxNbr + "-O-" + DateTime.Today.ToString("yyyyMMdd") + "-" + DateTime.Now.ToString("hhmmss") + ".txt";

                foreach (TWNGUITrans gUITrans in tWNGUITrans)
                {
                    // 主檔代號
                    lines += "M" + verticalBar;
                    // 訂單編號
                    lines += gUITrans.OrderNbr + verticalBar;
                    // 訂單狀態
                    lines += ((gUITrans.VATType != TWGUIFormatCode.vATOutCode33) ? "0" : "3") + verticalBar;
                    // 訂單日期
                    lines += gUITrans.TransDate.Value.ToString("yyyy/MM/dd") + verticalBar;
                    // 預計出貨日
                    lines += gUITrans.GUIDate.Value.ToString("yyyy/MM/dd") + verticalBar;
                    // 稅率別 -> 1:應稅 2:零稅率 3:免稅 4:特殊稅率(需帶36 & 37欄位)
                    lines += (gUITrans.GUIFormatcode.IsIn(TWGUIFormatCode.vATOutCode36, TWGUIFormatCode.vATOutCode37)) ? "4" : TWNExpGUIInv2BankPro.GetTaxType(gUITrans.VATType) + verticalBar;
                    // 訂單金額(未稅)
                    lines += gUITrans.NetAmount + verticalBar;
                    // 訂單稅額
                    lines += gUITrans.TaxAmount + verticalBar;
                    // 訂單金額(含稅)
                    lines += (gUITrans.NetAmount + gUITrans.TaxAmount) + verticalBar;
                    // 賣方統一編號
                    lines += gUITrans.OurTaxNbr + verticalBar;
                    // 賣方廠編
                    lines += verticalBar;
                    // 買方統一編號
                    lines += gUITrans.TaxNbr + verticalBar;
                    // 買受人公司名稱
                    lines += verticalBar;
                    // 會員編號
                    lines += gUITrans.CustVend + verticalBar;
                    // 會員姓名
                    // 會員郵遞區號
                    // 會員地址
                    // 會員電話
                    lines += new string(char.Parse(verticalBar), 4);
                    // 會員行動電話
                    PX.Objects.AR.Customer customer = PXSelectReadonly <PX.Objects.AR.Customer, Where <PX.Objects.AR.Customer.acctCD, Equal <Required <PX.Objects.AR.Customer.acctCD> > > > .Select(graph, gUITrans.CustVend);

                    PX.Objects.CR.CRContact contact = PX.Objects.CR.CRContact.PK.Find(graph, PX.Objects.AR.Customer.PK.Find(graph, customer.BAccountID).DefContactID);

                    lines += contact?.Phone1 + verticalBar;
                    // 會員電子郵件
                    lines += contact?.Email + verticalBar;
                    // 紅利點數折扣金額
                    lines += verticalBar;
                    // 索取紙本發票
                    lines += "N" + verticalBar;
                    // 發票捐贈註記
                    lines += gUITrans.NPONbr + verticalBar;
                    // 訂單註記
                    // 付款方式
                    // 相關號碼1(出貨單號)
                    lines += new string(char.Parse(verticalBar), 3);
                    // 相關號碼2
                    lines += gUITrans.BatchNbr + verticalBar;
                    // 相關號碼3
                    // 主檔備註
                    // 商品名稱
                    lines += new string(char.Parse(verticalBar), 3);
                    // 載具類別號碼
                    lines += gUITrans.CarrierType + verticalBar;
                    // 載具顯碼id1(明碼)
                    lines += gUITrans.CarrierID + verticalBar;
                    // 載具隱碼id2(內碼)
                    lines += verticalBar;
                    // 發票號碼
                    lines += gUITrans.GUINbr + verticalBar;
                    // 隨機碼
                    lines += gUITrans.OrderNbr.Substring(gUITrans.OrderNbr.Length - 4, 4) + verticalBar;
                    // 稅率代碼
                    // 稅率
                    lines += "0" + verticalBar + "\r\n";

                    int num = 1;
                    foreach (PXResult <PX.Objects.AR.ARTran> result in invGraph.RetrieveARTran(gUITrans.OrderNbr))
                    {
                        PX.Objects.AR.ARTran aRTran = result;

                        // 明細代號
                        lines += "D" + verticalBar;
                        // 序號
                        lines += num++ + verticalBar;
                        // 訂單編號
                        lines += aRTran.RefNbr + verticalBar;
                        // 商品編號
                        // 商品條碼
                        lines += new string(char.Parse(verticalBar), 2);
                        // 商品名稱
                        lines += aRTran.TranDesc + verticalBar;
                        // 商品規格
                        // 單位
                        // 單價
                        lines += new string(char.Parse(verticalBar), 3);
                        // 數量
                        lines += (aRTran.Qty == 0m ? 1 : aRTran.Qty) + verticalBar;
                        // 未稅金額
                        lines += verticalBar;
                        // 含稅金額
                        PX.Objects.AR.ARInvoice invoice = PX.Objects.AR.ARInvoice.PK.Find(graph, aRTran.TranType, aRTran.RefNbr);
                        lines += (invoice.TaxCalcMode != PX.Objects.TX.TaxCalculationMode.Gross ? aRTran.CuryTranAmt * (decimal)1.05 : aRTran.CuryTranAmt) + verticalBar;
                        // 健康捐
                        lines += "0" + verticalBar;
                        // 稅率別
                        lines += TWNExpGUIInv2BankPro.GetTaxType(gUITrans.VATType) + verticalBar;
                        // 紅利點數折扣金額
                        // 明細備註
                        lines += new string(char.Parse(verticalBar), 1) + "\r\n";
                    }

                    // The following method is only for voided invoice.
                    if (gUITrans.GUIStatus == TWNGUIStatus.Voided)
                    {
                        TWNExpGUIInv2BankPro.CreateVoidedDetailLine(verticalBar, gUITrans.OrderNbr, ref lines);
                    }
                }

                // Total Records
                lines += tWNGUITrans.Count;

                invGraph.UpdateGUITran(tWNGUITrans);
                invGraph.UploadFile2FTP(fileName, lines);
            }
            catch (Exception ex)
            {
                PXProcessing <TWNGUITrans> .SetError(ex);

                throw;
            }
        }
Esempio n. 2
0
        public static void Upload(List <TWNGUITrans> tWNGUITrans)
        {
            try
            {
                // Avoid to create empty content file in automation schedule.
                if (tWNGUITrans.Count == 0)
                {
                    return;
                }

                TWNExpGUIInv2BankPro graph = CreateInstance <TWNExpGUIInv2BankPro>();

                string lines = "", fileName = "";

                TWNGUIPreferences preferences = PXSelect <TWNGUIPreferences> .Select(graph);

                fileName = preferences.OurTaxNbr + "-AllowanceMD--Paper-" + DateTime.Today.ToString("yyyyMMdd") + "-" + DateTime.Now.ToString("hhmmss") + ".txt";

                foreach (TWNGUITrans gUITrans in tWNGUITrans)
                {
                    // File Type
                    lines += "M" + verticalBar;
                    // Bill type
                    lines += TWNExpGUIInv2BankPro.GetBillType(gUITrans) + verticalBar;
                    // Invoice No
                    lines += verticalBar;
                    // Invoice Date Time
                    lines += verticalBar;
                    // Allowance Date
                    lines += gUITrans.GUIDate.Value.ToString("yyyyMMdd") + verticalBar;
                    // Cancel Date
                    lines += TWNExpGUIInv2BankPro.GetCancelDate(gUITrans) + verticalBar;
                    // Bill Attribute
                    lines += verticalBar;
                    // Seller Ban
                    lines += gUITrans.OurTaxNbr + verticalBar;
                    // Seller Code
                    lines += verticalBar;
                    // Buyer Ban
                    lines += gUITrans.TaxNbr + verticalBar;
                    // Buyer Code
                    lines += verticalBar;
                    // Buyer CName
                    lines += gUITrans.GUITitle + verticalBar;
                    // Sales Amount
                    lines += TWNExpGUIInv2BankPro.GetSalesAmt(gUITrans) + verticalBar;
                    // Tax Type
                    lines += TWNExpGUIInv2BankPro.GetTaxType(gUITrans.VATType) + verticalBar;
                    // Tax Rate
                    lines += TWNExpGUIInv2BankPro.GetTaxRate(gUITrans.VATType) + verticalBar;
                    // Tax Amount
                    lines += TWNExpGUIInv2BankPro.GetTaxAmt(gUITrans) + verticalBar;
                    // Total Amount
                    lines += (gUITrans.NetAmount + gUITrans.TaxAmount).Value + verticalBar;
                    // Health Tax
                    lines += "0" + verticalBar;
                    // Buyer Remark
                    lines += verticalBar;
                    // Main Remark
                    lines += verticalBar;
                    // Order No = Relate Number1
                    lines += (gUITrans.OrderNbr.Length > 16) ? gUITrans.OrderNbr.Substring(0, 16) : gUITrans.OrderNbr + verticalBar;
                    // Relate Number2
                    // Relate Number3
                    // Relate Number4
                    // Relate Number5
                    // Group Mark
                    // Customs Clearance Mark
                    lines += new string(char.Parse(verticalBar), 5) + TWNExpGUIInv2BankPro.GetCustomClearance(gUITrans) + verticalBar;
                    // Bonded Area Enum
                    lines += verticalBar;
                    // Random Number
                    lines += (gUITrans.BatchNbr != null) ? gUITrans.BatchNbr.Substring(0, 4) : null;
                    // Carrier Type
                    // Carrier ID
                    // NPOBAN
                    // Request Paper
                    // Void Reason
                    // Project Number Void Approved
                    lines += new string(char.Parse(verticalBar), 6) + "\r\n";

                    foreach (PXResult <ARTran> result in graph.RetrieveARTran(gUITrans.OrderNbr))
                    {
                        ARTran aRTran = result;

                        // File Type
                        lines += "D" + verticalBar;
                        // Description
                        lines += aRTran.TranDesc + verticalBar;
                        // Quantity
                        lines += aRTran.Qty + verticalBar;
                        // Unit Price
                        // Amount
                        if (gUITrans.TaxNbr != null)
                        {
                            lines += aRTran.UnitPrice + verticalBar;
                            lines += aRTran.TranAmt + verticalBar;
                        }
                        else
                        {
                            lines += (aRTran.UnitPrice * TWNExpGUIInv2BankPro.fixedRate) + verticalBar;
                            lines += (aRTran.TranAmt * TWNExpGUIInv2BankPro.fixedRate) + verticalBar;
                        }
                        // Unit
                        lines += verticalBar;
                        // Package
                        lines += "0" + verticalBar;
                        // Gift Number 1 (Box)
                        lines += "0" + verticalBar;
                        // Gift Number 2 (Piece)
                        lines += "0" + verticalBar;
                        // Order No
                        lines += (gUITrans.OrderNbr.Length > 16) ? gUITrans.OrderNbr.Substring(0, 16) : gUITrans.OrderNbr + verticalBar;
                        // Buyer Barcode
                        // Buyer Prod No
                        // Seller Prod No
                        // Seller Account No
                        // Seller Shipping No
                        // Remark
                        // Relate Number1
                        // Relate Number2 (Invoice No)
                        lines += new string(char.Parse(verticalBar), 7) + gUITrans.GUINbr + verticalBar;
                        // Relate Number3 (Invoice Date)
                        // Relate Number4
                        // Relate Number5
                        lines += gUITrans.GUIDate.Value.ToString("yyyy/MM/dd HH:mm:ss");
                        lines += new string(char.Parse(verticalBar), 2) + "\r\n";
                    }

                    // The following method is only for voided invoice.
                    if (gUITrans.GUIStatus == TWNGUIStatus.Voided)
                    {
                        TWNExpGUIInv2BankPro.CreateVoidedDetailLine(verticalBar, gUITrans.OrderNbr, ref lines);
                    }
                }

                // Total Records
                lines += tWNGUITrans.Count;

                graph.UpdateGUITran(tWNGUITrans);
                graph.UploadFile2FTP(fileName, lines);
            }
            catch (Exception ex)
            {
                PXProcessing <TWNGUITrans> .SetError(ex);

                throw;
            }
        }