Exemplo n.º 1
0
        public void ValidateSinglePolicy(int dealID, int insuranceSubTypeID)
        {
            Deal deal = Deal.Get(dealID);

            if (deal == null)
            {
                ValidationErrors.Add("DealValidator", "Немате избрано валиден договор");
            }
            InsuranceSubType ist = InsuranceSubType.Get(insuranceSubTypeID);

            if (ist == null)
            {
                ValidationErrors.Add("InsuranceSubType", "Немате избрано подкласа на осигурување");
            }
        }
Exemplo n.º 2
0
        public static Facture Generate(DateTime startDate, DateTime endDate, InsuranceCompany ic, User u, DateTime dateOfPayment, List <PolicyItem> policiesToRemove)
        {
            List <Payment> paymentList                 = Payment.GetForFactureByDateAndInsuranceCompany(endDate, ic.ID);
            decimal        brokerageValue              = 0;
            decimal        totalSum                    = 0;
            decimal        currentBrokerageValue       = 0;
            Dictionary <int, decimal[]> dictionary     = new Dictionary <int, decimal[]>();
            List <PolicyItem>           policyItemList = new List <PolicyItem>();

            foreach (Payment p in paymentList)
            {
                //Koeficient so cel da se presmetuva brokerazata na polisiranata premija
                decimal k = 1;
                if (p.Rate.PolicyItem.PremiumValue > 0)
                {
                    k = p.Rate.PolicyItem.RealPremiumValue / p.Rate.PolicyItem.PremiumValue;
                }
                PolicyItem policyItem = p.Rate.PolicyItem;
                if (!policiesToRemove.Contains(policyItem))
                {
                    if (!policyItemList.Contains(policyItem))
                    {
                        policyItemList.Add(policyItem);
                    }
                    if (policyItem.Policy.PacketID != null)
                    {
                        if (policyItem.Policy.Client.IsLaw)
                        {
                            currentBrokerageValue = k * p.Value * policyItem.PacketsInsuranceSubType.BrokeragePecentageForLaws / 100;
                        }
                        else
                        {
                            currentBrokerageValue = k * p.Value * policyItem.PacketsInsuranceSubType.BrokeragePecentageForPrivates / 100;
                        }
                    }
                    else
                    {
                        if (policyItem.Policy.Client.IsLaw)
                        {
                            currentBrokerageValue = k * p.Value * policyItem.Brokerage.PercentageForLaws / 100;
                        }
                        else
                        {
                            currentBrokerageValue = k * p.Value * policyItem.Brokerage.PercentageForPrivates / 100;
                        }
                    }
                    brokerageValue += currentBrokerageValue;
                    if (dictionary.ContainsKey(policyItem.InsuranceSubTypeID))
                    {
                        dictionary[policyItem.InsuranceSubTypeID][0] += currentBrokerageValue;
                        dictionary[policyItem.InsuranceSubTypeID][1] += p.Value;
                        // dictionary[policyItem.InsuranceSubTypeID][2] += 1;
                    }
                    else
                    {
                        decimal[] newValues = { currentBrokerageValue, p.Value /*, 1 */ };
                        dictionary.Add(policyItem.InsuranceSubTypeID, newValues);
                    }
                    totalSum += p.Value;
                }
            }


            //da se zemat vo predvid i zaokruzuvanjata
            decimal calcBrokValue = 0;

            foreach (KeyValuePair <int, decimal[]> kvp in dictionary)
            {
                calcBrokValue += ScaleController.Scale5(kvp.Value[0]);
            }


            if (policyItemList.Count > 0)
            {
                Facture f = new Facture();
                //f.BrokerageValue = ScaleController.Scale5(brokerageValue);
                f.BrokerageValue = calcBrokValue;
                f.TotalCost      = totalSum;
                int    clientID = 1;
                Client client   = Client.GetByEmbg(ic.EMBG);
                if (client != null)
                {
                    clientID = client.ID;
                }
                else
                {
                    Client newClient = new Client();
                    newClient.Address            = ic.Address;
                    newClient.EMail              = string.Empty;
                    newClient.EMBG               = ic.EMBG;
                    newClient.Fax                = string.Empty;
                    newClient.IsInsuranceCompany = true;
                    newClient.Mobile             = string.Empty;
                    newClient.Name               = ic.Name;
                    newClient.Phone              = string.Empty;
                    newClient.PlaceID            = Place.Table.First().ID;
                    newClient.Insert();
                    clientID = newClient.ID;
                }
                f.ClientID          = clientID;
                f.DateOfCreation    = DateTime.Today;
                f.DocumentSubTypeID = DocumentSubType.GetByCode(DocumentSubType.FAKTURA_PROVIZIJA).ID;
                //f.FactureNumber = CodeGenerator.GenerateFactureNumber();
                f.FactureNumber      = CodeGenerator.GenerateFactureNumberForBrokerageFactures();
                f.FromDate           = startDate;
                f.ToDate             = endDate;
                f.StatusID           = Statuse.GetByCode(Statuse.NEPLATENA_IZLEZNA_FAKTURA_ZA_PROVIZIJA).ID;
                f.DateOfPayment      = dateOfPayment;
                f.Discard            = false;
                f.InsuranceCompanyID = ic.ID;
                f.UserID             = u.ID;
                f.Insert();

                //List<FactureItem> listFactureItems = new List<FactureItem>();
                int ordinalNumber = 1;
                foreach (KeyValuePair <int, decimal[]> kvPair in dictionary)
                {
                    FactureItem fi = new FactureItem();
                    fi.Facture            = f;
                    fi.BrokerageValue     = ScaleController.Scale5(kvPair.Value[0]);
                    fi.PremiumValue       = kvPair.Value[1];
                    fi.Number             = ordinalNumber;
                    fi.InsuranceSubTypeID = kvPair.Key;
                    List <PolicyItem> subList = policyItemList.Where(c => c.InsuranceSubTypeID == kvPair.Key).ToList();
                    fi.Count       = subList.Count;
                    fi.Description = InsuranceSubType.Get(kvPair.Key).ShortDescription;
                    ordinalNumber++;
                    f.FactureItems.Add(fi);
                    fi.Insert();
                    PolicyItemFactureItem.InsertForFacture(fi, subList);
                }

                Payment.SetFactured(paymentList, f, policiesToRemove);
                return(f);
            }
            return(null);
        }
