Ejemplo n.º 1
0
        public static string GetBillType(TWNGUITrans gUITran)
        {
            string billType = null;

            switch (gUITran.GUIFormatcode)
            {
            case TWGUIFormatCode.vATOutCode35:
            case TWGUIFormatCode.vATOutCode31:
                if (gUITran.GUIStatus == TWNGUIStatus.Used)
                {
                    billType = "O";
                }
                else if (gUITran.GUIStatus == TWNGUIStatus.Voided)
                {
                    billType = "C";
                }
                break;

            case TWGUIFormatCode.vATOutCode33:
                if (gUITran.GUIStatus == TWNGUIStatus.Used)
                {
                    billType = "A2";
                }
                else if (gUITran.GUIStatus == TWNGUIStatus.Voided)
                {
                    billType = "D";
                }
                break;
            }

            return(billType);
        }
Ejemplo n.º 2
0
        private string GetBuyerTaxID(TWNGUITrans tWNGUITrans)
        {
            if (tWNGUITrans.GUIFormatcode.StartsWith("2"))
            {
                return(tWNGUITrans.OurTaxNbr);
            }
            else if (tWNGUITrans.GUIFormatcode.StartsWith("3") &&
                     tWNGUITrans.GUIStatus != TWNGUIStatus.Voided)
            {
                return(tWNGUITrans.TaxNbr ?? new string(space, 8));
            }

            return(new string(space, 8));
        }
Ejemplo n.º 3
0
 public string GetGUINbr(TWNGUITrans tWNGUITrans)
 {
     if (tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode28))
     {
         return(tWNGUITrans.GUINbr.Substring(4, tWNGUITrans.GUINbr.Length - 4));
     }
     else if (string.IsNullOrEmpty(tWNGUITrans.GUINbr))
     {
         return(new string(space, 10));
     }
     else
     {
         return(tWNGUITrans.GUINbr.Substring(0, 10));
     }
 }
Ejemplo n.º 4
0
 private string GetSummaryRemark(TWNGUITrans tWNGUITrans)
 {
     if (tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode26) ||
         tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode27))
     {
         return("A");
     }
     else if (tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode25) && GetSellerTaxID(tWNGUITrans).Length != 8)
     {
         return("A");
     }
     else
     {
         return(new string(space, 1));
     }
 }
Ejemplo n.º 5
0
        public virtual void CheckCorrespondingInv(PXGraph graph, string gUINbr, string gUIFmtCode)
        {
            isCreditNote = false;

            switch (gUIFmtCode)
            {
            case TWGUIFormatCode.vATInCode23:
                tWNGUITrans = SelectFrom <TWNGUITrans> .Where <TWNGUITrans.gUINbr.IsEqual <@P.AsString>
                                                               .And <Where <TWNGUITrans.gUIFormatcode.IsEqual <@P.AsString>
                                                                            .Or <TWNGUITrans.gUIFormatcode.IsEqual <@P.AsString> > > > >
                              .View.ReadOnly.Select(graph, gUINbr, TWGUIFormatCode.vATInCode21, TWGUIFormatCode.vATInCode25);

                isCreditNote = (tWNGUITrans == null);
                break;

            case TWGUIFormatCode.vATInCode24:
                tWNGUITrans = SelectFrom <TWNGUITrans> .Where <TWNGUITrans.gUINbr.IsEqual <@P.AsString>
                                                               .And <TWNGUITrans.gUIFormatcode.IsEqual <@P.AsString> > >
                              .View.ReadOnly.Select(graph, gUINbr, TWGUIFormatCode.vATInCode22);

                isCreditNote = (tWNGUITrans == null);
                break;

            case TWGUIFormatCode.vATOutCode33:
                tWNGUITrans = SelectFrom <TWNGUITrans> .Where <TWNGUITrans.gUINbr.IsEqual <@P.AsString>
                                                               .And <Where <TWNGUITrans.gUIFormatcode.IsEqual <@P.AsString>
                                                                            .Or <TWNGUITrans.gUIFormatcode.IsEqual <@P.AsString> > > > >
                              .View.ReadOnly.Select(graph, gUINbr, TWGUIFormatCode.vATOutCode31, TWGUIFormatCode.vATOutCode35);

                isCreditNote = (tWNGUITrans == null);
                break;

            case TWGUIFormatCode.vATOutCode34:
                tWNGUITrans = SelectFrom <TWNGUITrans> .Where <TWNGUITrans.gUINbr.IsEqual <@P.AsString>
                                                               .And <TWNGUITrans.gUIFormatcode.IsEqual <@P.AsString> > >
                              .View.ReadOnly.Select(graph, gUINbr, TWGUIFormatCode.vATOutCode32);

                isCreditNote = (tWNGUITrans == null);
                break;
            }

            if (isCreditNote.Equals(true))
            {
                errorOccurred = true;
                errorMessage  = TWMessages.CNIsNotFound;
            }
        }
