Example #1
0
        protected virtual IEnumerable dummyCustomAction(PXAdapter adapter)
        {
            SOShipment      shipment        = Base.Document.Current;
            SOOrderShipment soOrderShipment = PXSelect <SOOrderShipment,
                                                        Where <SOOrderShipment.shipmentNbr, Equal <Required <SOOrderShipment.shipmentNbr> > > > .
                                              Select(Base, shipment.ShipmentNbr);

            ARInvoice arInvoice = PXSelect <ARInvoice, Where <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> >,
                                                              And <ARInvoice.docType, Equal <Required <ARInvoice.docType> > > > > .
                                  Select(Base, soOrderShipment.InvoiceNbr, "INV");

            PXLongOperation.StartOperation(Base, delegate()
            {
                SOInvoiceEntry soInvoiceGraph   = PXGraph.CreateInstance <SOInvoiceEntry>();
                SOShipmentEntry soShipmentGraph = PXGraph.CreateInstance <SOShipmentEntry>();
                //Release Sales Invoice
                soInvoiceGraph.Clear();
                soInvoiceGraph.Document.Current = soInvoiceGraph.Document.Search <ARInvoice.docType, ARInvoice.refNbr>(arInvoice.DocType, arInvoice.RefNbr);
                soInvoiceGraph.release.Press();
                //Update IN on Shipment
                soShipmentGraph.Clear();
                soShipmentGraph.Document.Current = soShipmentGraph.Document.Search <SOShipment.shipmentNbr>(shipment.ShipmentNbr);
                soShipmentGraph.UpdateIN.Press();
            });
            return(adapter.Get());
        }
 public virtual IEnumerable ViewDocument(PXAdapter adapter)
 {
     if (SOInvoiceList.Current != null)
     {
         SOInvoiceEntry docgraph = PXGraph.CreateInstance <SOInvoiceEntry>();
         docgraph.Document.Current = docgraph.Document.Search <ARInvoice.refNbr>(SOInvoiceList.Current.RefNbr, SOInvoiceList.Current.DocType);
         throw new PXRedirectRequiredException(docgraph, true, "Order")
               {
                   Mode = PXBaseRedirectException.WindowMode.NewWindow
               };
     }
     return(adapter.Get());
 }
