Exemple #1
0
        public static Facture GenerateForSinglePolicy(Policy p)
        {
            Facture           f  = new Facture();
            List <PolicyItem> pi = PolicyItem.GetByPolicy(p.ID);

            if (pi.Count == 1)
            {
                if (pi[0].RateDealInsuranceSubTypeID != null)
                {
                    f.ClientID = pi[0].RateDealInsuranceSubType.RateDeal.ClientID;
                }
                else
                {
                    f.ClientID = p.ClientID;
                }
            }
            else
            {
                f.ClientID = p.ClientID;
            }
            //f.DateOfCreation = p.ApplicationDate;
            f.DateOfCreation    = DateTime.Today;
            f.DocumentSubTypeID = DocumentSubType.GetByCode(DocumentSubType.FAKTURA_KLIENT).ID;
            f.FactureNumber     = CodeGenerator.GenerateFactureNumber();
            f.FromDate          = DateTime.Today;
            f.ToDate            = DateTime.Today;
            f.TotalCost         = p.TotalSum;
            f.UserID            = p.UserID;
            List <Payment> lstPayments = Payment.GetByPolicyItemID(pi[0].ID);

            if (lstPayments.Count > 0)
            {
                f.StatusID = Statuse.GetByCode(Statuse.DELUMNO_PLATENA_IZLEZNA_FAKTURA_KON_KLIENT).ID;
            }
            else
            {
                f.StatusID = Statuse.GetByCode(Statuse.NEPLATENA_IZLEZNA_FAKTURA_KON_KLIENT).ID;
            }
            f.DateOfPayment = DateTime.Today.Date.AddDays(int.Parse(Parameter.GetByCode(Parameter.DENOVI_ZA_NAPLATA_NA_FAKTURA).Value));
            List <PolicyItem> lpi      = PolicyItem.GetByPolicy(p.ID);
            List <Rate>       lstRates = Rate.GetByPolicyItemIDExtend(lpi.First().ID);

            if (lstRates.Count > 1)
            {
                f.DateOfPayment = lstRates.Last().Date.AddDays(1);
            }
            f.InsuranceCompanyID = p.InsuranceCompanyID;
            return(f);
        }
Exemple #2
0
        public static int CreateGroupFacture(int userID, int clientID, DateTime startDate, DateTime endDate)
        {
            List <PolicyItem> items = PolicyItem.GetForGroupFactures(startDate, endDate, clientID);
            Facture           f     = new Facture();
            Parameter         par   = Parameter.GetByCode(Parameter.DENOVI_ZA_NAPLATA_NA_FAKTURA);

            f.BrokerageValue     = 0;
            f.ClientID           = clientID;
            f.DateOfCreation     = DateTime.Today;
            f.DateOfPayment      = f.DateOfCreation.AddDays(Convert.ToDouble(par.Value));
            f.Discard            = false;
            f.DocumentSubTypeID  = DocumentSubType.GetByCode(DocumentSubType.GRUPNA_FAKTURA).ID;
            f.FactureNumber      = CodeGenerator.GenerateFactureNumber();
            f.FromDate           = startDate;
            f.InsuranceCompanyID = items[0].Policy.InsuranceCompanyID;
            f.StatusID           = Statuse.GetByCode(Statuse.NEPLATENA_GRUPNA_FAKTURA_KON_KLIENT).ID;
            f.ToDate             = endDate;
            f.TotalCost          = 0;
            f.UserID             = userID;
            f.Insert();

            decimal brokerageValue = 0;
            decimal totalValue     = 0;
            int     orderNumber    = 0;

            foreach (PolicyItem pi in items)
            {
                FactureItem fi = new FactureItem();
                fi.BrokerageValue     = pi.BrokerageValue;
                brokerageValue       += fi.BrokerageValue;
                fi.Count              = 1;
                fi.Description        = "Полиса бр. " + pi.PolicyNumber;
                fi.FactureID          = f.ID;
                fi.InsuranceSubTypeID = pi.InsuranceSubTypeID;
                fi.Number             = ++orderNumber;
                fi.PremiumValue       = pi.PremiumValue;
                totalValue           += fi.PremiumValue;
                fi.Insert();
                PolicyItemFactureItem pifi = new PolicyItemFactureItem();
                pifi.PolicyItemID  = pi.ID;
                pifi.FactureItemID = fi.ID;
                pifi.Insert();
                pi.UpdateFacturedStatus(true);
            }
            f.UpdateValues(totalValue, brokerageValue);

            return(f.ID);
        }