Exemple #1
0
        private Error validateModel(PurchaseOrderDetailTempModel model)
        {
            var error = isValidRequiredInt(model.ProductId, "ProductName", EvolutionResources.errAValidItemMustBeSelected);

            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.ProductDescription), 255, "ProductDescription", EvolutionResources.errTextDataRequiredInField);
            }

            return(error);
        }
Exemple #2
0
        public PurchaseOrderDetailTempModel FindPurchaseOrderDetailTempModel(int id, CompanyModel company, bool bCreateEmptyIfNotfound = true)
        {
            PurchaseOrderDetailTempModel model = null;

            var p = db.FindPurchaseOrderDetailTemp(id);

            if (p == null)
            {
                if (bCreateEmptyIfNotfound)
                {
                    model = new PurchaseOrderDetailTempModel {
                        CompanyId = company.Id
                    }
                }
                ;
            }
            else
            {
                model = MapToModel(p);
            }

            return(model);
        }
Exemple #3
0
        public PurchaseOrderDetailTempModel MapToModel(PurchaseOrderDetailTempModel item)
        {
            var newItem = Mapper.Map <PurchaseOrderDetailTempModel, PurchaseOrderDetailTempModel>(item);

            return(newItem);
        }
Exemple #4
0
 public string LockPurchaseOrderDetailTemp(PurchaseOrderDetailTempModel model)
 {
     return(db.LockRecord(typeof(PurchaseOrderDetailTemp).ToString(), model.Id));
 }
Exemple #5
0
        public Error InsertOrUpdatePurchaseOrderDetailTemp(PurchaseOrderDetailTempModel podt, UserModel user, string lockGuid)
        {
            if (podt.ProductId == null)
            {
                var product = db.FindProduct(podt.ProductName);
                if (product != null)
                {
                    podt.ProductId = product.Id;
                }
            }

            var error = validateModel(podt);

            if (!error.IsError)
            {
                // Check that the lock is still current
                if (!db.IsLockStillValid(typeof(PurchaseOrderDetailTemp).ToString(), podt.Id, lockGuid))
                {
                    error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "ProductName");
                }
                else
                {
                    PurchaseOrderDetailTemp temp = null;
                    if (podt.Id != 0)
                    {
                        // Existing record to be updated
                        temp = db.FindPurchaseOrderDetailTemp(podt.Id);

                        // The following fields are not copied:
                        //      OriginalRowId
                        //      LineNumber
                        Mapper.Map <PurchaseOrderDetailTempModel, PurchaseOrderDetailTemp>(podt, temp);
                        if (temp.LineNumber == null)
                        {
                            temp.LineNumber = db.GetNextPurchaseOrderDetailLineNumber(temp.PurchaseOrderHeaderTempId, true);
                        }
                    }
                    else
                    {
                        // New record, so copy values

                        // The following fields are not copied:
                        //      OriginalRowId
                        //      LineNumber
                        temp = Mapper.Map <PurchaseOrderDetailTempModel, PurchaseOrderDetailTemp>(podt);

                        temp.OriginalRowId = podt.OriginalRowId;
                        temp.LineNumber    = db.GetNextPurchaseOrderDetailLineNumber(temp.PurchaseOrderHeaderTempId, true);
                    }

                    temp.UserId = user.Id;

                    if (podt.UnitPriceExTax != null)
                    {
                        podt.LinePrice = podt.UnitPriceExTax * podt.OrderQty;
                        if (podt.DiscountPercent != null && podt.DiscountPercent.Value != 0)
                        {
                            podt.LinePrice = podt.LinePrice / 100 * (100 - podt.DiscountPercent);
                        }

                        var taxCode = db.FindTaxCode(podt.TaxCodeId);
                        if (taxCode != null)
                        {
                            temp.UnitPriceExTax = podt.UnitPriceExTax.Value / 100 * taxCode.TaxPercentageRate;
                        }
                    }

                    db.InsertOrUpdatePurchaseOrderDetailTemp(temp);

                    if (podt.UnitPriceExTax != null)
                    {
                        podt.LinePrice = podt.UnitPriceExTax * podt.OrderQty;
                    }
                    podt.Id = temp.Id;
                }
            }
            return(error);
        }