protected void SOShipment_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting baseMethod)
        {
            baseMethod(cache, e);

            SOShipment row = e.Row as SOShipment;

            if (row != null && e.Operation == PXDBOperation.Insert)
            {
                SOShipmentExt shipmentExt = row.GetExtension <SOShipmentExt>();
                foreach (PXResult <SOOrderShipment, SOOrder> result in Base.OrderList.Select())
                {
                    var order    = (SOOrder)result;
                    var orderExt = order.GetExtension <SOOrderExt>();

                    // As soon as we encounter an order marked Prime, we consider the shipment to be an Amazon Prime shipment.
                    if (orderExt.UsrISPrimeOrder == true)
                    {
                        shipmentExt.UsrISPrimeOrder = true;
                    }

                    if (shipmentExt.UsrDeliverByDate == null || orderExt.UsrDeliverByDate < shipmentExt.UsrDeliverByDate)
                    {
                        shipmentExt.UsrDeliverByDate = orderExt.UsrDeliverByDate;
                    }

                    if (orderExt.UsrGuaranteedDelivery == true)
                    {
                        shipmentExt.UsrGuaranteedDelivery = true;
                    }
                }
            }
        }
        private static void UpdateFeedStatus(SubmitFeedParamaters objParams)
        {
            if (objParams != null && objParams.importOrderStatus)
            {
                SOShipment currentshipment = objParams.objPartialMaint.Shipment.Select(objParams.shipmentType, objParams.shipmentNbr);
                if (currentshipment != null)
                {
                    SOShipmentAmazonExt currentshipmentext = currentshipment.GetExtension <SOShipmentAmazonExt>();
                    if (currentshipmentext != null)
                    {
                        objParams.objPartialMaint.Shipment.SetValueExt <SOShipmentAmazonExt.usrSubmitFeedupdate>(currentshipment, true);
                        objParams.objPartialMaint.Shipment.Cache.Update(currentshipment);
                    }
                }
            }
            SOSubmitProcessLog processUpdateCount = null;

            if (objParams != null && objParams.objSOAmazonSetup != null && objParams.processID != null)
            {
                processUpdateCount = objParams.objPartialMaint.UpdateFeedProcessLog.Select(objParams.objSOAmazonSetup.IntegrationID, objParams.processID);
            }
            if (processUpdateCount == null)
            {
                return;
            }
            processUpdateCount.SubmitRecordsCount       = objParams.importOrderStatus ? processUpdateCount.SubmitRecordsCount + 1 : processUpdateCount.SubmitRecordsCount;
            processUpdateCount.SubmitFailedRecordsCount = objParams.importOrderStatus == false ? processUpdateCount.SubmitFailedRecordsCount + 1 : processUpdateCount.SubmitFailedRecordsCount;
            objParams.objPartialMaint.UpdateFeedProcessLog.Update(processUpdateCount);
        }
        public static SOShipment GetSOShipment(SOOrder acumaticaOrder, KCAPIFulfillment fulfillment,
                                               SOShipment acumaticaShipment)
        {
            SOOrderEntry      orderGraph  = PXGraph.CreateInstance <SOOrderEntry>();
            KCSiteMasterMaint masterGraph = PXGraph.CreateInstance <KCSiteMasterMaint>();

            acumaticaShipment.Operation          = INDocType.Issue;
            acumaticaShipment.CustomerID         = acumaticaOrder.CustomerID;
            acumaticaShipment.CustomerLocationID = acumaticaOrder.CustomerLocationID;
            acumaticaShipment.SiteID             = masterGraph.SiteMaster.SelectSingle().SiteID;
            acumaticaShipment.ShipDate           = fulfillment.UpdatedDateUtc.DateTime;

            acumaticaShipment.GetExtension <KCSOShipmentExt>().UsrKCCAFulfillmentID = fulfillment.ID;

            return(acumaticaShipment);
        }