Exemplo n.º 3
0
        public static Facture GenerateForLife(DateTime startDate, DateTime endDate, InsuranceCompany ic, User u, DateTime dateOfPayment, List <LifePolicy> policiesToRemove)
        {
            List <LifePolicyBrokerage> paymentList = LifePolicyBrokerage.Table.Where(c => c.LifePolicy.InsuranceCompanyID == ic.ID && c.LifePolicy.Discard == false &&
                                                                                     c.FromDate.Date <= endDate.Date).ToList();
            decimal brokerageValue = 0;
            decimal totalSum       = 0;
            Dictionary <int, decimal[]> dictionary     = new Dictionary <int, decimal[]>();
            List <LifePolicy>           policyItemList = new List <LifePolicy>();

            foreach (LifePolicyBrokerage p in paymentList)
            {
                if (!policiesToRemove.Contains(p.LifePolicy))
                {
                    if (!policyItemList.Contains(p.LifePolicy))
                    {
                        policyItemList.Add(p.LifePolicy);
                    }
                    brokerageValue += p.Value;
                    if (dictionary.ContainsKey(p.LifePolicy.InsuranceSubTypeID))
                    {
                        dictionary[p.LifePolicy.InsuranceSubTypeID][0] += brokerageValue;
                        dictionary[p.LifePolicy.InsuranceSubTypeID][1] += p.LifePolicy.TotalPremumValue;
                    }
                    else
                    {
                        decimal[] newValues = { brokerageValue, p.LifePolicy.TotalPremumValue };
                        dictionary.Add(p.LifePolicy.InsuranceSubTypeID, newValues);
                    }
                    totalSum += p.LifePolicy.TotalPremumValue;
                }
            }


            //da se zemat vo predvid i zaokruzuvanjata
            decimal calcBrokValue = 0;

            foreach (KeyValuePair <int, decimal[]> kvp in dictionary)
            {
                calcBrokValue += ScaleController.Scale5(kvp.Value[0]);
            }


            if (policyItemList.Count > 0)
            {
                Facture f = new Facture();
                //f.BrokerageValue = ScaleController.Scale5(brokerageValue);
                f.BrokerageValue = calcBrokValue;
                f.TotalCost      = totalSum;
                int    clientID = 1;
                Client client   = Client.GetByEmbg(ic.EMBG);
                if (client != null)
                {
                    clientID = client.ID;
                }
                else
                {
                    Client newClient = new Client();
                    newClient.Address            = ic.Address;
                    newClient.EMail              = string.Empty;
                    newClient.EMBG               = ic.EMBG;
                    newClient.Fax                = string.Empty;
                    newClient.IsInsuranceCompany = true;
                    newClient.Mobile             = string.Empty;
                    newClient.Name               = ic.Name;
                    newClient.Phone              = string.Empty;
                    newClient.PlaceID            = Place.Table.First().ID;
                    newClient.Insert();
                    clientID = newClient.ID;
                }
                f.ClientID           = clientID;
                f.DateOfCreation     = DateTime.Today;
                f.DocumentSubTypeID  = DocumentSubType.GetByCode(DocumentSubType.IZLEZNA_FAKTURA_ZA_PROVZIJA_ZA_ZIVOTNO_OSUGURUVANjE).ID;
                f.FactureNumber      = CodeGenerator.GenerateFactureNumber();
                f.FromDate           = startDate;
                f.ToDate             = endDate;
                f.StatusID           = Statuse.GetByCode(Statuse.NEPLATENA_IZLEZNA_FAKTURA_ZA_PROVIZIJA_ZA_ZIVOTNO).ID;
                f.DateOfPayment      = dateOfPayment;
                f.Discard            = false;
                f.InsuranceCompanyID = ic.ID;
                f.UserID             = u.ID;
                f.Insert();

                //List<FactureItem> listFactureItems = new List<FactureItem>();
                int ordinalNumber = 1;
                foreach (KeyValuePair <int, decimal[]> kvPair in dictionary)
                {
                    FactureItem fi = new FactureItem();
                    fi.Facture            = f;
                    fi.BrokerageValue     = ScaleController.Scale5(kvPair.Value[0]);
                    fi.PremiumValue       = kvPair.Value[1];
                    fi.Number             = ordinalNumber;
                    fi.InsuranceSubTypeID = kvPair.Key;
                    List <LifePolicy> subList = policyItemList.Where(c => c.InsuranceSubTypeID == kvPair.Key).ToList();
                    fi.Count       = subList.Count;
                    fi.Description = InsuranceSubType.Get(kvPair.Key).ShortDescription;
                    ordinalNumber++;
                    f.FactureItems.Add(fi);
                    fi.Insert();
                    LifePolicyFactureItem.InsertForFacture(fi, subList);
                }

                LifePolicyBrokerage.SetFactured(paymentList, f, policiesToRemove);
                return(f);
            }
            return(null);
        }
