Пример #1
0
        /// <summary> Gnerate CA/UK csv data </summary>
        public virtual (StringBuilder csvText, string OrderNbr) CombineCSV(SOShipment soShipment, string csvType)
        {
            StringBuilder sb   = new StringBuilder();
            string        line = string.Empty;

            var inventoryItems = SelectFrom <InventoryItem> .View.Select(Base).RowCast <InventoryItem>().ToList();

            var shipLines = SelectFrom <SOShipLine> .Where <SOShipLine.shipmentNbr.IsEqual <P.AsString> >
                            .OrderBy <SOShipLine.lineNbr.Asc>
                            .View.Select(Base, soShipment?.ShipmentNbr).RowCast <SOShipLine>();

            SOShipmentContact shipContact     = SOShipmentContact.PK.Find(Base, soShipment.ShipContactID);
            SOShipmentAddress shipAddress     = SOShipmentAddress.PK.Find(Base, soShipment.ShipAddressID);
            SOOrderShipment   soOrderShipment = SelectFrom <SOOrderShipment>
                                                .Where <SOOrderShipment.shipmentNbr.IsEqual <P.AsString> >
                                                .View.Select(Base, soShipment.ShipmentNbr).RowCast <SOOrderShipment>().FirstOrDefault();

            SOOrder soOrder = SelectFrom <SOOrder>
                              .Where <SOOrder.orderType.IsEqual <P.AsString> .And <SOOrder.orderNbr.IsEqual <P.AsString> > >
                              .View.Select(Base, soOrderShipment.OrderType, soOrderShipment.OrderNbr)
                              .RowCast <SOOrder>().FirstOrDefault();

            if (!shipLines.Any())
            {
                throw new Exception("Can not find ShipLine");
            }

            #region Header
            line += "\"CustomerCode\";\"OrderRefNo\";\"SKUCode\";\"Qty\";\"DeliveryReqDate\";\"ReceiverName\";\"ReceiverCountry\";\"ReceiverCity\";\"ReceiverPostCode\";\"ReceiverAddress\";\"ReceiverPhone\";\"BatchNumber\";\"Notes\"";
            if (csvType == "P3PL")
            {
                line += ";\"CarrierCode\";\"CarrierServiceCode\"";
            }
            sb.AppendLine(line);
            #endregion

            #region Row

            foreach (var item in shipLines)
            {
                var _cd = inventoryItems.Where(x => x.InventoryID == item.InventoryID).FirstOrDefault()?.InventoryCD;
                line = string.Empty;
                // CustomerCode
                line += $"\"IPEVOMAN\";";
                // OrderRefNo
                line += $"\"{soShipment.CustomerOrderNbr}\";";
                // SKUCode
                line += $"\"{_cd}\";";
                // Qty
                line += $"\"{item?.ShippedQty}\";";
                // DeliveryReqDate
                line += $"\"{DateTime.Now.ToString("yyyyMMdd")}\";";
                // ReceiverName
                line += $"\"{shipContact.Attention}/{shipContact.FullName}\";";
                // ReceiverCountry
                line += $"\"{shipAddress.CountryID}\";";
                // ReceiverCity
                line += $"\"{shipAddress.City}\";";
                // ReceiverPostCode
                line += $"\"{shipAddress.PostalCode}\";";
                // ReceiverAddress
                line += $"\"{(shipAddress?.AddressLine1 + shipAddress?.AddressLine2).Replace(',','/')}\";";
                // ReceiverPhone
                line += $"\"{shipContact.Phone1}\";";
                // BatchNumber
                line += $"\"{soOrder.OrderNbr}\";";
                // Notes
                var note = string.Empty;
                if (_cd == "5-883-4-01-00" || _cd == "5-884-4-01-00")
                {
                    note = "VZ-R(sku#5-883-4-01-00) or VZ-X(sku#5-884-4-01-00) please scan the serial number for us.";
                }
                if (soOrderShipment?.OrderType == "FM" && !string.IsNullOrEmpty(soOrder?.OrderDesc))
                {
                    note = soOrder?.OrderDesc;
                }
                line += $"\"{note}\"";
                if (csvType == "P3PL")
                {
                    line += $";\"{string.Empty}\";\"{string.Empty}\"";
                }
                sb.AppendLine(line);
            }

            #endregion

            return(sb, soOrder.OrderNbr);
        }