Ejemplo n.º 6
0
 public static string GetCustomClearance(TWNGUITrans gUITran)
 {
     if (gUITran.CustomType == TWNGUICustomType.NotThruCustom &&
         gUITran.VATType == TWNGUIVATType.Five)
     {
         return("1");
     }
     if (gUITran.CustomType == TWNGUICustomType.ThruCustom &&
         gUITran.VATType == TWNGUIVATType.Zero)
     {
         return("2");
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 7
0
        public virtual void CreateNewGUITran(TWNGUITrans refTran)
        {
            TWNGUITrans newTran = PXCache <TWNGUITrans> .CreateCopy(refTran);

            newTran.GUIStatus            = TWNGUIStatus.Used;
            newTran.GUINbr               = Document.Current.NewGUINbr;
            newTran.GUIDate              = Document.Current.NewGUIDate;
            newTran.OrderNbr             = Document.Current.RequestID;
            newTran.NetAmount            = newTran.NetAmtRemain = Document.Current.CalcNetAmt;
            newTran.TaxAmount            = newTran.TaxAmtRemain = Document.Current.CalcTaxAmt;
            newTran.IdentityID           = null;
            newTran.BatchNbr             = null;
            newTran.EGUIExported         = null;
            newTran.EGUIExportedDateTime = null;
            newTran.NoteID               = null;

            GUIInvoice.Insert(newTran);
        }
Ejemplo n.º 8
0
        private string GetTaxAmt(TWNGUITrans tWNGUITrans)
        {
            fixedLen = 10;

            bool fixedFmtCode  = false;
            bool sellerFmtCode = false;
            bool buyerFmtCode  = false;

            string buyerTaxID = GetBuyerTaxID(tWNGUITrans);

            if (tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATOutCode32) ||
                tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode22) ||
                tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode27))
            {
                fixedFmtCode = true;
            }

            if (tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode25) &&
                GetSellerTaxID(tWNGUITrans).Length != 8)
            {
                sellerFmtCode = true;
            }

            if ((tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATOutCode31) && (string.IsNullOrEmpty(buyerTaxID) || buyerTaxID == new string(space, 8))) ||
                (tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATOutCode35) && (string.IsNullOrEmpty(buyerTaxID) || buyerTaxID == new string(space, 8)))
                )
            {
                buyerFmtCode = true;
            }

            if (tWNGUITrans.GUIStatus.Equals(TWNGUIStatus.Voided) ||
                fixedFmtCode || sellerFmtCode || buyerFmtCode)
            {
                return(new string(zero, fixedLen));
            }
            else
            {
                combinStr = tWNGUITrans.TaxAmount.ToString();

                return(combinStr.PadLeft(fixedLen, zero));
            }
        }