Exemple #4
0
        public void ExportShipments(KCStore store)
        {
            if (store.DateTo < store.DateFrom)
            {
                throw new PXException(KCMessages.DateToBiggerThanDateFrom);
            }
            if (store.DateTo.GetValueOrDefault() != default)
            {
                store.DateTo = store.DateTo.GetValueOrDefault().AddDays(1);
            }
            bool anyExported             = false;
            KCDataExchangeMaint    graph = PXGraph.CreateInstance <KCDataExchangeMaint>();
            SOOrderShipmentProcess orderShipmentGraph = PXGraph.CreateInstance <SOOrderShipmentProcess>();

            KCSiteMaster        connection     = graph.Connection.Select().RowCast <KCSiteMaster>().Where(x => x.SiteMasterCD.Equals(store.SiteMasterCD)).First();
            KCARestClient       client         = new KCARestClient(connection);
            KCOrderAPIHelper    helperOrder    = new KCOrderAPIHelper(client);
            KCShipmentAPIHelper helperShipment = new KCShipmentAPIHelper(client);

            List <SOOrder> orders = graph.Orders.Select().RowCast <SOOrder>().Where(x =>
                                                                                    x.GetExtension <KCSOOrderExt>().UsrKCSiteName?.EndsWith("/Non-FBA") == true).ToList();

            foreach (SOOrder order in orders)
            {
                IEnumerable <SOOrderShipment> orderShipments = KCGeneralDataHelper.GetOrderShipmentsByOrderNbr(graph, order.OrderNbr);
                if (orderShipments == null)
                {
                    continue;
                }

                foreach (SOOrderShipment orderShipment in orderShipments)
                {
                    if (!CheckData(orderShipment, store.DateFrom, store.DateTo))
                    {
                        continue;
                    }
                    PXResultset <SOLine> lines    = graph.OrderLines.Select(orderShipment.ShipmentNbr);
                    SOShipment           shipment = KCGeneralDataHelper.GetShipmentByShipmentNbr(orderShipmentGraph, orderShipment.ShipmentNbr);
                    if (!CheckShippingCarrier(helperShipment, shipment))
                    {
                        logger.Information(KCMessages.ShipViaDoesnotExist(shipment.ShipmentNbr));
                        continue;
                    }
                    KCSOShipmentExt shipmentKCExt  = shipment?.GetExtension <KCSOShipmentExt>();
                    SOPackageDetail package        = KCGeneralDataHelper.GetPackageByShipmentNbr(orderShipmentGraph, orderShipment.ShipmentNbr);
                    KCSOOrderExt    orderExt       = order.GetExtension <KCSOOrderExt>();
                    KCMapShipment   shipmentMapper = new KCMapShipment();

                    int?customerOrderNbr = Convert.ToInt32(order.CustomerOrderNbr);

                    if (shipment != null && orderShipment.Confirmed.GetValueOrDefault() &&
                        KCGeneralDataHelper.GetExistingCAOrderById(helperOrder, customerOrderNbr) != null && shipmentKCExt?.UsrKCExported != true)

                    {
                        string          log;
                        KCErrorResponse response = new KCErrorResponse();
                        logger.SetParentAndEntityIds(order.OrderNbr, shipment.ShipmentNbr);

                        try
                        {
                            response = helperShipment.MarkTheOrderAsShipped(shipmentMapper.GetAPIShipment(shipment, package, lines), customerOrderNbr);
                        }
                        catch (Exception ex)
                        {
                            log = KCMessages.CorruptedShipment(shipment.ShipmentNbr);
                            logger.Information(log);
                            continue;
                        }


                        if (response != null)
                        {
                            log = KCMessages.ShipmentExportFailure(shipment.ShipmentNbr, response.Error.Message);
                        }
                        else
                        {
                            shipmentKCExt.UsrKCExported = true;
                            orderShipmentGraph.Shipments.Update(shipment);
                            orderShipmentGraph.Save.Press();
                            anyExported = true;
                            log         = KCMessages.ShipmentExported(shipment.ShipmentNbr);
                        }

                        logger.Information(log);
                    }
                }
            }

            logger.ClearLoggingIds();
            logger.Information(anyExported ? KCMessages.ShipmentExportSuccess : KCMessages.NoShipmentsToExport);
        }
        protected virtual void SOShipment_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected baseHandler)
        {
            baseHandler?.Invoke(sender, e);

            if (e.Row == null)
            {
                return;
            }

            SOShipment      row           = (SOShipment)e.Row;
            KCSOShipmentExt rowKCExt      = row.GetExtension <KCSOShipmentExt>();
            SOOrderShipment orderShipment = PXSelect <SOOrderShipment, Where <SOOrderShipment.shipmentNbr,
                                                                              Equal <Required <SOOrderShipment.shipmentNbr> > > > .Select(Base, row.ShipmentNbr);

            if (orderShipment != null)
            {
                SOOrder order = PXSelect <SOOrder, Where <SOOrder.orderNbr,
                                                          Equal <Required <SOOrder.orderNbr> > > > .Select(Base, orderShipment.OrderNbr);

                bool?FBA         = order?.GetExtension <KCSOOrderExt>().UsrKCSiteName?.EndsWith("/FBA");
                var  buttonMenus = (Base.Actions["action"].GetState(null) as PXButtonState)?.Menus;

                if (FBA == true)
                {
                    bool enable = Base.Accessinfo.ScreenID == "KC.50.10.00";

                    var reportMenus = (Base.report.GetState(null) as PXButtonState)?.Menus;

                    foreach (var action in reportMenus)
                    {
                        action.Enabled = enable;
                    }

                    foreach (var action in buttonMenus)
                    {
                        if (action.Text != "Prepare Invoice")
                        {
                            action.Enabled = enable;
                        }
                    }

                    Base.Actions["InventorySummary"].SetEnabled(enable);
                    Base.Actions["LSSOShipLine_binLotSerial"].SetEnabled(enable);
                    Base.CarrierRatesExt.recalculatePackages.SetEnabled(enable);
                    Base.UpdateIN.SetEnabled(enable);
                    Base.Delete.SetEnabled(enable);

                    sender.AllowUpdate = enable;

                    Base.Transactions.Cache.AllowInsert = enable;
                    Base.Transactions.Cache.AllowUpdate = enable;
                    Base.Transactions.Cache.AllowDelete = enable;

                    Base.OrderList.View.AllowInsert = enable;
                    Base.OrderList.View.AllowUpdate = enable;
                    Base.OrderList.View.AllowDelete = enable;
                }
                else if (rowKCExt?.UsrKCExported == true)
                {
                    foreach (var action in buttonMenus)
                    {
                        if (action.Text.Equals("Correct Shipment"))
                        {
                            action.Enabled = false;
                        }
                    }
                }
            }
        }