Пример #2
0
		private void FillFreightDetails(SOOrder order, SOOrderShipment ordershipment)
		{
            SOFreightDetail freightdet;

            if (ordershipment.ShipmentType == SOShipmentType.DropShip)
			{
                freightdet = PXSelect<SOFreightDetail, Where<SOFreightDetail.docType, Equal<Current<ARInvoice.docType>>, And<SOFreightDetail.refNbr, Equal<Current<SOFreightDetail.refNbr>>, And<SOFreightDetail.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>>>>>.SelectSingleBound(this, new object[] { ordershipment });

                if (freightdet == null)
                {
                    freightdet = new SOFreightDetail();
                    freightdet.CuryInfoID = Document.Current.CuryInfoID;
                    freightdet.ShipmentNbr = ordershipment.ShipmentNbr;
                    freightdet.ShipmentType = ordershipment.ShipmentType;
                    freightdet.OrderType = ordershipment.OrderType;
                    freightdet.OrderNbr = ordershipment.OrderNbr;
                    freightdet.ProjectID = order.ProjectID;

                    int? accountID;
                    object subID;
                    GetFreightAccountAndSubAccount(order, order.ShipVia, out accountID, out subID);
                    freightdet.AccountID = accountID;
                    FreightDetails.Cache.RaiseFieldUpdating<SOFreightDetail.subID>(freightdet, ref subID);
                    freightdet.SubID = (int?)subID;

                    freightdet = FreightDetails.Insert(freightdet);
                }

                freightdet = PXCache<SOFreightDetail>.CreateCopy(freightdet);

                freightdet.ShipTermsID = order.ShipTermsID; //!!
                freightdet.ShipVia = order.ShipVia; //!!
                freightdet.ShipZoneID = order.ShipZoneID; //!!
                freightdet.TaxCategoryID = order.FreightTaxCategoryID;

                freightdet.Weight = 0m;
                freightdet.Volume = 0m;
                freightdet.CuryLineTotal = 0m;
                freightdet.CuryFreightCost = 0m;
                freightdet.CuryFreightAmt = 0m;
                freightdet.CuryPremiumFreightAmt = 0m;

                decimal dropShipLineAmt = 0m;
                foreach (PXResult<SOLine, PO.POLine, POReceiptLine> res in PXSelectJoin<SOLine, 
                    InnerJoin<PO.POLine, On<PO.POLine.lineNbr, Equal<SOLine.pOLineNbr>, And<PO.POLine.lineNbr, Equal<SOLine.pOLineNbr>>>, 
                    InnerJoin<POReceiptLine, On<POReceiptLine.pOLineNbr, Equal<PO.POLine.lineNbr>, And<POReceiptLine.pONbr, Equal<PO.POLine.orderNbr>>>>>, 
                    Where<POReceiptLine.receiptNbr, Equal<Required<POReceiptLine.receiptNbr>>, And<SOLine.orderType, 
                    Equal<Required<SOLine.orderType>>, And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>>>>>.Select(this, ordershipment.ShipmentNbr, ordershipment.OrderType, ordershipment.OrderNbr))
                {
                    SOLine line2 = (SOLine)res;
                    dropShipLineAmt += line2.LineAmt ?? 0m;
                }

                foreach (PXResult<SOOrderShipment, SOOrder> res in PXSelectJoin<SOOrderShipment, InnerJoin<SOOrder, On<SOOrder.orderType, Equal<SOOrderShipment.orderType>, And<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>>>>, Where<SOOrderShipment.invoiceType, Equal<Current<ARInvoice.docType>>, And<SOOrderShipment.invoiceNbr, Equal<Current<ARInvoice.refNbr>>>>>.SelectMultiBound(this, new object[] { ordershipment }))
                {
                    SOOrder order2 = (SOOrder)res;
                    freightdet.CuryLineTotal += dropShipLineAmt;
                    decimal? ShipRatio = order2.CuryLineTotal > 0m ? dropShipLineAmt / order2.LineTotal : 1m;

                    freightdet.CuryPremiumFreightAmt += PXDBCurrencyAttribute.Round(FreightDetails.Cache, freightdet, (decimal)(order2.CuryPremiumFreightAmt * (ShipRatio > 1m ? 1m : ShipRatio) ?? 0m), CMPrecision.TRANCURY);
                    freightdet.CuryFreightAmt += PXDBCurrencyAttribute.Round(FreightDetails.Cache, freightdet, (decimal)(order2.CuryFreightAmt * (ShipRatio > 1m ? 1m : ShipRatio) ?? 0m), CMPrecision.TRANCURY);
                }

                freightdet.CuryTotalFreightAmt = freightdet.CuryPremiumFreightAmt + freightdet.CuryFreightAmt;
                FreightDetails.Update(freightdet);

                if (freightdet.CuryTotalFreightAmt > 0 && freightdet.TaskID == null && !PM.ProjectDefaultAttribute.IsNonProject(this, freightdet.ProjectID))
                {
                    Account ac = PXSelect<Account, Where<Account.accountID, Equal<Required<Account.accountID>>>>.Select(this, freightdet.AccountID);
                    throw new PXException(Messages.TaskWasNotAssigned, ac.AccountCD);
                }
                return;
			}
			
			if (string.Equals(ordershipment.ShipmentNbr, Constants.NoShipmentNbr))
			{
				freightdet = PXSelect<SOFreightDetail, Where<SOFreightDetail.docType, Equal<Current<ARInvoice.docType>>, And<SOFreightDetail.refNbr, Equal<Current<SOFreightDetail.refNbr>>, And<SOFreightDetail.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>>>>>.SelectSingleBound(this, new object[] { ordershipment });

				if (freightdet == null)
				{
					freightdet = new SOFreightDetail();
					freightdet.CuryInfoID = Document.Current.CuryInfoID;
					freightdet.ShipmentNbr = ordershipment.ShipmentNbr;
					freightdet.ShipmentType = ordershipment.ShipmentType;
                    freightdet.OrderType = ordershipment.OrderType;
                    freightdet.OrderNbr = ordershipment.OrderNbr;
					freightdet.ProjectID = order.ProjectID;

					int? accountID;
					object subID;
					GetFreightAccountAndSubAccount(order, order.ShipVia, out accountID, out subID);
					freightdet.AccountID = accountID;
					FreightDetails.Cache.RaiseFieldUpdating<SOFreightDetail.subID>(freightdet, ref subID);
					freightdet.SubID = (int?)subID;

					freightdet = FreightDetails.Insert(freightdet);
				}

				freightdet = PXCache<SOFreightDetail>.CreateCopy(freightdet);

				freightdet.ShipTermsID = order.ShipTermsID; //!!
				freightdet.ShipVia = order.ShipVia; //!!
				freightdet.ShipZoneID = order.ShipZoneID; //!!
				freightdet.TaxCategoryID = order.FreightTaxCategoryID;

				freightdet.Weight = 0m;
				freightdet.Volume = 0m;
				freightdet.CuryLineTotal = 0m;
				freightdet.CuryFreightCost = 0m;
				freightdet.CuryFreightAmt = 0m;
				freightdet.CuryPremiumFreightAmt = 0m;

				foreach (PXResult<SOOrderShipment, SOOrder> res in PXSelectJoin<SOOrderShipment, InnerJoin<SOOrder, On<SOOrder.orderType, Equal<SOOrderShipment.orderType>, And<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>>>>, Where<SOOrderShipment.invoiceType, Equal<Current<ARInvoice.docType>>, And<SOOrderShipment.invoiceNbr, Equal<Current<ARInvoice.refNbr>>, And<SOOrderShipment.shipmentNbr, Equal<Constants.noShipmentNbr>>>>>.SelectMultiBound(this, new object[] { ordershipment }))
				{
					SOOrder order2 = (SOOrder)res;
					freightdet.Weight += order2.OrderWeight;
					freightdet.Volume += order2.OrderVolume;
					freightdet.CuryLineTotal += order2.CuryLineTotal;
					freightdet.CuryFreightCost += order2.CuryFreightCost;
					freightdet.CuryFreightAmt += order2.CuryFreightAmt;
					freightdet.CuryPremiumFreightAmt += order2.CuryPremiumFreightAmt;
				}

				freightdet.CuryTotalFreightAmt = freightdet.CuryPremiumFreightAmt + freightdet.CuryFreightAmt;
				FreightDetails.Update(freightdet);

				if (freightdet.CuryTotalFreightAmt > 0 && freightdet.TaskID == null && !PM.ProjectDefaultAttribute.IsNonProject(this, freightdet.ProjectID))
				{
					Account ac = PXSelect<Account, Where<Account.accountID, Equal<Required<Account.accountID>>>>.Select(this, freightdet.AccountID);
					throw new PXException(Messages.TaskWasNotAssigned, ac.AccountCD);
				}
			}
			else
			{
				freightdet = PXSelect<SOFreightDetail, Where<SOFreightDetail.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>>>.SelectSingleBound(this, new object[] { ordershipment });

				if (freightdet == null)
				{
					SOShipment shipment = PXSelect<SOShipment, Where<SOShipment.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>>>.Select(this, new object[] { ordershipment });

					if (shipment != null)
					{
						freightdet = new SOFreightDetail();
						freightdet.CuryInfoID = Document.Current.CuryInfoID;
						freightdet.ShipmentNbr = ordershipment.ShipmentNbr;
						freightdet.ShipmentType = ordershipment.ShipmentType;
                        if ((PXSelect<SOOrderShipment, Where<SOOrderShipment.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>>>.Select(this)).Count == 1)
                        {
                            freightdet.OrderType = ordershipment.OrderType;
                            freightdet.OrderNbr = ordershipment.OrderNbr;
                        }
						freightdet.ProjectID = order.ProjectID;

						freightdet.ShipTermsID = shipment.ShipTermsID;
						freightdet.ShipVia = shipment.ShipVia;
						freightdet.ShipZoneID = shipment.ShipZoneID;
						freightdet.TaxCategoryID = shipment.TaxCategoryID;
						freightdet.Weight = shipment.ShipmentWeight;
						freightdet.Volume = shipment.ShipmentVolume;
						freightdet.LineTotal = shipment.LineTotal;
						PXCurrencyAttribute.CuryConvCury<SOFreightDetail.curyLineTotal>(FreightDetails.Cache, freightdet);
						freightdet.FreightCost = shipment.FreightCost;
						PXCurrencyAttribute.CuryConvCury<SOFreightDetail.curyFreightCost>(FreightDetails.Cache, freightdet);
						freightdet.FreightAmt = shipment.FreightAmt;
						PXCurrencyAttribute.CuryConvCury<SOFreightDetail.curyFreightAmt>(FreightDetails.Cache, freightdet);

						freightdet.CuryPremiumFreightAmt = 0m;
						//recalculate All Premium Freight for Shipment
						foreach (PXResult<SOOrderShipment, SOOrder> res in PXSelectJoin<SOOrderShipment, InnerJoin<SOOrder, On<SOOrder.orderType, Equal<SOOrderShipment.orderType>, And<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>>>>, Where<SOOrderShipment.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>, And<SOOrderShipment.shipmentType, NotEqual<SOShipmentType.dropShip>>>>.SelectMultiBound(this, new object[] { ordershipment }))
						{
							SOOrderShipment ordershipment2 = (SOOrderShipment)res;
							SOOrder order2 = (SOOrder)res;

							if (sosetup.Current.FreightAllocation == FreightAllocationList.Prorate)
							{
								if (order2.CuryLineTotal > 0m)
								{
									decimal? ShipRatio = ordershipment2.LineTotal / order2.LineTotal;
									freightdet.CuryPremiumFreightAmt += PXDBCurrencyAttribute.Round(FreightDetails.Cache, freightdet, (decimal)(order2.CuryPremiumFreightAmt * (ShipRatio > 1m ? 1m : ShipRatio) ?? 0m), CMPrecision.TRANCURY);
								}
								else
								{
									freightdet.CuryPremiumFreightAmt += order2.CuryPremiumFreightAmt;
								}
							}
							else
							{
								SOOrderShipment prev_shipment = PXSelectReadonly<SOOrderShipment,
									Where<SOOrderShipment.shipmentNbr, NotEqual<Current<SOOrderShipment.shipmentNbr>>, And<SOOrderShipment.shipmentType, NotEqual<SOShipmentType.dropShip>,
									And<SOOrderShipment.orderType, Equal<Current<SOOrderShipment.orderType>>,
									And<SOOrderShipment.orderNbr, Equal<Current<SOOrderShipment.orderNbr>>,
									And<SOOrderShipment.invoiceNbr, IsNotNull>>>>>>.SelectSingleBound(this, new object[] { ordershipment2 });
								if (prev_shipment == null)
								{
									freightdet.CuryPremiumFreightAmt += order2.CuryPremiumFreightAmt;
								}
								else
								{
									freightdet.CuryPremiumFreightAmt = 0m;
								}
							}
						}

						freightdet.CuryTotalFreightAmt = freightdet.CuryPremiumFreightAmt + freightdet.CuryFreightAmt;

						int? accountID;
						object subID;
						GetFreightAccountAndSubAccount(order, shipment.ShipVia, out accountID, out subID);
						freightdet.AccountID = accountID;
						FreightDetails.Cache.RaiseFieldUpdating<SOFreightDetail.subID>(freightdet, ref subID);
						freightdet.SubID = (int?)subID;

						freightdet = FreightDetails.Insert(freightdet);
					}
				}
			}
		}