Beispiel #1
0
        private Dictionary <string, string> Validate()
        {
            Dictionary <string, string> ValErrors = new Dictionary <string, string>();

            if (VendorID <= 0)
            {
                ValErrors.Add("Vendor", "Vendor selection is required.");
            }
            if (OrganizationID <= 0)
            {
                ValErrors.Add("Organization ID", "Organization ID is required.");
            }
            if (StatusLUID <= 0 || GetPurchaseOrderStatuses(true).Where(x => x.Id == StatusLUID) == null)
            {
                ValErrors.Add("Status", "Status is not vaild.");
            }
            if (PurchaseOrderTypeLUID <= 0 || GetPurchaseOrderTypes(true).Where(x => x.Id == PurchaseOrderTypeLUID) == null)
            {
                ValErrors.Add("Purchase Order Type", "Purchase Order Type is required.");
            }

            if (ShipToAddress != null && !ShipToAddress.IsValid())
            {
                ValErrors.Add("Ship To Address", "Ship To Address is not valid.");
            }

            if (DefaultPaymentMethodID > 0 && DefaultPaymentMethod.PaymentMethodID <= 0)
            {
                ValErrors.Add("Payment Method", "Default Payment Method is invalid.");
            }

            return(ValErrors);
        }
Beispiel #2
0
        public void Save(string uid)
        {
            try
            {
                if (string.IsNullOrEmpty(uid))
                {
                    throw new ArgumentNullException("UID", "User Name is required.");
                }
                Dictionary <string, string> ValErrors = Validate();
                if (ValErrors.Count > 0)
                {
                    throw new RequisitionNotValidException("Purchase Order is not valid.", ValErrors);
                }

                using (PurchasingContext Context = ContextHelper.GetDBContext())
                {
                    Enums.HistoryType ChangeType;
                    PurchaseOrder     Original = null;

                    PurchaseOrderData data = null;
                    if (PurchaseOrderID > 0)
                    {
                        ChangeType = Enums.HistoryType.UPDATE;
                        data       = Context.PurchaseOrderDatas.FirstOrDefault(x => x.purchase_order_id == PurchaseOrderID);
                        Original   = new PurchaseOrder(data);
                    }
                    else
                    {
                        ChangeType        = Enums.HistoryType.ADD;
                        data              = new PurchaseOrderData();
                        data.created_by   = uid;
                        data.date_created = DateTime.Now;
                    }

                    data.vendor_id = VendorID;
                    data.purchase_order_type_luid = PurchaseOrderTypeLUID;
                    data.organization_id          = OrganizationID;

                    if (DateOrdered > DateTime.MinValue)
                    {
                        data.date_ordered = DateOrdered;
                    }
                    else
                    {
                        data.date_ordered = null;
                    }

                    if (OrderedByID > 0)
                    {
                        data.ordered_by = OrderedByID;
                    }
                    else
                    {
                        data.ordered_by = null;
                    }

                    data.status_luid = StatusLUID;

                    if (DateReceived > DateTime.MinValue)
                    {
                        data.date_received = DateReceived;
                    }
                    else
                    {
                        data.date_received = null;
                    }

                    if (DateClosed > DateTime.MinValue)
                    {
                        data.date_closed = DateClosed;
                    }
                    else
                    {
                        data.date_closed = null;
                    }

                    if (!String.IsNullOrEmpty(ShipToName))
                    {
                        data.ship_to_name = ShipToName;
                    }
                    else
                    {
                        data.ship_to_name = null;
                    }

                    if (!String.IsNullOrEmpty(ShipToAttn))
                    {
                        data.ship_to_attention = ShipToAttn;
                    }
                    else
                    {
                        data.ship_to_attention = null;
                    }

                    if (ShipToAddress != null && ShipToAddress.IsValid())
                    {
                        data.ship_to_address = ShipToAddress.ToArenaFormat();
                    }
                    else
                    {
                        data.ship_to_address = null;
                    }

                    if (ShippingCharge != 0)
                    {
                        data.shipping_charge = ShippingCharge;
                    }
                    else
                    {
                        data.shipping_charge = null;
                    }

                    if (OtherCharge != 0)
                    {
                        data.other_charge = OtherCharge;
                    }
                    else
                    {
                        data.other_charge = null;
                    }

                    if (DefaultPaymentMethodID > 0)
                    {
                        data.default_payment_method_id = DefaultPaymentMethodID;
                    }
                    else
                    {
                        data.default_payment_method_id = null;
                    }

                    data.modified_by   = uid;
                    data.date_modified = DateTime.Now;
                    data.active        = Active;

                    if (!String.IsNullOrEmpty(Terms))
                    {
                        data.terms = Terms.Trim();
                    }
                    else
                    {
                        data.terms = null;
                    }

                    data.has_been_billed = HasBeenBilled;

                    if (PurchaseOrderID <= 0)
                    {
                        Context.PurchaseOrderDatas.InsertOnSubmit(data);
                    }

                    Context.SubmitChanges();

                    Load(data);
                    SaveHistory(ChangeType, Original, uid);
                }
            }
            catch (Exception ex)
            {
                throw new RequisitionException("An error has occurred while saving purchase order.", ex);
            }
        }