Ejemplo n.º 9
0
        private string GetSellerTaxID(TWNGUITrans tWNGUITrans)
        {
            if (tWNGUITrans.GUIFormatcode.StartsWith("2"))
            {
                if (tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode28))
                {
                    return(new string(space, 4) + tWNGUITrans.GUINbr.Substring(0, 4));
                }
                else if (tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode26) || tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode27))
                {
                    return(tWNGUITrans.TaxNbr + new string(space, (8 - tWNGUITrans.TaxNbr.Length)));
                }
                else
                {
                    return(tWNGUITrans.TaxNbr ?? new string(space, 8));
                }
            }

            return(tWNGUITrans.OurTaxNbr);
        }
Ejemplo n.º 10
0
        public string GetNetAmt(TWNGUITrans tWNGUITrans)
        {
            fixedLen = 12;

            bool sellerFmtCode = false;
            bool buyerFmtCode  = false;

            string sellerTaxID = GetSellerTaxID(tWNGUITrans);
            string buyerTaxID  = GetBuyerTaxID(tWNGUITrans);

            if (tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATOutCode32) ||
                tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode22) ||
                tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode27))
            {
                sellerFmtCode = true;
            }

            if (tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATOutCode31) ||
                tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATOutCode35))
            {
                buyerFmtCode = true;
            }

            if (tWNGUITrans.GUIStatus.Equals(TWNGUIStatus.Voided))
            {
                combinStr = new string(zero, fixedLen);
            }
            else if (sellerFmtCode ||
                     (tWNGUITrans.GUIFormatcode.Equals(TWGUIFormatCode.vATInCode25) && sellerTaxID.Length != 8) ||
                     (buyerFmtCode && (string.IsNullOrEmpty(buyerTaxID) || buyerTaxID == new string(space, 8)))
                     )
            {
                combinStr = (tWNGUITrans.NetAmount + tWNGUITrans.TaxAmount).ToString();
            }
            else
            {
                combinStr = tWNGUITrans.NetAmount.ToString();
            }

            return(combinStr.PadLeft(fixedLen, zero));
        }
