/// <summary> /// this method calculates a Parcel value from contract /// </summary> /// <param name="companyId"></param> /// <param name="paymentMethodId"></param> /// <param name="qtdParcel"></param> /// <param name="contractValue"></param> /// <returns></returns> public Decimal CalculateParcelsValue(Int32 companyId, Int32 financierOperationId, Int32 qtdParcels, Decimal contractValue) { var accountManager = new AccountManager(this); FinancierCondition financierCondition = accountManager.GetFinancierConditionByParcelCount(companyId, financierOperationId, qtdParcels) ?? new FinancierCondition(); return(Convert.ToDecimal(contractValue * financierCondition.MonthlyTax)); }
/// <summary> /// this method save the receipt and its items /// </summary> /// <param name="original_entity">this parameter is used in update operation</param> /// <param name="entity">this parameter always is used</param> /// <param name="lstReceiptItem">this parameter contai the list of ReceiptItems</param> public void SaveReceipt(Receipt original_entity, Receipt entity, List <ReceiptItem> lstReceiptItem, List <Int32> lstServiceOrder, List <Int32> lstSale) { //Managers var accountManager = new AccountManager(this); var parcelsManager = new ParcelsManager(this); var financialManager = new FinancialManager(this); var invoice = new Invoice(); var bill = new Bill(); entity.ModifiedDate = DateTime.Now; if (original_entity.ReceiptId == 0) { //insert the Receipt //if (ExistReceiptNumber(entity.CompanyId, Convert.ToInt32(entity.ReceiptNumber))) // throw new InvalidOperationException(); DbContext.Receipts.InsertOnSubmit(entity); } else { //update original_entity.CopyPropertiesFrom(entity); //delete all receiptItens DeleteReceiptItemsByReceipt(entity.ReceiptId, entity.CompanyId); } DbContext.SubmitChanges(); foreach (ReceiptItem item in lstReceiptItem) { item.ReceiptId = entity.ReceiptId; item.CompanyId = entity.CompanyId; InsertReceiptItem(item); } ////insert the ReceiptItems //for (int i = 0; i < lstReceiptItem.Count; i++) //{ // lstReceiptItem[i].ReceiptId = entity.ReceiptId; // InsertReceiptItem(lstReceiptItem[i]); //} if (entity.SupplierId.HasValue) { bill.CompanyId = entity.CompanyId; bill.EntryDate = DateTime.Now; bill.SupplierId = entity.SupplierId; bill.DocumentNumber = Convert.ToString(entity.ReceiptNumber); //if (entity.ReceiptValue.HasValue) // bill.BillValue = entity.ReceiptValue.Value; financialManager.Insert(bill, null); } else { SetReceiptIdInSale(entity.CompanyId, lstSale, entity.ReceiptId); SetReceiptIdInServiceOrder(entity.CompanyId, lstServiceOrder, entity.ReceiptId); } DbContext.SubmitChanges(); if (bill.BillId != 0) { //insert the parcel var parcel = new Parcel(); parcel.PaymentMethodId = PaymentMethod.Cash; parcel.CompanyId = entity.CompanyId; parcel.DueDate = DateTime.Now; //parcel.Amount = bill.BillValue.Value; parcel.BillId = bill.BillId; parcelsManager.Insert(parcel, accountManager.GetFinancierConditionByParcelCount(entity.CompanyId, PaymentMethod.Cash, 1)); } DbContext.SubmitChanges(); }
/// <summary> /// this method save the invoice created by Sale /// </summary> /// <param name="sale"></param> private void SaveSaleInvoice(Sale sale, Invoice invoice, List<Parcel> lstParcels) { // // Save Invoice // var financialManager = new FinancialManager(this); sale.InvoiceId = financialManager.InsertRetrievingId(invoice); DbContext.SubmitChanges(); // // Save Parcels // var parcelsManager = new ParcelsManager(this); var accountManager = new AccountManager(this); var firstParcel = lstParcels.FirstOrDefault(); var condition = accountManager.GetFinancierConditionByParcelCount(firstParcel.CompanyId, firstParcel.FinancierOperationId.Value, lstParcels.Count()); foreach (Parcel parcel in lstParcels) { parcel.InvoiceId = invoice.InvoiceId; parcelsManager.Insert(parcel, condition); } }