Ejemplo n.º 1
0
        public static List <OperationContainerVm> GetOperationContainers(int id)
        {
            OperationsEntities          db            = new OperationsEntities();
            Dictionary <int, string>    contList      = ListCommonHelper.GetContainerList();
            Dictionary <int, string>    packageList   = ListCommonHelper.GetPackageTypeList();
            List <OperationContainerVm> oprContainers = new List <OperationContainerVm>();
            var operConDb = db.OperationContainers.Where(x => x.OperationId == id).ToList();

            Mapper.CreateMap <OperationContainer, OperationContainerVm>().IgnoreAllNonExisting();

            Mapper.Map(operConDb, oprContainers);
            foreach (var item in oprContainers)
            {
                try
                {
                    item.ContainerTypeName = contList[item.ContainerTypeId];
                }
                catch { }

                if (item.PackageTypeId != null)
                {
                    item.PackageTypeName = packageList[item.PackageTypeId.Value];
                }
            }

            if (oprContainers.Count == 0)
            {
                OperationContainerVm operContObj = new OperationContainerVm();
                oprContainers.Add(operContObj);
            }


            return(oprContainers);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get container summary for operation
        /// </summary>
        /// <param name="operationId">int operation id</param>
        /// <returns>string like 2x20' 4xLCL 3x40'</returns>
        internal static string GetContainersSummary(int operationId)
        {
            OperationsEntities db = new OperationsEntities();
            var contList          = db.OperationContainers.Where(x => x.OperationId == operationId)
                                    .GroupBy(x => x.ContainerTypeId, (key, values) => new { ContainerTypeId = key, count = values.Count() }).ToList();

            Dictionary <int, string> containerTypeList = ListCommonHelper.GetContainerList();
            StringBuilder            result            = new StringBuilder();

            foreach (var item in contList)
            {
                if (item.ContainerTypeId == 0)
                {
                    result.Append("Air Container");
                }
                else
                {
                    result.Append(containerTypeList[item.ContainerTypeId]);
                }

                result.Append("x");
                result.Append(item.count);
                result.Append("  ");
            }

            return(result.ToString());
        }
Ejemplo n.º 3
0
 public static void GetCCCashDepositCostList(int operationId)
 {
     var operCostObj                 = AccountingHelper.GetOperationCost(operationId, 0);
     var operCostList                = operCostObj.OperationCostAccVms;
     var operCostTotalList           = operCostObj.OperationCostTotalAccVms;
     Dictionary <int, string> ccCost = ListCommonHelper.GetCustClearCostList();
 }
Ejemplo n.º 4
0
        //internal static CcCostAccVm AddCCCostForAccounting(int operId, int CcCostAccId = 0)
        //{
        //    CcCostAccVm costAccVm;
        //    //Get custom cleance cost for the full operation
        //    var operCostObj = AccountingHelper.GetOperationCost(operId);

        //    var operCostList = operCostObj.OperationCostAccVms;
        //    var operCostTotalList = operCostObj.OperationCostTotalAccVms;

        //    CcCostAccDetailVm costAccDetailVm;


        //}


        internal static List <CustomClearanceDetailVm> GetCCDetailsListByOperId(int operId)
        {
            List <CustomClearanceDetailVm> detailsListVm = new List <CustomClearanceDetailVm>();
            OperationsEntities             db            = new OperationsEntities();
            var detailsListDb = db.CustomClearanceDetails.Where(x => x.CustomClearanceOrder.OperationId == operId).ToList();

            Mapper.CreateMap <CustomClearanceDetail, CustomClearanceDetailVm>().IgnoreAllNonExisting();
            Mapper.Map(detailsListDb, detailsListVm);

            Dictionary <int, string> ccCostLib    = ListCommonHelper.GetCustClearCostList();
            Dictionary <int, string> currencyList = ListCommonHelper.GetCurrencyList();

            foreach (var item in detailsListVm)
            {
                item.CCCostName   = ccCostLib[item.CCCostId];
                item.CurrencySign = currencyList[item.CurrencyId];
            }
            return(detailsListVm);
        }
Ejemplo n.º 5
0
        internal static List <QuotationContainerVm> GetQuotationContainers(int id)
        {
            OperationsEntities          db              = new OperationsEntities();
            Dictionary <int, string>    contList        = ListCommonHelper.GetContainerList();
            List <QuotationContainerVm> quoteContainers = new List <QuotationContainerVm>();
            var qouteConDb = db.QuotationContainers.Where(x => x.QuoteId == id).ToList();

            Mapper.CreateMap <QuotationContainer, QuotationContainerVm>().IgnoreAllNonExisting();

            Mapper.Map(qouteConDb, quoteContainers);
            foreach (var item in quoteContainers)
            {
                if (item.ContainerTypeId != 0)
                {
                    item.ContainerTypeName = contList[item.ContainerTypeId.Value];
                }
                else
                {
                    item.ContainerTypeName = "Air";
                }
            }

            return(quoteContainers);
        }
Ejemplo n.º 6
0
        public static InvoiceVm GetInvoiceInfoNew(int hbId = 0, int invId = 0, bool forEdit = true)
        {
            InvoiceVm invoiceVm = new InvoiceVm(0);


            AccountingEntities db = new AccountingEntities();

            if (invId != 0)
            {
                Invoice invDb = db.Invoices.Where(x => x.InvoiceId == invId).FirstOrDefault();
                Mapper.CreateMap <Invoice, InvoiceVm>().IgnoreAllNonExisting();
                Mapper.CreateMap <InvoiceDetail, InvoiceDetailVm>().IgnoreAllNonExisting();
                Mapper.CreateMap <InvoiceTotal, InvoiceTotalVm>().IgnoreAllNonExisting();
                Mapper.Map(invDb, invoiceVm);

                //invoiceVm.FromPort = hbInfo.FromPort;
                //invoiceVm.ToPort = hbInfo.ToPort;
                invoiceVm.PaymentTermName = invDb.PaymentTerm.PaymentTermEn;
                invoiceVm.CurrencySign    = invDb.Currency.CurrencySign;
                //invType = invDb.InvoiceType;

                //Add Tax part
                //decimal totalBeforeTax = invoiceVm.InvoiceDetails.Sum(x => x.InvoiceAmount);
                // invoiceVm.InvoiceTotals.FirstOrDefault().TotalBeforeTax = totalBeforeTax;
                // invoiceVm.InvoiceTotals.FirstOrDefault().TaxDepositAmount = totalBeforeTax - invoiceVm.InvoiceTotals.FirstOrDefault().TotalAmount;
            }
            else
            {
                invoiceVm.InvoiceCode = AdminHelper.GeneratePrefixCode(PrefixForEnum.AccountingInvoice, false);
            }

            if (hbId == 0)
            {
                hbId = invoiceVm.HouseBillId.Value;
            }

            OperationsEntities db1 = new OperationsEntities();
            var hbInfo             = db1.HouseBillViews.Where(x => x.HouseBillId == hbId).FirstOrDefault();

            Mapper.CreateMap <HouseBillView, InvoiceVm>()
            .ForMember(x => x.CreateBy, y => y.Ignore())
            .ForMember(x => x.CreateDate, y => y.Ignore())
            .IgnoreAllNonExisting();
            Mapper.Map(hbInfo, invoiceVm);

            if (hbInfo.OrderFrom == 1)
            {
                invoiceVm.CustomerName = hbInfo.ShipperNameEn;
                invoiceVm.ConsigneeId  = null;
            }
            else
            {
                invoiceVm.CustomerName = hbInfo.ConsigneeNameEn;
                invoiceVm.ShipperId    = null;
            }

            //Get Cost list
            var operCostObj = AccountingHelper.GetOperationCost(invoiceVm.OperationId, invoiceVm.HouseBillId.Value);

            var operCostList      = operCostObj.OperationCostAccVms;
            var operCostTotalList = operCostObj.OperationCostTotalAccVms;

            GetHbInvTotal(0, ref operCostList, ref operCostTotalList);

            invoiceVm.OperationCostAccVms      = operCostList;
            invoiceVm.OperationCostTotalAccVms = operCostTotalList;



            if (forEdit)
            {
                //Get prev invoice details for this HB
                // adding condation  [x.Invoice.IsDeleted==null] get undeleted invoices
                var prevInvDetails = db.InvoiceDetails
                                     .Where(x => x.Invoice.HouseBillId == hbId && x.Invoice.IsDeleted == null).OrderBy(x => x.ItemOrder)
                                     .Select(x => new { x.CostFkId, x.FkType })
                                     .ToList();
                InvoiceDetailVm invDetailVm;
                //Add other costs that are not inserted in inv details table
                for (int i = 1; i < 4; i++) // loop for the three cost types
                {
                    List <int> usedCost = invoiceVm.InvoiceDetails.Where(x => x.FkType == i).Select(x => x.CostFkId).ToList();
                    usedCost.AddRange(prevInvDetails.Where(x => x.FkType == i).Select(x => x.CostFkId).ToList());
                    var newCosts = operCostList.Where(x => !usedCost.Contains(x.CostFkId) && x.FkType == i).ToList();
                    foreach (var item in newCosts)
                    {
                        invDetailVm = new InvoiceDetailVm()
                        {
                            CostFkId       = item.CostFkId,
                            CostName       = item.CostName,
                            ExchangeRate   = 1,
                            FkType         = item.FkType,
                            InvDetailId    = 0,
                            InvoiceAmount  = item.SellingRate,
                            InvoiceId      = invoiceVm.InvoiceId,
                            MainAmount     = item.SellingRate,
                            MainCurrencyId = item.CurrencyIdSelling,
                            MainCurrSign   = item.CurrencySignSelling
                        };

                        invoiceVm.InvoiceDetails.Add(invDetailVm);
                    }
                }

                if (invoiceVm.InvoiceTotals.Count == 0)
                {
                    InvoiceTotalVm invTotal = new InvoiceTotalVm()
                    {
                        CurrencyId   = invoiceVm.InvCurrencyId,
                        CurrencySign = invoiceVm.CurrencySign,
                        InvoiceId    = invoiceVm.InvoiceId,
                        TotalAmount  = 0
                    };

                    invoiceVm.InvoiceTotals.Add(invTotal);
                }
            }
            else
            {
                Dictionary <int, string> operCost  = new Dictionary <int, string>();
                Dictionary <int, string> truckCost = new Dictionary <int, string>();
                Dictionary <int, string> ccCost    = new Dictionary <int, string>();
                if (invoiceVm.InvoiceDetails.Any(x => x.FkType == (byte)CostType.OperationCost))
                {
                    operCost = ListCommonHelper.GetOperationCostList();
                }
                if (invoiceVm.InvoiceDetails.Any(x => x.FkType == (byte)CostType.TruckingCost))
                {
                    truckCost = ListCommonHelper.GetTruckingCostNameList();
                }
                if (invoiceVm.InvoiceDetails.Any(x => x.FkType == (byte)CostType.CCCost))
                {
                    ccCost = ListCommonHelper.GetCustClearCostList();
                }
                //Get cost name for invoice items
                foreach (var item in invoiceVm.InvoiceDetails)
                {
                    item.CostName = invoiceVm.OperationCostAccVms
                                    .Where(x => x.CostFkId == item.CostFkId && x.FkType == item.FkType)
                                    .FirstOrDefault().CostName;
                }
            }
            invoiceVm.InvoiceDetails = invoiceVm.InvoiceDetails.OrderBy(z => z.ItemOrder).ToList();
            return(invoiceVm);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="operId"></param>
        /// <param name="invId"></param>
        /// <param name="invFor">if = 1  Invoice for Carrier .. if 2 invoice for Contractor .. if 3 custom clearance</param>
        /// <param name="forEdit"></param>
        /// <returns></returns>
        public static InvoiceVm GetInvoiceInfoFullOperation(int operId = 0, int invId = 0, byte invFor = 1, bool forEdit = true)
        {
            InvoiceVm          invoiceVm = new InvoiceVm(invFor);
            AccountingEntities db        = new AccountingEntities();

            if (invId != 0)
            {
                InvoiceAP invDb = db.InvoiceAPs.Include("InvoiceDetailAPs").Include("InvoiceTotalAPs")
                                  .Where(x => x.InvoiceId == invId && x.IsDeleted == null).FirstOrDefault();
                Mapper.CreateMap <InvoiceAP, InvoiceVm>()
                .IgnoreAllNonExisting();

                Mapper.Map(invDb, invoiceVm);

                Mapper.CreateMap <InvoiceDetailAP, InvoiceDetailVm>().IgnoreAllNonExisting();
                Mapper.CreateMap <InvoiceTotalAP, InvoiceTotalVm>().IgnoreAllNonExisting();

                InvoiceDetailVm invDetVm;
                foreach (var item in invDb.InvoiceDetailAPs)
                {
                    invDetVm = new InvoiceDetailVm();
                    Mapper.Map(item, invDetVm);
                    invoiceVm.InvoiceDetails.Add(invDetVm);
                }

                InvoiceTotalVm invTotalVm;
                foreach (var item in invDb.InvoiceTotalAPs)
                {
                    invTotalVm = new InvoiceTotalVm();
                    Mapper.Map(item, invTotalVm);
                    invoiceVm.InvoiceTotals.Add(invTotalVm);
                }


                invoiceVm.PaymentTermName = invDb.PaymentTerm.PaymentTermEn;
                invoiceVm.CurrencySign    = invDb.Currency.CurrencySign;
            }
            else
            {
                invoiceVm.InvoiceCode = AdminHelper.GeneratePrefixCode(PrefixForEnum.APInvoice, false);
            }

            if (operId == 0)
            {
                operId = invoiceVm.OperationId;
            }

            OperationsEntities db1 = new OperationsEntities();
            var hbInfo             = db1.OperationViews.Where(x => x.OperationId == operId).FirstOrDefault();

            Mapper.CreateMap <OperationView, InvoiceVm>()
            .ForMember(x => x.CreateBy, y => y.Ignore())
            .ForMember(x => x.CreateDate, y => y.Ignore())
            .IgnoreAllNonExisting();
            Mapper.Map(hbInfo, invoiceVm);

            if (invFor == 1) //Carrier
            {
                invoiceVm.ContractorId = null;
                invoiceVm.SupplierName = hbInfo.CarrierNameEn;
                invoiceVm.CustomerName = hbInfo.CarrierNameEn;
            }
            else if (invFor == 2)
            {
                var contractorInfo = db1.TruckingOrdersViews
                                     .Where(x => x.OperationId == operId)
                                     .Select(x => new { x.ContractorId, x.ContractorNameEn })
                                     .FirstOrDefault();
                if (contractorInfo != null)
                {
                    invoiceVm.CarrierId    = null;
                    invoiceVm.SupplierName = contractorInfo.ContractorNameEn;
                    invoiceVm.ContractorId = contractorInfo.ContractorId;
                    invoiceVm.CustomerName = contractorInfo.ContractorNameEn;
                }
            }
            else if (invFor == 3)
            {
                invoiceVm.SupplierName = "Custom Clearance";
                invoiceVm.CustomerName = "Custom Clearance";
            }

            //Get Cost list
            var operCostObj = AccountingHelper.GetOperationCost(invoiceVm.OperationId, 0);

            var operCostList      = operCostObj.OperationCostAccVms;
            var operCostTotalList = operCostObj.OperationCostTotalAccVms;

            // GetHbInvTotal(0, ref operCostList, ref operCostTotalList);

            invoiceVm.OperationCostAccVms      = operCostList;
            invoiceVm.OperationCostTotalAccVms = operCostTotalList;

            if (forEdit)
            {
                //Get prev invoice details for this HB
                var prevInvDetails = db.InvoiceDetailAPs
                                     .Where(x => x.InvoiceAP.OperationId == operId && x.InvoiceAP.IsDeleted == null)
                                     .Select(x => new { x.CostFkId, x.FkType })
                                     .ToList();

                InvoiceDetailVm invDetailVm;
                //invFor == 1 ..get operation cost only
                //invFor == 2 ..get trucking cost only
                //invFor == 3 ..get custom clearance cost only
                List <int> usedCost = invoiceVm.InvoiceDetails.Where(x => x.FkType == invFor).Select(x => x.CostFkId).ToList();
                usedCost.AddRange(prevInvDetails.Where(x => x.FkType == invFor).Select(x => x.CostFkId).ToList());
                var newCosts = operCostList.Where(x => !usedCost.Contains(x.CostFkId) && x.FkType == invFor).ToList();

                foreach (var item in newCosts.Where(x => x.NetRate > 0))
                {
                    invDetailVm = new InvoiceDetailVm()
                    {
                        CostFkId       = item.CostFkId,
                        CostName       = item.CostName,
                        ExchangeRate   = 1,
                        FkType         = item.FkType,
                        InvDetailId    = 0,
                        InvoiceAmount  = item.NetRate,
                        InvoiceId      = invoiceVm.InvoiceId,
                        MainAmount     = item.NetRate,
                        MainCurrencyId = item.CurrencyId,
                        MainCurrSign   = item.CurrencySign
                    };

                    invoiceVm.InvoiceDetails.Add(invDetailVm);
                }

                if (invoiceVm.InvoiceTotals.Count == 0)
                {
                    InvoiceTotalVm invTotal = new InvoiceTotalVm()
                    {
                        CurrencyId   = invoiceVm.InvCurrencyId,
                        CurrencySign = invoiceVm.CurrencySign,
                        InvoiceId    = invoiceVm.InvoiceId,
                        TotalAmount  = 0
                    };

                    invoiceVm.InvoiceTotals.Add(invTotal);
                }
            }
            else
            {
                Dictionary <int, string> operCost  = new Dictionary <int, string>();
                Dictionary <int, string> truckCost = new Dictionary <int, string>();
                Dictionary <int, string> ccCost    = new Dictionary <int, string>();
                if (invoiceVm.InvoiceDetails.Any(x => x.FkType == (byte)CostType.OperationCost))
                {
                    operCost = ListCommonHelper.GetOperationCostList();
                }
                else if (invoiceVm.InvoiceDetails.Any(x => x.FkType == (byte)CostType.TruckingCost))
                {
                    truckCost = ListCommonHelper.GetTruckingCostNameList();
                }
                else if (invoiceVm.InvoiceDetails.Any(x => x.FkType == (byte)CostType.CCCost))
                {
                    ccCost = ListCommonHelper.GetCustClearCostList();
                }
                //Get cost name for invoice items
                foreach (var item in invoiceVm.InvoiceDetails)
                {
                    item.CostName = invoiceVm.OperationCostAccVms
                                    .Where(x => x.CostFkId == item.CostFkId && x.FkType == item.FkType)
                                    .FirstOrDefault().CostName;
                }
            }

            return(invoiceVm);
        }