Ejemplo n.º 11
0
        //public string GetQREncrypter(STWNGUITran sGUITran)
        //{
        //    com.tradevan.qrutil.QREncrypter qrEncrypter = new com.tradevan.qrutil.QREncrypter();

        //    string result;

        //    try
        //    {
        //        string[][] abc = new string[1][];

        //        TWNGUIPreferences gUIPreferences = PXSelect<TWNGUIPreferences>.Select(this);

        //        if (string.IsNullOrEmpty(gUIPreferences.AESKey))
        //        {
        //            throw new MissingFieldException(string.Format("{0} {1}", nameof(TWNGUIPreferences.AESKey), PX.Data.InfoMessages.IsNull));
        //        }

        //        // a) Invoice number = GUITrans.GUINbr
        //        result = qrEncrypter.QRCodeINV(sGUITran.GUINbr,
        //                                       // b) Invoice date = GUITrans.GUIDate(If it is 2019 / 12 / 01, please change to 1081201.  107 = YYYY – 1911)
        //                                       TWNGenZeroTaxRateMedFile.GetTWNDate(sGUITran.GUIDate.Value),
        //                                       // c) Invoice time = “hhmmss” of GUITrans.GUIDate
        //                                       sGUITran.GUIDate.Value.ToString("hhmmss"),
        //                                       // d) Random number = If GUITrans.BatchNbr is not null then Right(Guitrans.bachNbrr,4) else Right(Guitrans.OrderNbrr, 4)
        //                                       string.IsNullOrEmpty(sGUITran.BatchNbr) ? sGUITran.BatchNbr.Substring(sGUITran.BatchNbr.Length - 4) : sGUITran.OrderNbr.Substring(sGUITran.OrderNbr.Length - 4),
        //                                       // e) Sales amount = GUITrans.Amount (No thousands separator, no decimal places)
        //                                       (int)sGUITran.NetAmount.Value,
        //                                       // f) Tax amount = GUITrans.Taxamount  (No thousands separator, no decimal places)
        //                                       (int)sGUITran.TaxAmount.Value,
        //                                       // g) Total amount = GUITrans.Amount + GUITrans.TaxAmount(No thousands separator, no decimal places)
        //                                       (int)(sGUITran.NetAmount + sGUITran.TaxAmount).Value,
        //                                       // h) Buyer identifier = GUITrans.TaxNbr(If it's blank or null, please use “00000000”)
        //                                       string.IsNullOrEmpty(sGUITran.TaxNbr) ? "00000000" : sGUITran.TaxNbr,
        //                                       // i) Representative identifier = “00000000”
        //                                       "00000000",
        //                                       // j) Sales identifier = GUITrans.OurTaxNbr
        //                                       sGUITran.OurTaxNbr,
        //                                       // k) Business identifier = GUITrans.OurTaxNbr
        //                                       sGUITran.OurTaxNbr,
        //                                       // l) AESKEY = GUIParameters.AESKEY
        //                                       gUIPreferences.AESKey);
        //    }
        //    catch
        //    {
        //        throw;
        //    }

        //    return result;
        //}

        public void CreateGUITrans(STWNGUITran sGUITran)
        {
            TWNGUITrans row = ViewGUITrans.Cache.CreateInstance() as TWNGUITrans;

            row.GUIFormatcode = sGUITran.VATCode;
            row.GUINbr        = sGUITran.GUINbr;
            row.SequenceNo    = SequenceNo;

            row = ViewGUITrans.Insert(row);

            row.GUIStatus     = sGUITran.GUIStatus;
            row.Branch        = GetBranchCD(sGUITran.BranchID);
            row.GUIDirection  = sGUITran.GUIDirection;
            row.GUIDate       = row.GUIDecPeriod = sGUITran.GUIDate;
            row.GUITitle      = sGUITran.GUITitle;
            row.TaxZoneID     = sGUITran.TaxZoneID;
            row.TaxCategoryID = sGUITran.TaxCategoryID;
            row.TaxID         = sGUITran.TaxID;
            row.VATType       = GetVATType(row.TaxID);
            row.TaxNbr        = sGUITran.TaxNbr;
            row.OurTaxNbr     = sGUITran.OurTaxNbr;
            row.NetAmount     = row.NetAmtRemain = sGUITran.NetAmount;
            row.TaxAmount     = row.TaxAmtRemain = sGUITran.TaxAmount;
            row.CustVend      = sGUITran.AcctCD;
            row.CustVendName  = sGUITran.AcctName;
            row.DeductionCode = sGUITran.DeductionCode;
            row.TransDate     = base.Accessinfo.BusinessDate;
            row.EGUIExcluded  = sGUITran.eGUIExcluded;
            row.Remark        = sGUITran.Remark;
            row.BatchNbr      = sGUITran.BatchNbr;
            row.OrderNbr      = sGUITran.OrderNbr;
            row.CarrierType   = sGUITran.CarrierType;
            row.CarrierID     = sGUITran.CarrierID;
            row.NPONbr        = sGUITran.NPONbr;
            row.B2CPrinted    = sGUITran.B2CPrinted;
            //row.QREncrypter   = sGUITran.GUIDirection.Equals(TWNGUIDirection.Issue) && sGUITran.NetAmount > 0 && sGUITran.eGUIExcluded.Equals(false) ? GetQREncrypter(sGUITran) : null;

            ViewGUITrans.Update(row);

            this.Actions.PressSave();
        }
