private Error validateModel(PurchaseOrderHeaderTempModel model)
        {
            var error = isValidNonRequiredString(getFieldValue(model.SupplierInv), 255, "SupplierInv", EvolutionResources.errTextDataRequiredInField);

            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.ShipAddress1), 255, "ShipAddress1", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.ShipAddress2), 255, "ShipAddress2", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.ShipAddress3), 255, "ShipAddress3", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.ShipAddress4), 255, "ShipAddress4", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.OrderComment), 255, "OrderComment", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.CancelMessage), 2048, "CancelMessage", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.OrderConfirmationNo), 20, "OrderConfirmationNo", EvolutionResources.errTextDataRequiredInField);
            }

            return(error);
        }
        public Error InsertOrUpdatePurchaseOrderHeaderTemp(PurchaseOrderHeaderTempModel poht, UserModel user, string lockGuid)
        {
            var error = validateModel(poht);

            if (!error.IsError)
            {
                // Check that the lock is still current
                if (!db.IsLockStillValid(typeof(PurchaseOrderHeaderTemp).ToString(), poht.Id, lockGuid))
                {
                    error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "OrderNumber");
                }
                else
                {
                    PurchaseOrderHeaderTemp temp = null;
                    if (poht.Id != 0)
                    {
                        temp = db.FindPurchaseOrderHeaderTemp(poht.Id);
                    }
                    if (temp == null)
                    {
                        temp = new PurchaseOrderHeaderTemp();
                    }

                    Mapper.Map <PurchaseOrderHeaderTempModel, PurchaseOrderHeaderTemp>(poht, temp);

                    db.InsertOrUpdatePurchaseOrderHeaderTemp(temp);
                    poht.Id = temp.Id;
                }
            }
            return(error);
        }
 private void adjustDates(PurchaseOrderHeaderTempModel model, string tz)
 {
     model.OrderDate                 = GetFieldValue(model.OrderDate, tz);
     model.CancelDate                = GetFieldValue(model.CancelDate, tz);
     model.RequiredDate              = GetFieldValue(model.RequiredDate, tz);
     model.RealisticRequiredDate     = GetFieldValue(model.RealisticRequiredDate, tz);
     model.CompletedDate             = GetFieldValue(model.CompletedDate, tz);
     model.RequiredShipDate          = GetFieldValue(model.RequiredShipDate, tz);
     model.RequiredShipDate_Original = GetFieldValue(model.RequiredShipDate_Original, tz);
     model.RequiredDate_Original     = GetFieldValue(model.RequiredDate_Original, tz);
     model.DatePOSentToSupplier      = GetFieldValue(model.DatePOSentToSupplier, tz);
     model.DateOrderConfirmed        = GetFieldValue(model.DateOrderConfirmed, tz);
     model.SupplierInvoiceDate       = GetFieldValue(model.SupplierInvoiceDate, tz);
 }
Пример #4
0
        public Error SendPurchaseOrderToSupplier(PurchaseOrderHeaderTempModel poht, UserModel sender, CompanyModel company)
        {
            // Create PO PDF and CSV, then send to Warehouse
            string pdfFile = "";
            var    error   = CreatePurchaseOrderPdf(poht, company.POSupplierTemplateId, null, ref pdfFile);

            if (!error.IsError)
            {
                FilePackagerService.FilePackagerService fpService = new FilePackagerService.FilePackagerService(db);
                error = fpService.SendPurchaseOrderToSupplier(poht.Id, sender, pdfFile);
            }
            if (error.IsError)
            {
                MediaService.MediaService.DeleteFile(pdfFile);
            }
            return(error);
        }
        public PurchaseOrderHeaderTempModel FindPurchaseOrderHeaderTempModel(int id, CompanyModel company, bool bCreateEmptyIfNotfound = true)
        {
            PurchaseOrderHeaderTempModel model = null;

            var p = db.FindPurchaseOrderHeaderTemp(id);

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

            return(model);
        }

        PurchaseOrderHeaderTempModel mapToModel(PurchaseOrderHeaderTemp item)
        {
            var newItem = Mapper.Map <PurchaseOrderHeaderTemp, PurchaseOrderHeaderTempModel>(item);

            var poStatus = db.FindPurchaseOrderHeaderStatus(newItem.POStatus);

            if (poStatus != null)
            {
                newItem.POStatusText  = poStatus.StatusName;
                newItem.POStatusValue = (PurchaseOrderStatus)poStatus.StatusValue;
            }
            newItem.SalesPersonName = db.MakeName(item.User_SalesPerson);
            newItem.Splitable       = item.PurchaseOrderDetailTemps.Count() > 0;

            return(newItem);
        }
        public PurchaseOrderSummaryModel CreateOrderSummary(PurchaseOrderHeaderTempModel poht,
                                                            string dateFormat)
        {
            var model = Mapper.Map <PurchaseOrderHeaderTempModel, PurchaseOrderSummaryModel>(poht);

            model.OrderNumber = poht.OrderNumber;

            model.TotalCbms        = 0;
            model.AllocValueEx     = 0;
            model.OrderValueEx     = 0;
            model.AllocatedPercent = 0;
            model.Tax   = 0;
            model.Total = 0;

            // The tax code comes from the supplier
            double   taxRate  = 0;
            Supplier supplier = null;

            if (poht.SupplierId != null)
            {
                supplier = db.FindSupplier(poht.SupplierId.Value);
                if (supplier.TaxCode != null)
                {
                    model.TaxCode = supplier.TaxCode.TaxCode1;
                    if (supplier.TaxCode.TaxPercentageRate != null)
                    {
                        taxRate = (double)supplier.TaxCode.TaxPercentageRate.Value;
                    }
                }
            }

            // Now traverse all the items on the order
            foreach (var orderLine in FindPurchaseOrderDetailTempsListModel(poht.CompanyId, poht.Id, 0, 1, 9999, "").Items)
            {
                if (orderLine.OrderQty != null)
                {
                    model.TotalCbms += orderLine.UnitCBM * orderLine.OrderQty;
                }
                //model.AllocValueEx +=

                double linePrice = 0;
                if (orderLine.UnitPriceExTax != null && orderLine.OrderQty != null)
                {
                    linePrice += (double)orderLine.UnitPriceExTax * (double)orderLine.OrderQty;
                }
                model.OrderValueEx += (double)orderLine.LinePrice;

                //model.AllocatedPercent +=

                double gstAmount = linePrice / 100 * taxRate;
                model.Tax += gstAmount;
            }
            model.Total = model.OrderValueEx + model.Tax;

            // Order status
            var poStatus = db.FindPurchaseOrderHeaderStatus(poht.POStatus);

            if (poStatus != null)
            {
                model.POStatusText = poStatus.StatusName;
            }

            // Landing date
            model.LandingDate = formatDate(poht.LandingDate, dateFormat);

            // Reallistic ETA
            model.RealisticRequiredDate = formatDate(poht.RealisticRequiredDate, dateFormat);

            // Adv US Final
            model.RequiredDate = formatDate(poht.RequiredDate, dateFormat);

            // Completed Date
            model.CompletedDate = formatDate(poht.CompletedDate, dateFormat);

            return(model);
        }
 public string LockPurchaseOrderHeaderTemp(PurchaseOrderHeaderTempModel model)
 {
     return(db.LockRecord(typeof(PurchaseOrderHeaderTemp).ToString(), model.Id));
 }