Exemplo n.º 4
0
        public static AccountFacture Generate(string factureNumber, DateTime startDate, DateTime endDate, InsuranceCompany ic, User u, DateTime dateOfPayment, List <PolicyItem> policiesToInclude, Branch branch)
        {
            decimal brokerageValue                          = 0;
            decimal totalSum                                = 0;
            decimal currentBrokerageValue                   = 0;
            Dictionary <int, decimal[]>   dictionary        = new Dictionary <int, decimal[]>();
            Dictionary <int, List <int> > dictionaryPolList = new Dictionary <int, List <int> >();

            foreach (PolicyItem policyItem in policiesToInclude)
            {
                if (policyItem.Policy.PacketID != null)
                {
                    if (policyItem.Policy.Client.IsLaw)
                    {
                        currentBrokerageValue = policyItem.PremiumValue * policyItem.PacketsInsuranceSubType.BrokeragePecentageForLaws / 100;
                    }
                    else
                    {
                        currentBrokerageValue = policyItem.PremiumValue * policyItem.PacketsInsuranceSubType.BrokeragePecentageForPrivates / 100;
                    }
                }
                else
                {
                    if (policyItem.Policy.Client.IsLaw)
                    {
                        currentBrokerageValue = policyItem.PremiumValue * policyItem.Brokerage.PercentageForLaws / 100;
                    }
                    else
                    {
                        currentBrokerageValue = policyItem.PremiumValue * policyItem.Brokerage.PercentageForPrivates / 100;
                    }
                }
                brokerageValue += currentBrokerageValue;
                if (dictionary.ContainsKey(policyItem.InsuranceSubTypeID))
                {
                    dictionary[policyItem.InsuranceSubTypeID][0] += currentBrokerageValue;
                    dictionary[policyItem.InsuranceSubTypeID][1] += policyItem.PremiumValue;
                    //dictionary[policyItem.InsuranceSubTypeID][2] += 1;
                    dictionaryPolList[policyItem.InsuranceSubTypeID].Add(policyItem.ID);
                }
                else
                {
                    decimal[] newValues = { currentBrokerageValue, policyItem.PremiumValue /*, 1*/ };
                    dictionary.Add(policyItem.InsuranceSubTypeID, newValues);
                    List <int> cL = new List <int>();
                    cL.Add(policyItem.ID);
                    dictionaryPolList.Add(policyItem.InsuranceSubTypeID, cL);
                }
                totalSum += policyItem.PremiumValue;
            }


            //da se zemat vo predvid i zaokruzuvanjata
            decimal calcBrokValue = 0;

            foreach (KeyValuePair <int, decimal[]> kvp in dictionary)
            {
                calcBrokValue += ScaleController.Scale5(kvp.Value[0]);
            }


            if (policiesToInclude.Count > 0)
            {
                AccountFacture f = new AccountFacture();
                //f.BrokerageValue = ScaleController.Scale5(brokerageValue);
                f.BrokerageValue = calcBrokValue;
                f.TotalCost      = totalSum;
                int    clientID = 1;
                Client client   = Client.GetByEmbg(ic.EMBG);
                if (client != null)
                {
                    clientID = client.ID;
                }
                else
                {
                    Client newClient = new Client();
                    newClient.Address            = ic.Address;
                    newClient.EMail              = string.Empty;
                    newClient.EMBG               = ic.EMBG;
                    newClient.Fax                = string.Empty;
                    newClient.IsInsuranceCompany = true;
                    newClient.Mobile             = string.Empty;
                    newClient.Name               = ic.Name;
                    newClient.Phone              = string.Empty;
                    newClient.PlaceID            = Place.Table.First().ID;
                    newClient.Insert();
                    clientID = newClient.ID;
                }
                f.ClientID           = clientID;
                f.DateOfCreation     = DateTime.Today;
                f.DocumentSubTypeID  = DocumentSubType.GetByCode(DocumentSubType.FAKTURA_PROVIZIJA).ID;
                f.FactureNumber      = factureNumber; //CodeGenerator.GenerateFactureNumber();
                f.FromDate           = startDate;
                f.ToDate             = endDate;
                f.BranchID           = branch.ID;
                f.StatusID           = Statuse.GetByCode(Statuse.NEPLATENA_IZLEZNA_FAKTURA_ZA_PROVIZIJA).ID;
                f.DateOfPayment      = dateOfPayment;
                f.Discard            = false;
                f.InsuranceCompanyID = ic.ID;
                f.UserID             = u.ID;
                f.IsAccountBooked    = false;
                f.Insert();

                int ordinalNumber = 1;
                foreach (KeyValuePair <int, decimal[]> kvPair in dictionary)
                {
                    AccountFactureItem fi = new AccountFactureItem();
                    fi.FactureID          = f.ID;
                    fi.BrokerageValue     = ScaleController.Scale5(kvPair.Value[0]);
                    fi.PremiumValue       = kvPair.Value[1];
                    fi.Number             = ordinalNumber;
                    fi.InsuranceSubTypeID = kvPair.Key;
                    fi.Count       = dictionaryPolList[kvPair.Key].Count;
                    fi.Description = InsuranceSubType.Get(kvPair.Key).ShortDescription;
                    ordinalNumber++;
                    fi.Insert();
                    AccountFactureItemPolicyItem.InsertForFacture(fi.ID, dictionaryPolList[kvPair.Key]);
                }
                PolicyItem.SetIsAccountFactured(policiesToInclude);
                return(f);
            }
            return(null);
        }
Exemplo n.º 5
0
 public static InsuranceType GetByInsuranceSubType(int insuranceSubTypeID)
 {
     return(InsuranceSubType.Get(insuranceSubTypeID).InsuranceType);
 }