Ejemplo n.º 12
0
 private string GetExportMethod(TWNGUITrans tWNGUITrans)
 {
     if (tWNGUITrans.VATType.Equals(TWNGUIVATType.Zero) &&
         tWNGUITrans.CustomType == TWNGUICustomType.NotThruCustom &&
         tWNGUITrans.GUIStatus != TWNGUIStatus.Voided &&
         tWNGUITrans.SequenceNo.Equals(0))
     {
         return("1");
     }
     else if (tWNGUITrans.VATType.Equals(TWNGUIVATType.Zero) &&
              tWNGUITrans.CustomType == TWNGUICustomType.ThruCustom &&
              tWNGUITrans.GUIStatus != TWNGUIStatus.Voided &&
              tWNGUITrans.SequenceNo.Equals(0))
     {
         return("2");
     }
     else
     {
         return(new string(space, 1));
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// When clicking the print button, verify the main GUI information.
        /// </summary>
        /// <param name="gUITrans"></param>
        public static void ButtonValidation(TWNGUITrans gUITrans)
        {
            string message = string.Empty;

            if (gUITrans == null)
            {
                message = TWMessages.SeltCorrGUI;
            }
            else if (gUITrans.GUIStatus != TWNGUIStatus.Used)
            {
                message = string.Format(TWMessages.StatusNotUsed, gUITrans.GUINbr);
            }
            else if (gUITrans.GUIFormatcode != TWGUIFormatCode.vATOutCode31 && gUITrans.GUIFormatcode != TWGUIFormatCode.vATOutCode35)
            {
                message = string.Format(TWMessages.FmtCodeIncort, gUITrans.GUINbr);
            }

            if (!string.IsNullOrEmpty(message))
            {
                throw new PXException(message);
            }
        }
Ejemplo n.º 14
0
 private string GetTaxGroup(TWNGUITrans tWNGUITrans)
 {
     if (tWNGUITrans.GUIStatus.Equals(TWNGUIStatus.Voided))
     {
         return("F");
     }
     else if (tWNGUITrans.VATType.Equals(TWNGUIVATType.Five))
     {
         return("1");
     }
     else if (tWNGUITrans.VATType.Equals(TWNGUIVATType.Zero))
     {
         return("2");
     }
     else if (tWNGUITrans.VATType.Equals(TWNGUIVATType.Exclude))
     {
         return("3");
     }
     else
     {
         return(new string(space, 1));
     }
 }
Ejemplo n.º 15
0
        public void Persist(PersistDelegate baseMethod)
        {
            baseMethod();

            APRegister    doc    = Base.APDocument.Current;
            APRegisterExt docExt = PXCache <APRegister> .GetExtension <APRegisterExt>(doc);

            // Check for document and released flag
            if (TWNGUIValidation.ActivateTWGUI(Base) == true &&
                doc != null &&
                doc.Released == true &&
                doc.DocType.IsIn(APDocType.Invoice, APDocType.DebitAdj))
            {
                //if (Base.APTaxTran_TranType_RefNbr.Current == null)
                //{
                //    throw new PXException(TWMessages.NoInvTaxDtls);
                //}

                foreach (TWNManualGUIAPBill row in SelectFrom <TWNManualGUIAPBill> .Where <TWNManualGUIAPBill.docType.IsEqual <@P.AsString>
                                                                                           .And <TWNManualGUIAPBill.refNbr.IsEqual <@P.AsString> > > .View.Select(Base, doc.DocType, doc.RefNbr))
                {
                    // Avoid standard logic calling this method twice and inserting duplicate records into TWNGUITrans.
                    if (CountExistedRec(Base, row.GUINbr, row.VATInCode, doc.RefNbr) >= 1)
                    {
                        return;
                    }

                    if (Tax.PK.Find(Base, row.TaxID).GetExtension <TaxExt>().UsrTWNGUI != true)
                    {
                        continue;
                    }

                    Vendor vendor = Vendor.PK.Find(Base, row.VendorID);

                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        TWNReleaseProcess rp = PXGraph.CreateInstance <TWNReleaseProcess>();

                        TWNGUITrans tWNGUITrans = rp.InitAndCheckOnAP(row.GUINbr, row.VATInCode);

                        rp.CreateGUITrans(new STWNGUITran()
                        {
                            VATCode       = row.VATInCode,
                            GUINbr        = row.GUINbr,
                            GUIStatus     = TWNGUIStatus.Used,
                            BranchID      = Base.APTran_TranType_RefNbr.Current.BranchID,
                            GUIDirection  = TWNGUIDirection.Receipt,
                            GUIDate       = row.GUIDate,
                            GUITitle      = vendor?.AcctName,
                            TaxZoneID     = row.TaxZoneID,
                            TaxCategoryID = row.TaxCategoryID,
                            TaxID         = row.TaxID,
                            TaxNbr        = row.TaxNbr,
                            OurTaxNbr     = row.OurTaxNbr,
                            NetAmount     = row.NetAmt,
                            TaxAmount     = row.TaxAmt,
                            AcctCD        = vendor?.AcctCD,
                            AcctName      = vendor?.AcctName,
                            DeductionCode = row.Deduction,
                            Remark        = row.Remark,
                            BatchNbr      = doc.BatchNbr,
                            OrderNbr      = doc.RefNbr
                        });

                        if (tWNGUITrans != null)
                        {
                            if (tWNGUITrans.NetAmtRemain < row.NetAmt)
                            {
                                throw new PXException(TWMessages.RemainAmt);
                            }

                            ViewGUITrans.SetValueExt <TWNGUITrans.netAmtRemain>(tWNGUITrans, (tWNGUITrans.NetAmtRemain -= row.NetAmt));
                            ViewGUITrans.SetValueExt <TWNGUITrans.taxAmtRemain>(tWNGUITrans, (tWNGUITrans.TaxAmtRemain -= row.TaxAmt));

                            tWNGUITrans = ViewGUITrans.Update(tWNGUITrans);
                        }

                        // Manually Saving as base code will not call base graph persis.
                        ViewGUITrans.Cache.Persist(PXDBOperation.Insert);
                        ViewGUITrans.Cache.Persist(PXDBOperation.Update);

                        ts.Complete(Base);
                    }
                }
            }

            // Triggering after save events.
            ViewGUITrans.Cache.Persisted(false);
        }
Ejemplo n.º 16
0
 public static decimal GetTaxAmt(TWNGUITrans gUITran)
 {
     return(string.IsNullOrEmpty(gUITran.TaxNbr) ? 0 : gUITran.TaxAmount.Value);
 }
Ejemplo n.º 17
0
 public static decimal GetSalesAmt(TWNGUITrans gUITran)
 {
     return(string.IsNullOrEmpty(gUITran.TaxNbr) ? (gUITran.NetAmount + gUITran.TaxAmount).Value : gUITran.NetAmount.Value);
 }
Ejemplo n.º 18
0
 public static string GetCancelDate(TWNGUITrans gUITran)
 {
     return(gUITran.GUIStatus.Equals(TWNGUIStatus.Voided) ? gUITran.GUIDate.Value.ToString("yyyyMMdd") : string.Empty);
 }
Ejemplo n.º 19
0
        public void Persist(PersistDelegate baseMethod)
        {
            baseMethod();

            if (skipPersist == false)
            {
                ARRegister    doc    = Base.ARDocument.Current;
                ARRegisterExt docExt = PXCache <ARRegister> .GetExtension <ARRegisterExt>(doc);

                // Check for document and released flag
                if (doc != null &&
                    doc.Released == true &&
                    doc.DocType.IsIn(ARDocType.Invoice, ARDocType.CreditMemo, ARDocType.CashSale) &&
                    ((string.IsNullOrEmpty(docExt.UsrGUINbr) && docExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode36) || !string.IsNullOrEmpty(docExt.UsrVATOutCode))
                    )
                {
                    if (docExt.UsrVATOutCode.IsIn(TWGUIFormatCode.vATOutCode33, TWGUIFormatCode.vATOutCode34) &&
                        docExt.UsrCreditAction == TWNCreditAction.NO)
                    {
                        throw new PXException(TWMessages.CRACIsNone);
                    }
                    else if (docExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode37)
                    {
                        throw new PXException(TWMessages.VATOutCodeIs37);
                    }

                    TaxTran xTran = APReleaseProcess_Extension.SelectTaxTran(Base, doc.DocType, doc.RefNbr, BatchModule.AR);

                    if (xTran == null)
                    {
                        throw new PXException(TWMessages.NoInvTaxDtls);
                    }

                    if (PXCache <Tax> .GetExtension <TaxExt>(Tax.PK.Find(Base, xTran.TaxID)).UsrTWNGUI != true)
                    {
                        return;
                    }

                    decimal?netAmt     = xTran.TaxableAmt + xTran.RetainedTaxableAmt;
                    decimal?taxAmt     = xTran.TaxAmt + xTran.RetainedTaxAmt;
                    decimal?remainNet  = netAmt;
                    decimal?remainTax  = taxAmt;
                    decimal?settledNet = 0;
                    decimal?settledTax = 0;

                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        TWNReleaseProcess rp = PXGraph.CreateInstance <TWNReleaseProcess>();

                        Customer customer = SelectFrom <Customer> .Where <Customer.bAccountID.IsEqual <@P.AsInt> > .View.ReadOnly.Select(Base, doc.CustomerID);

                        string[] gUINbrs = !string.IsNullOrEmpty(docExt.UsrGUINbr) ? docExt.UsrGUINbr.Split(';') : new string[1] {
                            string.Empty
                        };

                        for (int i = 0; i < gUINbrs.Length; i++)
                        {
                            string gUINbr = gUINbrs[i].TrimStart();

                            // Avoid standard logic calling this method twice and inserting duplicate records into TWNGUITrans.
                            if (APReleaseProcess_Extension.CountExistedRec(Base, gUINbr, docExt.UsrVATOutCode, doc.RefNbr) > 0)
                            {
                                return;
                            }

                            TWNGUITrans tWNGUITrans = rp.InitAndCheckOnAR(gUINbr, docExt.UsrVATOutCode);

                            string taxCateID = string.Empty;

                            foreach (ARTran row in Base.ARTran_TranType_RefNbr.Cache.Cached)
                            {
                                taxCateID = row.TaxCategoryID;

                                goto CreatGUI;
                            }

CreatGUI:
                            if (docExt.UsrCreditAction.IsIn(TWNCreditAction.CN, TWNCreditAction.NO))
                            {
                                //TWNGUIPreferences gUIPreferences = SelectFrom<TWNGUIPreferences>.View.Select(Base);

                                //string numberingSeq = (docExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode32) ? gUIPreferences.GUI2CopiesNumbering : gUIPreferences.GUI3CopiesNumbering;

                                //docExt.UsrGUINbr = ARGUINbrAutoNumAttribute.GetNextNumber(Base.ARDocument.Cache, doc, numberingSeq, doc.DocDate);

                                FSAppointment appointment = SelectFrom <FSAppointment> .LeftJoin <FSPostDoc> .On <FSPostDoc.appointmentID.IsEqual <FSAppointment.appointmentID> >
                                                            .Where <FSPostDoc.postDocType.IsEqual <@P.AsString>
                                                                    .And <FSPostDoc.postRefNbr.IsEqual <@P.AsString> > >
                                                            .View.ReadOnly.Select(Base, doc.DocType, doc.RefNbr);

                                if (tWNGUITrans != null)
                                {
                                    settledNet = (tWNGUITrans.NetAmtRemain < remainNet) ? tWNGUITrans.NetAmtRemain : remainNet;
                                    settledTax = (tWNGUITrans.TaxAmtRemain < remainTax) ? tWNGUITrans.TaxAmtRemain : remainTax;

                                    remainNet -= settledNet;
                                    remainTax -= settledTax;
                                }
                                else
                                {
                                    settledNet = remainNet;
                                    settledTax = remainTax;
                                }

                                rp.CreateGUITrans(new STWNGUITran()
                                {
                                    VATCode       = docExt.UsrVATOutCode,
                                    GUINbr        = gUINbr ?? string.Empty,
                                    GUIStatus     = doc.CuryOrigDocAmt == 0m ? TWNGUIStatus.Voided : TWNGUIStatus.Used,
                                    BranchID      = doc.BranchID,
                                    GUIDirection  = TWNGUIDirection.Issue,
                                    GUIDate       = docExt.UsrGUIDate.Value.Date.Add(doc.CreatedDateTime.Value.TimeOfDay),
                                    GUITitle      = customer.AcctName,
                                    TaxZoneID     = Base.ARInvoice_DocType_RefNbr.Current.TaxZoneID,
                                    TaxCategoryID = taxCateID,
                                    TaxID         = xTran.TaxID,
                                    TaxNbr        = docExt.UsrTaxNbr,
                                    OurTaxNbr     = docExt.UsrOurTaxNbr,
                                    NetAmount     = settledNet < 0 ? 0 : settledNet,
                                    TaxAmount     = settledTax < 0 ? 0 : settledTax,
                                    AcctCD        = customer.AcctCD,
                                    AcctName      = customer.AcctName,
                                    Remark        = (appointment is null) ? string.Empty : appointment.RefNbr,
                                    BatchNbr      = doc.BatchNbr,
                                    OrderNbr      = doc.RefNbr,
                                    CarrierType   = GetCarrierType(docExt.UsrCarrierID),
                                    CarrierID     = docExt.UsrB2CType == TWNB2CType.MC ? GetCarrierID(docExt.UsrTaxNbr, docExt.UsrCarrierID) : null,
                                    NPONbr        = docExt.UsrB2CType == TWNB2CType.NPO ? GetNPOBAN(docExt.UsrTaxNbr, docExt.UsrNPONbr) : null,
                                    B2CPrinted    = (docExt.UsrB2CType == TWNB2CType.DEF && string.IsNullOrEmpty(docExt.UsrTaxNbr)) ? true : false,
                                });
Ejemplo n.º 20
0
        public virtual void CreateGUIInvCredit()
        {
            TWNGUITrans     gUITran   = new TWNGUITrans();
            TWNGUIInvCredit invCredit = Document.Current;

            List <TWNGUITrans> lists = GUIInvoice.Cache.Updated.Cast <TWNGUITrans>().ToList();

            lists.Sort((x, y) =>
            {
                if (Convert.ToInt32(x.GUIFormatcode) < Convert.ToInt32(y.GUIFormatcode))
                {
                    return(0);
                }
                else
                {
                    return(((IComparable)x.GUIFormatcode).CompareTo(y.GUIFormatcode));
                }
            });

            int index = lists.FindIndex(tran => tran.Selected == false);

            if (index >= 0)
            {
                lists.RemoveAt(index);
            }

            for (int i = 0; i < lists.Count; i++)
            {
                TWNGUITrans row = lists[i];

                if (row.GUIFormatcode == TWGUIFormatCode.vATOutCode35)
                {
                    invCredit.GUINbr     = row.GUINbr;
                    invCredit.VATOutCode = row.GUIFormatcode;
                    invCredit.GUINetAmt  = row.NetAmount;
                    invCredit.GUITaxAmt  = row.TaxAmount;
                    invCredit.CNNetAmt   = invCredit.CNTaxAmt = 0;
                    invCredit.NewGUINbr  = ARGUINbrAutoNumAttribute.GetNextNumber(Document.Cache, invCredit, Preferences.Current.GUI3CopiesNumbering, Document.Current.NewGUIDate);

                    gUITran = row;
                }
                else
                {
                    invCredit.CNGUINbr    += (row.GUINbr + ";");
                    invCredit.CNVATOutCode = row.GUIFormatcode;
                    invCredit.CNNetAmt    += row.NetAmount;
                    invCredit.CNTaxAmt    += row.TaxAmount;
                    invCredit.CalcNetAmt   = invCredit.GUINetAmt - invCredit.CNNetAmt;
                    invCredit.CalcTaxAmt   = invCredit.GUITaxAmt - invCredit.CNTaxAmt;
                }

                row.GUIStatus    = TWNGUIStatus.Voided;
                row.EGUIExported = false;

                GUIInvoice.Cache.Update(row);
            }

            invCredit.CNGUINbr = invCredit.CNGUINbr.Substring(0, invCredit.CNGUINbr.Length - 1);

            this.Save.Press();

            CreateNewGUITran(gUITran);
        }