Пример #8
0
 public Error CreatePurchaseOrderPdf(PurchaseOrderHeaderTempModel poht, int?templateId,
                                     string pdfFile, ref string outputFile)
 {
     return(CreatePurchaseOrderPdf(db.FindPurchaseOrderHeader(poht.OriginalRowId), templateId ?? 0, pdfFile, ref outputFile));
 }
Пример #9
0
        public PurchaseOrderHeaderTempModel CopyPurchaseOrderToTemp(CompanyModel company,
                                                                    PurchaseOrderHeaderModel purchaseOrderHeader,
                                                                    UserModel user)
        {
            PurchaseOrderHeaderTempModel result = new PurchaseOrderHeaderTempModel();
            PurchaseOrderHeaderTemp      poht   = new PurchaseOrderHeaderTemp();

            // Clean the temp tables
            if (purchaseOrderHeader.Id > 0)
            {
                // Editing an existing order
                var poh = db.FindPurchaseOrderHeader(purchaseOrderHeader.Id);
                if (poh != null)
                {
                    // Copy the header
                    poht = db.FindPurchaseOrderHeaderTemps(company.Id)
                           .Where(p => p.UserId == user.Id &&
                                  p.OriginalRowId == purchaseOrderHeader.Id)
                           .FirstOrDefault();
                    if (poht != null)
                    {
                        // Already exists in the temp tables so update it with the latest data
                        int tempId = poht.Id;
                        Mapper.Map <PurchaseOrderHeader, PurchaseOrderHeaderTemp>(poh, poht);
                        poht.Id            = tempId;
                        poht.OriginalRowId = purchaseOrderHeader.Id;
                        poht.UserId        = user.Id;

                        db.InsertOrUpdatePurchaseOrderHeaderTemp(poht);
                        result = mapToModel(poht);
                    }
                    else
                    {
                        // Doesn't exist, so copy
                        poht               = Mapper.Map <PurchaseOrderHeader, PurchaseOrderHeaderTemp>(poh);
                        poht.Id            = 0;
                        poht.OriginalRowId = purchaseOrderHeader.Id;
                        poht.UserId        = user.Id;

                        db.InsertOrUpdatePurchaseOrderHeaderTemp(poht);
                        result = mapToModel(poht);
                    }

                    // Now copy/merge the details
                    db.CopyPurchaseOrderToTemp(company.Id, user.Id, purchaseOrderHeader.Id, poht.Id);

                    result.Splitable = db.FindPurchaseOrderDetailTemps(company.Id, poht.Id).Count() > 0;
                }
            }
            else
            {
                // New purchase
                poht.CompanyId       = company.Id;
                poht.UserId          = user.Id;
                poht.OrderNumber     = purchaseOrderHeader.OrderNumber;
                poht.OrderDate       = purchaseOrderHeader.OrderDate;
                poht.SalespersonId   = purchaseOrderHeader.SalespersonId;
                poht.BrandCategoryId = purchaseOrderHeader.BrandCategoryId;
                poht.LocationId      = purchaseOrderHeader.LocationId;
                poht.CancelMessage   = purchaseOrderHeader.CancelMessage;

                db.InsertOrUpdatePurchaseOrderHeaderTemp(poht);
                result = mapToModel(poht);
            }

            return(result);
        }