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; } } } } }