Example #3
0
        public virtual void OpenInvoice()
        {
            SOInvoiceEntry graphSOInvoiceEntry = PXGraph.CreateInstance <SOInvoiceEntry>();

            if (InventoryItems.Current != null &&
                InventoryItems.Current.InvoiceRefNbr != null)
            {
                graphSOInvoiceEntry.Document.Current = graphSOInvoiceEntry.Document.Search <ARInvoice.refNbr>(InventoryItems.Current.InvoiceRefNbr, InventoryItems.Current.DocType);
                throw new PXRedirectRequiredException(graphSOInvoiceEntry, null)
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
        }
        public virtual void Persist(Action persist)
        {
            if (Base.Document.Current != null && IsExternalTax(Base.Document.Current.TaxZoneID) && Base.Document.Current.Released != true)
            {
                //Avalara - validate that valid ShipTo address can be returned - no mixed carriers, and no mixeds shipto address:
                GetToAddress(Base.Document.Current);
            }

            persist();

            if (Base.Document.Current != null && IsExternalTax(Base.Document.Current.TaxZoneID) && Base.Document.Current.InstallmentNbr == null && Base.Document.Current.IsTaxValid != true && !skipExternalTaxCalcOnSave && Base.Document.Current.Released != true)
            {
                if (PXLongOperation.GetCurrentItem() == null)
                {
                    PXLongOperation.StartOperation(Base, delegate
                    {
                        if (Base.Document.Current.OrigModule == GL.BatchModule.SO)
                        {
                            SOInvoiceEntry rg = PXGraph.CreateInstance <SOInvoiceEntry>();

                            rg.Document.Current = PXSelect <ARInvoice, Where <ARInvoice.docType, Equal <Required <ARInvoice.docType> >, And <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> > > > > .Select(rg, Base.Document.Current.DocType, Base.Document.Current.RefNbr);
                            rg.Document.Current.ApplyPaymentWhenTaxAvailable = Base.Document.Current.ApplyPaymentWhenTaxAvailable;
                            rg.SODocument.Current = PXSelect <SOInvoice, Where <SOInvoice.docType, Equal <Required <SOInvoice.docType> >, And <SOInvoice.refNbr, Equal <Required <SOInvoice.refNbr> > > > > .Select(rg, Base.Document.Current.DocType, Base.Document.Current.RefNbr);

                            rg.CalculateExternalTax(rg.Document.Current);
                        }
                        else
                        {
                            ARInvoiceEntry rg = PXGraph.CreateInstance <ARInvoiceEntry>();

                            rg.Document.Current = PXSelect <ARInvoice, Where <ARInvoice.docType, Equal <Required <ARInvoice.docType> >, And <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> > > > > .Select(rg, Base.Document.Current.DocType, Base.Document.Current.RefNbr);

                            rg.CalculateExternalTax(rg.Document.Current);
                        }

                        Base.RecalcUnbilledTax();
                    });
                }
                else
                {
                    Base.CalculateExternalTax(Base.Document.Current);

                    Base.RecalcUnbilledTax();
                }
            }
        }
Example #5
0
        public virtual void openDocument()
        {
            FSPostDoc postingBatchDetailRow = BatchDetailsInfo.Current;

            if (postingBatchDetailRow.PostedTO == ID.Batch_PostTo.SO)
            {
                if (PXAccess.FeatureInstalled <FeaturesSet.distributionModule>())
                {
                    SOOrderEntry graphSOOrderEntry = PXGraph.CreateInstance <SOOrderEntry>();
                    graphSOOrderEntry.Document.Current = graphSOOrderEntry.Document.Search <SOOrder.orderNbr>(postingBatchDetailRow.PostRefNbr, postingBatchDetailRow.PostDocType);
                    throw new PXRedirectRequiredException(graphSOOrderEntry, null)
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
            }
            else if (postingBatchDetailRow.PostedTO == ID.Batch_PostTo.AR)
            {
                ARInvoiceEntry graphARInvoiceEntry = PXGraph.CreateInstance <ARInvoiceEntry>();
                graphARInvoiceEntry.Document.Current = graphARInvoiceEntry.Document.Search <ARInvoice.refNbr>(postingBatchDetailRow.PostRefNbr, postingBatchDetailRow.PostDocType);
                throw new PXRedirectRequiredException(graphARInvoiceEntry, null)
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (postingBatchDetailRow.PostedTO == ID.Batch_PostTo.AP)
            {
                APInvoiceEntry graphAPInvoiceEntry = PXGraph.CreateInstance <APInvoiceEntry>();
                graphAPInvoiceEntry.Document.Current = graphAPInvoiceEntry.Document.Search <APInvoice.refNbr>(postingBatchDetailRow.PostRefNbr, postingBatchDetailRow.PostDocType);
                throw new PXRedirectRequiredException(graphAPInvoiceEntry, null)
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (postingBatchDetailRow.PostedTO == ID.Batch_PostTo.SI)
            {
                SOInvoiceEntry graphSOInvoiceEntry = PXGraph.CreateInstance <SOInvoiceEntry>();
                graphSOInvoiceEntry.Document.Current = graphSOInvoiceEntry.Document.Search <ARInvoice.refNbr>(postingBatchDetailRow.PostRefNbr, postingBatchDetailRow.PostDocType);
                throw new PXRedirectRequiredException(graphSOInvoiceEntry, null)
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
        }
 private void openDocument(FSPostDet fsPostDetRow)
 {
     if (fsPostDetRow.SOPosted == true)
     {
         if (PXAccess.FeatureInstalled <FeaturesSet.distributionModule>())
         {
             SOOrderEntry graphSOOrderEntry = PXGraph.CreateInstance <SOOrderEntry>();
             graphSOOrderEntry.Document.Current = graphSOOrderEntry.Document.Search <SOOrder.orderNbr>(fsPostDetRow.SOOrderNbr, fsPostDetRow.SOOrderType);
             throw new PXRedirectRequiredException(graphSOOrderEntry, null)
                   {
                       Mode = PXBaseRedirectException.WindowMode.NewWindow
                   };
         }
     }
     else if (fsPostDetRow.ARPosted == true)
     {
         ARInvoiceEntry graphARInvoiceEntry = PXGraph.CreateInstance <ARInvoiceEntry>();
         graphARInvoiceEntry.Document.Current = graphARInvoiceEntry.Document.Search <ARInvoice.refNbr>(fsPostDetRow.ARRefNbr, fsPostDetRow.ARDocType);
         throw new PXRedirectRequiredException(graphARInvoiceEntry, null)
               {
                   Mode = PXBaseRedirectException.WindowMode.NewWindow
               };
     }
     else if (fsPostDetRow.SOInvPosted == true)
     {
         SOInvoiceEntry graphSOInvoiceEntry = PXGraph.CreateInstance <SOInvoiceEntry>();
         graphSOInvoiceEntry.Document.Current = graphSOInvoiceEntry.Document.Search <ARInvoice.refNbr>(fsPostDetRow.ARRefNbr, fsPostDetRow.ARDocType);
         throw new PXRedirectRequiredException(graphSOInvoiceEntry, null)
               {
                   Mode = PXBaseRedirectException.WindowMode.NewWindow
               };
     }
     else if (fsPostDetRow.APPosted == true)
     {
         APInvoiceEntry graphAPInvoiceEntry = PXGraph.CreateInstance <APInvoiceEntry>();
         graphAPInvoiceEntry.Document.Current = graphAPInvoiceEntry.Document.Search <APInvoice.refNbr>(fsPostDetRow.APRefNbr, fsPostDetRow.APDocType);
         throw new PXRedirectRequiredException(graphAPInvoiceEntry, null)
               {
                   Mode = PXBaseRedirectException.WindowMode.NewWindow
               };
     }
 }
        public static ARInvoice Process(ARInvoice doc)
        {
            if (doc.OrigModule == GL.BatchModule.SO)
            {
                SOInvoiceEntry rg = PXGraph.CreateInstance <SOInvoiceEntry>();
                rg.Document.Current = PXSelect <ARInvoice, Where <ARInvoice.docType, Equal <Required <ARInvoice.docType> >, And <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> > > > > .Select(rg, doc.DocType, doc.RefNbr);

                rg.Document.Current.ApplyPaymentWhenTaxAvailable = doc.ApplyPaymentWhenTaxAvailable;
                rg.SODocument.Current = PXSelect <SOInvoice, Where <SOInvoice.docType, Equal <Required <SOInvoice.docType> >, And <SOInvoice.refNbr, Equal <Required <SOInvoice.refNbr> > > > > .Select(rg, doc.DocType, doc.RefNbr);

                return(rg.CalculateAvalaraTax(rg.Document.Current));
            }
            else
            {
                List <ARInvoice> list = new List <ARInvoice>();
                list.Add(doc);

                List <ARInvoice> listWithTax = Process(list, false);

                return(listWithTax[0]);
            }
        }
        public static void ValidateCCPayment(PXGraph graph, List <IExternalTransaction> list, bool isMassProcess)
        {
            bool            failed          = false;
            ARCashSaleEntry arCashSaleGraph = null;
            ARPaymentEntry  arPaymentGraph  = null;
            SOInvoiceEntry  soInvoiceGraph  = null;

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i] == null)
                {
                    continue;
                }

                if ((i % 100) == 0)
                {
                    if (arCashSaleGraph != null)
                    {
                        arCashSaleGraph.Clear();
                    }
                    if (arPaymentGraph != null)
                    {
                        arPaymentGraph.Clear();
                    }
                    if (soInvoiceGraph != null)
                    {
                        soInvoiceGraph.Clear();
                    }
                }

                IExternalTransaction tran = list[i];

                var resultSet = PXSelectJoin <Standalone.ARRegister,
                                              LeftJoin <ARPayment,
                                                        On <ARPayment.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                            And <ARPayment.docType, Equal <Standalone.ARRegister.docType> > >,
                                                        LeftJoin <ARInvoice,
                                                                  On <ARInvoice.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                                      And <ARInvoice.docType, Equal <Standalone.ARRegister.docType> > >,
                                                                  LeftJoin <SOInvoice,
                                                                            On <SOInvoice.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                                                And <SOInvoice.docType, Equal <Standalone.ARRegister.docType> > >,
                                                                            LeftJoin <Standalone.ARCashSale,
                                                                                      On <Standalone.ARCashSale.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                                                          And <Standalone.ARCashSale.docType, Equal <Standalone.ARRegister.docType> > > > > > >,
                                              Where <Standalone.ARRegister.refNbr, Equal <Required <Standalone.ARRegister.refNbr> >,
                                                     And <Standalone.ARRegister.docType, Equal <Required <Standalone.ARRegister.docType> > > > >
                                .SelectSingleBound(graph, null, tran.RefNbr, tran.DocType);

                foreach (PXResult <Standalone.ARRegister, ARPayment, ARInvoice, SOInvoice, Standalone.ARCashSale> arDoc in resultSet)
                {
                    if (arDoc == null)
                    {
                        continue;
                    }

                    try
                    {
                        if ((ARInvoice)arDoc is ARInvoice arInvoice &&
                            arInvoice != null && arInvoice.RefNbr != null)
                        {
                            if ((SOInvoice)arDoc is SOInvoice soInvoice &&
                                soInvoice != null && soInvoice.RefNbr != null)
                            {
                                soInvoiceGraph = soInvoiceGraph != null ? soInvoiceGraph : PXGraph.CreateInstance <SOInvoiceEntry>();
                                SOInvoiceEntry.PaymentTransaction ext = soInvoiceGraph.GetExtension <SOInvoiceEntry.PaymentTransaction>();
                                soInvoiceGraph.Document.Current   = arInvoice;
                                soInvoiceGraph.SODocument.Current = soInvoice;
                                if (ext.CanValidate(arInvoice))
                                {
                                    ext.validateCCPayment.Press();
                                }
                            }
                            else if ((Standalone.ARCashSale)arDoc is Standalone.ARCashSale arCashSale &&
                                     arCashSale != null && arCashSale.RefNbr != null)
                            {
                                arCashSaleGraph = arCashSaleGraph != null ? arCashSaleGraph : PXGraph.CreateInstance <ARCashSaleEntry>();
                                ARCashSaleEntry.PaymentTransaction ext = arCashSaleGraph.GetExtension <ARCashSaleEntry.PaymentTransaction>();
                                arCashSaleGraph.Document.Current = arCashSale;
                                if (ext.CanValidate(arCashSaleGraph.Document.Current))
                                {
                                    ext.validateCCPayment.Press();
                                }
                            }
                        }
Example #9
0
        protected virtual IEnumerable LumCallDCLShipemnt(PXAdapter adapter, [PXDate] DateTime?shipDate, [PXInt] int?siteID, [SOOperation.List] string operation)
        {
            try
            {
                var _soOrder = adapter.Get <SOOrder>().ToList()[0];

                // Get DCL SO. Data(正式:order_number = SO.OrderNbr)
                //var dclOrders = JsonConvert.DeserializeObject<OrderResponse>(
                //    DCLHelper.CallDCLToGetSOByOrderNumbers(
                //        this.DCLSetup.Select().RowCast<LUMVendCntrlSetup>().FirstOrDefault(), soOrder.OrderNbr).ContentResult);

                // Get DCL SO. Data(理論上資料一定存在,因為Process Order已經先篩選了)
                var dclOrders = JsonConvert.DeserializeObject <OrderResponse>(
                    DCLHelper.CallDCLToGetSOByOrderNumbers(
                        this.DCLSetup.Select().RowCast <LUMVendCntrlSetup>().FirstOrDefault(), _soOrder.CustomerRefNbr).ContentResult);

                if (dclOrders.orders == null)
                {
                    throw new Exception("Can not Mapping DCL Data");
                }

                if (!dclOrders.orders.Any(x => x.order_stage == 60))
                {
                    throw new Exception("DCL Order stage is not Fully Shipped");
                }

                if (_soOrder.OrderType == "FM")
                {
                    var setup           = this.MiddlewareSetup.Select().RowCast <LUMMiddleWareSetup>().FirstOrDefault();
                    var shippingCarrier = dclOrders.orders.FirstOrDefault()?.shipping_carrier;
                    var packagesInfo    = dclOrders.orders.FirstOrDefault().shipments.SelectMany(x => x.packages);
                    var _merchant       = string.IsNullOrEmpty(PXAccess.GetCompanyName()?.Split(' ')[1]) ? "us" :
                                          PXAccess.GetCompanyName()?.Split(' ')[1].ToLower() == "uk" ? "gb" : PXAccess.GetCompanyName()?.Split(' ')[1].ToLower();
                    MiddleWare_Shipment metaData = new MiddleWare_Shipment()
                    {
                        merchant        = _merchant,
                        amazon_order_id = dclOrders.orders.FirstOrDefault().po_number,
                        shipment_date   = dclOrders.orders.FirstOrDefault()?.shipments?.FirstOrDefault()?.ship_date + " 00:00:00",
                        shipping_method = "Standard",
                        carrier         = shippingCarrier,
                        tracking_number = string.Join("|", packagesInfo.Select(x => x.tracking_number))
                    };
                    // Update FBM
                    var updateResult = MiddleWareHelper.CallMiddleWareToUpdateFBM(setup, metaData);
                    // Check HttpStatusCode
                    if (updateResult.StatusCode != System.Net.HttpStatusCode.OK)
                    {
                        throw new PXException($"Update MiddleWare FBM fail , Code = {updateResult.StatusCode}");
                    }
                    // Check Response status
                    var updateModel = JsonConvert.DeserializeObject <MiddleWare_Response>(updateResult.ContentResult);
                    if (!updateModel.Status)
                    {
                        throw new PXException($"Update Middleware FBM fail, Msg = {updateModel.Message}");
                    }
                    _soOrder.GetExtension <SOOrderExt>().UsrSendToMiddleware = true;
                    Base.Document.Update(_soOrder);
                    Base.Save.Press();
                }
                else
                {
                    using (PXTransactionScope sc = new PXTransactionScope())
                    {
                        Base.CreateShipmentIssue(adapter, shipDate, siteID);
                        var processResult = PXProcessing <SOOrder> .GetItemMessage();

                        if (processResult.ErrorLevel != PXErrorLevel.RowInfo)
                        {
                            return(adapter.Get());
                        }

                        // Create SOShipment Graph
                        var graph = PXGraph.CreateInstance <SOShipmentEntry>();

                        // Find SOShipment
                        var _soOrderShipments =
                            FbqlSelect <SelectFromBase <SOOrderShipment, TypeArrayOf <IFbqlJoin> .Empty> .Where <BqlChainableConditionBase <TypeArrayOf <IBqlBinary> .FilledWith <And <Compare <SOOrderShipment.orderType, Equal <P.AsString> > > > > .And <BqlOperand <SOOrderShipment.orderNbr, IBqlString> .IsEqual <P.AsString> > >, SOOrderShipment> .View.Select(Base, _soOrder.OrderType, _soOrder.OrderNbr)
                            .RowCast <SOOrderShipment>();

                        foreach (var refItem in _soOrderShipments)
                        {
                            // Create new Adapter
                            var newAdapter = new PXAdapter(graph.Document)
                            {
                                Searches = new Object[] { refItem.ShipmentNbr }
                            };
                            // Select Current Shipment
                            var _soShipment = newAdapter.Get <SOShipment>().ToList()[0];

                            try
                            {
                                // Get Carrier and TrackingNbr
                                var shippingCarrier = dclOrders.orders.FirstOrDefault().shipping_carrier;
                                var packagesInfo    = dclOrders.orders.FirstOrDefault().shipments.SelectMany(x => x.packages);
                                _soShipment.GetExtension <SOShipmentExt>().UsrCarrier     = shippingCarrier;
                                _soShipment.GetExtension <SOShipmentExt>().UsrTrackingNbr = string.Join("|", packagesInfo.Select(x => x.tracking_number));
                                _soShipment.ShipmentDesc = $"Carrier: {shippingCarrier}|" +
                                                           $"TrackingNbr: {string.Join("|", packagesInfo.Select(x => x.tracking_number))}";
                                if (_soShipment.ShipmentDesc.Length > 256)
                                {
                                    _soShipment.ShipmentDesc = _soShipment.ShipmentDesc.Substring(0, 255);
                                }
                            }
                            catch (Exception e)
                            {
                                _soShipment.ShipmentDesc = e.Message;
                            }

                            // Update Data
                            graph.Document.Update(_soShipment);

                            // Remove Hold
                            graph.releaseFromHold.PressButton(newAdapter);
                            // Confirm Shipment
                            graph.confirmShipmentAction.PressButton(newAdapter);
                            // Prepare Invoice For 3D Orders
                            try
                            {
                                if (_soOrder.OrderType == "3D")
                                {
                                    newAdapter.AllowRedirect = true;
                                    graph.createInvoice.PressButton(newAdapter);
                                }
                            }
                            catch (PXRedirectRequiredException ex)
                            {
                                SOInvoiceEntry invoiceEntry = ex.Graph as SOInvoiceEntry;
                                var            soTax        = SelectFrom <SOTaxTran>
                                                              .Where <SOTaxTran.orderNbr.IsEqual <P.AsString>
                                                                      .And <SOTaxTran.orderType.IsEqual <P.AsString> > >
                                                              .View.Select(Base, _soOrder.OrderNbr, _soOrder.OrderType)
                                                              .RowCast <SOTaxTran>().FirstOrDefault();

                                var balance = invoiceEntry.Document.Current.CuryDocBal;
                                var refNbr  = invoiceEntry.Document.Current.RefNbr;
                                var invTax  = SelectFrom <ARTaxTran> .Where <ARTaxTran.refNbr.IsEqual <P.AsString> >
                                              .View.Select(Base, refNbr).RowCast <ARTaxTran>().FirstOrDefault();

                                var adjd = SelectFrom <ARAdjust2> .Where <ARAdjust2.adjdRefNbr.IsEqual <P.AsString> >
                                           .View.Select(Base, refNbr).RowCast <ARAdjust2>().FirstOrDefault();

                                if (soTax != null)
                                {
                                    // setting Tax
                                    invoiceEntry.Taxes.SetValueExt <ARTaxTran.curyTaxAmt>(invTax, soTax.CuryTaxAmt);
                                    invoiceEntry.Taxes.Update(invTax);
                                    // setting Document
                                    invoiceEntry.Document.SetValueExt <ARInvoice.curyTaxTotal>(invoiceEntry.Document.Current, soTax.CuryTaxAmt);
                                    invoiceEntry.Document.SetValueExt <ARInvoice.curyDocBal>(invoiceEntry.Document.Current, balance + (soTax.CuryTaxAmt ?? 0));
                                    invoiceEntry.Document.Update(invoiceEntry.Document.Current);
                                    invoiceEntry.Adjustments.SetValueExt <ARAdjust2.curyAdjdAmt>(adjd, adjd.CuryAdjdAmt + (soTax.CuryTaxAmt ?? 0));
                                    invoiceEntry.Adjustments.Update(adjd);
                                    invoiceEntry.releaseFromCreditHold.Press();
                                    invoiceEntry.Save.Press();
                                }
                            }
                            catch (Exception ex)
                            {
                                throw new Exception(ex.Message);
                            }
                        }

                        sc.Complete();
                    }
                }
            }
            catch (Exception e)
            {
                PXProcessing.SetError <SOOrder>(e.Message);
            }

            return(adapter.Get());
        }